adba95c5c7a1d04b1d206c6dc619c58da0bc288d
[friendica-addons.git/.git] / notimeline / notimeline.php
1 <?php
2 /**
3  * Name: Notimeline
4  * Description: Disable "Archives" widget on profile page
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * Status: Unsupported
8  *
9  */
10 use Friendica\Core\Addon;
11 use Friendica\Core\L10n;
12 use Friendica\Core\PConfig;
13
14 function notimeline_install()
15 {
16         Addon::registerHook('addon_settings', 'addon/notimeline/notimeline.php', 'notimeline_settings');
17         Addon::registerHook('addon_settings_post', 'addon/notimeline/notimeline.php', 'notimeline_settings_post');
18 }
19
20 function notimeline_uninstall()
21 {
22         Addon::unregisterHook('addon_settings', 'addon/notimeline/notimeline.php', 'notimeline_settings');
23         Addon::unregisterHook('addon_settings_post', 'addon/notimeline/notimeline.php', 'notimeline_settings_post');
24 }
25
26 function notimeline_settings_post($a, $post)
27 {
28         if (!local_user() || empty($_POST['notimeline-submit'])) {
29                 return;
30         }
31
32         PConfig::set(local_user(), 'system', 'no_wall_archive_widget', intval($_POST['notimeline']));
33         info(L10n::t('No Timeline settings updated.') . EOL);
34 }
35
36 function notimeline_settings(&$a, &$s)
37 {
38         if (! local_user()) {
39                 return;
40         }
41
42         /* Add our stylesheet to the page so we can make our settings look nice */
43
44         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/notimeline/notimeline.css' . '" media="all" />' . "\r\n";
45
46         /* Get the current state of our config variable */
47
48         $notimeline = PConfig::get(local_user(), 'system', 'no_wall_archive_widget', false);
49
50         $notimeline_checked = (($notimeline) ? ' checked="checked" ' : '');
51
52         
53         /* Add some HTML to the existing form */
54
55         $s .= '<div class="settings-block">';
56         $s .= '<h3>' . L10n::t('No Timeline Settings') . '</h3>';
57         $s .= '<div id="notimeline-wrapper">';
58         $s .= '<label id="notimeline-label" for="notimeline-checkbox">' . L10n::t('Disable Archive selector on profile wall') . '</label>';
59         $s .= '<input id="notimeline-checkbox" type="checkbox" name="notimeline" value="1" ' . $notimeline_checked . '/>';
60         $s .= '</div><div class="clear"></div>';
61
62         /* provide a submit button */
63
64         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="notimeline-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
65 }