]> git.mxchange.org Git - friendica.git/blobdiff - include/plugin.php
It is better this way
[friendica.git] / include / plugin.php
index 487ab575156d4812d6d959922496ac5f04efdb1a..336b213aa3491324db2582196159a628822dbdb3 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 /**
  * @file include/plugin.php
- * 
+ *
  * @brief Some functions to handle addons and themes.
  */
 
+use Friendica\App;
 
 /**
  * @brief uninstalls an addon.
@@ -129,7 +130,7 @@ function reload_plugins() {
  */
 function plugin_enabled($plugin) {
        $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
-       return((bool)(count($r) > 0));
+       return ((dbm::is_result($r)) && (count($r) > 0));
 }
 
 
@@ -164,7 +165,7 @@ function register_hook($hook,$file,$function,$priority=0) {
 
 /**
  * @brief unregisters a hook.
- * 
+ *
  * @param string $hook the name of the hook
  * @param string $file the name of the file that hooks into
  * @param string $function the name of the function that the hook called
@@ -187,8 +188,9 @@ function load_hooks() {
        $a = get_app();
        $a->hooks = array();
        $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC, `file`");
+
        if (dbm::is_result($r)) {
-               foreach($r as $rr) {
+               foreach ($r as $rr) {
                        if(! array_key_exists($rr['hook'],$a->hooks))
                                $a->hooks[$rr['hook']] = array();
                        $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
@@ -324,7 +326,7 @@ function get_plugin_info($plugin){
 
 /**
  * @brief Parse theme comment in search of theme infos.
- * 
+ *
  * like
  * \code
  * ..* Name: My Theme
@@ -410,13 +412,13 @@ function get_theme_info($theme){
  * @return string
  */
 function get_theme_screenshot($theme) {
-       $a = get_app();
        $exts = array('.png','.jpg');
        foreach($exts as $ext) {
-               if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
-                       return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
+               if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
+                       return(App::get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
+               }
        }
-       return($a->get_baseurl() . '/images/blank.png');
+       return(App::get_baseurl() . '/images/blank.png');
 }
 
 // install and uninstall theme
@@ -424,8 +426,8 @@ 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")) {
+       include_once("view/theme/$theme/theme.php");
+       if (function_exists("{$theme}_uninstall")) {
                $func = "{$theme}_uninstall";
                $func();
        }
@@ -435,19 +437,19 @@ if (! function_exists('install_theme')){
 function install_theme($theme) {
        // silently fail if theme was removed
 
-       if(! file_exists("view/theme/$theme/theme.php"))
+       if (! file_exists("view/theme/$theme/theme.php")) {
                return false;
+       }
 
        logger("Addons: installing theme $theme");
 
-       @include_once("view/theme/$theme/theme.php");
+       include_once("view/theme/$theme/theme.php");
 
-       if(function_exists("{$theme}_install")) {
+       if (function_exists("{$theme}_install")) {
                $func = "{$theme}_install";
                $func();
                return true;
-       }
-       else {
+       } else {
                logger("Addons: FAILED installing theme $theme");
                return false;
        }
@@ -466,10 +468,9 @@ function install_theme($theme) {
 
 function service_class_allows($uid,$property,$usage = false) {
 
-       if($uid == local_user()) {
+       if ($uid == local_user()) {
                $service_class = $a->user['service_class'];
-       }
-       else {
+       } else {
                $r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1",
                        intval($uid)
                );
@@ -477,18 +478,23 @@ function service_class_allows($uid,$property,$usage = false) {
                        $service_class = $r[0]['service_class'];
                }
        }
-       if(! x($service_class))
-               return true; // everything is allowed
+
+       if (! x($service_class)) {
+               // everything is allowed
+               return true;
+       }
 
        $arr = get_config('service_class',$service_class);
-       if(! is_array($arr) || (! count($arr)))
+       if (! is_array($arr) || (! count($arr))) {
                return true;
+       }
 
-       if($usage === false)
+       if ($usage === false) {
                return ((x($arr[$property])) ? (bool) $arr['property'] : true);
-       else {
-               if(! array_key_exists($property,$arr))
+       else {
+               if (! array_key_exists($property,$arr)) {
                        return true;
+               }
                return (((intval($usage)) < intval($arr[$property])) ? true : false);
        }
 }
@@ -496,10 +502,9 @@ function service_class_allows($uid,$property,$usage = false) {
 
 function service_class_fetch($uid,$property) {
 
-       if($uid == local_user()) {
+       if ($uid == local_user()) {
                $service_class = $a->user['service_class'];
-       }
-       else {
+       } else {
                $r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1",
                        intval($uid)
                );
@@ -541,11 +546,11 @@ function upgrade_bool_message($bbcode = false) {
 
 /**
  * @brief Get the full path to relevant theme files by filename
- * 
+ *
  * This function search in the theme directory (and if not present in global theme directory)
  * if there is a directory with the file extension and  for a file with the given
- * filename. 
- * 
+ * filename.
+ *
  * @param string $file Filename
  * @param string $root Full root path
  * @return string Path to the file or empty string if the file isn't found