X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fplugin.php;h=9795cacf92019116a439edee50ef28faca5713c3;hb=93143702ed5fe88c0fce77d778d86ec651d4331e;hp=db3224f29658ff2a1fe1ca8e302388ab77e353b3;hpb=234598280d96627861a1ff1dcfc8a4a59bd37054;p=friendica.git diff --git a/include/plugin.php b/include/plugin.php index db3224f296..9795cacf92 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -8,7 +8,7 @@ function uninstall_plugin($plugin){ q("DELETE FROM `addon` WHERE `name` = '%s' ", dbesc($plugin) ); - + @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_uninstall')) { $func = $plugin . '_uninstall'; @@ -28,9 +28,9 @@ function install_plugin($plugin) { if(function_exists($plugin . '_install')) { $func = $plugin . '_install'; $func(); - + $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0); - + $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ", dbesc($plugin), intval($t), @@ -158,10 +158,16 @@ function load_hooks() { if(! function_exists('call_hooks')) { function call_hooks($name, &$data = null) { + $stamp1 = microtime(true); + $a = get_app(); if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) { foreach($a->hooks[$name] as $hook) { + // Don't run a theme's hook if the user isn't using the theme + if(strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false) + continue; + @include_once($hook[0]); if(function_exists($hook[1])) { $func = $hook[1]; @@ -177,7 +183,6 @@ function call_hooks($name, &$data = null) { } } } - }} @@ -195,18 +200,24 @@ function call_hooks($name, &$data = null) { if (! function_exists('get_plugin_info')){ function get_plugin_info($plugin){ + + $a = get_app(); + $info=Array( 'name' => $plugin, 'description' => "", 'author' => array(), 'version' => "" ); - + if (!is_file("addon/$plugin/$plugin.php")) return $info; - + + $stamp1 = microtime(true); $f = file_get_contents("addon/$plugin/$plugin.php"); + $a->save_timestamp($stamp1, "file"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { @@ -226,10 +237,10 @@ function get_plugin_info($plugin){ $info[$k]=$v; } } - + } } - + } return $info; }} @@ -238,7 +249,7 @@ function get_plugin_info($plugin){ /* * parse theme comment in search of theme infos. * like - * + * * * Name: My Theme * * Description: My Cool Theme * * Version: 1.2.3 @@ -266,11 +277,14 @@ function get_theme_info($theme){ $info['unsupported'] = true; if (!is_file("view/theme/$theme/theme.php")) return $info; - + + $a = get_app(); + $stamp1 = microtime(true); $f = file_get_contents("view/theme/$theme/theme.php"); + $a->save_timestamp($stamp1, "file"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); - - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { @@ -318,6 +332,42 @@ function get_theme_screenshot($theme) { return($a->get_baseurl() . '/images/blank.png'); } +// install and uninstall theme +if (! function_exists('uninstall_theme')){ +function uninstall_theme($theme){ + logger("Addons: uninstalling theme " . $theme); + + @include_once("view/theme/$theme/theme.php"); + if(function_exists("{$theme}_uninstall")) { + $func = "{$theme}_uninstall"; + $func(); + } +}} + +if (! function_exists('install_theme')){ +function install_theme($theme) { + // silently fail if theme was removed + + if(! file_exists("view/theme/$theme/theme.php")) + return false; + + logger("Addons: installing theme $theme"); + + @include_once("view/theme/$theme/theme.php"); + + if(function_exists("{$theme}_install")) { + $func = "{$theme}_install"; + $func(); + return true; + } + else { + logger("Addons: FAILED installing theme $theme"); + return false; + } + +}} + + // check service_class restrictions. If there are no service_classes defined, everything is allowed. // if $usage is supplied, we check against a maximum count and return true if the current usage is