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