147 lines
3.5 KiB
PHP
Executable File
147 lines
3.5 KiB
PHP
Executable File
<?php
|
|
/*
|
|
Crispage CMS
|
|
crispycat <the@crispy.cat>
|
|
https://crispy.cat/software/crispage
|
|
|
|
Crispage is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
*/
|
|
|
|
namespace Crispage\Assets;
|
|
|
|
defined("ROOT") or die();
|
|
|
|
use \Crispage\Auth\CorePermissions;
|
|
|
|
class Plugin extends \Crispage\Asset {
|
|
public static function getNames(): array {
|
|
return ["{%PLUGIN}", "{%PLUGINS}"];
|
|
}
|
|
|
|
public static function getPermissions(): array {
|
|
return [
|
|
"create" => CorePermissions::NEVER,
|
|
"modify" => CorePermissions::MODIFY_SETTINGS,
|
|
"modify_own"=> CorePermissions::MODIFY_SETTINGS,
|
|
"delete" => CorePermissions::MODIFY_SETTINGS,
|
|
"delete_own"=> CorePermissions::MODIFY_SETTINGS
|
|
];
|
|
}
|
|
|
|
public static function getSortingInfo(): array {
|
|
return [
|
|
"field" => "priority",
|
|
"desc" => false
|
|
];
|
|
}
|
|
|
|
public static function getListColumns(): array {
|
|
global $Crispage;
|
|
return [
|
|
"id" => ["label" => "{%ID}"],
|
|
"runnable" => [
|
|
"label" => "{%TYPE}",
|
|
"filter" => "\\Crispage\\Utils\\TextUtils::codeify"
|
|
],
|
|
"priority" => [
|
|
"label" => "{%PRIORITY}",
|
|
"filter" => null
|
|
],
|
|
"enabled" => [
|
|
"label" => "{%STATE}",
|
|
"filter" => function(bool $s): string {
|
|
global $Crispage;
|
|
return $Crispage->i18n->translate(
|
|
($s) ? "{%ENABLED}" : "{%DISABLED}"
|
|
);
|
|
}
|
|
],
|
|
"mtime" => [
|
|
"label" => "{%MODIFIED}",
|
|
"filter" => [$Crispage->i18n, "datetime"]
|
|
]
|
|
];
|
|
}
|
|
|
|
public static function getListActions(): array {
|
|
return [];
|
|
}
|
|
|
|
public static function getListItemActions(): array {
|
|
return [
|
|
[
|
|
"route" => "assets/editor",
|
|
"label" => "{%EDIT}",
|
|
"color" => "primary",
|
|
"fields" => [
|
|
"asset_id" => "id"
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
public static function getEditorFields(): array {
|
|
return [
|
|
"enabled" => [
|
|
"column" => 0,
|
|
"component" => "\\Crispage\\Components\\Fields\\BooleanFieldComponent",
|
|
"com_data" => [
|
|
"label" => "{%ENABLED}:"
|
|
],
|
|
"filter" => "boolval"
|
|
],
|
|
"priority" => [
|
|
"column" => 1,
|
|
"component" => "\\Crispage\\Components\\Fields\\NumberFieldComponent",
|
|
"com_data" => [
|
|
"label" => "{%PRIORITY}:",
|
|
"attrs" => ["required"]
|
|
],
|
|
"filter" => "intval"
|
|
]
|
|
];
|
|
}
|
|
|
|
public static function getOptionFields(): array {
|
|
return [
|
|
"config" => [
|
|
"component" => "\\Crispage\\Components\\Fields\\PluginConfigFieldComponent",
|
|
"com_data" => [],
|
|
"filter" => function($data): array {
|
|
global $Crispage;
|
|
if (!is_array($data)) return [];
|
|
$asset = $Crispage->assets->get(
|
|
intval($Crispage->request->params["asset_id"]) ?? 0
|
|
);
|
|
|
|
$Crispage->loadClass($asset->component);
|
|
|
|
$ndata = [];
|
|
foreach ($asset->component::getPluginFields() as $name => $field)
|
|
$ndata[$name] = $field["filter"]($data[$name] ?? null);
|
|
return $ndata;
|
|
}
|
|
]
|
|
];
|
|
}
|
|
|
|
public string $runnable;
|
|
public int $priority;
|
|
public bool $enabled;
|
|
|
|
public function __construct(array $props) {
|
|
parent::__construct($props);
|
|
$this->runnable = $props["runnable"] ?? "\\Crispage\\Plugins\\DefaultPluginRunnable";
|
|
$this->priority = $props["priority"] ?? 0;
|
|
$this->enabled = $props["enabled"] ?? false;
|
|
}
|
|
|
|
public function config(string $key, $default = null) {
|
|
return $this->_options_array["config"][$key] ?? $default;
|
|
}
|
|
}
|
|
?>
|