@@ -32,64 +32,64 @@ |
||
32 | 32 | |
33 | 33 | class PluginLang extends Plugin implements ICompilableBlock { |
34 | 34 | |
35 | - protected static $domain = ""; |
|
36 | - |
|
37 | - /** |
|
38 | - * @param Compiler $compiler |
|
39 | - * @param mixed $value |
|
40 | - * @param mixed $var |
|
41 | - * |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - /*public static function compile(Compiler $compiler, $value, $domain = "") { |
|
35 | + protected static $domain = ""; |
|
36 | + |
|
37 | + /** |
|
38 | + * @param Compiler $compiler |
|
39 | + * @param mixed $value |
|
40 | + * @param mixed $var |
|
41 | + * |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + /*public static function compile(Compiler $compiler, $value, $domain = "") { |
|
45 | 45 | return 'Translator::translate(' . $value . ', ' . $domain . ')'; |
46 | 46 | }*/ |
47 | 47 | |
48 | - // parameters go here if you need any settings |
|
49 | - public function init() { |
|
50 | - // |
|
51 | - } |
|
48 | + // parameters go here if you need any settings |
|
49 | + public function init() { |
|
50 | + // |
|
51 | + } |
|
52 | 52 | |
53 | - // this can be ommitted, it's called once when the block ends, don't implement if you don't need it |
|
54 | - public function end() { |
|
55 | - // |
|
56 | - } |
|
53 | + // this can be ommitted, it's called once when the block ends, don't implement if you don't need it |
|
54 | + public function end() { |
|
55 | + // |
|
56 | + } |
|
57 | 57 | |
58 | - // this is called when the block is required to output it's data, it should read $this->buffer, process it and return it |
|
59 | - /*public function process(){ |
|
58 | + // this is called when the block is required to output it's data, it should read $this->buffer, process it and return it |
|
59 | + /*public function process(){ |
|
60 | 60 | var_dump($this->buffer); |
61 | 61 | |
62 | 62 | return strtoupper($this->buffer); |
63 | 63 | }*/ |
64 | 64 | |
65 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { |
|
66 | - $domain = ""; |
|
65 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { |
|
66 | + $domain = ""; |
|
67 | 67 | |
68 | - /*if (isset($params[1])) { |
|
68 | + /*if (isset($params[1])) { |
|
69 | 69 | $domain = $params[1][1]; |
70 | 70 | } |
71 | 71 | |
72 | 72 | return Compiler::PHP_OPEN . $prepend . " echo Translator::translate(\"" . $params[0][1] . "\", \"" . $domain . "\"); " . $append . Compiler::PHP_CLOSE;*/ |
73 | 73 | |
74 | - if (isset($params[0])) { |
|
75 | - $domain = $params[0][1]; |
|
76 | - } |
|
74 | + if (isset($params[0])) { |
|
75 | + $domain = $params[0][1]; |
|
76 | + } |
|
77 | 77 | |
78 | - self::$domain = $domain; |
|
78 | + self::$domain = $domain; |
|
79 | 79 | |
80 | - return Compiler::PHP_OPEN . "echo Translator::translate(\""; |
|
81 | - } |
|
80 | + return Compiler::PHP_OPEN . "echo Translator::translate(\""; |
|
81 | + } |
|
82 | 82 | |
83 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { |
|
84 | - /** |
|
85 | - * the block is responsible for outputting it's entire content (passed as $content), |
|
86 | - * so you can transform it and then return it, but in this case we don't because |
|
87 | - * we want the content to be uppercased at runtime and not at compile time |
|
88 | - */ |
|
89 | - //return $content . Compiler::PHP_OPEN . $prepend . ' ' . $append . Compiler::PHP_CLOSE; |
|
83 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { |
|
84 | + /** |
|
85 | + * the block is responsible for outputting it's entire content (passed as $content), |
|
86 | + * so you can transform it and then return it, but in this case we don't because |
|
87 | + * we want the content to be uppercased at runtime and not at compile time |
|
88 | + */ |
|
89 | + //return $content . Compiler::PHP_OPEN . $prepend . ' ' . $append . Compiler::PHP_CLOSE; |
|
90 | 90 | |
91 | - return $content . "\", \"" . self::$domain . "\"); " . Compiler::PHP_CLOSE; |
|
92 | - } |
|
91 | + return $content . "\", \"" . self::$domain . "\"); " . Compiler::PHP_CLOSE; |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
95 | 95 |
@@ -27,155 +27,155 @@ |
||
27 | 27 | |
28 | 28 | class DwooTemplate extends Template { |
29 | 29 | |
30 | - protected static $core = null; |
|
30 | + protected static $core = null; |
|
31 | 31 | |
32 | - protected static $files = array(); |
|
32 | + protected static $files = array(); |
|
33 | 33 | |
34 | - protected static $benchmark = array(); |
|
34 | + protected static $benchmark = array(); |
|
35 | 35 | |
36 | - //variables |
|
37 | - //protected $vars = array(); |
|
38 | - protected $data = null; |
|
36 | + //variables |
|
37 | + //protected $vars = array(); |
|
38 | + protected $data = null; |
|
39 | 39 | |
40 | - protected $file = ""; |
|
41 | - protected $template = null; |
|
40 | + protected $file = ""; |
|
41 | + protected $template = null; |
|
42 | 42 | |
43 | - public function __construct($file, Registry $registry = null) { |
|
44 | - if ($registry == null) { |
|
45 | - $registry = Registry::singleton(); |
|
46 | - } |
|
43 | + public function __construct($file, Registry $registry = null) { |
|
44 | + if ($registry == null) { |
|
45 | + $registry = Registry::singleton(); |
|
46 | + } |
|
47 | 47 | |
48 | - //initialize core if neccessary |
|
49 | - self::initCoreIfAbsent(); |
|
48 | + //initialize core if neccessary |
|
49 | + self::initCoreIfAbsent(); |
|
50 | 50 | |
51 | - $start_time = microtime(true); |
|
51 | + $start_time = microtime(true); |
|
52 | 52 | |
53 | - //find file |
|
54 | - $this->file = Template::findTemplate($file, $registry); |
|
53 | + //find file |
|
54 | + $this->file = Template::findTemplate($file, $registry); |
|
55 | 55 | |
56 | - //load a template file, this is reusable if you want to render multiple times the same template with different data |
|
57 | - if (isset(self::$files[$file])) { |
|
58 | - $this->template = self::$files[$this->file]; |
|
59 | - } else { |
|
60 | - $this->template = new Dwoo\Template\File($this->file); |
|
61 | - self::$files[$file] = $this->template; |
|
62 | - } |
|
56 | + //load a template file, this is reusable if you want to render multiple times the same template with different data |
|
57 | + if (isset(self::$files[$file])) { |
|
58 | + $this->template = self::$files[$this->file]; |
|
59 | + } else { |
|
60 | + $this->template = new Dwoo\Template\File($this->file); |
|
61 | + self::$files[$file] = $this->template; |
|
62 | + } |
|
63 | 63 | |
64 | - //create a data set, this data set can be reused to render multiple templates if it contains enough data to fill them all |
|
65 | - $this->data = new Dwoo\Data(); |
|
64 | + //create a data set, this data set can be reused to render multiple templates if it contains enough data to fill them all |
|
65 | + $this->data = new Dwoo\Data(); |
|
66 | 66 | |
67 | - //set default values |
|
68 | - $this->assign("REGISTRY", $registry->listSettings()); |
|
67 | + //set default values |
|
68 | + $this->assign("REGISTRY", $registry->listSettings()); |
|
69 | 69 | |
70 | - //set CSRF token |
|
71 | - $this->assign("CSRF_TOKEN", Security::getCSRFToken()); |
|
70 | + //set CSRF token |
|
71 | + $this->assign("CSRF_TOKEN", Security::getCSRFToken()); |
|
72 | 72 | |
73 | - //set domain, current page and so on |
|
74 | - $this->assign("DOMAIN", DomainUtils::getCurrentDomain()); |
|
75 | - $this->assign("BASE_URL", DomainUtils::getBaseURL()); |
|
76 | - $this->assign("CURRENT_URL", DomainUtils::getURL()); |
|
77 | - $this->assign("FOLDER", $registry->getSetting("folder")); |
|
73 | + //set domain, current page and so on |
|
74 | + $this->assign("DOMAIN", DomainUtils::getCurrentDomain()); |
|
75 | + $this->assign("BASE_URL", DomainUtils::getBaseURL()); |
|
76 | + $this->assign("CURRENT_URL", DomainUtils::getURL()); |
|
77 | + $this->assign("FOLDER", $registry->getSetting("folder")); |
|
78 | 78 | |
79 | - //set language settings |
|
80 | - $this->assign("PREF_LANG", $registry->getSetting("pref_lang")); |
|
81 | - $this->assign("LANG_TOKEN", $registry->getSetting("lang_token")); |
|
79 | + //set language settings |
|
80 | + $this->assign("PREF_LANG", $registry->getSetting("pref_lang")); |
|
81 | + $this->assign("LANG_TOKEN", $registry->getSetting("lang_token")); |
|
82 | 82 | |
83 | - $domain = $registry->getObject("domain"); |
|
84 | - $this->assign("HOME_PAGE", $domain->getHomePage()); |
|
85 | - $this->assign("LOGIN_PAGE", Settings::get("login_page", "login")); |
|
86 | - $this->assign("LOGIN_URL", $registry->getSetting("login_url")); |
|
87 | - $this->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout")); |
|
88 | - $this->assign("LOGOUT_URL", $registry->getSetting("logout_url")); |
|
83 | + $domain = $registry->getObject("domain"); |
|
84 | + $this->assign("HOME_PAGE", $domain->getHomePage()); |
|
85 | + $this->assign("LOGIN_PAGE", Settings::get("login_page", "login")); |
|
86 | + $this->assign("LOGIN_URL", $registry->getSetting("login_url")); |
|
87 | + $this->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout")); |
|
88 | + $this->assign("LOGOUT_URL", $registry->getSetting("logout_url")); |
|
89 | 89 | |
90 | - //set user variables |
|
91 | - $this->assign("USERID", User::current()->getID()); |
|
92 | - $this->assign("USERNAME", User::current()->getUsername()); |
|
90 | + //set user variables |
|
91 | + $this->assign("USERID", User::current()->getID()); |
|
92 | + $this->assign("USERNAME", User::current()->getUsername()); |
|
93 | 93 | |
94 | - $style_name = $registry->getSetting("current_style_name"); |
|
95 | - $this->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
94 | + $style_name = $registry->getSetting("current_style_name"); |
|
95 | + $this->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/"); |
|
96 | 96 | |
97 | - $end_time = microtime(true); |
|
98 | - $exec_time = $end_time - $start_time; |
|
97 | + $end_time = microtime(true); |
|
98 | + $exec_time = $end_time - $start_time; |
|
99 | 99 | |
100 | - //store benchmark |
|
101 | - self::$benchmark[$this->file] = $exec_time; |
|
102 | - } |
|
100 | + //store benchmark |
|
101 | + self::$benchmark[$this->file] = $exec_time; |
|
102 | + } |
|
103 | 103 | |
104 | - public function assign ($var, $value) { |
|
105 | - //$this->vars[$var] = $value; |
|
106 | - $this->data->assign($var, $value); |
|
107 | - } |
|
104 | + public function assign ($var, $value) { |
|
105 | + //$this->vars[$var] = $value; |
|
106 | + $this->data->assign($var, $value); |
|
107 | + } |
|
108 | 108 | |
109 | - public function parse ($name = "main") { |
|
110 | - throw new Exception("Method DwooTemplate::parse() is not supported from Dwoo template engine."); |
|
111 | - } |
|
109 | + public function parse ($name = "main") { |
|
110 | + throw new Exception("Method DwooTemplate::parse() is not supported from Dwoo template engine."); |
|
111 | + } |
|
112 | 112 | |
113 | - public function getCode ($name = "main") { |
|
114 | - $start_time = microtime(true); |
|
113 | + public function getCode ($name = "main") { |
|
114 | + $start_time = microtime(true); |
|
115 | 115 | |
116 | - // Output the result |
|
117 | - $html = self::$core->get($this->template, $this->data); |
|
116 | + // Output the result |
|
117 | + $html = self::$core->get($this->template, $this->data); |
|
118 | 118 | |
119 | - $end_time = microtime(true); |
|
120 | - $exec_time = $end_time - $start_time; |
|
119 | + $end_time = microtime(true); |
|
120 | + $exec_time = $end_time - $start_time; |
|
121 | 121 | |
122 | - //store benchmark |
|
123 | - if (isset(self::$benchmark[$this->file])) { |
|
124 | - self::$benchmark[$this->file] = self::$benchmark[$this->file] + $exec_time; |
|
125 | - } else { |
|
126 | - self::$benchmark[$this->file] = $exec_time; |
|
127 | - } |
|
122 | + //store benchmark |
|
123 | + if (isset(self::$benchmark[$this->file])) { |
|
124 | + self::$benchmark[$this->file] = self::$benchmark[$this->file] + $exec_time; |
|
125 | + } else { |
|
126 | + self::$benchmark[$this->file] = $exec_time; |
|
127 | + } |
|
128 | 128 | |
129 | - return $html; |
|
130 | - } |
|
129 | + return $html; |
|
130 | + } |
|
131 | 131 | |
132 | - protected static function initCoreIfAbsent () { |
|
133 | - if (self::$core == null) { |
|
134 | - self::$core = new Dwoo\Core(); |
|
132 | + protected static function initCoreIfAbsent () { |
|
133 | + if (self::$core == null) { |
|
134 | + self::$core = new Dwoo\Core(); |
|
135 | 135 | |
136 | - $cache_dir = CACHE_PATH . "dwoo/"; |
|
137 | - $compile_dir = CACHE_PATH . "dwoo-compile/"; |
|
136 | + $cache_dir = CACHE_PATH . "dwoo/"; |
|
137 | + $compile_dir = CACHE_PATH . "dwoo-compile/"; |
|
138 | 138 | |
139 | - //check, if cache dir exists |
|
140 | - if (!file_exists($cache_dir)) { |
|
141 | - mkdir($cache_dir); |
|
142 | - } |
|
139 | + //check, if cache dir exists |
|
140 | + if (!file_exists($cache_dir)) { |
|
141 | + mkdir($cache_dir); |
|
142 | + } |
|
143 | 143 | |
144 | - //check, if compile dir exists |
|
145 | - if (!file_exists($compile_dir)) { |
|
146 | - mkdir($compile_dir); |
|
147 | - } |
|
144 | + //check, if compile dir exists |
|
145 | + if (!file_exists($compile_dir)) { |
|
146 | + mkdir($compile_dir); |
|
147 | + } |
|
148 | 148 | |
149 | - //set cache dir |
|
150 | - self::$core->setCacheDir($cache_dir); |
|
151 | - self::$core->setCompileDir($compile_dir); |
|
149 | + //set cache dir |
|
150 | + self::$core->setCacheDir($cache_dir); |
|
151 | + self::$core->setCompileDir($compile_dir); |
|
152 | 152 | |
153 | - //allow some php functions |
|
154 | - //self::$core->setSecurityPolicy(new \Dwoo\Security\Policy()); |
|
155 | - //self::$core->getSecurityPolicy()->allowPhpFunction("count"); |
|
156 | - //self::$core->getSecurityPolicy()->allowPhpFunction("sizeof"); |
|
157 | - |
|
158 | - //add plugins |
|
159 | - //self::$core->addPlugin("if"); |
|
153 | + //allow some php functions |
|
154 | + //self::$core->setSecurityPolicy(new \Dwoo\Security\Policy()); |
|
155 | + //self::$core->getSecurityPolicy()->allowPhpFunction("count"); |
|
156 | + //self::$core->getSecurityPolicy()->allowPhpFunction("sizeof"); |
|
157 | + |
|
158 | + //add plugins |
|
159 | + //self::$core->addPlugin("if"); |
|
160 | 160 | |
161 | - //self::$core->addPlugin("lang", new \Dwoo\Plugins\Functions\PluginLang(self::$core)); |
|
161 | + //self::$core->addPlugin("lang", new \Dwoo\Plugins\Functions\PluginLang(self::$core)); |
|
162 | 162 | |
163 | - // add custom plugin |
|
164 | - /*self::$core->addPlugin('lang', function (Dwoo\Core $core, $str, $str1 = "") { |
|
163 | + // add custom plugin |
|
164 | + /*self::$core->addPlugin('lang', function (Dwoo\Core $core, $str, $str1 = "") { |
|
165 | 165 | return "test_" . $str; |
166 | 166 | });*/ |
167 | 167 | |
168 | - Events::throwEvent("init_dwoo", array( |
|
169 | - 'core' => &self::$core, |
|
170 | - 'cache_path' => CACHE_PATH, |
|
171 | - 'cache_dir' => $cache_dir |
|
172 | - )); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - public static function listFileBenchmark () { |
|
177 | - return self::$benchmark; |
|
178 | - } |
|
168 | + Events::throwEvent("init_dwoo", array( |
|
169 | + 'core' => &self::$core, |
|
170 | + 'cache_path' => CACHE_PATH, |
|
171 | + 'cache_dir' => $cache_dir |
|
172 | + )); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + public static function listFileBenchmark () { |
|
177 | + return self::$benchmark; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
181 | 181 |
@@ -27,19 +27,19 @@ |
||
27 | 27 | |
28 | 28 | abstract class PluginInstaller_Plugin { |
29 | 29 | |
30 | - public abstract function install (Plugin $plugin, array $install_json) : bool; |
|
30 | + public abstract function install (Plugin $plugin, array $install_json) : bool; |
|
31 | 31 | |
32 | - public abstract function uninstall (Plugin $plugin, array $install_json) : bool; |
|
32 | + public abstract function uninstall (Plugin $plugin, array $install_json) : bool; |
|
33 | 33 | |
34 | - public abstract function upgrade (Plugin $plugin, array $install_json) : bool; |
|
34 | + public abstract function upgrade (Plugin $plugin, array $install_json) : bool; |
|
35 | 35 | |
36 | - public function getPriority () : int { |
|
37 | - return 10; |
|
38 | - } |
|
36 | + public function getPriority () : int { |
|
37 | + return 10; |
|
38 | + } |
|
39 | 39 | |
40 | - public static function cast (PluginInstaller_Plugin $plugin) : PluginInstaller_Plugin { |
|
41 | - return $plugin; |
|
42 | - } |
|
40 | + public static function cast (PluginInstaller_Plugin $plugin) : PluginInstaller_Plugin { |
|
41 | + return $plugin; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
45 | 45 |
@@ -27,24 +27,24 @@ |
||
27 | 27 | |
28 | 28 | class Validator_PluginName implements Validator_Base { |
29 | 29 | |
30 | - protected static $instance = null; |
|
30 | + protected static $instance = null; |
|
31 | 31 | |
32 | - public function isValide($value): bool { |
|
33 | - return $value === $this->validate($value); |
|
34 | - } |
|
32 | + public function isValide($value): bool { |
|
33 | + return $value === $this->validate($value); |
|
34 | + } |
|
35 | 35 | |
36 | - public function validate($value) { |
|
37 | - //remove all characters except except a-z, A-Z and 0-9 |
|
38 | - return preg_replace("/[^a-zA-Z_\-0-9]+/", "", $value); |
|
39 | - } |
|
36 | + public function validate($value) { |
|
37 | + //remove all characters except except a-z, A-Z and 0-9 |
|
38 | + return preg_replace("/[^a-zA-Z_\-0-9]+/", "", $value); |
|
39 | + } |
|
40 | 40 | |
41 | - public static function getInstance () : Validator_PluginName { |
|
42 | - if (self::$instance == null) { |
|
43 | - self::$instance = new Validator_PluginName(); |
|
44 | - } |
|
41 | + public static function getInstance () : Validator_PluginName { |
|
42 | + if (self::$instance == null) { |
|
43 | + self::$instance = new Validator_PluginName(); |
|
44 | + } |
|
45 | 45 | |
46 | - return self::$instance; |
|
47 | - } |
|
46 | + return self::$instance; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
50 | 50 |
@@ -27,107 +27,107 @@ |
||
27 | 27 | |
28 | 28 | class Plugins { |
29 | 29 | |
30 | - public static function listAvailablePluginNames () : array { |
|
31 | - $names = array(); |
|
30 | + public static function listAvailablePluginNames () : array { |
|
31 | + $names = array(); |
|
32 | 32 | |
33 | - //use directory iterator |
|
34 | - $dir = new DirectoryIterator(PLUGIN_PATH); |
|
33 | + //use directory iterator |
|
34 | + $dir = new DirectoryIterator(PLUGIN_PATH); |
|
35 | 35 | |
36 | - foreach ($dir as $fileinfo) { |
|
37 | - if ($fileinfo->isDir() && !$fileinfo->isDot()) { |
|
38 | - $names[] = $fileinfo->getFilename(); |
|
39 | - } |
|
40 | - } |
|
36 | + foreach ($dir as $fileinfo) { |
|
37 | + if ($fileinfo->isDir() && !$fileinfo->isDot()) { |
|
38 | + $names[] = $fileinfo->getFilename(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - return $names; |
|
43 | - } |
|
42 | + return $names; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function listInstalledPluginNames () : array { |
|
46 | - if (Cache::contains("plugins", "installed_plugin_names")) { |
|
47 | - return Cache::get("plugins", "installed_plugin_names"); |
|
48 | - } else { |
|
49 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
45 | + public static function listInstalledPluginNames () : array { |
|
46 | + if (Cache::contains("plugins", "installed_plugin_names")) { |
|
47 | + return Cache::get("plugins", "installed_plugin_names"); |
|
48 | + } else { |
|
49 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
50 | 50 | |
51 | - $array = array(); |
|
51 | + $array = array(); |
|
52 | 52 | |
53 | - foreach ($rows as $row) { |
|
54 | - $array[] = $row['name']; |
|
55 | - } |
|
53 | + foreach ($rows as $row) { |
|
54 | + $array[] = $row['name']; |
|
55 | + } |
|
56 | 56 | |
57 | - //cache rows |
|
58 | - Cache::put("plugins", "installed_plugin_names", $array); |
|
57 | + //cache rows |
|
58 | + Cache::put("plugins", "installed_plugin_names", $array); |
|
59 | 59 | |
60 | - return $array; |
|
61 | - } |
|
62 | - } |
|
60 | + return $array; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - public static function listInstalledPlugins () : array { |
|
65 | - if (Cache::contains("plugins", "installed_plugins")) { |
|
66 | - return Cache::get("plugins", "installed_plugins"); |
|
67 | - } else { |
|
68 | - //read installed plugins from database |
|
69 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
64 | + public static function listInstalledPlugins () : array { |
|
65 | + if (Cache::contains("plugins", "installed_plugins")) { |
|
66 | + return Cache::get("plugins", "installed_plugins"); |
|
67 | + } else { |
|
68 | + //read installed plugins from database |
|
69 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugins` WHERE `installed` = '1'; "); |
|
70 | 70 | |
71 | - $plugins = array(); |
|
71 | + $plugins = array(); |
|
72 | 72 | |
73 | - foreach ($rows as $row) { |
|
74 | - //create new plugin instance |
|
75 | - $plugin = new Plugin($row['name'], $row); |
|
73 | + foreach ($rows as $row) { |
|
74 | + //create new plugin instance |
|
75 | + $plugin = new Plugin($row['name'], $row); |
|
76 | 76 | |
77 | - //load plugin |
|
78 | - $plugin->load(); |
|
77 | + //load plugin |
|
78 | + $plugin->load(); |
|
79 | 79 | |
80 | - $plugins[$plugin->getName()] = $plugin; |
|
81 | - } |
|
80 | + $plugins[$plugin->getName()] = $plugin; |
|
81 | + } |
|
82 | 82 | |
83 | - //cache plugins |
|
84 | - Cache::put("plugins", "installed_plugins", $plugins); |
|
83 | + //cache plugins |
|
84 | + Cache::put("plugins", "installed_plugins", $plugins); |
|
85 | 85 | |
86 | - return $plugins; |
|
87 | - } |
|
88 | - } |
|
86 | + return $plugins; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - public static function listUninstalledPlugins () : array { |
|
91 | - $installed_plugin_names = self::listInstalledPluginNames(); |
|
90 | + public static function listUninstalledPlugins () : array { |
|
91 | + $installed_plugin_names = self::listInstalledPluginNames(); |
|
92 | 92 | |
93 | - //create new empty list |
|
94 | - $list = array(); |
|
93 | + //create new empty list |
|
94 | + $list = array(); |
|
95 | 95 | |
96 | - $dir = new DirectoryIterator(PLUGIN_PATH); |
|
96 | + $dir = new DirectoryIterator(PLUGIN_PATH); |
|
97 | 97 | |
98 | - foreach ($dir as $fileInfo) { |
|
99 | - if ($fileInfo->isDot()) { |
|
100 | - //dont parse directory "." |
|
101 | - continue; |
|
102 | - } |
|
98 | + foreach ($dir as $fileInfo) { |
|
99 | + if ($fileInfo->isDot()) { |
|
100 | + //dont parse directory "." |
|
101 | + continue; |
|
102 | + } |
|
103 | 103 | |
104 | - if (!$fileInfo->isDir()) { |
|
105 | - //we only search for directories |
|
106 | - continue; |
|
107 | - } |
|
104 | + if (!$fileInfo->isDir()) { |
|
105 | + //we only search for directories |
|
106 | + continue; |
|
107 | + } |
|
108 | 108 | |
109 | - //get directory name |
|
110 | - $name = $fileInfo->getFilename(); |
|
109 | + //get directory name |
|
110 | + $name = $fileInfo->getFilename(); |
|
111 | 111 | |
112 | - //check, if plugin is already installed |
|
113 | - if (in_array($name, $installed_plugin_names)) { |
|
114 | - continue; |
|
115 | - } |
|
112 | + //check, if plugin is already installed |
|
113 | + if (in_array($name, $installed_plugin_names)) { |
|
114 | + continue; |
|
115 | + } |
|
116 | 116 | |
117 | - //create and load new plugin |
|
118 | - $plugin = new Plugin($name); |
|
119 | - $plugin->load(); |
|
117 | + //create and load new plugin |
|
118 | + $plugin = new Plugin($name); |
|
119 | + $plugin->load(); |
|
120 | 120 | |
121 | - //add plugin to list |
|
122 | - $list[] = $plugin; |
|
123 | - } |
|
121 | + //add plugin to list |
|
122 | + $list[] = $plugin; |
|
123 | + } |
|
124 | 124 | |
125 | - return $list; |
|
126 | - } |
|
125 | + return $list; |
|
126 | + } |
|
127 | 127 | |
128 | - public static function clearCache () { |
|
129 | - Cache::clear("plugins"); |
|
130 | - } |
|
128 | + public static function clearCache () { |
|
129 | + Cache::clear("plugins"); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
133 | 133 |
@@ -27,92 +27,92 @@ discard block |
||
27 | 27 | |
28 | 28 | class PluginsPage extends PageType { |
29 | 29 | |
30 | - public function getContent(): string { |
|
31 | - $template = new DwooTemplate("pages/plugins"); |
|
32 | - |
|
33 | - //get list with installed plugins |
|
34 | - $installed_plugins = Plugins::listInstalledPlugins(); |
|
35 | - |
|
36 | - $array = array(); |
|
37 | - |
|
38 | - $lang_token = substr(Registry::singleton()->getSetting("lang_token"), 0, 2); |
|
39 | - |
|
40 | - foreach ($installed_plugins as $plugin) { |
|
41 | - $plugin = Plugin::castPlugin($plugin); |
|
42 | - |
|
43 | - //create new instance of PluginInstaller to check plugin compatibility |
|
44 | - $installer = new PluginInstaller($plugin); |
|
45 | - |
|
46 | - $array[] = array( |
|
47 | - 'name' => $plugin->getName(), |
|
48 | - 'title' => $plugin->getTitle(), |
|
49 | - 'description' => $plugin->getDescription($lang_token), |
|
50 | - 'version' => $plugin->getVersion(), |
|
51 | - 'installed_version' => $plugin->getInstalledVersion(), |
|
52 | - 'homepage' => $plugin->getHomepage(), |
|
53 | - 'authors' => $plugin->listAuthors(), |
|
54 | - 'license' => $plugin->getLicense(), |
|
55 | - 'keywords' => $plugin->listKeywords(), |
|
56 | - 'categories' => $plugin->listCategories(), |
|
57 | - 'text' => "", |
|
58 | - 'issues' => $plugin->getIssuesLink(), |
|
59 | - 'source' => $plugin->getSourceLink(), |
|
60 | - 'support_mail' => $plugin->getSupportMail(), |
|
61 | - 'support_links' => $plugin->listSupportLinks(), |
|
62 | - 'compatible' => $installer->checkRequirements(true), |
|
63 | - 'uptodate' => true,//TODO: check, if plugin is newest version |
|
64 | - 'alpha' => $plugin->isAlpha(), |
|
65 | - 'beta' => $plugin->isBeta(), |
|
66 | - 'installed' => false, |
|
67 | - 'activated' => $plugin->isActivated() |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - //assign list with installed plugins |
|
72 | - $template->assign("installed_plugins", $array); |
|
73 | - |
|
74 | - //get list with all uninstalled plugins |
|
75 | - $plugins = Plugins::listUninstalledPlugins(); |
|
76 | - |
|
77 | - $plugin_list = array(); |
|
78 | - |
|
79 | - foreach ($plugins as $plugin) { |
|
80 | - $plugin = Plugin::castPlugin($plugin); |
|
81 | - |
|
82 | - //create new instance of PluginInstaller to check plugin compatibility |
|
83 | - $installer = new PluginInstaller($plugin); |
|
84 | - |
|
85 | - $plugin_list[] = array( |
|
86 | - 'name' => $plugin->getName(), |
|
87 | - 'title' => $plugin->getTitle(), |
|
88 | - 'description' => $plugin->getDescription($lang_token), |
|
89 | - 'version' => $plugin->getVersion(), |
|
90 | - 'homepage' => $plugin->getHomepage(), |
|
91 | - 'authors' => $plugin->listAuthors(), |
|
92 | - 'license' => $plugin->getLicense(), |
|
93 | - 'keywords' => $plugin->listKeywords(), |
|
94 | - 'categories' => $plugin->listCategories(), |
|
95 | - 'text' => "", |
|
96 | - 'issues' => $plugin->getIssuesLink(), |
|
97 | - 'source' => $plugin->getSourceLink(), |
|
98 | - 'support_mail' => $plugin->getSupportMail(), |
|
99 | - 'support_links' => $plugin->listSupportLinks(), |
|
100 | - 'compatible' => $installer->checkRequirements(true), |
|
101 | - 'uptodate' => true,//TODO: check, if plugin is newest version |
|
102 | - 'alpha' => $plugin->isAlpha(), |
|
103 | - 'beta' => $plugin->isBeta(), |
|
104 | - 'installed' => false, |
|
105 | - 'activated' => $plugin->isActivated() |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - $template->assign("plugins", $plugin_list); |
|
110 | - |
|
111 | - return $template->getCode(); |
|
112 | - } |
|
113 | - |
|
114 | - public function getFooterScripts(): string { |
|
115 | - return "<!-- page script --> |
|
30 | + public function getContent(): string { |
|
31 | + $template = new DwooTemplate("pages/plugins"); |
|
32 | + |
|
33 | + //get list with installed plugins |
|
34 | + $installed_plugins = Plugins::listInstalledPlugins(); |
|
35 | + |
|
36 | + $array = array(); |
|
37 | + |
|
38 | + $lang_token = substr(Registry::singleton()->getSetting("lang_token"), 0, 2); |
|
39 | + |
|
40 | + foreach ($installed_plugins as $plugin) { |
|
41 | + $plugin = Plugin::castPlugin($plugin); |
|
42 | + |
|
43 | + //create new instance of PluginInstaller to check plugin compatibility |
|
44 | + $installer = new PluginInstaller($plugin); |
|
45 | + |
|
46 | + $array[] = array( |
|
47 | + 'name' => $plugin->getName(), |
|
48 | + 'title' => $plugin->getTitle(), |
|
49 | + 'description' => $plugin->getDescription($lang_token), |
|
50 | + 'version' => $plugin->getVersion(), |
|
51 | + 'installed_version' => $plugin->getInstalledVersion(), |
|
52 | + 'homepage' => $plugin->getHomepage(), |
|
53 | + 'authors' => $plugin->listAuthors(), |
|
54 | + 'license' => $plugin->getLicense(), |
|
55 | + 'keywords' => $plugin->listKeywords(), |
|
56 | + 'categories' => $plugin->listCategories(), |
|
57 | + 'text' => "", |
|
58 | + 'issues' => $plugin->getIssuesLink(), |
|
59 | + 'source' => $plugin->getSourceLink(), |
|
60 | + 'support_mail' => $plugin->getSupportMail(), |
|
61 | + 'support_links' => $plugin->listSupportLinks(), |
|
62 | + 'compatible' => $installer->checkRequirements(true), |
|
63 | + 'uptodate' => true,//TODO: check, if plugin is newest version |
|
64 | + 'alpha' => $plugin->isAlpha(), |
|
65 | + 'beta' => $plugin->isBeta(), |
|
66 | + 'installed' => false, |
|
67 | + 'activated' => $plugin->isActivated() |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + //assign list with installed plugins |
|
72 | + $template->assign("installed_plugins", $array); |
|
73 | + |
|
74 | + //get list with all uninstalled plugins |
|
75 | + $plugins = Plugins::listUninstalledPlugins(); |
|
76 | + |
|
77 | + $plugin_list = array(); |
|
78 | + |
|
79 | + foreach ($plugins as $plugin) { |
|
80 | + $plugin = Plugin::castPlugin($plugin); |
|
81 | + |
|
82 | + //create new instance of PluginInstaller to check plugin compatibility |
|
83 | + $installer = new PluginInstaller($plugin); |
|
84 | + |
|
85 | + $plugin_list[] = array( |
|
86 | + 'name' => $plugin->getName(), |
|
87 | + 'title' => $plugin->getTitle(), |
|
88 | + 'description' => $plugin->getDescription($lang_token), |
|
89 | + 'version' => $plugin->getVersion(), |
|
90 | + 'homepage' => $plugin->getHomepage(), |
|
91 | + 'authors' => $plugin->listAuthors(), |
|
92 | + 'license' => $plugin->getLicense(), |
|
93 | + 'keywords' => $plugin->listKeywords(), |
|
94 | + 'categories' => $plugin->listCategories(), |
|
95 | + 'text' => "", |
|
96 | + 'issues' => $plugin->getIssuesLink(), |
|
97 | + 'source' => $plugin->getSourceLink(), |
|
98 | + 'support_mail' => $plugin->getSupportMail(), |
|
99 | + 'support_links' => $plugin->listSupportLinks(), |
|
100 | + 'compatible' => $installer->checkRequirements(true), |
|
101 | + 'uptodate' => true,//TODO: check, if plugin is newest version |
|
102 | + 'alpha' => $plugin->isAlpha(), |
|
103 | + 'beta' => $plugin->isBeta(), |
|
104 | + 'installed' => false, |
|
105 | + 'activated' => $plugin->isActivated() |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + $template->assign("plugins", $plugin_list); |
|
110 | + |
|
111 | + return $template->getCode(); |
|
112 | + } |
|
113 | + |
|
114 | + public function getFooterScripts(): string { |
|
115 | + return "<!-- page script --> |
|
116 | 116 | <script> |
117 | 117 | $(function () { |
118 | 118 | /*$('#example1').DataTable();*/ |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | }); |
135 | 135 | }); |
136 | 136 | </script>"; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | 139 | } |
140 | 140 |
@@ -27,164 +27,164 @@ |
||
27 | 27 | |
28 | 28 | class PluginInstallerPage extends PageType { |
29 | 29 | |
30 | - public function getContent(): string { |
|
31 | - $template = new DwooTemplate("pages/plugininstaller"); |
|
32 | - |
|
33 | - $error = false; |
|
34 | - |
|
35 | - $template->assign("error_message", ""); |
|
36 | - |
|
37 | - if (isset($_REQUEST['action']) && !empty($_REQUEST['action'])) { |
|
38 | - // |
|
39 | - } else { |
|
40 | - //set error message |
|
41 | - $template->assign("error_message", "Invalide request, no action set!"); |
|
42 | - |
|
43 | - $error = true; |
|
44 | - } |
|
45 | - |
|
46 | - if (!isset($_REQUEST['plugin']) || empty($_REQUEST['plugin'])) { |
|
47 | - //set error message |
|
48 | - $template->assign("error_message", "Invalide request, no plugin was set!"); |
|
49 | - |
|
50 | - $error = true; |
|
51 | - } |
|
52 | - |
|
53 | - if (!$error) { |
|
54 | - $plugin = $_REQUEST['plugin']; |
|
55 | - $action = $_REQUEST['action']; |
|
56 | - |
|
57 | - //validate plugin |
|
58 | - if (!Validator_PluginName::getInstance()->isValide($plugin)) { |
|
59 | - //set error message |
|
60 | - $template->assign("error_message", "Invalide plugin name '" . htmlentities($plugin) . "'!"); |
|
61 | - |
|
62 | - $error = true; |
|
63 | - } else { |
|
64 | - //create new instance |
|
65 | - $plugin = new Plugin($plugin); |
|
66 | - |
|
67 | - if (!$plugin->exists()) { |
|
68 | - //set error message |
|
69 | - $template->assign("error_message", "Plugin '" . htmlentities($plugin->getName()) . "' doesnt exists!"); |
|
70 | - |
|
71 | - $error = true; |
|
72 | - } else { |
|
73 | - //load plugin.json |
|
74 | - $plugin->load(); |
|
75 | - $plugin->loadRow(); |
|
76 | - |
|
77 | - switch ($action) { |
|
78 | - case "install": |
|
79 | - //install plugin |
|
80 | - if ($this->installPlugin($plugin) === TRUE) { |
|
81 | - //send redirect header |
|
82 | - header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
83 | - |
|
84 | - $template->assign("success_message", "Plugin '" . $plugin->getName() . "' installed successfully!"); |
|
85 | - } else { |
|
86 | - //set error message |
|
87 | - $template->assign("error_message", "Couldnt install plugin '" . htmlentities($plugin->getName()) . "'!"); |
|
88 | - } |
|
89 | - |
|
90 | - break; |
|
91 | - case "uninstall": |
|
92 | - //load database row |
|
93 | - $plugin->loadRow(); |
|
94 | - |
|
95 | - //uninstall plugin |
|
96 | - if ($this->uninstallPlugin($plugin) === TRUE) { |
|
97 | - //send redirect header |
|
98 | - header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
99 | - |
|
100 | - $template->assign("success_message", "Plugin '" . $plugin->getName() . "' uninstalled successfully!"); |
|
101 | - } else { |
|
102 | - //set error message |
|
103 | - $template->assign("error_message", "Couldnt uninstall plugin '" . htmlentities($plugin) . "'!"); |
|
104 | - } |
|
105 | - |
|
106 | - break; |
|
107 | - case "upgrade": |
|
108 | - //load database row |
|
109 | - $plugin->loadRow(); |
|
110 | - |
|
111 | - //upgrade plugin |
|
112 | - if ($this->upgradePlugin($plugin) === TRUE) { |
|
113 | - //send redirect header |
|
114 | - header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
115 | - |
|
116 | - $template->assign("success_message", "Plugin '" . $plugin->getName() . "' upgraded successfully!"); |
|
117 | - } else { |
|
118 | - //set error message |
|
119 | - $template->assign("error_message", "Couldnt upgrade plugin '" . htmlentities($plugin) . "'!"); |
|
120 | - } |
|
121 | - |
|
122 | - break; |
|
123 | - default: |
|
124 | - //set error message |
|
125 | - $template->assign("error_message", "Unknown action type '" . htmlentities($action) . "'!"); |
|
126 | - |
|
127 | - break; |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - return $template->getCode(); |
|
134 | - } |
|
135 | - |
|
136 | - protected function installPlugin (Plugin $plugin) { |
|
137 | - $installer = new PluginInstaller($plugin); |
|
138 | - |
|
139 | - $res = $installer->checkRequirements(); |
|
140 | - |
|
141 | - //check requirements first |
|
142 | - if ($res !== TRUE) { |
|
143 | - return array( |
|
144 | - 'error' => $res |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - //check, if plugin is already installed |
|
149 | - if ($plugin->isInstalled()) { |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - //try to install plugin |
|
154 | - return $installer->install(); |
|
155 | - } |
|
156 | - |
|
157 | - protected function uninstallPlugin (Plugin $plugin) { |
|
158 | - //first check, if plugin is installed |
|
159 | - if (!PluginInstaller::isPluginInstalled($plugin->getName())) { |
|
160 | - return array( |
|
161 | - 'error' => "plugin_not_installed" |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - $installer = new PluginInstaller($plugin); |
|
166 | - |
|
167 | - //try to uninstall plugin |
|
168 | - return $installer->uninstall(); |
|
169 | - } |
|
170 | - |
|
171 | - protected function upgradePlugin (Plugin $plugin) { |
|
172 | - //first check, if plugin is installed |
|
173 | - if (!PluginInstaller::isPluginInstalled($plugin->getName())) { |
|
174 | - return array( |
|
175 | - 'error' => "plugin_not_installed" |
|
176 | - ); |
|
177 | - } |
|
178 | - |
|
179 | - $installer = new PluginInstaller($plugin); |
|
180 | - |
|
181 | - //try to uninstall plugin |
|
182 | - return $installer->upgrade(); |
|
183 | - } |
|
184 | - |
|
185 | - public function listRequiredPermissions(): array { |
|
186 | - return array("can_install_plugins"); |
|
187 | - } |
|
30 | + public function getContent(): string { |
|
31 | + $template = new DwooTemplate("pages/plugininstaller"); |
|
32 | + |
|
33 | + $error = false; |
|
34 | + |
|
35 | + $template->assign("error_message", ""); |
|
36 | + |
|
37 | + if (isset($_REQUEST['action']) && !empty($_REQUEST['action'])) { |
|
38 | + // |
|
39 | + } else { |
|
40 | + //set error message |
|
41 | + $template->assign("error_message", "Invalide request, no action set!"); |
|
42 | + |
|
43 | + $error = true; |
|
44 | + } |
|
45 | + |
|
46 | + if (!isset($_REQUEST['plugin']) || empty($_REQUEST['plugin'])) { |
|
47 | + //set error message |
|
48 | + $template->assign("error_message", "Invalide request, no plugin was set!"); |
|
49 | + |
|
50 | + $error = true; |
|
51 | + } |
|
52 | + |
|
53 | + if (!$error) { |
|
54 | + $plugin = $_REQUEST['plugin']; |
|
55 | + $action = $_REQUEST['action']; |
|
56 | + |
|
57 | + //validate plugin |
|
58 | + if (!Validator_PluginName::getInstance()->isValide($plugin)) { |
|
59 | + //set error message |
|
60 | + $template->assign("error_message", "Invalide plugin name '" . htmlentities($plugin) . "'!"); |
|
61 | + |
|
62 | + $error = true; |
|
63 | + } else { |
|
64 | + //create new instance |
|
65 | + $plugin = new Plugin($plugin); |
|
66 | + |
|
67 | + if (!$plugin->exists()) { |
|
68 | + //set error message |
|
69 | + $template->assign("error_message", "Plugin '" . htmlentities($plugin->getName()) . "' doesnt exists!"); |
|
70 | + |
|
71 | + $error = true; |
|
72 | + } else { |
|
73 | + //load plugin.json |
|
74 | + $plugin->load(); |
|
75 | + $plugin->loadRow(); |
|
76 | + |
|
77 | + switch ($action) { |
|
78 | + case "install": |
|
79 | + //install plugin |
|
80 | + if ($this->installPlugin($plugin) === TRUE) { |
|
81 | + //send redirect header |
|
82 | + header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
83 | + |
|
84 | + $template->assign("success_message", "Plugin '" . $plugin->getName() . "' installed successfully!"); |
|
85 | + } else { |
|
86 | + //set error message |
|
87 | + $template->assign("error_message", "Couldnt install plugin '" . htmlentities($plugin->getName()) . "'!"); |
|
88 | + } |
|
89 | + |
|
90 | + break; |
|
91 | + case "uninstall": |
|
92 | + //load database row |
|
93 | + $plugin->loadRow(); |
|
94 | + |
|
95 | + //uninstall plugin |
|
96 | + if ($this->uninstallPlugin($plugin) === TRUE) { |
|
97 | + //send redirect header |
|
98 | + header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
99 | + |
|
100 | + $template->assign("success_message", "Plugin '" . $plugin->getName() . "' uninstalled successfully!"); |
|
101 | + } else { |
|
102 | + //set error message |
|
103 | + $template->assign("error_message", "Couldnt uninstall plugin '" . htmlentities($plugin) . "'!"); |
|
104 | + } |
|
105 | + |
|
106 | + break; |
|
107 | + case "upgrade": |
|
108 | + //load database row |
|
109 | + $plugin->loadRow(); |
|
110 | + |
|
111 | + //upgrade plugin |
|
112 | + if ($this->upgradePlugin($plugin) === TRUE) { |
|
113 | + //send redirect header |
|
114 | + header("Location: " . DomainUtils::generateURL("admin/plugins")); |
|
115 | + |
|
116 | + $template->assign("success_message", "Plugin '" . $plugin->getName() . "' upgraded successfully!"); |
|
117 | + } else { |
|
118 | + //set error message |
|
119 | + $template->assign("error_message", "Couldnt upgrade plugin '" . htmlentities($plugin) . "'!"); |
|
120 | + } |
|
121 | + |
|
122 | + break; |
|
123 | + default: |
|
124 | + //set error message |
|
125 | + $template->assign("error_message", "Unknown action type '" . htmlentities($action) . "'!"); |
|
126 | + |
|
127 | + break; |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + return $template->getCode(); |
|
134 | + } |
|
135 | + |
|
136 | + protected function installPlugin (Plugin $plugin) { |
|
137 | + $installer = new PluginInstaller($plugin); |
|
138 | + |
|
139 | + $res = $installer->checkRequirements(); |
|
140 | + |
|
141 | + //check requirements first |
|
142 | + if ($res !== TRUE) { |
|
143 | + return array( |
|
144 | + 'error' => $res |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + //check, if plugin is already installed |
|
149 | + if ($plugin->isInstalled()) { |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + //try to install plugin |
|
154 | + return $installer->install(); |
|
155 | + } |
|
156 | + |
|
157 | + protected function uninstallPlugin (Plugin $plugin) { |
|
158 | + //first check, if plugin is installed |
|
159 | + if (!PluginInstaller::isPluginInstalled($plugin->getName())) { |
|
160 | + return array( |
|
161 | + 'error' => "plugin_not_installed" |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + $installer = new PluginInstaller($plugin); |
|
166 | + |
|
167 | + //try to uninstall plugin |
|
168 | + return $installer->uninstall(); |
|
169 | + } |
|
170 | + |
|
171 | + protected function upgradePlugin (Plugin $plugin) { |
|
172 | + //first check, if plugin is installed |
|
173 | + if (!PluginInstaller::isPluginInstalled($plugin->getName())) { |
|
174 | + return array( |
|
175 | + 'error' => "plugin_not_installed" |
|
176 | + ); |
|
177 | + } |
|
178 | + |
|
179 | + $installer = new PluginInstaller($plugin); |
|
180 | + |
|
181 | + //try to uninstall plugin |
|
182 | + return $installer->upgrade(); |
|
183 | + } |
|
184 | + |
|
185 | + public function listRequiredPermissions(): array { |
|
186 | + return array("can_install_plugins"); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | } |
190 | 190 |
@@ -27,34 +27,34 @@ |
||
27 | 27 | |
28 | 28 | class FolderInstaller extends PluginInstaller_Plugin { |
29 | 29 | |
30 | - public function install(Plugin $plugin, array $install_json): bool { |
|
31 | - if (isset($install_json['folders'])) { |
|
32 | - foreach ($install_json['folders'] as $folder) { |
|
33 | - $name = $folder['folder']; |
|
34 | - $hidden = (isset($folder['hidden']) ? boolval($folder['hidden']) : false); |
|
35 | - $permissions = (isset($folder['permissions']) ? $folder['permissions'] : array("none")); |
|
36 | - $main_menu = (isset($folder['main_menu']) ? intval($folder['main_menu']) : -1); |
|
37 | - $local_menu = (isset($folder['local_menu']) ? intval($folder['local_menu']) : -1); |
|
38 | - $force_template = (isset($folder['force_template']) ? $folder['force_template'] : "none"); |
|
39 | - $title_translation = (isset($folder['title_translation']) ? boolval($folder['title_translation']) : true); |
|
40 | - |
|
41 | - //create folder |
|
42 | - Folder::createFolderIfAbsent($name, $hidden, $permissions, $main_menu, $local_menu, $force_template, $title_translation); |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - return true; |
|
47 | - } |
|
48 | - |
|
49 | - public function uninstall(Plugin $plugin, array $install_json): bool { |
|
50 | - //folders will not removed, because they can contain pages |
|
51 | - return true; |
|
52 | - } |
|
53 | - |
|
54 | - public function upgrade(Plugin $plugin, array $install_json): bool { |
|
55 | - //install supports ON DUPLICATE KEY |
|
56 | - return $this->install($plugin, $install_json); |
|
57 | - } |
|
30 | + public function install(Plugin $plugin, array $install_json): bool { |
|
31 | + if (isset($install_json['folders'])) { |
|
32 | + foreach ($install_json['folders'] as $folder) { |
|
33 | + $name = $folder['folder']; |
|
34 | + $hidden = (isset($folder['hidden']) ? boolval($folder['hidden']) : false); |
|
35 | + $permissions = (isset($folder['permissions']) ? $folder['permissions'] : array("none")); |
|
36 | + $main_menu = (isset($folder['main_menu']) ? intval($folder['main_menu']) : -1); |
|
37 | + $local_menu = (isset($folder['local_menu']) ? intval($folder['local_menu']) : -1); |
|
38 | + $force_template = (isset($folder['force_template']) ? $folder['force_template'] : "none"); |
|
39 | + $title_translation = (isset($folder['title_translation']) ? boolval($folder['title_translation']) : true); |
|
40 | + |
|
41 | + //create folder |
|
42 | + Folder::createFolderIfAbsent($name, $hidden, $permissions, $main_menu, $local_menu, $force_template, $title_translation); |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + return true; |
|
47 | + } |
|
48 | + |
|
49 | + public function uninstall(Plugin $plugin, array $install_json): bool { |
|
50 | + //folders will not removed, because they can contain pages |
|
51 | + return true; |
|
52 | + } |
|
53 | + |
|
54 | + public function upgrade(Plugin $plugin, array $install_json): bool { |
|
55 | + //install supports ON DUPLICATE KEY |
|
56 | + return $this->install($plugin, $install_json); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
60 | 60 |
@@ -27,39 +27,39 @@ |
||
27 | 27 | |
28 | 28 | class PermissionInstaller extends PluginInstaller_Plugin { |
29 | 29 | |
30 | - public function install(Plugin $plugin, array $install_json): bool { |
|
31 | - if (isset($install_json['permissions'])) { |
|
32 | - $permissions = $install_json['permissions']; |
|
30 | + public function install(Plugin $plugin, array $install_json): bool { |
|
31 | + if (isset($install_json['permissions'])) { |
|
32 | + $permissions = $install_json['permissions']; |
|
33 | 33 | |
34 | - foreach ($permissions as $permission) { |
|
35 | - $token = $permission['token']; |
|
36 | - $title = $permission['title']; |
|
37 | - $description = $permission['description']; |
|
38 | - $category = (isset($permission['category']) ? $permission['category'] : "plugins"); |
|
39 | - $order = (isset($permission['order']) ? intval($permission['order']) : 100); |
|
34 | + foreach ($permissions as $permission) { |
|
35 | + $token = $permission['token']; |
|
36 | + $title = $permission['title']; |
|
37 | + $description = $permission['description']; |
|
38 | + $category = (isset($permission['category']) ? $permission['category'] : "plugins"); |
|
39 | + $order = (isset($permission['order']) ? intval($permission['order']) : 100); |
|
40 | 40 | |
41 | - Permissions::createPermission($token, $title, $description, $category, "plugin_" . $plugin->getName(), $order); |
|
42 | - } |
|
43 | - } |
|
41 | + Permissions::createPermission($token, $title, $description, $category, "plugin_" . $plugin->getName(), $order); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - return true; |
|
46 | - } |
|
45 | + return true; |
|
46 | + } |
|
47 | 47 | |
48 | - public function uninstall(Plugin $plugin, array $install_json): bool { |
|
49 | - //delete permissions with plugin owner |
|
50 | - if (isset($install_json['permissions'])) { |
|
51 | - Permissions::deletePermissionsByOwner("plugin_" . $plugin->getName()); |
|
52 | - } |
|
48 | + public function uninstall(Plugin $plugin, array $install_json): bool { |
|
49 | + //delete permissions with plugin owner |
|
50 | + if (isset($install_json['permissions'])) { |
|
51 | + Permissions::deletePermissionsByOwner("plugin_" . $plugin->getName()); |
|
52 | + } |
|
53 | 53 | |
54 | - return true; |
|
55 | - } |
|
54 | + return true; |
|
55 | + } |
|
56 | 56 | |
57 | - public function upgrade(Plugin $plugin, array $install_json): bool { |
|
58 | - //TODO: remove permissions, which arent longer in install json |
|
57 | + public function upgrade(Plugin $plugin, array $install_json): bool { |
|
58 | + //TODO: remove permissions, which arent longer in install json |
|
59 | 59 | |
60 | - //install queries supports ON DUPLICATE KEY |
|
61 | - return $this->install($plugin, $install_json); |
|
62 | - } |
|
60 | + //install queries supports ON DUPLICATE KEY |
|
61 | + return $this->install($plugin, $install_json); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
65 | 65 |