X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=startpage%2Fstartpage.php;h=d72effde22fdb032be2ce1fa8a33effb57696ec9;hb=19ae3851e88a5b0fb1205c05a1a3b51e2f824474;hp=85988298691976a22eaae60db1664d6d7ddf9be8;hpb=47abeb00ecf763aa66380efa5db3a0ed40941ffd;p=friendica-addons.git diff --git a/startpage/startpage.php b/startpage/startpage.php index 85988298..d72effde 100644 --- a/startpage/startpage.php +++ b/startpage/startpage.php @@ -4,35 +4,29 @@ * Description: Set a preferred page to load on login from home page * Version: 1.0 * Author: Mike Macgirvin - * + * */ +use Friendica\App; +use Friendica\Core\Hook; +use Friendica\Core\Renderer; +use Friendica\DI; function startpage_install() { - register_hook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init'); - register_hook('plugin_settings', 'addon/startpage/startpage.php', 'startpage_settings'); - register_hook('plugin_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); -} - - -function startpage_uninstall() { - unregister_hook('home_init', 'addon/startpage/startpage.php', 'startpage_home_init'); - unregister_hook('plugin_settings', 'addon/startpage/startpage.php', 'startpage_settings'); - unregister_hook('plugin_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); + Hook::register('home_init', 'addon/startpage/startpage.php', 'startpage_home_init'); + Hook::register('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings'); + Hook::register('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); } - - -function startpage_home_init($a, $b) { - if(! local_user()) +function startpage_home_init($a, $b) +{ + if (!local_user()) { return; + } - $page = get_pconfig(local_user(),'startpage','startpage'); - if(strlen($page)) { - $slash = ((strpos($page,'/') === 0) ? true : false); - if(stristr($page,'://')) - goaway($page); - goaway($a->get_baseurl() . (($slash) ? '' : '/') . $page); + $page = DI::pConfig()->get(local_user(), 'startpage', 'startpage'); + if (strlen($page)) { + DI::baseUrl()->redirect($page); } return; } @@ -46,49 +40,39 @@ function startpage_home_init($a, $b) { * */ -function startpage_settings_post($a,$post) { - if(! local_user()) +function startpage_settings_post($a, $post) +{ + if (!local_user()) { return; - if($_POST['startpage-submit']) - set_pconfig(local_user(),'startpage','startpage',strip_tags(trim($_POST['startpage']))); -} + } + if (!empty($_POST['startpage-submit'])) { + DI::pConfig()->set(local_user(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage']))); + } +} /** * - * Called from the Plugin Setting form. + * Called from the Addon Setting form. * Add our own settings info to the page. * */ - - - -function startpage_settings(&$a,&$s) { - - if(! local_user()) +function startpage_settings(App &$a, array &$data) +{ + if (!local_user()) { return; + } - /* Add our stylesheet to the page so we can make our settings look nice */ - - $a->page['htmlhead'] .= '' . "\r\n"; - - /* Get the current state of our config variable */ - - $page = get_pconfig(local_user(),'startpage','startpage'); - - - /* Add some HTML to the existing form */ - - $s .= '
'; - $s .= '

' . t('Startpage Settings') . '

'; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - $s .= '
' . t('Examples: "network" or "notifications/system"') . '
'; - - /* provide a submit button */ + $startpage = DI::pConfig()->get(local_user(), 'startpage', 'startpage'); - $s .= '
'; + $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/startpage/'); + $html = Renderer::replaceMacros($t, [ + '$startpage' => ['startpage', DI::l10n()->t('Home page to load after login - leave blank for profile wall'), $startpage, DI::l10n()->t('Examples: "network" or "notifications/system"')], + ]); + $data = [ + 'addon' => 'startpage', + 'title' => DI::l10n()->t('Startpage'), + 'html' => $html, + ]; }