mirror of
https://github.com/friendica/friendica
synced 2024-12-22 23:20:16 +00:00
Posts per author/server on the community pages (#13764)
* Posts per author/server on the community pages * Updated database.sql
This commit is contained in:
parent
d2feade9cf
commit
f23ecaff6a
7 changed files with 448 additions and 403 deletions
|
@ -1,5 +1,5 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2023.12 (Yellow archangel)
|
||||
-- Friendica 2024.03-dev (Yellow Archangel)
|
||||
-- DB_UPDATE_VERSION 1542
|
||||
-- ------------------------------------------
|
||||
|
||||
|
|
|
@ -106,6 +106,7 @@ class Site extends BaseAdmin
|
|||
$register_notification = !empty($_POST['register_notification']);
|
||||
$community_page_style = (!empty($_POST['community_page_style']) ? intval(trim($_POST['community_page_style'])) : 0);
|
||||
$max_author_posts_community_page = (!empty($_POST['max_author_posts_community_page']) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
|
||||
$max_server_posts_community_page = (!empty($_POST['max_server_posts_community_page']) ? intval(trim($_POST['max_server_posts_community_page'])) : 0);
|
||||
|
||||
$verifyssl = !empty($_POST['verifyssl']);
|
||||
$proxyuser = (!empty($_POST['proxyuser']) ? trim($_POST['proxyuser']) : '');
|
||||
|
@ -276,6 +277,7 @@ class Site extends BaseAdmin
|
|||
$transactionConfig->set('system', 'register_notification' , $register_notification);
|
||||
$transactionConfig->set('system', 'community_page_style' , $community_page_style);
|
||||
$transactionConfig->set('system', 'max_author_posts_community_page', $max_author_posts_community_page);
|
||||
$transactionConfig->set('system', 'max_server_posts_community_page', $max_server_posts_community_page);
|
||||
$transactionConfig->set('system', 'verifyssl' , $verifyssl);
|
||||
$transactionConfig->set('system', 'proxyuser' , $proxyuser);
|
||||
$transactionConfig->set('system', 'proxy' , $proxy);
|
||||
|
@ -519,7 +521,8 @@ class Site extends BaseAdmin
|
|||
'$enable_regfullname' => ['enable_regfullname', DI::l10n()->t('Enable full name check'), !DI::config()->get('system', 'no_regfullname'), DI::l10n()->t('Prevents users from registering with a display name with fewer than two parts separated by spaces.')],
|
||||
'$register_notification' => ['register_notification', DI::l10n()->t('Email administrators on new registration'), DI::config()->get('system', 'register_notification'), DI::l10n()->t('If enabled and the system is set to an open registration, an email for each new registration is sent to the administrators.')],
|
||||
'$community_page_style' => ['community_page_style', DI::l10n()->t('Community pages for visitors'), DI::config()->get('system', 'community_page_style'), DI::l10n()->t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices],
|
||||
'$max_author_posts_community_page' => ['max_author_posts_community_page', DI::l10n()->t('Posts per user on community page'), DI::config()->get('system', 'max_author_posts_community_page'), DI::l10n()->t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')],
|
||||
'$max_author_posts_community_page' => ['max_author_posts_community_page', DI::l10n()->t('Posts per user on community page'), DI::config()->get('system', 'max_author_posts_community_page'), DI::l10n()->t('The maximum number of posts per user on the local community page. This is useful, when a single user floods the local community page.')],
|
||||
'$max_server_posts_community_page' => ['max_server_posts_community_page', DI::l10n()->t('Posts per server on community page'), DI::config()->get('system', 'max_server_posts_community_page'), DI::l10n()->t('The maximum number of posts per server on the global community page. This is useful, when posts from a single server flood the global community page.')],
|
||||
'$mail_able' => function_exists('imap_open'),
|
||||
'$mail_enabled' => ['mail_enabled', DI::l10n()->t('Enable Mail support'), !DI::config()->get('system', 'imap_disabled', !function_exists('imap_open')), DI::l10n()->t('Enable built-in mail support to poll IMAP folders and to reply via mail.')],
|
||||
'$mail_not_able' => DI::l10n()->t('Mail support can\'t be enabled because the PHP IMAP module is not installed.'),
|
||||
|
|
|
@ -520,37 +520,54 @@ class Timeline extends BaseModule
|
|||
{
|
||||
$items = $this->selectItems();
|
||||
|
||||
$maxpostperauthor = (int) $this->config->get('system', 'max_author_posts_community_page');
|
||||
if ($maxpostperauthor != 0 && $this->selectedTab == 'local') {
|
||||
if ($this->selectedTab == 'local') {
|
||||
$maxpostperauthor = (int)$this->config->get('system', 'max_author_posts_community_page');
|
||||
$key = 'author-id';
|
||||
} elseif ($this->selectedTab == 'global') {
|
||||
$maxpostperauthor = (int)$this->config->get('system', 'max_server_posts_community_page');
|
||||
$key = 'author-gsid';
|
||||
} else {
|
||||
$maxpostperauthor = 0;
|
||||
}
|
||||
if ($maxpostperauthor != 0) {
|
||||
$count = 1;
|
||||
$previousauthor = '';
|
||||
$numposts = 0;
|
||||
$author_posts = [];
|
||||
$selected_items = [];
|
||||
|
||||
while (count($selected_items) < $this->itemsPerPage && ++$count < 50 && count($items) > 0) {
|
||||
foreach ($items as $item) {
|
||||
if ($previousauthor == $item["author-link"]) {
|
||||
++$numposts;
|
||||
} else {
|
||||
$numposts = 0;
|
||||
}
|
||||
$previousauthor = $item["author-link"];
|
||||
$maxposts = round((count($items) / $this->itemsPerPage) * $maxpostperauthor);
|
||||
$minId = $items[array_key_first($items)]['received'];
|
||||
$maxId = $items[array_key_last($items)]['received'];
|
||||
$this->logger->debug('Blubb', ['tab' => $this->selectedTab, 'count' => $count, 'min' => $minId, 'max' => $maxId]);
|
||||
|
||||
if (($numposts < $maxpostperauthor) && (count($selected_items) < $this->itemsPerPage)) {
|
||||
$selected_items[] = $item;
|
||||
foreach ($items as $item) {
|
||||
$author_posts[$item[$key]][$item['uri-id']] = $item['received'];
|
||||
}
|
||||
foreach ($author_posts as $posts) {
|
||||
if (count($posts) <= $maxposts) {
|
||||
continue;
|
||||
}
|
||||
asort($posts);
|
||||
while (count($posts) > $maxposts) {
|
||||
$uri_id = array_key_first($posts);
|
||||
unset($posts[$uri_id]);
|
||||
unset($items[$uri_id]);
|
||||
}
|
||||
}
|
||||
$selected_items = array_merge($selected_items, $items);
|
||||
|
||||
// If we're looking at a "previous page", the lookup continues forward in time because the list is
|
||||
// sorted in chronologically decreasing order
|
||||
if (isset($this->minId)) {
|
||||
$this->minId = $items[0]['received'];
|
||||
if (!empty($this->minId)) {
|
||||
$this->minId = $minId;
|
||||
} else {
|
||||
// In any other case, the lookup continues backwards in time
|
||||
$this->maxId = $items[count($items) - 1]['received'];
|
||||
$this->maxId = $maxId;
|
||||
}
|
||||
|
||||
$items = $this->selectItems();
|
||||
if (count($selected_items) < $this->itemsPerPage) {
|
||||
$items = $this->selectItems();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$selected_items = $items;
|
||||
|
@ -606,9 +623,14 @@ class Timeline extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$r = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'received', 'author-link'], $condition, $params);
|
||||
$items = [];
|
||||
$result = Post::selectThreadForUser($this->session->getLocalUserId() ?: 0, ['uri-id', 'received', 'author-id', 'author-gsid'], $condition, $params);
|
||||
|
||||
while ($item = $this->database->fetch($result)) {
|
||||
$items[$item['uri-id']] = $item;
|
||||
}
|
||||
$this->database->close($result);
|
||||
|
||||
$items = Post::toArray($r);
|
||||
if (empty($items)) {
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -166,6 +166,10 @@ return [
|
|||
// Has to be one of these values: emergency, alert, critical, error, warning, notice, info, debug
|
||||
'loglevel' => 'notice',
|
||||
|
||||
// max_author_posts_community_page (Integer)
|
||||
// The maximum number of posts on the local community page from a single author.
|
||||
'max_author_posts_community_page' => 0,
|
||||
|
||||
// max_image_length (Integer)
|
||||
// An alternate way of limiting picture upload sizes.
|
||||
// Specify the maximum pixel length that pictures are allowed to be (for non-square pictures, it will apply to the longest side).
|
||||
|
@ -173,6 +177,10 @@ return [
|
|||
// If you don't want to set a maximum length, set to -1.
|
||||
'max_image_length' => -1,
|
||||
|
||||
// max_server_posts_community_page (Integer)
|
||||
// The maximum number of posts on the global community page from a single server.
|
||||
'max_server_posts_community_page' => 0,
|
||||
|
||||
// maximagesize (Integer)
|
||||
// Maximum size in bytes of an uploaded photo.
|
||||
'maximagesize' => 800000,
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -56,6 +56,7 @@
|
|||
{{include file="field_checkbox.tpl" field=$force_publish}}
|
||||
{{include file="field_select.tpl" field=$community_page_style}}
|
||||
{{include file="field_input.tpl" field=$max_author_posts_community_page}}
|
||||
{{include file="field_input.tpl" field=$max_server_posts_community_page}}
|
||||
|
||||
{{if $mail_able}}
|
||||
{{include file="field_checkbox.tpl" field=$mail_enabled}}
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
{{include file="field_checkbox.tpl" field=$force_publish}}
|
||||
{{include file="field_select.tpl" field=$community_page_style}}
|
||||
{{include file="field_input.tpl" field=$max_author_posts_community_page}}
|
||||
{{include file="field_input.tpl" field=$max_server_posts_community_page}}
|
||||
|
||||
{{if $mail_able}}
|
||||
{{include file="field_checkbox.tpl" field=$mail_enabled}}
|
||||
|
|
Loading…
Reference in a new issue