From 4dd986a2db3cfa3bf38ccb0b6bdaff04f3891792 Mon Sep 17 00:00:00 2001 From: nobody Date: Sat, 12 Feb 2022 00:50:48 -0800 Subject: [PATCH] This checkin is surely broken, but I need to commit it because it represents a fair bit of work. --- Zotlabs/Access/PermissionLimits.php | 3 +- Zotlabs/Access/PermissionRoles.php | 7 +- Zotlabs/Access/Permissions.php | 5 +- Zotlabs/Daemon/Addon.php | 4 +- Zotlabs/Daemon/Cron_daily.php | 3 +- Zotlabs/Daemon/Cron_weekly.php | 3 +- Zotlabs/Daemon/Cronhooks.php | 3 +- Zotlabs/Daemon/Deliver_hooks.php | 4 +- Zotlabs/Daemon/Notifier.php | 11 +- Zotlabs/Daemon/Run.php | 6 +- Zotlabs/Daemon/Thumbnail.php | 4 +- Zotlabs/Extend/Hook.php | 100 ++++++ Zotlabs/Import/Friendica.php | 3 +- Zotlabs/Lib/Account.php | 9 +- Zotlabs/Lib/Activity.php | 13 +- Zotlabs/Lib/Addon.php | 285 ++++++++++++++++++ Zotlabs/Lib/Apps.php | 20 +- Zotlabs/Lib/Channel.php | 19 +- Zotlabs/Lib/Chatroom.php | 3 +- Zotlabs/Lib/Connect.php | 3 +- Zotlabs/Lib/Crypto.php | 9 +- Zotlabs/Lib/DReport.php | 4 +- Zotlabs/Lib/Enotify.php | 11 +- Zotlabs/Lib/Features.php | 5 +- Zotlabs/Lib/Head.php | 209 +++++++++++++ Zotlabs/Lib/Infocon.php | 76 +++++ Zotlabs/Lib/Libprofile.php | 5 +- Zotlabs/Lib/Libsync.php | 3 +- Zotlabs/Lib/Libzot.php | 27 +- Zotlabs/Lib/Libzotdir.php | 5 +- Zotlabs/Lib/Markdown.php | 9 +- Zotlabs/Lib/Navbar.php | 10 +- Zotlabs/Lib/Oembed.php | 5 +- Zotlabs/Lib/Permcat.php | 3 +- Zotlabs/Lib/Queue.php | 3 +- Zotlabs/Lib/ServiceClass.php | 5 +- Zotlabs/Lib/Share.php | 3 +- Zotlabs/Lib/System.php | 3 +- Zotlabs/Lib/ThreadItem.php | 7 +- Zotlabs/Module/Admin.php | 16 +- Zotlabs/Module/Admin/Addons.php | 25 +- Zotlabs/Module/Admin/Channels.php | 3 +- Zotlabs/Module/Admin/Cover_photo.php | 3 +- Zotlabs/Module/Admin/Profile_photo.php | 3 +- Zotlabs/Module/Affinity.php | 5 +- Zotlabs/Module/Api.php | 3 +- Zotlabs/Module/Channel.php | 3 +- Zotlabs/Module/Chatsvc.php | 3 +- Zotlabs/Module/Connect.php | 3 +- Zotlabs/Module/Connedit.php | 9 +- Zotlabs/Module/Cover_photo.php | 3 +- Zotlabs/Module/Defperms.php | 3 +- Zotlabs/Module/Directory.php | 3 +- Zotlabs/Module/Display.php | 9 +- Zotlabs/Module/Home.php | 5 +- Zotlabs/Module/Hostxrd.php | 3 +- Zotlabs/Module/Import.php | 5 +- Zotlabs/Module/Item.php | 9 +- Zotlabs/Module/Like.php | 5 +- Zotlabs/Module/Linkinfo.php | 3 +- Zotlabs/Module/Magic.php | 3 +- Zotlabs/Module/Mood.php | 3 +- Zotlabs/Module/Notify.php | 3 +- Zotlabs/Module/Pdledit.php | 5 +- Zotlabs/Module/Photo.php | 3 +- Zotlabs/Module/Photos.php | 3 +- Zotlabs/Module/Ping.php | 3 +- Zotlabs/Module/Plike.php | 5 +- Zotlabs/Module/Profile.php | 3 +- Zotlabs/Module/Profile_photo.php | 3 +- Zotlabs/Module/Profiles.php | 19 +- Zotlabs/Module/Rmagic.php | 3 +- Zotlabs/Module/Rpost.php | 5 +- Zotlabs/Module/Settings/Account.php | 5 +- Zotlabs/Module/Settings/Channel.php | 7 +- Zotlabs/Module/Settings/Display.php | 5 +- Zotlabs/Module/Settings/Featured.php | 5 +- Zotlabs/Module/Share.php | 3 +- Zotlabs/Module/Siteinfo.php | 5 +- Zotlabs/Module/Stream.php | 5 +- Zotlabs/Module/Subthread.php | 3 +- Zotlabs/Module/Wall_attach.php | 5 +- Zotlabs/Module/Webfinger.php | 3 +- Zotlabs/Module/Well_known.php | 3 +- Zotlabs/Render/Comanche.php | 6 +- Zotlabs/Render/SimpleTemplate.php | 2 +- Zotlabs/Render/SmartyTemplate.php | 4 +- Zotlabs/Render/Theme.php | 45 +++ Zotlabs/Storage/Browser.php | 3 +- Zotlabs/Web/Router.php | 16 +- Zotlabs/Web/Session.php | 9 +- Zotlabs/Web/WebServer.php | 5 +- Zotlabs/Widget/Activity.php | 3 +- Zotlabs/Widget/Activity_filter.php | 3 +- Zotlabs/Widget/Admin.php | 5 +- Zotlabs/Widget/Affinity.php | 5 +- Zotlabs/Widget/Stream_order.php | 3 +- boot.php | 39 ++- include/addon.php | 8 +- include/api.php | 3 +- include/api_auth.php | 5 +- include/attach.php | 21 +- include/auth.php | 7 +- include/bbcode.php | 5 +- include/connections.php | 5 +- include/conversation.php | 27 +- include/dba/dba_pdo.php | 18 +- include/event.php | 7 +- include/feedutils.php | 13 +- include/html2bbcode.php | 5 +- include/items.php | 35 +-- include/language.php | 3 +- include/network.php | 17 +- include/permissions.php | 9 +- include/photos.php | 13 +- include/security.php | 7 +- include/taxonomy.php | 3 +- include/text.php | 33 +- include/zid.php | 9 +- tests/unit/Access/PermissionLimitsTest.php | 3 +- tests/unit/Access/PermissionRolesTest.php | 3 +- tests/unit/Access/PermissionsTest.php | 11 +- util/addons | 44 +-- .../src/generate_hooks_index/core.clj | 4 +- util/genhook | 2 +- 125 files changed, 1213 insertions(+), 399 deletions(-) create mode 100644 Zotlabs/Lib/Addon.php create mode 100644 Zotlabs/Lib/Head.php create mode 100644 Zotlabs/Lib/Infocon.php diff --git a/Zotlabs/Access/PermissionLimits.php b/Zotlabs/Access/PermissionLimits.php index 1ad259d95..a47621e5d 100644 --- a/Zotlabs/Access/PermissionLimits.php +++ b/Zotlabs/Access/PermissionLimits.php @@ -4,6 +4,7 @@ namespace Zotlabs\Access; use App; use Zotlabs\Lib\PConfig; +use Zotlabs\Extend\Hook; /** * @brief Permission limits. @@ -92,7 +93,7 @@ class PermissionLimits $x = PConfig::Get($channel_id, 'perm_limits', $perm); if ($x === false) { $a = [ 'channel_id' => $channel_id, 'permission' => $perm, 'value' => $x ]; - call_hooks('permission_limits_get', $a); + Hook::call('permission_limits_get', $a); return intval($a['value']); } return intval($x); diff --git a/Zotlabs/Access/PermissionRoles.php b/Zotlabs/Access/PermissionRoles.php index 901dfbd7a..03c1fdd04 100644 --- a/Zotlabs/Access/PermissionRoles.php +++ b/Zotlabs/Access/PermissionRoles.php @@ -2,6 +2,9 @@ namespace Zotlabs\Access; +use Zotlabs\Extend\Hook; + + /** * @brief PermissionRoles class. * @@ -115,7 +118,7 @@ class PermissionRoles */ $x = ['role' => $role, 'result' => $ret]; - call_hooks('get_role_perms', $x); + Hook::call('get_role_perms', $x); return $x['result']; } @@ -144,7 +147,7 @@ class PermissionRoles ], ]; - call_hooks('list_permission_roles', $roles); + Hook::call('list_permission_roles', $roles); return $roles; } diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index 019cd0166..8631f070f 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -4,6 +4,7 @@ namespace Zotlabs\Access; use Zotlabs\Lib as Zlib; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; /** * @brief Extensible permissions. @@ -80,7 +81,7 @@ class Permissions * * \e array \b permissions * * \e string \b filter */ - call_hooks('permissions_list', $x); + Hook::call('permissions_list', $x); return($x['permissions']); } @@ -108,7 +109,7 @@ class Permissions * @hooks write_perms * * \e array \b permissions */ - call_hooks('write_perms', $x); + Hook::call('write_perms', $x); return($x['permissions']); } diff --git a/Zotlabs/Daemon/Addon.php b/Zotlabs/Daemon/Addon.php index 97c473e53..64d550adf 100644 --- a/Zotlabs/Daemon/Addon.php +++ b/Zotlabs/Daemon/Addon.php @@ -2,12 +2,14 @@ namespace Zotlabs\Daemon; +use Zotlabs\Extend\Hook; + class Addon { public static function run($argc, $argv) { - call_hooks('daemon_addon', $argv); + Hook::call('daemon_addon', $argv); } } diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php index c01f05251..83f75b996 100644 --- a/Zotlabs/Daemon/Cron_daily.php +++ b/Zotlabs/Daemon/Cron_daily.php @@ -6,6 +6,7 @@ use Zotlabs\Lib\ServiceClass; use Zotlabs\Lib\Libzotdir; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Statistics; +use Zotlabs\Extend\Hook; class Cron_daily { @@ -105,7 +106,7 @@ class Cron_daily remove_obsolete_hublocs(); - call_hooks('cron_daily', datetime_convert()); + Hook::call('cron_daily', datetime_convert()); set_config('system', 'last_expire_day', intval(datetime_convert('UTC', 'UTC', 'now', 'd'))); diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php index 91998e181..afea4cd07 100644 --- a/Zotlabs/Daemon/Cron_weekly.php +++ b/Zotlabs/Daemon/Cron_weekly.php @@ -3,6 +3,7 @@ namespace Zotlabs\Daemon; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class Cron_weekly { @@ -17,7 +18,7 @@ class Cron_weekly * */ - call_hooks('cron_weekly', datetime_convert()); + Hook::call('cron_weekly', datetime_convert()); z_check_cert(); diff --git a/Zotlabs/Daemon/Cronhooks.php b/Zotlabs/Daemon/Cronhooks.php index 44d9f159e..242f69981 100644 --- a/Zotlabs/Daemon/Cronhooks.php +++ b/Zotlabs/Daemon/Cronhooks.php @@ -3,6 +3,7 @@ /** @file */ namespace Zotlabs\Daemon; +use Zotlabs\Extend\Hook; class Cronhooks { @@ -14,7 +15,7 @@ class Cronhooks $d = datetime_convert(); - call_hooks('cron', $d); + Hook::call('cron', $d); return; } diff --git a/Zotlabs/Daemon/Deliver_hooks.php b/Zotlabs/Daemon/Deliver_hooks.php index 1693ac37b..9bf5db099 100644 --- a/Zotlabs/Daemon/Deliver_hooks.php +++ b/Zotlabs/Daemon/Deliver_hooks.php @@ -2,6 +2,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Extend\Hook; + class Deliver_hooks { @@ -18,7 +20,7 @@ class Deliver_hooks intval($argv[1]) ); if ($r) { - call_hooks('notifier_normal', $r[0]); + Hook::call('notifier_normal', $r[0]); } } } diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 06e6745e9..5ca85b705 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\ActivityPub; use Zotlabs\Lib\LDSignatures; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/html2plain.php'); require_once('include/conversation.php'); @@ -178,7 +179,7 @@ class Notifier break; } if (! $perm_update['success']) { - call_hooks($cmd, $perm_update); + Hook::call($cmd, $perm_update); } if ($perm_update['success']) { @@ -278,7 +279,7 @@ class Notifier 'deliver' => false ]; - call_hooks('customitem_deliver', $hookinfo); + Hook::call('customitem_deliver', $hookinfo); } if (! $hookinfo['deliver']) { @@ -552,7 +553,7 @@ class Notifier 'queued' => [] ]; - call_hooks('notifier_process', $narr); + Hook::call('notifier_process', $narr); if ($narr['queued']) { foreach ($narr['queued'] as $pq) { self::$deliveries[] = $pq; @@ -690,7 +691,7 @@ class Notifier ActivityPub::notifier_process($narr); - call_hooks('notifier_hub', $narr); + Hook::call('notifier_hub', $narr); if ($narr['queued']) { foreach ($narr['queued'] as $pq) { self::$deliveries[] = $pq; @@ -807,7 +808,7 @@ class Notifier } } - call_hooks('notifier_end', $target_item); + Hook::call('notifier_end', $target_item); logger('notifer: complete.'); return; diff --git a/Zotlabs/Daemon/Run.php b/Zotlabs/Daemon/Run.php index 86245852a..484fa8bb5 100644 --- a/Zotlabs/Daemon/Run.php +++ b/Zotlabs/Daemon/Run.php @@ -2,6 +2,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Extend\Hook; + if (array_search(__file__, get_included_files()) === 0) { require_once('include/cli_startup.php'); array_shift($argv); @@ -38,7 +40,7 @@ class Run 'long_running' => self::$long_running ]; - call_hooks('daemon_summon', $hookinfo); + Hook::call('daemon_summon', $hookinfo); $arr = $hookinfo['argv']; $argc = count($arr); @@ -60,7 +62,7 @@ class Run 'long_running' => self::$long_running ]; - call_hooks('daemon_release', $hookinfo); + Hook::call('daemon_release', $hookinfo); $argv = $hookinfo['argv']; $argc = count($argv); diff --git a/Zotlabs/Daemon/Thumbnail.php b/Zotlabs/Daemon/Thumbnail.php index dfc00f3db..25bd3790f 100644 --- a/Zotlabs/Daemon/Thumbnail.php +++ b/Zotlabs/Daemon/Thumbnail.php @@ -4,6 +4,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Extend\Hook; + class Thumbnail { @@ -46,7 +48,7 @@ class Thumbnail * * \e string \b thumbnail */ - call_hooks('thumbnail', $p); + Hook::call('thumbnail', $p); if ($p['thumbnail']) { return; } diff --git a/Zotlabs/Extend/Hook.php b/Zotlabs/Extend/Hook.php index 2f95aa65c..1977ea028 100644 --- a/Zotlabs/Extend/Hook.php +++ b/Zotlabs/Extend/Hook.php @@ -133,4 +133,104 @@ class Hook App::$hooks[$hook][] = [ '', $fn, $priority, $version ]; } + + + /** + * @brief loads all active hooks into memory + * alters: App::$hooks + * Called during initialisation + * Duplicated hooks are removed and the duplicates ignored + * + * It might not be obvious but themes can manually add hooks to the App::$hooks + * array in their theme_init() and use this to customise the app behaviour. + * use insert_hook($hookname,$function_name) to do this. + */ + + + public static function load() + { + + App::$hooks = []; + + $r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC"); + if ($r) { + foreach ($r as $rv) { + $duplicated = false; + if (! array_key_exists($rv['hook'], App::$hooks)) { + App::$hooks[$rv['hook']] = []; + } else { + foreach (App::$hooks[$rv['hook']] as $h) { + if ($h[0] === $rv['file'] && $h[1] === $rv['fn']) { + $duplicated = true; + q( + "delete from hook where id = %d", + intval($rv['id']) + ); + logger('duplicate hook ' . $h[1] . ' removed'); + } + } + } + if (! $duplicated) { + App::$hooks[$rv['hook']][] = [ $rv['file'], $rv['fn'], $rv['priority'], $rv['hook_version']]; + } + } + } + // logger('hooks: ' . print_r(App::$hooks,true)); + } + + /** + * @brief Calls a hook. + * + * Use this function when you want to be able to allow a hook to manipulate + * the provided data. + * + * @param string $name of the hook to call + * @param[in,out] string|array &$data to transmit to the callback handler + */ + static public function call($name, &$data = null) + { + $a = 0; + + if (isset(App::$hooks[$name])) { + foreach (App::$hooks[$name] as $hook) { + $origfn = $hook[1]; + if ($hook[0]) { + @include_once($hook[0]); + } + if (preg_match('|^a:[0-9]+:{.*}$|s', $hook[1])) { + $hook[1] = unserialize($hook[1]); + } elseif (strpos($hook[1], '::')) { + // We shouldn't need to do this, but it appears that PHP + // isn't able to directly execute a string variable with a class + // method in the manner we are attempting it, so we'll + // turn it into an array. + $hook[1] = explode('::', $hook[1]); + } + + if (is_callable($hook[1])) { + $func = $hook[1]; + if ($hook[3]) { + $func($data); + } else { + $func($a, $data); + } + } else { + // Don't do any DB write calls if we're currently logging a possibly failed DB call. + if (! DBA::$logging) { + // The hook should be removed so we don't process it. + q( + "DELETE FROM hook WHERE hook = '%s' AND file = '%s' AND fn = '%s'", + dbesc($name), + dbesc($hook[0]), + dbesc($origfn) + ); + } + } + } + } + } + + + + } diff --git a/Zotlabs/Import/Friendica.php b/Zotlabs/Import/Friendica.php index 3fe383012..6118363fe 100644 --- a/Zotlabs/Import/Friendica.php +++ b/Zotlabs/Import/Friendica.php @@ -13,6 +13,7 @@ use Zotlabs\Access\PermissionLimits; use Zotlabs\Access\PermissionRoles; use Zotlabs\Access\Permissions; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; class Friendica { @@ -295,7 +296,7 @@ class Friendica } } - call_hooks('create_identity', $newuid); + Hook::call('create_identity', $newuid); } $this->groups = ((isset($this->data['group'])) ? $this->data['group'] : null); diff --git a/Zotlabs/Lib/Account.php b/Zotlabs/Lib/Account.php index 630eaf7d2..9e36fb1ec 100644 --- a/Zotlabs/Lib/Account.php +++ b/Zotlabs/Lib/Account.php @@ -11,6 +11,7 @@ use App; use Zotlabs\Lib\Crypto; use Zotlabs\Lib\System; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class Account { @@ -45,7 +46,7 @@ class Account { } $arr = array('email' => $email, 'result' => $result); - call_hooks('check_account_email', $arr); + Hook::call('check_account_email', $arr); return $arr['result']; } @@ -59,7 +60,7 @@ class Account { // Use hooked functions to perform complexity requirement checks. $arr = [ 'password' => $password, 'result' => $result ]; - call_hooks('check_account_password', $arr); + Hook::call('check_account_password', $arr); return $arr['result']; } @@ -84,7 +85,7 @@ class Account { } $arr = [ 'invite_code' => $invite_code, 'result' => $result ]; - call_hooks('check_account_invite', $arr); + Hook::call('check_account_invite', $arr); return $arr['result']; } @@ -255,7 +256,7 @@ class Account { $result['email'] = $email; $result['password'] = $password; - call_hooks('register_account', $result); + Hook::call('register_account', $result); return $result; } diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 74fc11d3a..dc66e7578 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -18,6 +18,7 @@ use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Nodeinfo; use Zotlabs\Lib\System; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; use Emoji; require_once('include/html2bbcode.php'); @@ -68,7 +69,7 @@ class Activity return self::fetch_thing($x); } - call_hooks('encode_object', $x); + Hook::call('encode_object', $x); return $x; } @@ -1732,7 +1733,7 @@ class Activity } $arr = ['xchan' => $p, 'encoded' => $ret, 'activitypub' => $activitypub]; - call_hooks('encode_person', $arr); + Hook::call('encode_person', $arr); $ret = $arr['encoded']; @@ -1813,7 +1814,7 @@ class Activity 'http://activitystrea.ms/schema/1.0/unfollow' => 'Ignore', ]; - call_hooks('activity_mapper', $acts); + Hook::call('activity_mapper', $acts); if (array_key_exists($verb, $acts) && $acts[$verb]) { return $acts[$verb]; @@ -1863,7 +1864,7 @@ class Activity ]; - call_hooks('activity_obj_mapper', $objs); + Hook::call('activity_obj_mapper', $objs); if ($obj === 'Answer') { return 'Note'; @@ -3358,7 +3359,7 @@ class Activity 's' => $s ]; - call_hooks('decode_note', $hookinfo); + Hook::call('decode_note', $hookinfo); $s = $hookinfo['s']; @@ -3956,7 +3957,7 @@ class Activity 'item' => $item ]; - call_hooks('fetch_and_store', $hookinfo); + Hook::call('fetch_and_store', $hookinfo); $item = $hookinfo['item']; diff --git a/Zotlabs/Lib/Addon.php b/Zotlabs/Lib/Addon.php new file mode 100644 index 000000000..e71eba3ad --- /dev/null +++ b/Zotlabs/Lib/Addon.php @@ -0,0 +1,285 @@ +getMessage()); + } + } + } + + /** + * @brief Uninstalls an addon. + * + * @param string $addon name of the addon + * @return bool + */ + public static function uninstall($addon) + { + + self::unload($addon); + + if (! file_exists('addon/' . $addon . '/' . $addon . '.php')) { + q( + "DELETE FROM addon WHERE aname = '%s' ", + dbesc($addon) + ); + return false; + } + + logger("Addons: uninstalling " . $addon); + //$t = @filemtime('addon/' . $addon . '/' . $addon . '.php'); + @include_once('addon/' . $addon . '/' . $addon . '.php'); + if (function_exists($addon . '_uninstall')) { + $func = $addon . '_uninstall'; + try { + $func(); + } catch (Exception $e) { + self::ErrorHandler($addon, "Unable to uninstall.", "Unable to run _uninstall : ".$e->getMessage()); + } + } + + q( + "DELETE FROM addon WHERE aname = '%s' ", + dbesc($addon) + ); + } + + /** + * @brief Installs an addon. + * + * This function is called once to install the addon (either from the cli or via + * the web admin). This will also call load_plugin() once. + * + * @param string $addon name of the addon + * @return bool + */ + public static function install($addon) + { + if (! file_exists('addon/' . $addon . '/' . $addon . '.php')) { + return false; + } + + logger("Addons: installing " . $addon); + $t = @filemtime('addon/' . $addon . '/' . $addon . '.php'); + @include_once('addon/' . $addon . '/' . $addon . '.php'); + if (function_exists($addon . '_install')) { + $func = $addon . '_install'; + try { + $func(); + } catch (Exception $e) { + self::ErrorHandler($addon, "Install failed.", "Install failed : ".$e->getMessage()); + return; + } + } + + $addon_admin = (function_exists($addon . '_plugin_admin') ? 1 : 0); + + $d = q( + "select * from addon where aname = '%s' limit 1", + dbesc($addon) + ); + if (! $d) { + q( + "INSERT INTO addon (aname, installed, tstamp, plugin_admin) VALUES ( '%s', 1, %d , %d ) ", + dbesc($addon), + intval($t), + $addon_admin + ); + } + + self::load($addon); + } + + /** + * @brief loads an addon by it's name. + * + * @param string $addon name of the addon + * @return bool + */ + public static function load($addon) + { + // silently fail if plugin was removed + if (! file_exists('addon/' . $addon . '/' . $addon . '.php')) { + return false; + } + + logger("Addons: loading " . $addon, LOGGER_DEBUG); + //$t = @filemtime('addon/' . $addon . '/' . $addon . '.php'); + @include_once('addon/' . $addon . '/' . $addon . '.php'); + if (function_exists($addon . '_load')) { + $func = $addon . '_load'; + try { + $func(); + } catch (Exception $e) { + self::ErrorHandler($addon, "Unable to load.", "FAILED loading : ".$e->getMessage(), true); + return; + } + + // we can add the following with the previous SQL + // once most site tables have been updated. + // This way the system won't fall over dead during the update. + + if (file_exists('addon/' . $addon . '/.hidden')) { + q( + "update addon set hidden = 1 where name = '%s'", + dbesc($addon) + ); + } + return true; + } else { + logger("Addons: FAILED loading " . $addon . " (missing _load function)"); + return false; + } + } + + /** + * @brief Check if addon is installed. + * + * @param string $name + * @return bool + */ + + public static function is_installed($name) + { + $r = q( + "select aname from addon where aname = '%s' and installed = 1 limit 1", + dbesc($name) + ); + if ($r) { + return true; + } + + return false; + } + + + /** + * @brief Reload all updated plugins. + */ + public static function reload_all() + { + $addons = get_config('system', 'addon'); + if (strlen($addons)) { + $r = q("SELECT * FROM addon WHERE installed = 1"); + if (count($r)) { + $installed = $r; + } else { + $installed = []; + } + + $parr = explode(',', $addons); + + if (count($parr)) { + foreach ($parr as $pl) { + $pl = trim($pl); + + $fname = 'addon/' . $pl . '/' . $pl . '.php'; + + if (file_exists($fname)) { + $t = @filemtime($fname); + foreach ($installed as $i) { + if (($i['aname'] == $pl) && ($i['tstamp'] != $t)) { + logger('Reloading plugin: ' . $i['aname']); + @include_once($fname); + + if (function_exists($pl . '_unload')) { + $func = $pl . '_unload'; + try { + $func(); + } catch (Exception $e) { + self::ErrorHandler($addon, "", "UNLOAD FAILED (uninstalling) : ".$e->getMessage(), true); + continue; + } + } + if (function_exists($pl . '_load')) { + $func = $pl . '_load'; + try { + $func(); + } catch (Exception $e) { + self::ErrorHandler($addon, "", "LOAD FAILED (uninstalling): ".$e->getMessage(), true); + continue; + } + } + q( + "UPDATE addon SET tstamp = %d WHERE id = %d", + intval($t), + intval($i['id']) + ); + } + } + } + } + } + } + } + + + public static function list_installed() + { + + $r = q("select * from addon where installed = 1 order by aname asc"); + return(($r) ? ids_to_array($r, 'aname') : []); + } + + + /** + * @brief Get a list of non hidden addons. + * + * @return array + */ + public static function list_visible() + { + + $r = q("select * from addon where hidden = 0 order by aname asc"); + $x = (($r) ? ids_to_array($r, 'aname') : []); + $y = []; + if ($x) { + foreach ($x as $xv) { + if (is_dir('addon/' . $xv)) { + $y[] = $xv; + } + } + } + return $y; + } + + +} \ No newline at end of file diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 4ee7c2940..8c4fe9e19 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -6,6 +6,8 @@ use App; use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Channel; use Zotlabs\Lib\Features; +use Zotlabs\Extend\Hook; +use Zotlabs\Lib\Addon; /** * Apps @@ -42,7 +44,7 @@ class Apps foreach ($files as $f) { $path = explode('/', $f); $plugin = trim($path[1]); - if (addon_is_installed($plugin)) { + if (Addon::is_installed($plugin)) { $x = self::parse_app_description($f, $translate); if ($x) { $x['plugin'] = $plugin; @@ -52,7 +54,7 @@ class Apps } } - call_hooks('get_system_apps', $ret); + Hook::call('get_system_apps', $ret); return $ret; } @@ -92,7 +94,7 @@ class Apps } $x = get_config('system', 'base_apps', $default_apps); - call_hooks('get_base_apps', $x); + Hook::call('get_base_apps', $x); return $x; } @@ -464,7 +466,7 @@ class Apps self::translate_system_apps($papp); - if (isset($papp['plugin']) && trim($papp['plugin']) && (!addon_is_installed(trim($papp['plugin'])))) { + if (isset($papp['plugin']) && trim($papp['plugin']) && (!Addon::is_installed(trim($papp['plugin'])))) { return ''; } @@ -740,7 +742,7 @@ class Apps intval(TERM_OBJ_APP), intval($x[0]['id']) ); - call_hooks('app_destroy', $x[0]); + Hook::call('app_destroy', $x[0]); } else { $r = q( "update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", @@ -825,7 +827,7 @@ class Apps 'app' => $app, 'installed' => $r ]; - call_hooks('app_installed_filter', $filter_arr); + Hook::call('app_installed_filter', $filter_arr); $r = $filter_arr['installed']; } @@ -846,7 +848,7 @@ class Apps 'app' => $app, 'installed' => $r ]; - call_hooks('addon_app_installed_filter', $filter_arr); + Hook::call('addon_app_installed_filter', $filter_arr); $r = $filter_arr['installed']; } @@ -867,7 +869,7 @@ class Apps 'app' => $app, 'installed' => $r ]; - call_hooks('system_app_installed_filter', $filter_arr); + Hook::call('system_app_installed_filter', $filter_arr); $r = $filter_arr['installed']; } @@ -911,7 +913,7 @@ class Apps if ($r) { $hookinfo = ['uid' => $uid, 'deleted' => $deleted, 'cats' => $cats, 'apps' => $r]; - call_hooks('app_list', $hookinfo); + Hook::call('app_list', $hookinfo); $r = $hookinfo['apps']; for ($x = 0; $x < count($r); $x++) { if (!$r[$x]['app_system']) { diff --git a/Zotlabs/Lib/Channel.php b/Zotlabs/Lib/Channel.php index 1ae1fa6bc..ea90b7298 100644 --- a/Zotlabs/Lib/Channel.php +++ b/Zotlabs/Lib/Channel.php @@ -20,6 +20,7 @@ use Zotlabs\Daemon\Run; use Zotlabs\Lib\System; use Zotlabs\Render\Comanche; use Zotlabs\Lib\ServiceClass; +use Zotlabs\Extend\Hook; require_once('include/photo_factory.php'); @@ -60,7 +61,7 @@ class Channel * * \e string \b name * * \e string \b message - return error message */ - call_hooks('validate_channelname', $arr); + Hook::call('validate_channelname', $arr); if (x($arr, 'message')) { return $arr['message']; @@ -360,7 +361,7 @@ class Channel * * \e array \b channel * * \e string \b photo_url - Return value */ - call_hooks('create_channel_photo', $z); + Hook::call('create_channel_photo', $z); // The site channel gets the project logo as a profile photo. if ($arr['account_id'] === 'xxx') { @@ -558,7 +559,7 @@ class Channel * * \e int - The UID of the created identity */ - call_hooks('create_identity', $newuid); + Hook::call('create_identity', $newuid); Run::Summon([ 'Directory', $ret['channel']['channel_id'] ]); } @@ -851,7 +852,7 @@ class Channel * Called to get the default list of functional data groups to export in Channel::basic_export(). * * \e array \b sections - return value */ - call_hooks('get_default_export_sections', $cb); + Hook::call('get_default_export_sections', $cb); return $cb['sections']; } @@ -1152,7 +1153,7 @@ class Channel * * \e array \b sections * * \e array \b data - The data will get returned */ - call_hooks('identity_basic_export', $addon); + Hook::call('identity_basic_export', $addon); $ret = $addon['data']; return $ret; @@ -1364,7 +1365,7 @@ class Channel * * \e string \b zid - their zid * * \e string \b url - the destination url */ - call_hooks('zid_init', $arr); + Hook::call('zid_init', $arr); if (! local_channel()) { $r = q( @@ -1472,7 +1473,7 @@ class Channel if (! is_dir('images/default_profile_photos/' . $scheme)) { $x = [ 'scheme' => $scheme, 'size' => $size, 'url' => '' ]; - call_hooks('default_profile_photo', $x); + Hook::call('default_profile_photo', $x); if ($x['url']) { return $x['url']; } else { @@ -2252,7 +2253,7 @@ class Channel * * \e array with entry from channel tabel for $channel_id */ - call_hooks('channel_remove', $channel); + Hook::call('channel_remove', $channel); $r = q( "select iid from iconfig left join item on item.id = iconfig.iid @@ -2428,7 +2429,7 @@ class Channel * * \e string \b xchan - return value * * \e string|int \b success - Must be a number, so xchan return value gets used */ - call_hooks('anon_identity_init', $x); + Hook::call('anon_identity_init', $x); if ($x['success'] !== 'unset' && intval($x['success']) && $x['xchan']) { return $x['xchan']; diff --git a/Zotlabs/Lib/Chatroom.php b/Zotlabs/Lib/Chatroom.php index 7e2ebdbdd..a82da7910 100644 --- a/Zotlabs/Lib/Chatroom.php +++ b/Zotlabs/Lib/Chatroom.php @@ -4,6 +4,7 @@ namespace Zotlabs\Lib; use Zotlabs\Lib\Libsync; use Zotlabs\Lib\ServiceClass; +use Zotlabs\Extend\Hook; /** * @brief A class with chatroom related static methods. @@ -297,7 +298,7 @@ class Chatroom * * \e string \b chat_xchan * * \e string \b chat_text */ - call_hooks('chat_message', $arr); + Hook::call('chat_message', $arr); $x = q( "insert into chat ( chat_room, chat_xchan, created, chat_text ) diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index 46229e4f4..e14eaee64 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -6,6 +6,7 @@ use App; use Zotlabs\Lib\ServiceClass; use Zotlabs\Access\Permissions; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; class Connect { @@ -293,7 +294,7 @@ class Connect $arr = ['channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook']]; - call_hooks('follow', $arr); + Hook::call('follow', $arr); /** If there is a default group for this channel, add this connection to it */ diff --git a/Zotlabs/Lib/Crypto.php b/Zotlabs/Lib/Crypto.php index b08c967e4..edf69f9f3 100644 --- a/Zotlabs/Lib/Crypto.php +++ b/Zotlabs/Lib/Crypto.php @@ -3,6 +3,7 @@ namespace Zotlabs\Lib; use Exception; +use Zotlabs\Extend\Hook; class Crypto { @@ -26,7 +27,7 @@ class Crypto $ret[] = $ossl[0] . '.oaep'; } - call_hooks('crypto_methods', $ret); + Hook::call('crypto_methods', $ret); return $ret; } @@ -35,7 +36,7 @@ class Crypto { $ret = [ 'sha256' ]; - call_hooks('signing_methods', $ret); + Hook::call('signing_methods', $ret); return $ret; } @@ -162,7 +163,7 @@ class Crypto return $result; } else { $x = [ 'data' => $data, 'pubkey' => $pubkey, 'alg' => $alg, 'result' => $data ]; - call_hooks('crypto_encapsulate', $x); + Hook::call('crypto_encapsulate', $x); return $x['result']; } } @@ -206,7 +207,7 @@ class Crypto return openssl_decrypt(base64url_decode($data['data']), $method[1], substr($k, 0, $method[2]), OPENSSL_RAW_DATA, substr($i, 0, $method[3])); } else { $x = [ 'data' => $data, 'prvkey' => $prvkey, 'alg' => $data['alg'], 'result' => $data ]; - call_hooks('crypto_unencapsulate', $x); + Hook::call('crypto_unencapsulate', $x); return $x['result']; } } diff --git a/Zotlabs/Lib/DReport.php b/Zotlabs/Lib/DReport.php index d0330e098..908dabee7 100644 --- a/Zotlabs/Lib/DReport.php +++ b/Zotlabs/Lib/DReport.php @@ -2,6 +2,8 @@ namespace Zotlabs\Lib; +use Zotlabs\Extend\Hook; + class DReport { @@ -84,7 +86,7 @@ class DReport * * \e array */ - call_hooks('dreport_is_storable', $dr); + Hook::call('dreport_is_storable', $dr); // let plugins accept or reject - if neither, continue on if (array_key_exists('accept', $dr) && intval($dr['accept'])) { diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 7ebe0203b..c39235953 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -6,6 +6,7 @@ use App; use Zotlabs\Lib\LibBlock; use Zotlabs\Lib\System; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; /** * @brief File with functions and a class for generating system and email notifications. @@ -510,7 +511,7 @@ class Enotify 'recipient' => $recip ); - call_hooks('enotify', $h); + Hook::call('enotify', $h); $subject = $h['subject']; $preamble = $h['preamble']; @@ -568,7 +569,7 @@ class Enotify } } - call_hooks('enotify_store', $datarray); + Hook::call('enotify_store', $datarray); if ($datarray['abort']) { pop_lang(); @@ -718,7 +719,7 @@ class Enotify $datarray['headers'] = $additional_mail_header; $datarray['email_secure'] = false; - call_hooks('enotify_mail', $datarray); + Hook::call('enotify_mail', $datarray); // Default to private - don't disclose message contents over insecure channels (such as email) // Might be interesting to use GPG,PGP,S/MIME encryption instead @@ -849,7 +850,7 @@ class Enotify $params['sent'] = false; $params['result'] = false; - call_hooks('email_send', $params); + Hook::call('email_send', $params); if ($params['sent']) { logger("notification: enotify::send (addon) returns " . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG); @@ -972,7 +973,7 @@ class Enotify return []; } - call_hooks('enotify_format', $x); + Hook::call('enotify_format', $x); if (! $x['display']) { return []; } diff --git a/Zotlabs/Lib/Features.php b/Zotlabs/Lib/Features.php index 1231e6522..a21630323 100644 --- a/Zotlabs/Lib/Features.php +++ b/Zotlabs/Lib/Features.php @@ -3,6 +3,7 @@ namespace Zotlabs\Lib; use App; +use Zotlabs\Extend\Hook; class Features { @@ -21,7 +22,7 @@ class Features { } } $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x); - call_hooks('feature_enabled', $arr); + Hook::call('feature_enabled', $arr); return($arr['enabled']); } @@ -531,7 +532,7 @@ class Features { ]; $x = [ 'features' => $arr, ]; - call_hooks('get_features', $x); + Hook::call('get_features', $x); $arr = $x['features']; diff --git a/Zotlabs/Lib/Head.php b/Zotlabs/Lib/Head.php new file mode 100644 index 000000000..5d75daed5 --- /dev/null +++ b/Zotlabs/Lib/Head.php @@ -0,0 +1,209 @@ + + * + * @param string $src + * @param string $media change media attribute (default to 'screen') + */ + public static function add_css($src, $media = 'screen') + { + App::$css_sources[] = [ $src, $media ]; + } + + public static function remove_css($src, $media = 'screen') + { + + $index = array_search([$src, $media], App::$css_sources); + if ($index !== false) { + unset(App::$css_sources[$index]); + } + // re-index the array + App::$css_sources = array_values(App::$css_sources); + } + + public static function get_css() + { + $str = EMPTY_STR; + $sources = App::$css_sources; + if (is_array($sources) && $sources) { + foreach ($sources as $source) { + $str .= self::format_css_if_exists($source); + } + } + + return $str; + } + + public static function add_link($arr) + { + if ($arr) { + App::$linkrel[] = $arr; + } + } + + public static function get_links() + { + $str = ''; + $sources = App::$linkrel; + if (is_array($sources) && $sources) { + foreach ($sources as $source) { + if (is_array($source) && $source) { + $str .= ' $v) { + $str .= ' ' . $k . '="' . $v . '"'; + } + $str .= ' />' . "\r\n"; + } + } + } + + return $str; + } + + public static function format_css_if_exists($source) + { + + // script_path() returns https://yoursite.tld + + $path_prefix = self::script_path(); + + $script = $source[0]; + + if (strpos($script, '/') !== false) { + // The script is a path relative to the server root + $path = $script; + // If the url starts with // then it's an absolute URL + if (substr($script, 0, 2) === '//') { + $path_prefix = ''; + } + } else { + // It's a file from the theme + FIXME + $path = '/' . Theme::include($script); + } + + if ($path) { + $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; + return '' . "\r\n"; + } + } + + /** + * This basically calculates the baseurl. We have other functions to do that, but + * there was an issue with script paths and mixed-content whose details are arcane + * and perhaps lost in the message archives. The short answer is that we're ignoring + * the URL which we are "supposed" to use, and generating script paths relative to + * the URL which we are currently using; in order to ensure they are found and aren't + * blocked due to mixed content issues. + * + * @return string + */ + public static function script_path() + { + if (x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) { + $scheme = 'https'; + } elseif (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) { + $scheme = 'https'; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { + $scheme = 'https'; + } else { + $scheme = 'http'; + } + + // Some proxy setups may require using http_host + + if (isset(App::$config['system']['script_path_use_http_host']) && intval(App::$config['system']['script_path_use_http_host'])) { + $server_var = 'HTTP_HOST'; + } else { + $server_var = 'SERVER_NAME'; + } + + + if (x($_SERVER, $server_var)) { + $hostname = $_SERVER[$server_var]; + } else { + return z_root(); + } + + return $scheme . '://' . $hostname; + } + + public static function add_js($src, $priority = 0) + { + if (! (isset(App::$js_sources[$priority]) && is_array(App::$js_sources[$priority]))) { + App::$js_sources[$priority] = []; + } + App::$js_sources[$priority][] = $src; + } + + public static function remove_js($src, $priority = 0) + { + + $index = array_search($src, App::$js_sources[$priority]); + if ($index !== false) { + unset(App::$js_sources[$priority][$index]); + } + } + + /** + * We should probably try to register main.js with a high priority, but currently + * we handle it separately and put it at the end of the html head block in case + * any other javascript is added outside the head_add_js construct. + * + * @return string + */ + public static function get_js() + { + + $str = ''; + if (App::$js_sources) { + ksort(App::$js_sources, SORT_NUMERIC); + foreach (App::$js_sources as $sources) { + if (count($sources)) { + foreach ($sources as $source) { + if ($source === 'main.js') { + continue; + } + $str .= self::format_js_if_exists($source); + } + } + } + } + + return $str; + } + + public static function get_main_js() + { + return self::self::format_js_if_exists('main.js', true); + } + + public static function format_js_if_exists($source) + { + $path_prefix = self::script_path(); + + if (strpos($source, '/') !== false) { + // The source is a known path on the system + $path = $source; + // If the url starts with // then it's an absolute URL + if (substr($source, 0, 2) === '//') { + $path_prefix = ''; + } + } else { + // It's a file from the theme + $path = '/' . Theme::include($source); + } + if ($path) { + $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; + return '' . "\r\n" ; + } + } + +} \ No newline at end of file diff --git a/Zotlabs/Lib/Infocon.php b/Zotlabs/Lib/Infocon.php new file mode 100644 index 000000000..4e33d6bff --- /dev/null +++ b/Zotlabs/Lib/Infocon.php @@ -0,0 +1,76 @@ + false); $dirmode = intval(get_config('system', 'directory_mode')); @@ -1194,7 +1195,7 @@ class Libzot if (is_array($x) && array_key_exists('delivery_report', $x) && is_array($x['delivery_report'])) { foreach ($x['delivery_report'] as $xx) { - call_hooks('dreport_process', $xx); + Hook::call('dreport_process', $xx); if (is_array($xx) && array_key_exists('message_id', $xx) && DReport::is_storable($xx)) { q( "insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan, dreport_log ) values ( '%s', '%s', '%s','%s','%s','%s','%s','%s' ) ", @@ -2203,7 +2204,7 @@ class Libzot * Called when an item has been posted on this machine via mod/item.php (also via API). * * \e array with an item */ - call_hooks('post_local', $arr); + Hook::call('post_local', $arr); } $item_id = 0; @@ -2246,7 +2247,7 @@ class Libzot * * \e array \b sender * * \e array \b channel */ - call_hooks('activity_received', $parr); + Hook::call('activity_received', $parr); // don't add a source route if it's a relay or later recipients will get a route mismatch if (!$relay) { add_source_route($item_id, $sender); @@ -2785,7 +2786,7 @@ class Libzot * * \e array \b channel * * \e array \b locations */ - call_hooks('location_move', $arr); + Hook::call('location_move', $arr); } } @@ -3399,7 +3400,7 @@ class Libzot } $ret['site'] = self::site_info(); - call_hooks('zotinfo', $ret); + Hook::call('zotinfo', $ret); return ($ret); } @@ -3473,15 +3474,15 @@ class Libzot $ret['site']['admin'] = get_config('system', 'admin_email'); $visible_plugins = []; - if (is_array(App::$plugins) && count(App::$plugins)) { - $r = q("select * from addon where hidden = 0"); - if ($r) { - foreach ($r as $rr) { - $visible_plugins[] = $rr['aname']; - } + + $r = q("select * from addon where hidden = 0"); + if ($r) { + foreach ($r as $rr) { + $visible_plugins[] = $rr['aname']; } } + $ret['site']['about'] = bbcode(get_config('system', 'siteinfo'), ['export' => true]); $ret['site']['plugins'] = $visible_plugins; $ret['site']['sitehash'] = get_config('system', 'location_hash'); diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index cb2d54211..de253b3d5 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -7,6 +7,7 @@ use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Webfinger; use Zotlabs\Lib\Zotfinger; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/permissions.php'); @@ -245,7 +246,7 @@ class Libzotdir } $arr = ['channel_id' => $uid, 'hash' => $hash, 'profile' => $profile]; - call_hooks('local_dir_update', $arr); + Hook::call('local_dir_update', $arr); $address = Channel::get_webfinger($p[0]); @@ -436,7 +437,7 @@ class Libzotdir * * \e boolean \b update */ - call_hooks('import_directory_profile', $d); + Hook::call('import_directory_profile', $d); if (($d['update']) && (!$suppress_update)) { self::update_modtime($arr['xprof_hash'], new_uuid(), $addr, $ud_flags); diff --git a/Zotlabs/Lib/Markdown.php b/Zotlabs/Lib/Markdown.php index 41aaf6e1e..c48d8acad 100644 --- a/Zotlabs/Lib/Markdown.php +++ b/Zotlabs/Lib/Markdown.php @@ -11,6 +11,7 @@ use League\HTMLToMarkdown\HtmlConverter; use League\HTMLToMarkdown\Environment; use League\HTMLToMarkdown\Converter\ConverterInterface; use League\HTMLToMarkdown\ElementInterface; +use Zotlabs\Extend\Hook; require_once("include/event.php"); require_once("include/html2bbcode.php"); @@ -62,7 +63,7 @@ class Markdown * * \e boolean \b zrl * * \e array \b options */ - call_hooks('markdown_to_bb_init', $x); + Hook::call('markdown_to_bb_init', $x); $s = $x['text']; @@ -99,7 +100,7 @@ class Markdown * @hooks markdown_to_bb * * \e string - The already converted message as bbcode */ - call_hooks('markdown_to_bb', $s); + Hook::call('markdown_to_bb', $s); return $s; } @@ -264,7 +265,7 @@ class Markdown * * \e string \b bbcode - The message as bbcode and what will get returned * * \e array \b options */ - call_hooks('bb_to_markdown_bb', $x); + Hook::call('bb_to_markdown_bb', $x); $Text = $x['bbcode']; @@ -294,7 +295,7 @@ class Markdown * @hooks bb_to_markdown * * \e string - The already converted message as bbcode and what will get returned */ - call_hooks('bb_to_markdown', $Text); + Hook::call('bb_to_markdown', $Text); return $Text; } diff --git a/Zotlabs/Lib/Navbar.php b/Zotlabs/Lib/Navbar.php index 71feee138..bc88d5659 100644 --- a/Zotlabs/Lib/Navbar.php +++ b/Zotlabs/Lib/Navbar.php @@ -9,6 +9,8 @@ use Zotlabs\Lib\Channel; use Zotlabs\Lib\System; use Zotlabs\Lib\Features; use Zotlabs\Lib\Menu; +use Zotlabs\Render\Theme; +use Zotlabs\Extend\Hook; require_once('include/security.php'); @@ -198,7 +200,7 @@ class Navbar { $x = array('nav' => $nav, 'usermenu' => $userinfo ); - call_hooks('nav', $x); + Hook::call('nav', $x); // Not sure the best place to put this on the page. So I'm implementing it but leaving it // turned off until somebody discovers this and figures out a good location for it. @@ -285,7 +287,7 @@ class Navbar { } } - $c = theme_include('navbar_' . purify_filename($template) . '.css'); + $c = Theme::include('navbar_' . purify_filename($template) . '.css'); $tpl = get_markup_template('navbar_' . purify_filename($template) . '.tpl'); if ($c && $tpl) { @@ -338,7 +340,7 @@ class Navbar { unset($_SESSION['reload_avatar']); } - call_hooks('page_header', App::$page['nav']); + Hook::call('page_header', App::$page['nav']); } /* @@ -532,7 +534,7 @@ class Navbar { $arr = array('is_owner' => $is_owner, 'nickname' => $nickname, 'tab' => (($tab) ? $tab : false), 'tabs' => $tabs); - call_hooks('channel_apps', $arr); + Hook::call('channel_apps', $arr); return replace_macros( get_markup_template('profile_tabs.tpl'), diff --git a/Zotlabs/Lib/Oembed.php b/Zotlabs/Lib/Oembed.php index 1b0a2be31..5e3067332 100644 --- a/Zotlabs/Lib/Oembed.php +++ b/Zotlabs/Lib/Oembed.php @@ -4,6 +4,7 @@ namespace Zotlabs\Lib; use App; use Zotlabs\Lib\Cache; +use Zotlabs\Extend\Hook; class Oembed { @@ -105,7 +106,7 @@ class Oembed } $arr = array('url' => $embedurl, 'action' => $action); - call_hooks('oembed_action', $arr); + Hook::call('oembed_action', $arr); //logger('action: ' . $arr['action'] . ' url: ' . $arr['url'], LOGGER_DEBUG,LOG_DEBUG); @@ -231,7 +232,7 @@ class Oembed if ($txt == false || $txt == "") { $x = array('url' => $embedurl,'videowidth' => App::$videowidth); - call_hooks('oembed_probe', $x); + Hook::call('oembed_probe', $x); if (array_key_exists('embed', $x)) { $txt = $x['embed']; } diff --git a/Zotlabs/Lib/Permcat.php b/Zotlabs/Lib/Permcat.php index afe2c2597..c9c0d7cce 100644 --- a/Zotlabs/Lib/Permcat.php +++ b/Zotlabs/Lib/Permcat.php @@ -5,6 +5,7 @@ namespace Zotlabs\Lib; use Zotlabs\Access\PermissionRoles; use Zotlabs\Access\Permissions; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; /** * @brief Permission Categories. Permission rules for various classes of connections. @@ -195,7 +196,7 @@ class Permcat * @hooks permcats * * \e array */ - call_hooks('permcats', $permcats); + Hook::call('permcats', $permcats); return $permcats; } diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php index afaab74b5..c25014496 100644 --- a/Zotlabs/Lib/Queue.php +++ b/Zotlabs/Lib/Queue.php @@ -11,6 +11,7 @@ use Zotlabs\Lib\ActivityStreams; use Zotlabs\Lib\Channel; use Zotlabs\Zot6\Receiver; use Zotlabs\Zot6\Zot6Handler; +use Zotlabs\Extend\Hook; class Queue { @@ -226,7 +227,7 @@ class Queue } $arr = array('outq' => $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate); - call_hooks('queue_deliver', $arr); + Hook::call('queue_deliver', $arr); if ($arr['handled']) { return; } diff --git a/Zotlabs/Lib/ServiceClass.php b/Zotlabs/Lib/ServiceClass.php index 9ac44953d..05995f615 100644 --- a/Zotlabs/Lib/ServiceClass.php +++ b/Zotlabs/Lib/ServiceClass.php @@ -4,6 +4,7 @@ namespace Zotlabs\Lib; use App; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class ServiceClass { @@ -89,7 +90,7 @@ class ServiceClass { intval($rr['account_id']) ); $ret = [ 'account' => $rr ]; - call_hooks('account_downgrade', $ret); + Hook::call('account_downgrade', $ret); logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' downgraded.'); } else { $x = q( @@ -98,7 +99,7 @@ class ServiceClass { intval($rr['account_id']) ); $ret = [ 'account' => $rr ]; - call_hooks('account_downgrade', $ret); + Hook::call('account_downgrade', $ret); logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' expired.'); } } diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php index 0630326a5..bbd8cda45 100644 --- a/Zotlabs/Lib/Share.php +++ b/Zotlabs/Lib/Share.php @@ -6,6 +6,7 @@ use App; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class Share { @@ -146,7 +147,7 @@ class Share $arr['id'] = $post_id; - call_hooks('post_local_end', $arr); + Hook::call('post_local_end', $arr); $r = q( "select * from item where id = %d", diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php index 45498ae64..c63a1b959 100644 --- a/Zotlabs/Lib/System.php +++ b/Zotlabs/Lib/System.php @@ -4,6 +4,7 @@ namespace Zotlabs\Lib; use App; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; use URLify; class System @@ -146,7 +147,7 @@ class System public static function get_zot_revision() { $x = [ 'revision' => ZOT_REVISION ]; - call_hooks('zot_revision', $x); + Hook::call('zot_revision', $x); return $x['revision']; } diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 996a00ca3..fc9e5df1a 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -6,6 +6,7 @@ namespace Zotlabs\Lib; use App; use Zotlabs\Lib\Features; +use Zotlabs\Extend\Hook; require_once('include/text.php'); @@ -373,7 +374,7 @@ class ThreadItem $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false); $dropdown_extras_arr = [ 'item' => $item , 'dropdown_extras' => '' ]; - call_hooks('dropdown_extras', $dropdown_extras_arr); + Hook::call('dropdown_extras', $dropdown_extras_arr); $dropdown_extras = $dropdown_extras_arr['dropdown_extras']; // Pinned item processing @@ -513,7 +514,7 @@ class ThreadItem ); $arr = array('item' => $item, 'output' => $tmp_item); - call_hooks('display_item', $arr); + Hook::call('display_item', $arr); $result = $arr['output']; @@ -927,7 +928,7 @@ class ThreadItem $observer = $conv->get_observer(); $arr = array('comment_buttons' => '','id' => $this->get_id()); - call_hooks('comment_buttons', $arr); + Hook::call('comment_buttons', $arr); $comment_buttons = $arr['comment_buttons']; $feature_auto_save_draft = ((Features::enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false"); diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php index e79bb5486..b099df77b 100644 --- a/Zotlabs/Module/Admin.php +++ b/Zotlabs/Module/Admin.php @@ -15,7 +15,8 @@ use Zotlabs\Web\SubModule; use Zotlabs\Lib\Config; use Zotlabs\Lib\Channel; use Zotlabs\Lib\Navbar; - +use Zotlabs\Lib\Addon; + /** * @brief Admin area. * @@ -151,18 +152,7 @@ class Admin extends Controller $queue = (($r) ? $r[0]['total'] : 0); $queues = ['label' => t('Message queues'), 'queue' => $queue]; - $plugins = []; - - if (is_array(App::$plugins) && App::$plugins) { - foreach (App::$plugins as $p) { - if ($p) { - $plugins[] = $p; - } - } - sort($plugins); - } else { - $plugins = 0; - } + $plugins = Addon::list_installed(); // Could be extended to provide also other alerts to the admin diff --git a/Zotlabs/Module/Admin/Addons.php b/Zotlabs/Module/Admin/Addons.php index 62f57c364..21e031696 100644 --- a/Zotlabs/Module/Admin/Addons.php +++ b/Zotlabs/Module/Admin/Addons.php @@ -6,6 +6,7 @@ use App; use PHPGit\Exception\GitException; use Zotlabs\Storage\GitRepo; use Michelf\MarkdownExtra; +use Zotlabs\Lib\Addon; class Addons { @@ -260,7 +261,7 @@ class Addons return ''; } - $enabled = in_array($plugin, App::$plugins); + $enabled = in_array($plugin, Addon::list_installed()); $info = get_plugin_info($plugin); $x = check_plugin_versions($info); @@ -268,12 +269,7 @@ class Addons if ($enabled && !$x) { $enabled = false; - $idz = array_search($plugin, App::$plugins); - if ($idz !== false) { - unset(App::$plugins[$idz]); - uninstall_plugin($plugin); - set_config("system", "addon", implode(", ", App::$plugins)); - } + uninstall_plugin($plugin); } $info['disabled'] = 1 - intval($x); @@ -281,19 +277,16 @@ class Addons check_form_security_token_redirectOnErr('/admin/addons', 'admin_addons', 't'); $pinstalled = false; // Toggle plugin status - $idx = array_search($plugin, App::$plugins); + $idx = array_search($plugin, Addon::list_installed()); if ($idx !== false) { - unset(App::$plugins[$idx]); - uninstall_plugin($plugin); + Addon::uninstall($plugin); $pinstalled = false; info(sprintf(t("Plugin %s disabled."), $plugin)); } else { - App::$plugins[] = $plugin; - install_plugin($plugin); + Addon::install($plugin); $pinstalled = true; info(sprintf(t("Plugin %s enabled."), $plugin)); } - set_config("system", "addon", implode(", ", App::$plugins)); if ($pinstalled) { @require_once("addon/$plugin/$plugin.php"); @@ -306,7 +299,7 @@ class Addons // display plugin details - if (in_array($plugin, App::$plugins)) { + if (in_array($plugin, Addon::list_installed())) { $status = 'on'; $action = t('Disable'); } else { @@ -389,11 +382,9 @@ class Addons if ($enabled && !$x) { $enabled = false; - $idz = array_search($id, App::$plugins); + $idz = array_search($id, Addon::list_installed()); if ($idz !== false) { - unset(App::$plugins[$idz]); uninstall_plugin($id); - set_config("system", "addon", implode(", ", App::$plugins)); } } $info['disabled'] = 1 - intval($x); diff --git a/Zotlabs/Module/Admin/Channels.php b/Zotlabs/Module/Admin/Channels.php index 785bdc43b..ee3e32a69 100644 --- a/Zotlabs/Module/Admin/Channels.php +++ b/Zotlabs/Module/Admin/Channels.php @@ -5,6 +5,7 @@ namespace Zotlabs\Module\Admin; use App; use Zotlabs\Lib\Channel; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; /** * @brief Admin Module for Channels. @@ -163,7 +164,7 @@ class Channels } } - call_hooks('admin_channels', $channels); + Hook::call('admin_channels', $channels); $o = replace_macros(get_markup_template('admin_channels.tpl'), [ // strings // diff --git a/Zotlabs/Module/Admin/Cover_photo.php b/Zotlabs/Module/Admin/Cover_photo.php index 93abddf01..2d2aa64ee 100644 --- a/Zotlabs/Module/Admin/Cover_photo.php +++ b/Zotlabs/Module/Admin/Cover_photo.php @@ -8,6 +8,7 @@ use Zotlabs\Lib\Libprofile; use Zotlabs\Access\AccessControl; use Zotlabs\Web\Controller; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; /* @file cover_photo.php @@ -389,7 +390,7 @@ class Cover_photo ]); - call_hooks('cover_photo_content_end', $o); + Hook::call('cover_photo_content_end', $o); return $o; } else { diff --git a/Zotlabs/Module/Admin/Profile_photo.php b/Zotlabs/Module/Admin/Profile_photo.php index 154a7e65c..07add3aaf 100644 --- a/Zotlabs/Module/Admin/Profile_photo.php +++ b/Zotlabs/Module/Admin/Profile_photo.php @@ -15,6 +15,7 @@ use Zotlabs\Lib\Libprofile; use Zotlabs\Lib\Config; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/photo_factory.php'); require_once('include/photos.php'); @@ -484,7 +485,7 @@ class Profile_photo '$select' => t('Select previously uploaded photo'), ]); - call_hooks('profile_photo_content_end', $o); + Hook::call('profile_photo_content_end', $o); return $o; } else { // present a cropping form diff --git a/Zotlabs/Module/Affinity.php b/Zotlabs/Module/Affinity.php index 1df26928b..dd52da5cc 100644 --- a/Zotlabs/Module/Affinity.php +++ b/Zotlabs/Module/Affinity.php @@ -5,6 +5,7 @@ namespace Zotlabs\Module; use Zotlabs\Lib\Apps; use Zotlabs\Lib\Libsync; use Zotlabs\Web\Controller; +use Zotlabs\Extend\Hook; class Affinity extends Controller { @@ -65,7 +66,7 @@ class Affinity extends Controller 80 => t('Connections'), 99 => t('All') ); - call_hooks('affinity_labels', $labels); + Hook::call('affinity_labels', $labels); $tpl = get_markup_template('affinity.tpl'); $x = replace_macros($tpl, [ @@ -78,7 +79,7 @@ class Affinity extends Controller $arr = array('html' => $x); - call_hooks('affinity_slider', $arr); + Hook::call('affinity_slider', $arr); $setting_fields .= $arr['html']; } diff --git a/Zotlabs/Module/Api.php b/Zotlabs/Module/Api.php index a64a7fad6..e943997b4 100644 --- a/Zotlabs/Module/Api.php +++ b/Zotlabs/Module/Api.php @@ -8,6 +8,7 @@ use OAuth1Request; use OAuth1Consumer; use OAuth1Util; use Zotlabs\Web\Controller; +use Zotlabs\Extend\Hook; require_once('include/api.php'); @@ -24,7 +25,7 @@ class Api extends Controller api_register_func('api/oauth/access_token', 'api_oauth_access_token', false); $args = []; - call_hooks('api_register', $args); + Hook::call('api_register', $args); return; } diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index bfa50a885..579f89361 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -17,6 +17,7 @@ use Zotlabs\Lib\PermissionDescription; use Zotlabs\Widget\Pinned; use Zotlabs\Lib\Navbar; use Zotlabs\Lib\Libacl; +use Zotlabs\Extend\Hook; require_once('include/items.php'); require_once('include/security.php'); @@ -528,7 +529,7 @@ class Channel extends Controller if ($is_owner && $update_unseen && (!$_SESSION['sudo'])) { $x = ['channel_id' => local_channel(), 'update' => 'unset']; - call_hooks('update_unseen', $x); + Hook::call('update_unseen', $x); if ($x['update'] === 'unset' || intval($x['update'])) { $r = q( "UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", diff --git a/Zotlabs/Module/Chatsvc.php b/Zotlabs/Module/Chatsvc.php index b1adea2a7..69dd42911 100644 --- a/Zotlabs/Module/Chatsvc.php +++ b/Zotlabs/Module/Chatsvc.php @@ -9,6 +9,7 @@ use App; use Zotlabs\Lib as Zlib; use Zotlabs\Web\Controller; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/security.php'); @@ -66,7 +67,7 @@ class Chatsvc extends Controller 'chat_text' => $text ); - call_hooks('chat_post', $arr); + Hook::call('chat_post', $arr); $x = q( "insert into chat ( chat_room, chat_xchan, created, chat_text ) diff --git a/Zotlabs/Module/Connect.php b/Zotlabs/Module/Connect.php index 477323e77..c8db76d70 100644 --- a/Zotlabs/Module/Connect.php +++ b/Zotlabs/Module/Connect.php @@ -7,6 +7,7 @@ use Zotlabs\Web\Controller; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Libprofile; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class Connect extends Controller { @@ -119,7 +120,7 @@ class Connect extends Controller )); $arr = array('channel' => App::$data['channel'], 'observer' => App::get_observer(), 'sellpage' => $o, 'submit' => $submit); - call_hooks('connect_premium', $arr); + Hook::call('connect_premium', $arr); $o = $arr['sellpage']; } diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index 741f2b260..db93d28ef 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -15,6 +15,7 @@ use Zotlabs\Access\PermissionLimits; use Zotlabs\Lib\Permcat; use Zotlabs\Lib\Features; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; use Zotlabs\Web\HTTPHeaders; use Sabre\VObject\Reader; @@ -92,7 +93,7 @@ class Connedit extends Controller $orig_record = array_shift($orig_record); - call_hooks('contact_edit_post', $_POST); + Hook::call('contact_edit_post', $_POST); $vc = get_abconfig(local_channel(), $orig_record['abook_xchan'], 'system', 'vcard'); $vcard = (($vc) ? Reader::read($vc) : null); @@ -274,7 +275,7 @@ class Connedit extends Controller if ($new_friend) { $arr = ['channel_id' => local_channel(), 'abook' => App::$poi]; - call_hooks('accept_follow', $arr); + Hook::call('accept_follow', $arr); } $this->connedit_clone($a); @@ -675,7 +676,7 @@ class Connedit extends Controller 80 => t('Connections'), 99 => t('All') ]; - call_hooks('affinity_labels', $labels); + Hook::call('affinity_labels', $labels); $slider_tpl = get_markup_template('contact_slider.tpl'); @@ -897,7 +898,7 @@ class Connedit extends Controller $arr = array('contact' => $contact, 'output' => $o); - call_hooks('contact_edit', $arr); + Hook::call('contact_edit', $arr); return $arr['output']; } diff --git a/Zotlabs/Module/Cover_photo.php b/Zotlabs/Module/Cover_photo.php index c93f19afe..5e6953bf2 100644 --- a/Zotlabs/Module/Cover_photo.php +++ b/Zotlabs/Module/Cover_photo.php @@ -8,6 +8,7 @@ use Zotlabs\Lib\Libprofile; use Zotlabs\Access\AccessControl; use Zotlabs\Web\Controller; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; /* @file cover_photo.php @@ -435,7 +436,7 @@ class Cover_photo extends Controller ]); - call_hooks('cover_photo_content_end', $o); + Hook::call('cover_photo_content_end', $o); return $o; } else { diff --git a/Zotlabs/Module/Defperms.php b/Zotlabs/Module/Defperms.php index e4b02f8ba..3d1dc9988 100644 --- a/Zotlabs/Module/Defperms.php +++ b/Zotlabs/Module/Defperms.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\Apps; use Zotlabs\Web\Controller; use Zotlabs\Access\Permissions; use Zotlabs\Access\PermissionLimits; +use Zotlabs\Extend\Hook; require_once('include/socgraph.php'); @@ -268,7 +269,7 @@ class Defperms extends Controller $arr = array('contact' => $contact, 'output' => $o); - call_hooks('contact_edit', $arr); + Hook::call('contact_edit', $arr); return $arr['output']; } diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index 7f65f907d..b4f9cf061 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\Libsync; use Zotlabs\Lib\LibBlock; use Zotlabs\Lib\Channel; use Zotlabs\Lib\Navbar; +use Zotlabs\Extend\Hook; require_once('include/socgraph.php'); require_once('include/bbcode.php'); @@ -435,7 +436,7 @@ class Directory extends Controller $arr = array('contact' => $rr, 'entry' => $entry); - call_hooks('directory_item', $arr); + Hook::call('directory_item', $arr); unset($profile); unset($location); diff --git a/Zotlabs/Module/Display.php b/Zotlabs/Module/Display.php index 5416f4db2..df3e79942 100644 --- a/Zotlabs/Module/Display.php +++ b/Zotlabs/Module/Display.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\PConfig; use Zotlabs\Web\Controller; use Zotlabs\Lib\Channel; use Zotlabs\Lib\Libacl; +use Zotlabs\Extend\Hook; require_once("include/bbcode.php"); require_once('include/security.php'); @@ -197,7 +198,7 @@ class Display extends Controller } } if ($target_item['item_type'] == ITEM_TYPE_CUSTOM) { - call_hooks('item_custom_display', $target_item); + Hook::call('item_custom_display', $target_item); notice(t('Page not found.') . EOL); return ''; } @@ -460,12 +461,12 @@ class Display extends Controller )); $x = ['xml' => $atom, 'channel' => $channel, 'observer_hash' => $observer_hash, 'params' => $params]; - call_hooks('atom_feed_top', $x); + Hook::call('atom_feed_top', $x); $atom = $x['xml']; // a much simpler interface - call_hooks('atom_feed', $atom); + Hook::call('atom_feed', $atom); if ($items) { @@ -478,7 +479,7 @@ class Display extends Controller } } - call_hooks('atom_feed_end', $atom); + Hook::call('atom_feed_end', $atom); $atom .= '' . "\r\n"; diff --git a/Zotlabs/Module/Home.php b/Zotlabs/Module/Home.php index 8038d6223..472d0262b 100644 --- a/Zotlabs/Module/Home.php +++ b/Zotlabs/Module/Home.php @@ -11,6 +11,7 @@ use Zotlabs\Lib\Crypto; use Zotlabs\Web\HTTPSig; use Zotlabs\Web\Controller; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/conversation.php'); @@ -23,7 +24,7 @@ class Home extends Controller $ret = []; - call_hooks('home_init', $ret); + Hook::call('home_init', $ret); if (ActivityStreams::is_as_request()) { $x = array_merge(['@context' => [ @@ -129,7 +130,7 @@ class Home extends Controller $splash = ((argc() > 1 && argv(1) === 'splash') ? true : false); - call_hooks('home_content', $o); + Hook::call('home_content', $o); if ($o) { return $o; } diff --git a/Zotlabs/Module/Hostxrd.php b/Zotlabs/Module/Hostxrd.php index 2aa569c64..9fa7386a9 100644 --- a/Zotlabs/Module/Hostxrd.php +++ b/Zotlabs/Module/Hostxrd.php @@ -4,6 +4,7 @@ namespace Zotlabs\Module; use App; use Zotlabs\Web\Controller; +use Zotlabs\Extend\Hook; class Hostxrd extends Controller { @@ -21,7 +22,7 @@ class Hostxrd extends Controller '$zroot' => z_root() )); $arr = array('xrd' => $x); - call_hooks('hostxrd', $arr); + Hook::call('hostxrd', $arr); echo $arr['xrd']; killme(); diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 114da9d3b..0035779ef 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -12,6 +12,7 @@ use Zotlabs\Lib\Channel; use Zotlabs\Daemon\Run; use Zotlabs\Import\Friendica; use Zotlabs\Lib\ServiceClass; +use Zotlabs\Extend\Hook; require_once('include/import.php'); require_once('include/photo_factory.php'); @@ -128,7 +129,7 @@ class Import extends Controller } if (!array_key_exists('compatibility', $data)) { - call_hooks('import_foreign_channel_data', $data); + Hook::call('import_foreign_channel_data', $data); if ($data['handled']) { return; } @@ -539,7 +540,7 @@ class Import extends Controller // import_items($channel,$data['webpages'],false,$relocate); // } $addon = array('channel' => $channel, 'data' => $data); - call_hooks('import_channel', $addon); + Hook::call('import_channel', $addon); $saved_notification_flags = Channel::notifications_off($channel['channel_id']); if ($import_posts && array_key_exists('item', $data) && $data['item']) { diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 2bb883e54..fdf8096db 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -38,6 +38,7 @@ use Zotlabs\Lib\Apps; use Zotlabs\Access\PermissionLimits; use Zotlabs\Access\PermissionRoles; use Zotlabs\Access\AccessControl; +use Zotlabs\Extend\Hook; use Zotlabs\Daemon\Run; use App; use URLify; @@ -416,7 +417,7 @@ class Item extends Controller $observer = $sys; } - call_hooks('post_local_start', $_REQUEST); + Hook::call('post_local_start', $_REQUEST); // logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA); @@ -940,7 +941,7 @@ class Item extends Controller $arr = ['profile_uid' => $profile_uid, 'summary' => $summary, 'content' => $body, 'mimetype' => $mimetype]; - call_hooks('post_content', $arr); + Hook::call('post_content', $arr); $summary = $arr['summary']; $body = $arr['content']; $mimetype = $arr['mimetype']; @@ -1517,7 +1518,7 @@ class Item extends Controller } } - call_hooks('post_local', $datarray); + Hook::call('post_local', $datarray); // This is no longer needed unset($datarray['edit']); @@ -1702,7 +1703,7 @@ class Item extends Controller $datarray['id'] = $post_id; $datarray['llink'] = z_root() . '/display/' . gen_link_id($datarray['mid']); - call_hooks('post_local_end', $datarray); + Hook::call('post_local_end', $datarray); if ($groupww) { $nopush = false; diff --git a/Zotlabs/Module/Like.php b/Zotlabs/Module/Like.php index 3aca63598..84abe972f 100644 --- a/Zotlabs/Module/Like.php +++ b/Zotlabs/Module/Like.php @@ -8,6 +8,7 @@ use Zotlabs\Lib\Activity; use Zotlabs\Web\Controller; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/security.php'); require_once('include/bbcode.php'); @@ -284,7 +285,7 @@ class Like extends Controller $arr['deny_gid'] = $deny_gid; $arr['item_private'] = $private; - call_hooks('post_local', $arr); + Hook::call('post_local', $arr); $post = item_store($arr); $post_id = $post['item_id']; @@ -297,7 +298,7 @@ class Like extends Controller $arr['id'] = $post_id; - call_hooks('post_local_end', $arr); + Hook::call('post_local_end', $arr); $r = q( "select * from item where id = %d", diff --git a/Zotlabs/Module/Linkinfo.php b/Zotlabs/Module/Linkinfo.php index c041d6e3e..9e6a4fbfc 100644 --- a/Zotlabs/Module/Linkinfo.php +++ b/Zotlabs/Module/Linkinfo.php @@ -12,6 +12,7 @@ use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Channel; use Zotlabs\Lib\Oembed; use Zotlabs\Lib as Zlib; +use Zotlabs\Extend\Hook; require_once('include/security.php'); @@ -188,7 +189,7 @@ class Linkinfo extends Controller $arr = array('url' => $url, 'text' => ''); - call_hooks('parse_link', $arr); + Hook::call('parse_link', $arr); if (strlen($arr['text'])) { echo $arr['text']; diff --git a/Zotlabs/Module/Magic.php b/Zotlabs/Module/Magic.php index 49238ece7..007a15823 100644 --- a/Zotlabs/Module/Magic.php +++ b/Zotlabs/Module/Magic.php @@ -8,6 +8,7 @@ use Zotlabs\Web\HTTPSig; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\SConfig; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; class Magic extends Controller { @@ -56,7 +57,7 @@ class Magic extends Controller 'proceed' => true ]; - call_hooks('magic_auth', $arr); + Hook::call('magic_auth', $arr); $dest = $arr['destination']; if (!$arr['proceed']) { goaway($dest); diff --git a/Zotlabs/Module/Mood.php b/Zotlabs/Module/Mood.php index 12161c1bc..878ddc492 100644 --- a/Zotlabs/Module/Mood.php +++ b/Zotlabs/Module/Mood.php @@ -7,6 +7,7 @@ use Zotlabs\Lib\Apps; use Zotlabs\Web\Controller; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Navbar; +use Zotlabs\Extend\Hook; require_once('include/security.php'); require_once('include/bbcode.php'); @@ -116,7 +117,7 @@ class Mood extends Controller Run::Summon(['Notifier', 'activity', $item_id]); } - call_hooks('post_local_end', $arr); + Hook::call('post_local_end', $arr); if ($_SESSION['return_url']) { goaway(z_root() . '/' . $_SESSION['return_url']); diff --git a/Zotlabs/Module/Notify.php b/Zotlabs/Module/Notify.php index 3bafdfc6a..8230ca8cd 100644 --- a/Zotlabs/Module/Notify.php +++ b/Zotlabs/Module/Notify.php @@ -4,6 +4,7 @@ namespace Zotlabs\Module; use App; use Zotlabs\Web\Controller; +use Zotlabs\Extend\Hook; class Notify extends Controller { @@ -27,7 +28,7 @@ class Notify extends Controller ); if ($r) { $x = ['channel_id' => local_channel(), 'update' => 'unset']; - call_hooks('update_unseen', $x); + Hook::call('update_unseen', $x); if ((!$_SESSION['sudo']) && ($x['update'] === 'unset' || intval($x['update']))) { q( "update notify set seen = 1 where (( parent != '' and parent = '%s' and otype = '%s' ) or link = '%s' ) and uid = %d", diff --git a/Zotlabs/Module/Pdledit.php b/Zotlabs/Module/Pdledit.php index 756601242..84868e86a 100644 --- a/Zotlabs/Module/Pdledit.php +++ b/Zotlabs/Module/Pdledit.php @@ -4,6 +4,7 @@ namespace Zotlabs\Module; use Zotlabs\Lib\Libsync; use Zotlabs\Web\Controller; +use Zotlabs\Render\Theme; class Pdledit extends Controller { @@ -66,7 +67,7 @@ class Pdledit extends Controller if ($files) { foreach ($files as $f) { $name = lcfirst(basename($f, '.php')); - $x = theme_include('mod_' . $name . '.pdl'); + $x = Theme::include('mod_' . $name . '.pdl'); if ($x) { $o .= '' . $name . '' . ((in_array($name, $edited)) ? ' ' . t('(modified)') . ' ' . t('Reset') . '' : '') . '
'; } @@ -87,7 +88,7 @@ class Pdledit extends Controller } $t = get_pconfig(local_channel(), 'system', $module); - $s = @file_get_contents(theme_include($module)); + $s = @file_get_contents(Theme::include($module)); if (!$s) { $a = glob('addon/*/' . $module); if ($a) { diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 5a5115636..1909d4533 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -9,6 +9,7 @@ use Zotlabs\Lib\Config; use Zotlabs\Lib\Channel; use Zotlabs\Lib\LDSignatures; use Zotlabs\Web\HTTPSig; +use Zotlabs\Extend\Hook; require_once('include/security.php'); require_once('include/attach.php'); @@ -114,7 +115,7 @@ class Photo extends Controller $uid = $person; $d = ['imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data' => '', 'mimetype' => '']; - call_hooks('get_profile_photo', $d); + Hook::call('get_profile_photo', $d); $resolution = $d['imgscale']; $uid = $d['channel_id']; diff --git a/Zotlabs/Module/Photos.php b/Zotlabs/Module/Photos.php index dd22a5c88..edbd5c224 100644 --- a/Zotlabs/Module/Photos.php +++ b/Zotlabs/Module/Photos.php @@ -15,6 +15,7 @@ use Zotlabs\Daemon\Run; use Zotlabs\Lib\Navbar; use Zotlabs\Lib\Libacl; use Zotlabs\Lib\Features; +use Zotlabs\Extend\Hook; require_once('include/photo_factory.php'); require_once('include/photos.php'); @@ -669,7 +670,7 @@ class Photos extends Controller 'addon_text' => $uploader, 'default_upload' => true); - call_hooks('photo_upload_form', $ret); + Hook::call('photo_upload_form', $ret); /* Show space usage */ diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index d201d10ff..12b285f01 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -8,6 +8,7 @@ use Zotlabs\Lib\Enotify; use Zotlabs\Lib\Apps; use Zotlabs\Lib\PConfig; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/bbcode.php'); @@ -611,7 +612,7 @@ class Ping extends Controller if ($r) { $arr = array('items' => $r); - call_hooks('network_ping', $arr); + Hook::call('network_ping', $arr); foreach ($r as $it) { if ($it['author_xchan'] === $ob_hash) { diff --git a/Zotlabs/Module/Plike.php b/Zotlabs/Module/Plike.php index 6940d06d3..2e2e892fe 100644 --- a/Zotlabs/Module/Plike.php +++ b/Zotlabs/Module/Plike.php @@ -8,6 +8,7 @@ use Zotlabs\Lib\Activity; use Zotlabs\Web\Controller; use Zotlabs\Daemon\Run; use Zotlabs\Lib\Channel; +use Zotlabs\Extend\Hook; require_once('include/security.php'); require_once('include/bbcode.php'); @@ -254,7 +255,7 @@ class Plike extends Controller $arr['deny_gid'] = $deny_gid; $arr['item_private'] = $private; - call_hooks('post_local', $arr); + Hook::call('post_local', $arr); $post = item_store($arr); $post_id = $post['item_id']; @@ -267,7 +268,7 @@ class Plike extends Controller $arr['id'] = $post_id; - call_hooks('post_local_end', $arr); + Hook::call('post_local_end', $arr); $r = q( "select * from item where id = %d", diff --git a/Zotlabs/Module/Profile.php b/Zotlabs/Module/Profile.php index 18e6a5da1..1edd83fb3 100644 --- a/Zotlabs/Module/Profile.php +++ b/Zotlabs/Module/Profile.php @@ -11,6 +11,7 @@ use Zotlabs\Lib\LDSignatures; use Zotlabs\Lib\Channel; use Zotlabs\Web\HTTPSig; use Zotlabs\Lib\Navbar; +use Zotlabs\Extend\Hook; require_once("include/bbcode.php"); require_once('include/security.php'); @@ -132,7 +133,7 @@ class Profile extends Controller ]); $o .= Libprofile::advanced(); - call_hooks('profile_advanced', $o); + Hook::call('profile_advanced', $o); return $o; } } diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php index 55f7a40fc..ea9986a96 100644 --- a/Zotlabs/Module/Profile_photo.php +++ b/Zotlabs/Module/Profile_photo.php @@ -14,6 +14,7 @@ use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Libprofile; use Zotlabs\Lib\Channel; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; require_once('include/photo_factory.php'); require_once('include/photos.php'); @@ -523,7 +524,7 @@ class Profile_photo extends Controller '$select' => t('Select previously uploaded photo'), ]); - call_hooks('profile_photo_content_end', $o); + Hook::call('profile_photo_content_end', $o); return $o; } else { // present a cropping form diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php index be2f61bfb..43d290655 100644 --- a/Zotlabs/Module/Profiles.php +++ b/Zotlabs/Module/Profiles.php @@ -11,6 +11,7 @@ use Zotlabs\Lib\Channel; use Zotlabs\Lib\Navbar; use Zotlabs\Lib\Features; use Zotlabs\Daemon\Run; +use Zotlabs\Extend\Hook; use Sabre\VObject\Reader; class Profiles extends Controller @@ -244,7 +245,7 @@ class Profiles extends Controller } } - call_hooks('profile_post', $_POST); + Hook::call('profile_post', $_POST); if ((argc() > 1) && (argv(1) !== "new") && intval(argv(1))) { @@ -852,7 +853,7 @@ class Profiles extends Controller )); $arr = array('profile' => $r[0], 'entry' => $o); - call_hooks('profile_edit', $arr); + Hook::call('profile_edit', $arr); return $o; } else { @@ -985,7 +986,7 @@ class Profiles extends Controller $o = ''; $select = array('', t('Male'), t('Female'), t('Currently Male'), t('Currently Female'), t('Mostly Male'), t('Mostly Female'), t('Transgender'), t('Intersex'), t('Transsexual'), t('Hermaphrodite'), t('Neuter'), t('Non-specific'), t('Other'), t('Undecided')); - call_hooks('gender_selector', $select); + Hook::call('gender_selector', $select); $o .= ""; foreach ($select as $selection) { @@ -1021,7 +1022,7 @@ class Profiles extends Controller $o = ''; $select = array('', t('He/Him'), t('She/Her'), t('They/Them')); - call_hooks('pronouns_selector', $select); + Hook::call('pronouns_selector', $select); $o .= ""; foreach ($select as $selection) { @@ -1073,7 +1074,7 @@ class Profiles extends Controller $o = ''; $select = array('', t('Males'), t('Females'), t('Other')); - call_hooks('sexpref_selector_min', $select); + Hook::call('sexpref_selector_min', $select); $o .= ""; foreach ($select as $selection) { @@ -1110,7 +1111,7 @@ class Profiles extends Controller $o = ''; $select = array('', t('Single'), t('Dating'), t('Cohabiting'), t('Married'), t('Separated'), t('Divorced'), t('Widowed'), t('It\'s complicated'), t('Other')); - call_hooks('marital_selector_min', $select); + Hook::call('marital_selector_min', $select); $o .= "