]> git.mxchange.org Git - friendica.git/blobdiff - include/plugin.php
Merge pull request #608 from fermionic/20130204-diabook-reduce-css
[friendica.git] / include / plugin.php
index ffa562273fb6b3ee8637148867abe8896aae5308..ef0ddd05ef108c41c482b2b365ac970cd79c85fb 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';
@@ -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'))
@@ -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) {
@@ -111,7 +110,7 @@ function reload_plugins() {
 
 
 if(! function_exists('register_hook')) {
-function register_hook($hook,$file,$function) {
+function register_hook($hook,$file,$function,$priority=0) {
 
        $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
                dbesc($hook),
@@ -121,10 +120,11 @@ function register_hook($hook,$file,$function) {
        if(count($r))
                return true;
 
-       $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
+       $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
                dbesc($hook),
                dbesc($file),
-               dbesc($function)
+               dbesc($function),
+               dbesc($priority)
        );
        return $r;
 }}
@@ -145,7 +145,7 @@ if(! function_exists('load_hooks')) {
 function load_hooks() {
        $a = get_app();
        $a->hooks = array();
-       $r = q("SELECT * FROM `hook` WHERE 1");
+       $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
        if(count($r)) {
                foreach($r as $rr) {
                        if(! array_key_exists($rr['hook'],$a->hooks))
@@ -162,6 +162,10 @@ function call_hooks($name, &$data = null) {
 
        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];
@@ -255,6 +259,7 @@ function get_theme_info($theme){
                'author' => array(),
                'maintainer' => array(),
                'version' => "",
+               'credits' => "",
                'experimental' => false,
                'unsupported' => false
        );
@@ -317,6 +322,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