friendica-addons/numfriends/numfriends.php

66 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* Name: Numfriends
* Description: Change number of contacts shown of profile sidebar
* Version: 1.0
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*/
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
2022-10-18 22:42:46 +02:00
use Friendica\Core\Session;
use Friendica\DI;
function numfriends_install() {
Hook::register('addon_settings', 'addon/numfriends/numfriends.php', 'numfriends_settings');
Hook::register('addon_settings_post', 'addon/numfriends/numfriends.php', 'numfriends_settings_post');
Logger::notice("installed numfriends");
}
/**
*
* Callback from the settings post function.
* $post contains the $_POST array.
* We will make sure we've got a valid user account
* and if so set our configuration setting for this person.
*
*/
function numfriends_settings_post(App $a, $post) {
2022-10-18 22:42:46 +02:00
if (! Session::getLocalUser() || empty($_POST['numfriends-submit'])) {
return;
}
2022-10-18 22:42:46 +02:00
DI::pConfig()->set(Session::getLocalUser(), 'system', 'display_friend_count', intval($_POST['numfriends']));
}
/**
*
* Called from the Addon Setting form.
* Add our own settings info to the page.
*
*/
function numfriends_settings(App &$a, array &$data)
{
2022-10-18 22:42:46 +02:00
if (!Session::getLocalUser()) {
return;
}
2022-10-18 22:42:46 +02:00
$numfriends = DI::pConfig()->get(Session::getLocalUser(), 'system', 'display_friend_count', 24);
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/numfriends/');
$html = Renderer::replaceMacros($t, [
'$numfriends' => ['numfriends', DI::l10n()->t('How many contacts to display on profile sidebar'), $numfriends],
]);
$data = [
'addon' => 'numfriends',
'title' => DI::l10n()->t('Numfriends Settings'),
'html' => $html,
];
}