X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=startpage%2Fstartpage.php;h=e4d80c0c20f831649c1f028424eacd2e7cc58cbe;hb=39c654da00e63a58b6a930e7d0e555bfb248b44b;hp=c4324576609d90f07978c24366457a4645db13dc;hpb=48dcbc6f3fc3edae74e3ea2c823011bfb7c26081;p=friendica-addons.git diff --git a/startpage/startpage.php b/startpage/startpage.php index c4324576..e4d80c0c 100644 --- a/startpage/startpage.php +++ b/startpage/startpage.php @@ -4,38 +4,30 @@ * Description: Set a preferred page to load on login from home page * Version: 1.0 * Author: Mike Macgirvin - * + * */ -use Friendica\Core\PConfig; +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($b) +{ + if (!DI::userSession()->getLocalUserId()) { return; + } - $page = PConfig::get(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(DI::userSession()->getLocalUserId(), 'startpage', 'startpage'); + if ($page) { + DI::baseUrl()->redirect($page); } - return; } /** @@ -47,54 +39,39 @@ function startpage_home_init($a, $b) { * */ -function startpage_settings_post($a,$post) { - if(! local_user()) +function startpage_settings_post($post) +{ + if (!DI::userSession()->getLocalUserId()) { return; - if($_POST['startpage-submit']) - PConfig::set(local_user(),'startpage','startpage',strip_tags(trim($_POST['startpage']))); -} + } + if (!empty($_POST['startpage-submit'])) { + DI::pConfig()->set(DI::userSession()->getLocalUserId(), '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(array &$data) +{ + if (!DI::userSession()->getLocalUserId()) { 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 = PConfig::get(local_user(),'startpage','startpage'); - - - /* Add some HTML to the existing form */ - - $s .= ''; - $s .= '

' . t('Startpage') . '

'; - $s .= '
'; - $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, + ]; }