4 * Description: Change number of contacts shown of profile sidebar
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
8 use Friendica\Core\Hook;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Logger;
13 function numfriends_install() {
15 Hook::register('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
16 Hook::register('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
18 Logger::log("installed numfriends");
22 function numfriends_uninstall() {
24 Hook::unregister('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
25 Hook::unregister('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
28 Logger::log("removed numfriends");
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.
39 function numfriends_settings_post($a,$post) {
40 if(! local_user() || empty($_POST['numfriends-submit']))
43 DI::pConfig()->set(local_user(),'system','display_friend_count',intval($_POST['numfriends']));
44 info( L10n::t('Numfriends settings updated.') . EOL);
50 * Called from the Addon Setting form.
51 * Add our own settings info to the page.
54 function numfriends_settings(&$a, &$s)
60 /* Add our stylesheet to the page so we can make our settings look nice */
62 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/numfriends/numfriends.css' . '" media="all" />' . "\r\n";
64 /* Get the current state of our config variable */
66 $numfriends = DI::pConfig()->get(local_user(), 'system', 'display_friend_count', 24);
68 /* Add some HTML to the existing form */
70 $s .= '<div class="settings-block">';
71 $s .= '<h3>' . L10n::t('Numfriends Settings') . '</h3>';
72 $s .= '<div id="numfriends-wrapper">';
73 $s .= '<label id="numfriends-label" for="numfriends">' . L10n::t('How many contacts to display on profile sidebar') . '</label>';
74 $s .= '<input id="numfriends-input" type="text" name="numfriends" value="' . intval($numfriends) . '" ' . '/>';
75 $s .= '</div><div class="clear"></div>';
77 /* provide a submit button */
79 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="numfriends-submit" class="settings-submit" value="' . L10n::t('Save Settings') . '" /></div></div>';