Merge remote-tracking branch 'upstream/2023.09-rc' into site-settings

This commit is contained in:
Michael 2023-11-28 16:08:22 +00:00
commit 752172ab54
6 changed files with 130 additions and 106 deletions

View File

@ -482,12 +482,11 @@ class Relation
*/ */
public static function countFollows(int $cid, array $condition = []): int public static function countFollows(int $cid, array $condition = []): int
{ {
$condition = DBA::mergeConditions($condition, [ $condition = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
'`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)', $sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
$cid,
]);
return DI::dba()->count('contact', $condition); $result = DBA::fetchFirst($sql, $condition);
return $result['total'] ?? 0;
} }
/** /**
@ -497,20 +496,18 @@ class Relation
* @param array $condition Additional condition on the contact table * @param array $condition Additional condition on the contact table
* @param int $count * @param int $count
* @param int $offset * @param int $offset
* @param bool $shuffle
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)', $sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition);
$cid] if ($count > 0) {
); $sql .= " LIMIT ?, ?";
$condition = array_merge($condition, [$offset, $count]);
return DI::dba()->selectToArray('contact', [], $condition, }
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] return DBA::toArray(DBA::p($sql, $condition));
);
} }
/** /**
@ -523,12 +520,11 @@ class Relation
*/ */
public static function countFollowers(int $cid, array $condition = []) public static function countFollowers(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $sql = "SELECT COUNT(*) AS `total` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
$cid]
);
return DI::dba()->count('contact', $condition); $result = DBA::fetchFirst($sql, $condition);
return $result['total'] ?? 0;
} }
/** /**
@ -538,19 +534,18 @@ class Relation
* @param array $condition Additional condition on the contact table * @param array $condition Additional condition on the contact table
* @param int $count * @param int $count
* @param int $offset * @param int $offset
* @param bool $shuffle
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0)
{ {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $cid] $sql = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition);
); if ($count > 0) {
$sql .= " LIMIT ?, ?";
return DI::dba()->selectToArray('contact', [], $condition, $condition = array_merge($condition, [$offset, $count]);
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] }
); return DBA::toArray(DBA::p($sql, $condition));
} }
/** /**
@ -563,13 +558,21 @@ class Relation
*/ */
public static function countMutuals(int $cid, array $condition = []) public static function countMutuals(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
$cid, $cid] $sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " INTERSECT " . $sql2;
return DI::dba()->count('contact', $condition); $contacts = 0;
$query = DBA::p($sql, $union);
while (DBA::fetch($query)) {
$contacts++;
}
DBA::close($query);
return $contacts;
} }
/** /**
@ -579,24 +582,24 @@ class Relation
* @param array $condition Additional condition on the contact table * @param array $condition Additional condition on the contact table
* @param int $count * @param int $count
* @param int $offset * @param int $offset
* @param bool $shuffle
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public static function listMutuals(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listMutuals(int $cid, array $condition = [], int $count = 30, int $offset = 0)
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
$cid, $cid] $sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " INTERSECT " . $sql2;
return DI::dba()->selectToArray('contact', [], $condition, if ($count > 0) {
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] $sql .= " LIMIT ?, ?";
); $union = array_merge($union, [$offset, $count]);
}
return DBA::toArray(DBA::p($sql, $union));
} }
/** /**
* Counts the number of contacts with any relationship with the provided public contact. * Counts the number of contacts with any relationship with the provided public contact.
* *
@ -607,13 +610,21 @@ class Relation
*/ */
public static function countAll(int $cid, array $condition = []) public static function countAll(int $cid, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))', $sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
$cid, $cid] $sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " UNION " . $sql2;
return DI::dba()->count('contact', $condition); $contacts = 0;
$query = DBA::p($sql, $union);
while (DBA::fetch($query)) {
$contacts++;
}
DBA::close($query);
return $contacts;
} }
/** /**
@ -623,21 +634,22 @@ class Relation
* @param array $condition Additional condition on the contact table * @param array $condition Additional condition on the contact table
* @param int $count * @param int $count
* @param int $offset * @param int $offset
* @param bool $shuffle
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
public static function listAll(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listAll(int $cid, array $condition = [], int $count = 30, int $offset = 0)
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`cid` = ? and `follows`", $cid]);
['(`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ? and `follows`", $cid]);
OR `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`))', $sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `relation-cid` WHERE " . array_shift($condition1);
$cid, $cid] $sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " UNION " . $sql2;
return DI::dba()->selectToArray('contact', [], $condition, if ($count > 0) {
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] $sql .= " LIMIT ?, ?";
); $union = array_merge($union, [$offset, $count]);
}
return DBA::toArray(DBA::p($sql, $union));
} }
/** /**
@ -652,13 +664,21 @@ class Relation
*/ */
public static function countCommon(int $sourceId, int $targetId, array $condition = []) public static function countCommon(int $sourceId, int $targetId, array $condition = [])
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $sourceId]);
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $targetId]);
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)', $sql1 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
$sourceId, $targetId] $sql2 = "SELECT `contact`.`id` FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " INTERSECT " . $sql2;
return DI::dba()->count('contact', $condition); $contacts = 0;
$query = DBA::p($sql, $union);
while (DBA::fetch($query)) {
$contacts++;
}
DBA::close($query);
return $contacts;
} }
/** /**
@ -670,21 +690,22 @@ class Relation
* @param array $condition Additional condition on the contact table * @param array $condition Additional condition on the contact table
* @param int $count * @param int $count
* @param int $offset * @param int $offset
* @param bool $shuffle
* @return array|bool Array on success, false on failure * @return array|bool Array on success, false on failure
* @throws Exception * @throws Exception
*/ */
public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false) public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0)
{ {
$condition = DBA::mergeConditions($condition, $condition1 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $sourceId]);
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?) $condition2 = DBA::mergeConditions($condition, ["`relation-cid` = ?", $targetId]);
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)", $sql1 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " . array_shift($condition1);
$sourceId, $targetId] $sql2 = "SELECT `contact`.* FROM `contact-relation` INNER JOIN `contact` ON `contact`.`id` = `cid` WHERE " .array_shift($condition2);
); $union = array_merge($condition1, $condition2);
$sql = $sql1 . " INTERSECT " . $sql2;
return DI::dba()->selectToArray('contact', [], $condition, if ($count > 0) {
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']] $sql .= " LIMIT ?, ?";
); $union = array_merge($union, [$offset, $count]);
}
return DBA::toArray(DBA::p($sql, $union));
} }
/** /**

View File

@ -103,7 +103,7 @@ class Channel extends Timeline
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]); $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
} }
if (empty($request['mode']) || ($request['mode'] != 'raw')) { if (!$this->raw) {
$tabs = $this->getTabArray($this->channel->getTimelines($this->session->getLocalUserId()), 'channel'); $tabs = $this->getTabArray($this->channel->getTimelines($this->session->getLocalUserId()), 'channel');
$tabs = array_merge($tabs, $this->getTabArray($this->channelRepository->selectByUid($this->session->getLocalUserId()), 'channel')); $tabs = array_merge($tabs, $this->getTabArray($this->channelRepository->selectByUid($this->session->getLocalUserId()), 'channel'));
$tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel')); $tabs = array_merge($tabs, $this->getTabArray($this->community->getTimelines(true), 'channel'));

View File

@ -97,7 +97,7 @@ class Community extends Timeline
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]); $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
} }
if (empty($request['mode']) || ($request['mode'] != 'raw')) { if (!$this->raw) {
$tabs = $this->getTabArray($this->community->getTimelines($this->session->isAuthenticated()), 'community'); $tabs = $this->getTabArray($this->community->getTimelines($this->session->isAuthenticated()), 'community');
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl'); $tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
$o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]); $o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);

View File

@ -157,7 +157,7 @@ class Network extends Timeline
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]); $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
} }
if (!(isset($_GET['mode']) and ($_GET['mode'] == 'raw'))) { if (!$this->raw) {
$o .= $this->getTabsHTML(); $o .= $this->getTabsHTML();
Nav::setSelected($this->args->get(0)); Nav::setSelected($this->args->get(0));
@ -210,30 +210,30 @@ class Network extends Timeline
]; ];
$o .= $this->conversation->statusEditor($x); $o .= $this->conversation->statusEditor($x);
}
if ($this->circleId) { if ($this->circleId) {
$circle = $this->database->selectFirst('group', ['name'], ['id' => $this->circleId, 'uid' => $this->session->getLocalUserId()]); $circle = $this->database->selectFirst('group', ['name'], ['id' => $this->circleId, 'uid' => $this->session->getLocalUserId()]);
if (!$this->database->isResult($circle)) { if (!$this->database->isResult($circle)) {
$this->systemMessages->addNotice($this->l10n->t('No such circle')); $this->systemMessages->addNotice($this->l10n->t('No such circle'));
} }
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [ $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
'$title' => $this->l10n->t('Circle: %s', $circle['name']) '$title' => $this->l10n->t('Circle: %s', $circle['name'])
]) . $o;
} elseif ($this->groupContactId) {
$contact = Contact::getById($this->groupContactId);
if ($this->database->isResult($contact)) {
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('contact/list.tpl'), [
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
'id' => $this->args->get(0),
]) . $o; ]) . $o;
} else { } elseif ($this->groupContactId) {
$this->systemMessages->addNotice($this->l10n->t('Invalid contact.')); $contact = Contact::getById($this->groupContactId);
if ($this->database->isResult($contact)) {
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('contact/list.tpl'), [
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
'id' => $this->args->get(0),
]) . $o;
} else {
$this->systemMessages->addNotice($this->l10n->t('Invalid contact.'));
}
} elseif (Profile::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) {
$o .= Profile::getBirthdays($this->session->getLocalUserId());
$o .= Profile::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId());
} }
} elseif (Profile::shouldDisplayEventList($this->session->getLocalUserId(), $this->mode)) {
$o .= Profile::getBirthdays($this->session->getLocalUserId());
$o .= Profile::getEventsReminderHTML($this->session->getLocalUserId(), $this->session->getPublicContactId());
} }
try { try {

View File

@ -68,6 +68,8 @@ class Timeline extends BaseModule
protected $force; protected $force;
/** @var bool */ /** @var bool */
protected $update; protected $update;
/** @var bool */
protected $raw;
/** @var App\Mode $mode */ /** @var App\Mode $mode */
protected $mode; protected $mode;
@ -140,6 +142,7 @@ class Timeline extends BaseModule
$this->noSharer = !empty($request['no_sharer']); $this->noSharer = !empty($request['no_sharer']);
$this->force = !empty($request['force']) && !empty($request['item']); $this->force = !empty($request['force']) && !empty($request['item']);
$this->update = !empty($request['force']) && !empty($request['first_received']) && !empty($request['first_created']) && !empty($request['first_uriid']) && !empty($request['first_commented']); $this->update = !empty($request['force']) && !empty($request['first_received']) && !empty($request['first_created']) && !empty($request['first_uriid']) && !empty($request['first_commented']);
$this->raw = !empty($request['mode']) && ($request['mode'] == 'raw');
} }
protected function getNoSharerWidget(string $base): string protected function getNoSharerWidget(string $base): string

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2023.09-rc\n" "Project-Id-Version: 2023.09-rc\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-28 06:59+0000\n" "POT-Creation-Date: 2023-11-28 12:50+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -4433,7 +4433,7 @@ msgstr ""
msgid "Policies" msgid "Policies"
msgstr "" msgstr ""
#: src/Module/Admin/Site.php:416 src/Module/Calendar/Event/Form.php:252 #: src/Module/Admin/Site.php:408 src/Module/Calendar/Event/Form.php:252
#: src/Module/Contact.php:546 src/Module/Profile/Profile.php:276 #: src/Module/Contact.php:546 src/Module/Profile/Profile.php:276
msgid "Advanced" msgid "Advanced"
msgstr "" msgstr ""