]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Addon.php
We now can show "Friendica (AP)" as network name
[friendica.git] / src / Core / Addon.php
index 5a1392c0932fcd21438684408ac3449bb8dc19c6..4c20c96ad4705546ed0ab6c429c0e64351a74f9b 100644 (file)
@@ -4,11 +4,8 @@
  */
 namespace Friendica\Core;
 
-use Friendica\Core\Config;
-use Friendica\Database\DBM;
-use Friendica\Core\Worker;
-
-use dba;
+use Friendica\App;
+use Friendica\Database\DBA;
 
 require_once 'include/dba.php';
 
@@ -26,7 +23,7 @@ class Addon
        public static function uninstall($addon)
        {
                logger("Addons: uninstalling " . $addon);
-               dba::delete('addon', ['name' => $addon]);
+               DBA::delete('addon', ['name' => $addon]);
 
                @include_once('addon/' . $addon . '/' . $addon . '.php');
                if (function_exists($addon . '_uninstall')) {
@@ -57,7 +54,7 @@ class Addon
 
                        $addon_admin = (function_exists($addon."_addon_admin") ? 1 : 0);
 
-                       dba::insert('addon', ['name' => $addon, 'installed' => true,
+                       DBA::insert('addon', ['name' => $addon, 'installed' => true,
                                                'timestamp' => $t, 'plugin_admin' => $addon_admin]);
 
                        // we can add the following with the previous SQL
@@ -65,7 +62,7 @@ class Addon
                        // This way the system won't fall over dead during the update.
 
                        if (file_exists('addon/' . $addon . '/.hidden')) {
-                               dba::update('addon', ['hidden' => true], ['name' => $addon]);
+                               DBA::update('addon', ['hidden' => true], ['name' => $addon]);
                        }
                        return true;
                } else {
@@ -81,9 +78,9 @@ class Addon
        {
                $addons = Config::get('system', 'addon');
                if (strlen($addons)) {
-                       $r = dba::select('addon', [], ['installed' => 1]);
-                       if (DBM::is_result($r)) {
-                               $installed = dba::inArray($r);
+                       $r = DBA::select('addon', [], ['installed' => 1]);
+                       if (DBA::isResult($r)) {
+                               $installed = DBA::toArray($r);
                        } else {
                                $installed = [];
                        }
@@ -110,7 +107,7 @@ class Addon
                                                                        $func = $addon . '_install';
                                                                        $func();
                                                                }
-                                                               dba::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
+                                                               DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
                                                        }
                                                }
                                        }
@@ -127,7 +124,7 @@ class Addon
         */
        public static function isEnabled($addon)
        {
-               return dba::exists('addon', ['installed' => true, 'name' => $addon]);
+               return DBA::exists('addon', ['installed' => true, 'name' => $addon]);
        }
 
 
@@ -142,13 +139,15 @@ class Addon
         */
        public static function registerHook($hook, $file, $function, $priority = 0)
        {
+               $file = str_replace(get_app()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
+
                $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
-               $exists = dba::exists('hook', $condition);
+               $exists = DBA::exists('hook', $condition);
                if ($exists) {
                        return true;
                }
 
-               $r = dba::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
+               $r = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
 
                return $r;
        }
@@ -163,8 +162,14 @@ class Addon
         */
        public static function unregisterHook($hook, $file, $function)
        {
+               $relative_file = str_replace(get_app()->get_basepath() . DIRECTORY_SEPARATOR, '', $file);
+
+               // This here is only needed for fixing a problem that existed on the develop branch
                $condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
-               $r = dba::delete('hook', $condition);
+               DBA::delete('hook', $condition);
+
+               $condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
+               $r = DBA::delete('hook', $condition);
                return $r;
        }
 
@@ -175,15 +180,15 @@ class Addon
        {
                $a = get_app();
                $a->hooks = [];
-               $r = dba::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
+               $r = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
 
-               while ($rr = dba::fetch($r)) {
+               while ($rr = DBA::fetch($r)) {
                        if (! array_key_exists($rr['hook'], $a->hooks)) {
                                $a->hooks[$rr['hook']] = [];
                        }
                        $a->hooks[$rr['hook']][] = [$rr['file'],$rr['function']];
                }
-               dba::close($r);
+               DBA::close($r);
        }
 
        /**
@@ -200,7 +205,7 @@ class Addon
 
                if (is_array($a->hooks) && array_key_exists($name, $a->hooks)) {
                        foreach ($a->hooks[$name] as $hook) {
-                               Worker::add($priority, 'ForkHook', $name, json_encode($hook), json_encode($data));
+                               Worker::add($priority, 'ForkHook', $name, $hook, $data);
                        }
                }
        }
@@ -228,14 +233,15 @@ class Addon
        /**
         * @brief Calls a single hook.
         *
-        * @param string $name of the hook to call
-        * @param array $hook Hook data
-        * @param string|array &$data to transmit to the callback handler
+        * @param App $a
+        * @param string         $name of the hook to call
+        * @param array          $hook Hook data
+        * @param string|array   &$data to transmit to the callback handler
         */
-       public static function callSingleHook($a, $name, $hook, &$data = null)
+       public static function callSingleHook(App $a, $name, $hook, &$data = null)
        {
                // 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) {
+               if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
                        return;
                }
 
@@ -246,7 +252,7 @@ class Addon
                } else {
                        // remove orphan hooks
                        $condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
-                       dba::delete('hook', $condition);
+                       DBA::delete('hook', $condition, ['cascade' => false]);
                }
        }
 
@@ -313,7 +319,12 @@ class Addon
                        foreach ($ll as $l) {
                                $l = trim($l, "\t\n\r */");
                                if ($l != "") {
-                                       list($type, $v) = array_map("trim", explode(":", $l, 2));
+                                       $addon_info = array_map("trim", explode(":", $l, 2));
+                                       if (count($addon_info) < 2) {
+                                               continue;
+                                       }
+
+                                       list($type, $v) = $addon_info;
                                        $type = strtolower($type);
                                        if ($type == "author" || $type == "maintainer") {
                                                $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m);