]> git.mxchange.org Git - friendica.git/blobdiff - include/plugin.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / include / plugin.php
index a6928793d4061d118c392536eee7f3ec6f1b6f12..9795cacf92019116a439edee50ef28faca5713c3 100644 (file)
@@ -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,6 +200,9 @@ 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' => "",
@@ -229,10 +237,10 @@ function get_plugin_info($plugin){
                                                $info[$k]=$v;
                                        }
                                }
-                               
+
                        }
                }
-               
+
        }
        return $info;
 }}
@@ -241,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
@@ -270,6 +278,7 @@ function get_theme_info($theme){
 
        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");
@@ -323,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