5d6575c44a2b865888764e98b6803e0fc5b9e592
[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\Addon;
9 use Friendica\Core\PConfig;
10
11 function numfriends_install() {
12
13         Addon::registerHook('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
14         Addon::registerHook('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
15
16         logger("installed numfriends");
17 }
18
19
20 function numfriends_uninstall() {
21
22         Addon::unregisterHook('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
23         Addon::unregisterHook('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
24
25
26         logger("removed numfriends");
27 }
28
29 /**
30  *
31  * Callback from the settings post function.
32  * $post contains the $_POST array.
33  * We will make sure we've got a valid user account
34  * and if so set our configuration setting for this person.
35  *
36  */
37 function numfriends_settings_post($a,$post) {
38         if(! local_user() || (! x($_POST,'numfriends-submit')))
39                 return;
40
41         PConfig::set(local_user(),'system','display_friend_count',intval($_POST['numfriends']));
42         info( t('Numfriends settings updated.') . EOL);
43 }
44
45
46 /**
47  *
48  * Called from the Addon Setting form. 
49  * Add our own settings info to the page.
50  *
51  */
52 function numfriends_settings(&$a, &$s)
53 {
54         if (! local_user()) {
55                 return;
56         }
57
58         /* Add our stylesheet to the page so we can make our settings look nice */
59
60         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/numfriends/numfriends.css' . '" media="all" />' . "\r\n";
61
62         /* Get the current state of our config variable */
63
64         $numfriends = PConfig::get(local_user(), 'system', 'display_friend_count', 24);
65         
66         /* Add some HTML to the existing form */
67
68         $s .= '<div class="settings-block">';
69         $s .= '<h3>' . t('Numfriends Settings') . '</h3>';
70         $s .= '<div id="numfriends-wrapper">';
71         $s .= '<label id="numfriends-label" for="numfriends">' . t('How many contacts to display on profile sidebar') . '</label>';
72         $s .= '<input id="numfriends-input" type="text" name="numfriends" value="' . intval($numfriends) . '" ' . '/>';
73         $s .= '</div><div class="clear"></div>';
74
75         /* provide a submit button */
76
77         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="numfriends-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
78 }