]> git.mxchange.org Git - friendica-addons.git/blob - numfriends/numfriends.php
audon/lang/C/messages.po aktualisiert
[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($post) {
32         if (! DI::userSession()->getLocalUserId() || empty($_POST['numfriends-submit'])) {
33                 return;
34         }
35
36         DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'system', 'display_friend_count', intval($_POST['numfriends']));
37 }
38
39
40 /**
41  *
42  * Called from the Addon Setting form. 
43  * Add our own settings info to the page.
44  *
45  */
46 function numfriends_settings(array &$data)
47 {
48         if (!DI::userSession()->getLocalUserId()) {
49                 return;
50         }
51
52         $numfriends = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'display_friend_count', 24);
53         
54         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/numfriends/');
55         $html = Renderer::replaceMacros($t, [
56                 '$numfriends' => ['numfriends', DI::l10n()->t('How many contacts to display on profile sidebar'), $numfriends],
57         ]);
58
59         $data = [
60                 'addon' => 'numfriends',
61                 'title' => DI::l10n()->t('Numfriends Settings'),
62                 'html'  => $html,
63         ];
64 }