From 6bc3200bd921b60801b8b78ab14a1c4fbda23dea Mon Sep 17 00:00:00 2001 From: zlaxy Date: Thu, 2 Apr 2020 14:38:07 +0300 Subject: [PATCH] add settings page for optional Link on Hub button --- link/README.md | 2 ++ link/link.php | 27 ++++++++++++++++++++++++--- link/view/tpl/admin.tpl | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 link/view/tpl/admin.tpl diff --git a/link/README.md b/link/README.md index f40702c..f484cbd 100644 --- a/link/README.md +++ b/link/README.md @@ -9,4 +9,6 @@ hub.domain/link/item where an item is the numeric value of an object from the database. +It is possible to use /admin/addons/link settings page for enabling or disabling of showing "Link on Hub" button (currently used javascript hack for the integrating with wall-item-menu, it will be fixed later) + Based on Zotlabs/Module/Display.php \ No newline at end of file diff --git a/link/link.php b/link/link.php index afe4203..cbb2032 100644 --- a/link/link.php +++ b/link/link.php @@ -12,16 +12,37 @@ use Zotlabs\Extend\Hook; use Zotlabs\Extend\Route; function link_load() { - register_hook('page_end', 'addon/link/link.php', 'link_active'); Route::register('addon/link/Mod_Link.php','link'); + if (get_config('link','linkonhub')) + register_hook('page_end', 'addon/link/link.php', 'link_active'); } function link_unload() { - unregister_hook('page_end', 'addon/link/link.php', 'link_active'); Route::unregister('addon/link/Mod_Link.php','link'); + unregister_hook('page_end', 'addon/link/link.php', 'link_active'); +} + +function link_plugin_admin(&$a,&$o) { + $linkonhub = get_config('link','linkonhub'); + + $t = get_markup_template( "admin.tpl", "addon/link/" ); + $o = replace_macros($t, array( + '$submit' => t('Submit'), + '$linkonhub' => array('linkonhub', t('Show "Link on Hub" button'), get_config('link', 'linkonhub'), t('Currently used javascript hack for the integrating with wall-item-menu (will be fixed later)')), + )); + +} + +function link_plugin_admin_post(&$a) { + set_config('link','linkonhub',trim($_POST['linkonhub'])); + info( t('Settings updated.') . EOL); + if (get_config('link','linkonhub')) + register_hook('page_end', 'addon/link/link.php', 'link_active'); + else + unregister_hook('page_end', 'addon/link/link.php', 'link_active'); } function link_active(&$a,&$b) { - // Javascript code for "Link on Hub" button insert - it is not good, it is temporarily, just for testing purposes + // Javascript code for "Link on Hub" button insert - it is not good, it is temporarily, works not good $b .= "\n\n"; } diff --git a/link/view/tpl/admin.tpl b/link/view/tpl/admin.tpl new file mode 100644 index 0000000..410db8f --- /dev/null +++ b/link/view/tpl/admin.tpl @@ -0,0 +1,2 @@ +{{include file="field_checkbox.tpl" field=$linkonhub}} +