]> git.mxchange.org Git - friendica-addons.git/blob - numfriends/numfriends.php
planets translation update THX SpcCw
[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
9 use Friendica\App;
10 use Friendica\Core\Hook;
11 use Friendica\Core\Logger;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function numfriends_install() {
16
17         Hook::register('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
18         Hook::register('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
19
20         Logger::notice("installed numfriends");
21 }
22
23 /**
24  *
25  * Callback from the settings post function.
26  * $post contains the $_POST array.
27  * We will make sure we've got a valid user account
28  * and if so set our configuration setting for this person.
29  *
30  */
31 function numfriends_settings_post($a,$post) {
32         if(! local_user() || empty($_POST['numfriends-submit']))
33                 return;
34
35         DI::pConfig()->set(local_user(),'system','display_friend_count',intval($_POST['numfriends']));
36 }
37
38
39 /**
40  *
41  * Called from the Addon Setting form. 
42  * Add our own settings info to the page.
43  *
44  */
45 function numfriends_settings(App &$a, array &$data)
46 {
47         if (! local_user()) {
48                 return;
49         }
50
51         $numfriends = DI::pConfig()->get(local_user(), 'system', 'display_friend_count', 24);
52         
53         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/numfriends/');
54         $html = Renderer::replaceMacros($t, [
55                 '$numfriends' => ['numfriends', DI::l10n()->t('How many contacts to display on profile sidebar'), $numfriends],
56         ]);
57
58         $data = [
59                 'addon' => 'numfriends',
60                 'title' => DI::l10n()->t('Numfriends Settings'),
61                 'html'  => $html,
62         ];
63 }