From 36717e5f32a154582a2069ebc60e4fa256bb9f90 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 22 Dec 2015 19:53:00 -0800 Subject: start on refactor of plugin/theme/widget info block parsing --- include/plugin.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 4a35a0170..4da73dfd8 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -313,7 +313,6 @@ function call_hooks($name, &$data = null) { * * Version: 1.2.3 * * Author: John * * Author: Jane - * * Compat: Red [(version)], Friendica [(version)] * * *\endcode * @param string $plugin the name of the plugin @@ -325,8 +324,8 @@ function get_plugin_info($plugin){ 'name' => $plugin, 'description' => '', 'author' => array(), - 'version' => '', - 'compat' => '' + 'maintainer' => array(), + 'version' => '' ); if (!is_file("addon/$plugin/$plugin.php")) @@ -342,22 +341,23 @@ function get_plugin_info($plugin){ if ($l != ""){ list($k, $v) = array_map("trim", explode(":", $l, 2)); $k = strtolower($k); - if ($k == 'author'){ + if ($k == 'author' || $k == 'maintainer'){ $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { - $info['author'][] = array('name' => $m[1], 'link' => $m[2]); + $info[$k][] = array('name' => $m[1], 'link' => $m[2]); } else { - $info['author'][] = array('name' => $v); + $info[$k][] = array('name' => $v); } } else { - if (array_key_exists($k, $info)){ +// if (array_key_exists($k, $info)){ $info[$k] = $v; - } +// } } } } } + return $info; } -- cgit v1.2.3 From 66c8658898b16f6a6468bddbbc6f882b3eaf3a7d Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 11 Jan 2016 16:34:12 -0800 Subject: plugin version compatibility checking. To use, set MinVersion, MaxVersion or MinPHPversion in the plugin header block. Case is not important. We check the project versions against STD_VERSION, which should be rolled to a new y of x.x.y if the plugin interface or project code changes in an incompatible way. --- include/plugin.php | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 4da73dfd8..ccd88d963 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -348,19 +348,46 @@ function get_plugin_info($plugin){ } else { $info[$k][] = array('name' => $v); } - } else { -// if (array_key_exists($k, $info)){ - $info[$k] = $v; -// } + } + else { + $info[$k] = $v; } } } } - return $info; } +function check_plugin_versions($info) { + + if(! is_array($info)) + return true; + + if(array_key_exists('minversion',$info)) { + if(version_compare(trim($info['minversion']),STD_VERSION, '<')) { + logger('minversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); + return false; + } + } + if(array_key_exists('maxversion',$info)) { + if(version_compare(trim($info['maxversion']),STD_VERSION, '>')) { + logger('maxversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); + return false; + } + } + if(array_key_exists('minphpversion',$info)) { + if(version_compare(trim($info['minphpversion']),PHP_VERSION, '<')) { + logger('minphpversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); + return false; + } + } + + return true; +} + + + /** * @brief Parse theme comment in search of theme infos. -- cgit v1.2.3 From a8a5cb05a7f0e85f0979b38280e7887bc12e80ed Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 11 Jan 2016 17:29:27 -0800 Subject: logic reversal in version checking --- include/plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index ccd88d963..2bc363556 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -365,19 +365,19 @@ function check_plugin_versions($info) { return true; if(array_key_exists('minversion',$info)) { - if(version_compare(trim($info['minversion']),STD_VERSION, '<')) { + if(version_compare(trim($info['minversion']),STD_VERSION, '>=')) { logger('minversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('maxversion',$info)) { - if(version_compare(trim($info['maxversion']),STD_VERSION, '>')) { + if(version_compare(STD_VERSION,trim($info['maxversion']), '>')) { logger('maxversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } } if(array_key_exists('minphpversion',$info)) { - if(version_compare(trim($info['minphpversion']),PHP_VERSION, '<')) { + if(version_compare(trim($info['minphpversion']),PHP_VERSION, '>=')) { logger('minphpversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } -- cgit v1.2.3 From da9a8d54de70d290668da24a3ec930dd9230aab1 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 17 Jan 2016 00:17:23 -0800 Subject: minversion issue --- include/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 2bc363556..a47558b63 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -365,7 +365,7 @@ function check_plugin_versions($info) { return true; if(array_key_exists('minversion',$info)) { - if(version_compare(trim($info['minversion']),STD_VERSION, '>=')) { + if(! version_compare(STD_VERSION,trim($info['minversion']), '>=')) { logger('minversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } @@ -377,7 +377,7 @@ function check_plugin_versions($info) { } } if(array_key_exists('minphpversion',$info)) { - if(version_compare(trim($info['minphpversion']),PHP_VERSION, '>=')) { + if(! version_compare(PHP_VERSION,trim($info['minphpversion']), '>=')) { logger('minphpversion limit: ' . $info['name'],LOGGER_NORMAL,LOG_WARNING); return false; } -- cgit v1.2.3 From af7c7642bb62759fb2cc39d897cc5bd1a592fb5b Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 11 Feb 2016 20:37:30 -0800 Subject: whitespace --- include/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index a47558b63..da4568ad7 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -291,7 +291,7 @@ function call_hooks($name, &$data = null) { $func = $hook[1]; $func($a, $data); } else { - // remove orphan hooks + q("DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND function = '%s'", dbesc($name), dbesc($hook[0]), -- cgit v1.2.3 From 342fda94e4162634eeb67c18c1d284e7d78f217f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 18 Feb 2016 15:24:58 -0800 Subject: Provide Zotlabs\Project and System class for querying details about the project/version info. Move these out of /boot.php --- include/plugin.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index da4568ad7..5afded542 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -653,17 +653,6 @@ function get_markup_template($s, $root = '') { return $template; } -// return the standardised version. Since we can't easily compare -// before the STD_VERSION definition was applied, we have to treat -// all prior release versions the same. You can dig through them -// with other means (such as RED_VERSION) if necessary. - -function get_std_version() { - if(defined('STD_VERSION')) - return STD_VERSION; - return '0.0.0'; -} - function folder_exists($folder) { -- cgit v1.2.3 From 7e6febe2a6609457eca1f1caf650375534780048 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 24 Feb 2016 15:19:28 -0800 Subject: add 'requires' field to plugin info to list other dependent plugins/addons and disable if dependencies are not installed/enabled --- include/plugin.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 5afded542..bd844442f 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -325,7 +325,8 @@ function get_plugin_info($plugin){ 'description' => '', 'author' => array(), 'maintainer' => array(), - 'version' => '' + 'version' => '', + 'requires' => '' ); if (!is_file("addon/$plugin/$plugin.php")) @@ -383,6 +384,22 @@ function check_plugin_versions($info) { } } + if(array_key_exists('requires',$info)) { + $arr = explode(',',$info['requires']); + $found = true; + if($arr) { + foreach($arr as $test) { + $test = trim($test); + if(! $test) + continue; + if(! in_array($test,get_app()->plugins)) + $found = false; + } + } + if(! $found) + return false; + } + return true; } -- cgit v1.2.3 From 1cd3b4182595b838a535dd6b6990251db05d49e6 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 30 Mar 2016 22:13:24 -0700 Subject: deprecate $a->get_baseurl() --- include/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index bd844442f..e0973b976 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -495,10 +495,10 @@ function get_theme_screenshot($theme) { $exts = array('.png', '.jpg'); foreach($exts as $ext) { if(file_exists('view/theme/' . $theme . '/img/screenshot' . $ext)) - return($a->get_baseurl() . '/view/theme/' . $theme . '/img/screenshot' . $ext); + return(z_root() . '/view/theme/' . $theme . '/img/screenshot' . $ext); } - return($a->get_baseurl() . '/images/blank.png'); + return(z_root() . '/images/blank.png'); } /** -- cgit v1.2.3 From 9abd95fad3784a10fc48bc40f9b8a75d7d74edda Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 31 Mar 2016 16:06:03 -0700 Subject: static App --- include/plugin.php | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index e0973b976..8dceb8fb1 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -219,7 +219,7 @@ function unregister_hook($hook, $file, $function) { // -// It might not be obvious but themes can manually add hooks to the $a->hooks +// It might not be obvious but themes can manually add hooks to the App::$hooks // array in their theme_init() and use this to customise the app behaviour. // UPDATE: use insert_hook($hookname,$function_name) to do this // @@ -227,19 +227,19 @@ function unregister_hook($hook, $file, $function) { function load_hooks() { $a = get_app(); -// if(! is_array($a->hooks)) - $a->hooks = array(); +// if(! is_array(App::$hooks)) + App::$hooks = array(); $r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC"); if($r) { foreach($r as $rr) { - if(! array_key_exists($rr['hook'],$a->hooks)) - $a->hooks[$rr['hook']] = array(); + if(! array_key_exists($rr['hook'],App::$hooks)) + App::$hooks[$rr['hook']] = array(); - $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']); + App::$hooks[$rr['hook']][] = array($rr['file'],$rr['function']); } } -//logger('hooks: ' . print_r($a->hooks,true)); +//logger('hooks: ' . print_r(App::$hooks,true)); } /** @@ -261,13 +261,13 @@ function load_hooks() { */ function insert_hook($hook, $fn) { $a = get_app(); - if(! is_array($a->hooks)) - $a->hooks = array(); + if(! is_array(App::$hooks)) + App::$hooks = array(); - if(! array_key_exists($hook, $a->hooks)) - $a->hooks[$hook] = array(); + if(! array_key_exists($hook, App::$hooks)) + App::$hooks[$hook] = array(); - $a->hooks[$hook][] = array('', $fn); + App::$hooks[$hook][] = array('', $fn); } /** @@ -282,8 +282,8 @@ function insert_hook($hook, $fn) { function call_hooks($name, &$data = null) { $a = get_app(); - if((is_array($a->hooks)) && (array_key_exists($name, $a->hooks))) { - foreach($a->hooks[$name] as $hook) { + if((is_array(App::$hooks)) && (array_key_exists($name, App::$hooks))) { + foreach(App::$hooks[$name] as $hook) { if($hook[0]) @include_once($hook[0]); @@ -392,7 +392,7 @@ function check_plugin_versions($info) { $test = trim($test); if(! $test) continue; - if(! in_array($test,get_app()->plugins)) + if(! in_array($test,App::$plugins)) $found = false; } } @@ -508,19 +508,19 @@ function get_theme_screenshot($theme) { * @param string $media change media attribute (default to 'screen') */ function head_add_css($src, $media = 'screen') { - get_app()->css_sources[] = array($src, $media); + App::$css_sources[] = array($src, $media); } function head_remove_css($src, $media = 'screen') { $a = get_app(); - $index = array_search(array($src, $media), $a->css_sources); + $index = array_search(array($src, $media), App::$css_sources); if ($index !== false) - unset($a->css_sources[$index]); + unset(App::$css_sources[$index]); } function head_get_css() { $str = ''; - $sources = get_app()->css_sources; + $sources = App::$css_sources; if (count($sources)) { foreach ($sources as $source) $str .= format_css_if_exists($source); @@ -560,7 +560,7 @@ function script_path() { // Some proxy setups may require using http_host - if(intval(get_app()->config['system']['script_path_use_http_host'])) + if(intval(App::$config['system']['script_path_use_http_host'])) $server_var = 'HTTP_HOST'; else $server_var = 'SERVER_NAME'; @@ -576,19 +576,19 @@ function script_path() { } function head_add_js($src) { - get_app()->js_sources[] = $src; + App::$js_sources[] = $src; } function head_remove_js($src) { $a = get_app(); - $index = array_search($src, $a->js_sources); + $index = array_search($src, App::$js_sources); if($index !== false) - unset($a->js_sources[$index]); + unset(App::$js_sources[$index]); } function head_get_js() { $str = ''; - $sources = get_app()->js_sources; + $sources = App::$js_sources; if(count($sources)) foreach($sources as $source) { if($source === 'main.js') @@ -624,7 +624,7 @@ function theme_include($file, $root = '') { if($root !== '' && $root[strlen($root)-1] !== '/') $root = $root . '/'; - $theme_info = $a->theme_info; + $theme_info = App::$theme_info; if(array_key_exists('extends',$theme_info)) $parent = $theme_info['extends']; @@ -656,7 +656,7 @@ function theme_include($file, $root = '') { function get_intltext_template($s, $root = '') { $a = get_app(); - $t = $a->template_engine(); + $t = App::template_engine(); $template = $t->get_intltext_template($s, $root); return $template; @@ -665,7 +665,7 @@ function get_intltext_template($s, $root = '') { function get_markup_template($s, $root = '') { $a = get_app(); - $t = $a->template_engine(); + $t = App::template_engine(); $template = $t->get_markup_template($s, $root); return $template; } -- cgit v1.2.3