]> git.mxchange.org Git - friendica-addons.git/blob - startpage/startpage.php
[saml] Replace $_SESSION with DI::session()
[friendica-addons.git] / startpage / startpage.php
1 <?php
2 /**
3  * Name: Start Page
4  * Description: Set a preferred page to load on login from home page
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  *
8  */
9
10 use Friendica\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function startpage_install() {
16         Hook::register('home_init', 'addon/startpage/startpage.php', 'startpage_home_init');
17         Hook::register('addon_settings', 'addon/startpage/startpage.php', 'startpage_settings');
18         Hook::register('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post');
19 }
20
21 function startpage_home_init(App $a, $b)
22 {
23         if (!DI::userSession()->getLocalUserId()) {
24                 return;
25         }
26
27         $page = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'startpage', 'startpage');
28         if (strlen($page)) {
29                 DI::baseUrl()->redirect($page);
30         }
31         return;
32 }
33
34 /**
35  *
36  * Callback from the settings post function.
37  * $post contains the $_POST array.
38  * We will make sure we've got a valid user account
39  * and if so set our configuration setting for this person.
40  *
41  */
42
43 function startpage_settings_post(App $a, $post)
44 {
45         if (!DI::userSession()->getLocalUserId()) {
46                 return;
47         }
48
49         if (!empty($_POST['startpage-submit'])) {
50                 DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'startpage', 'startpage', strip_tags(trim($_POST['startpage'])));
51         }
52 }
53
54 /**
55  *
56  * Called from the Addon Setting form.
57  * Add our own settings info to the page.
58  *
59  */
60 function startpage_settings(App &$a, array &$data)
61 {
62         if (!DI::userSession()->getLocalUserId()) {
63                 return;
64         }
65
66         $startpage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'startpage', 'startpage');
67
68         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/startpage/');
69         $html = Renderer::replaceMacros($t, [
70                 '$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"')],
71         ]);
72
73         $data = [
74                 'addon' => 'startpage',
75                 'title' => DI::l10n()->t('Startpage'),
76                 'html'  => $html,
77         ];
78 }