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