]> git.mxchange.org Git - friendica-addons.git/blob - numfriends/numfriends.php
Update obsolete App::getBaseUrl calls to DI::baseUrl
[friendica-addons.git] / numfriends / numfriends.php
1 <?php
2 /**
3  * Name: Numfriends
4  * Description: Change number of contacts shown of profile sidebar
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  */
8 use Friendica\Core\Hook;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Logger;
11 use Friendica\Core\PConfig;
12 use Friendica\DI;
13
14 function numfriends_install() {
15
16         Hook::register('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
17         Hook::register('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
18
19         Logger::log("installed numfriends");
20 }
21
22
23 function numfriends_uninstall() {
24
25         Hook::unregister('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
26         Hook::unregister('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
27
28
29         Logger::log("removed numfriends");
30 }
31
32 /**
33  *
34  * Callback from the settings post function.
35  * $post contains the $_POST array.
36  * We will make sure we've got a valid user account
37  * and if so set our configuration setting for this person.
38  *
39  */
40 function numfriends_settings_post($a,$post) {
41         if(! local_user() || empty($_POST['numfriends-submit']))
42                 return;
43
44         PConfig::set(local_user(),'system','display_friend_count',intval($_POST['numfriends']));
45         info( L10n::t('Numfriends settings updated.') . EOL);
46 }
47
48
49 /**
50  *
51  * Called from the Addon Setting form. 
52  * Add our own settings info to the page.
53  *
54  */
55 function numfriends_settings(&$a, &$s)
56 {
57         if (! local_user()) {
58                 return;
59         }
60
61         /* Add our stylesheet to the page so we can make our settings look nice */
62
63         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . DI::baseUrl()->get() . '/addon/numfriends/numfriends.css' . '" media="all" />' . "\r\n";
64
65         /* Get the current state of our config variable */
66
67         $numfriends = PConfig::get(local_user(), 'system', 'display_friend_count', 24);
68         
69         /* Add some HTML to the existing form */
70
71         $s .= '<div class="settings-block">';
72         $s .= '<h3>' . L10n::t('Numfriends Settings') . '</h3>';
73         $s .= '<div id="numfriends-wrapper">';
74         $s .= '<label id="numfriends-label" for="numfriends">' . L10n::t('How many contacts to display on profile sidebar') . '</label>';
75         $s .= '<input id="numfriends-input" type="text" name="numfriends" value="' . intval($numfriends) . '" ' . '/>';
76         $s .= '</div><div class="clear"></div>';
77
78         /* provide a submit button */
79
80         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="numfriends-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';
81 }