]> git.mxchange.org Git - friendica-addons.git/blobdiff - startpage/startpage.php
audon/lang/C/messages.po aktualisiert
[friendica-addons.git] / startpage / startpage.php
index 8feb63128b9087e2587bafad66dc0677c9bf56a0..e4d80c0c20f831649c1f028424eacd2e7cc58cbe 100644 (file)
@@ -6,10 +6,10 @@
  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
  *
  */
+
+use Friendica\App;
 use Friendica\Core\Hook;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\System;
+use Friendica\Core\Renderer;
 use Friendica\DI;
 
 function startpage_install() {
@@ -18,24 +18,16 @@ function startpage_install() {
        Hook::register('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
 }
 
-function startpage_uninstall()
+function startpage_home_init($b)
 {
-       Hook::unregister('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
-       Hook::unregister('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings');
-       Hook::unregister('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
-}
-
-function startpage_home_init($a, $b)
-{
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       $page = DI::pConfig()->get(local_user(), 'startpage', 'startpage');
-       if (strlen($page)) {
+       $page = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'startpage', 'startpage');
+       if ($page) {
                DI::baseUrl()->redirect($page);
        }
-       return;
 }
 
 /**
@@ -47,14 +39,14 @@ function startpage_home_init($a, $b)
  *
  */
 
-function startpage_settings_post($a, $post)
+function startpage_settings_post($post)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
        if (!empty($_POST['startpage-submit'])) {
-               DI::pConfig()->set(local_user(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage'])));
+               DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage'])));
        }
 }
 
@@ -64,36 +56,22 @@ function startpage_settings_post($a, $post)
  * Add our own settings info to the page.
  *
  */
-function startpage_settings(&$a, &$s)
+function startpage_settings(array &$data)
 {
-       if (!local_user()) {
+       if (!DI::userSession()->getLocalUserId()) {
                return;
        }
 
-       /* Add our stylesheet to the page so we can make our settings look nice */
-
-       DI::page()['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/startpage/startpage.css' . '" media="all" />' . "\r\n";
-
-       /* Get the current state of our config variable */
-
-       $page = DI::pConfig()->get(local_user(), 'startpage', 'startpage');
-
-       /* Add some HTML to the existing form */
-
-       $s .= '<span id="settings_startpage_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">';
-       $s .= '<h3>' . L10n::t('Startpage') . '</h3>';
-       $s .= '</span>';
-       $s .= '<div id="settings_startpage_expanded" class="settings-block" style="display: none;">';
-       $s .= '<span class="fakelink" onclick="openClose(\'settings_startpage_expanded\'); openClose(\'settings_startpage_inflated\');">';
-       $s .= '<h3>' . L10n::t('Startpage') . '</h3>';
-       $s .= '</span>';
-       $s .= '<div id="startpage-page-wrapper">';
-       $s .= '<label id="startpage-page-label" for="startpage-page">' . L10n::t('Home page to load after login  - leave blank for profile wall') . '</label>';
-       $s .= '<input id="startpage-page" type="text" name="startpage" value="' . $page . '" />';
-       $s .= '</div><div class="clear"></div>';
-       $s .= '<div id="startpage-desc">' . L10n::t('Examples: &quot;network&quot; or &quot;notifications/system&quot;') . '</div>';
+       $startpage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'startpage', 'startpage');
 
-       /* provide a submit button */
+       $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"')],
+       ]);
 
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="startpage-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
+       $data = [
+               'addon' => 'startpage',
+               'title' => DI::l10n()->t('Startpage'),
+               'html'  => $html,
+       ];
 }