]> git.mxchange.org Git - friendica.git/blobdiff - include/plugin.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / include / plugin.php
index f60a7d2961069b11ec183c4f606f44853063374c..9795cacf92019116a439edee50ef28faca5713c3 100644 (file)
@@ -18,7 +18,6 @@ function uninstall_plugin($plugin){
 
 if (! function_exists('install_plugin')){
 function install_plugin($plugin) {
-
        // silently fail if plugin was removed
 
        if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php'))
@@ -29,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),
@@ -77,7 +76,7 @@ function reload_plugins() {
                                $pl = trim($pl);
 
                                $fname = 'addon/' . $pl . '/' . $pl . '.php';
-                               
+
                                if(file_exists($fname)) {
                                        $t = @filemtime($fname);
                                        foreach($installed as $i) {
@@ -159,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];
@@ -178,7 +183,6 @@ function call_hooks($name, &$data = null) {
                        }
                }
        }
-
 }}
 
 
@@ -196,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 ) {
@@ -227,10 +237,10 @@ function get_plugin_info($plugin){
                                                $info[$k]=$v;
                                        }
                                }
-                               
+
                        }
                }
-               
+
        }
        return $info;
 }}
@@ -239,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
@@ -256,6 +266,7 @@ function get_theme_info($theme){
                'author' => array(),
                'maintainer' => array(),
                'version' => "",
+               'credits' => "",
                'experimental' => false,
                'unsupported' => false
        );
@@ -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