4 * Description: Change number of contacts shown of profile sidebar
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
8 use Friendica\Core\Addon;
9 use Friendica\Core\PConfig;
11 function numfriends_install() {
13 Addon::registerHook('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
14 Addon::registerHook('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
16 logger("installed numfriends");
20 function numfriends_uninstall() {
22 Addon::unregisterHook('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
23 Addon::unregisterHook('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
26 logger("removed numfriends");
31 * Callback from the settings post function.
32 * $post contains the $_POST array.
33 * We will make sure we've got a valid user account
34 * and if so set our configuration setting for this person.
37 function numfriends_settings_post($a,$post) {
38 if(! local_user() || (! x($_POST,'numfriends-submit')))
41 PConfig::set(local_user(),'system','display_friend_count',intval($_POST['numfriends']));
42 info( t('Numfriends settings updated.') . EOL);
48 * Called from the Addon Setting form.
49 * Add our own settings info to the page.
52 function numfriends_settings(&$a, &$s)
58 /* Add our stylesheet to the page so we can make our settings look nice */
60 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/numfriends/numfriends.css' . '" media="all" />' . "\r\n";
62 /* Get the current state of our config variable */
64 $numfriends = PConfig::get(local_user(), 'system', 'display_friend_count', 24);
66 /* Add some HTML to the existing form */
68 $s .= '<div class="settings-block">';
69 $s .= '<h3>' . t('Numfriends Settings') . '</h3>';
70 $s .= '<div id="numfriends-wrapper">';
71 $s .= '<label id="numfriends-label" for="numfriends">' . t('How many contacts to display on profile sidebar') . '</label>';
72 $s .= '<input id="numfriends-input" type="text" name="numfriends" value="' . intval($numfriends) . '" ' . '/>';
73 $s .= '</div><div class="clear"></div>';
75 /* provide a submit button */
77 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="numfriends-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';