From 1ba6c51364c53fdae35d93fb4fc9019a4a7d78dd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Jun 2021 17:38:34 +0000 Subject: [PATCH 1/3] Issue 10386: Reworked match --- mod/match.php | 89 ++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/mod/match.php b/mod/match.php index 29d4e086a..fcaf8b529 100644 --- a/mod/match.php +++ b/mod/match.php @@ -66,54 +66,27 @@ function match_content(App $a) $params = []; $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']); + if (DI::mode()->isMobile()) { + $limit = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', + DI::config()->get('system', 'itemspage_network_mobile')); + } else { + $limit = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', + DI::config()->get('system', 'itemspage_network')); + } + $params['s'] = $tags; $params['n'] = 100; - if (strlen(DI::config()->get('system', 'directory'))) { - $host = Search::getGlobalDirectory(); - } else { - $host = DI::baseUrl(); - } - - $msearch_json = DI::httpRequest()->post($host . '/msearch', $params)->getBody(); - - $msearch = json_decode($msearch_json); - - $start = $_GET['start'] ?? 0; $entries = []; - $paginate = ''; - - if (!empty($msearch->results)) { - for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) { - $profile = $msearch->results[$i]; - - // Already known contact - if (!$profile || Contact::getIdForURL($profile->url, local_user())) { - continue; - } - - $contact = Contact::getByURLForUser($profile->url, local_user()); - if (!empty($contact)) { - $entries[] = ModuleContact::getContactTemplateVars($contact); - } + foreach ([Search::getGlobalDirectory(), DI::baseUrl()] as $server) { + if (empty($server)) { + continue; } - $data = [ - 'class' => 'pager', - 'first' => [ - 'url' => 'match', - 'text' => DI::l10n()->t('first'), - 'class' => 'previous' . ($start == 0 ? 'disabled' : '') - ], - 'next' => [ - 'url' => 'match?start=' . $i, - 'text' => DI::l10n()->t('next'), - 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '') - ] - ]; - - $tpl = Renderer::getMarkupTemplate('paginate.tpl'); - $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]); + $msearch = json_decode(DI::httpRequest()->post($server . '/msearch', $params)->getBody()); + if (!empty($msearch)) { + $entries = match_get_contacts($msearch, $entries, $limit); + } } if (empty($entries)) { @@ -123,9 +96,37 @@ function match_content(App $a) $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl'); $o = Renderer::replaceMacros($tpl, [ '$title' => DI::l10n()->t('Profile Match'), - '$contacts' => $entries, - '$paginate' => $paginate + '$contacts' => array_slice($entries, 0, $limit), ]); return $o; } + +function match_get_contacts($msearch, $entries, $limit) +{ + if (empty($msearch->results)) { + return $entries; + } + + foreach ($msearch->results as $profile) { + if (!$profile) { + continue; + } + + // Already known contact + $contact = Contact::getByURL($profile->url, null, ['rel'], local_user()); + if (!empty($contact) && in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { + continue; + } + + $contact = Contact::getByURLForUser($profile->url, local_user()); + if (!empty($contact)) { + $entries[$contact['id']] = ModuleContact::getContactTemplateVars($contact); + } + + if (count($entries) == $limit) { + break; + } + } + return $entries; +} \ No newline at end of file From 63d2bbcfa06f5f1ceea812ce98e540f0accc29ca Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 13 Jun 2021 17:56:06 +0000 Subject: [PATCH 2/3] Updated messages.po --- view/lang/C/messages.po | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 5e9941df4..93cfa0fc3 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.06-rc\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-06-10 06:29+0000\n" +"POT-Creation-Date: 2021-06-13 17:55+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,26 +18,26 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" -#: include/api.php:1143 +#: include/api.php:1135 #, php-format msgid "Daily posting limit of %d post reached. The post was rejected." msgid_plural "Daily posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1157 +#: include/api.php:1149 #, php-format msgid "Weekly posting limit of %d post reached. The post was rejected." msgid_plural "Weekly posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1171 +#: include/api.php:1163 #, php-format msgid "Monthly posting limit of %d post reached. The post was rejected." msgstr "" -#: include/api.php:4534 mod/photos.php:107 mod/photos.php:211 +#: include/api.php:4526 mod/photos.php:107 mod/photos.php:211 #: mod/photos.php:639 mod/photos.php:1043 mod/photos.php:1060 #: mod/photos.php:1609 src/Model/User.php:1100 src/Model/User.php:1108 #: src/Model/User.php:1116 src/Module/Settings/Profile/Photo/Crop.php:97 @@ -1599,19 +1599,11 @@ msgstr "" msgid "No keywords to match. Please add keywords to your profile." msgstr "" -#: mod/match.php:105 src/Content/Pager.php:216 -msgid "first" -msgstr "" - -#: mod/match.php:110 src/Content/Pager.php:276 -msgid "next" -msgstr "" - -#: mod/match.php:120 src/Module/BaseSearch.php:117 +#: mod/match.php:93 src/Module/BaseSearch.php:117 msgid "No matches" msgstr "" -#: mod/match.php:125 +#: mod/match.php:98 msgid "Profile Match" msgstr "" @@ -3626,10 +3618,18 @@ msgstr "" msgid "Embedded content" msgstr "" +#: src/Content/Pager.php:216 +msgid "first" +msgstr "" + #: src/Content/Pager.php:221 msgid "prev" msgstr "" +#: src/Content/Pager.php:276 +msgid "next" +msgstr "" + #: src/Content/Pager.php:281 msgid "last" msgstr "" @@ -5234,7 +5234,7 @@ msgstr "" #: src/Module/Admin/Addons/Details.php:111 src/Module/Admin/Addons/Index.php:67 #: src/Module/Admin/Blocklist/Contact.php:78 -#: src/Module/Admin/Blocklist/Server.php:88 src/Module/Admin/Federation.php:141 +#: src/Module/Admin/Blocklist/Server.php:88 src/Module/Admin/Federation.php:159 #: src/Module/Admin/Item/Delete.php:65 src/Module/Admin/Logs/Settings.php:80 #: src/Module/Admin/Logs/View.php:64 src/Module/Admin/Queue.php:72 #: src/Module/Admin/Site.php:579 src/Module/Admin/Summary.php:232 @@ -5567,26 +5567,26 @@ msgstr "" msgid "Manage Additional Features" msgstr "" -#: src/Module/Admin/Federation.php:54 +#: src/Module/Admin/Federation.php:56 msgid "Other" msgstr "" -#: src/Module/Admin/Federation.php:108 src/Module/Admin/Federation.php:268 +#: src/Module/Admin/Federation.php:118 src/Module/Admin/Federation.php:348 msgid "unknown" msgstr "" -#: src/Module/Admin/Federation.php:136 +#: src/Module/Admin/Federation.php:154 msgid "" "This page offers you some numbers to the known part of the federated social " "network your Friendica node is part of. These numbers are not complete but " "only reflect the part of the network your node is aware of." msgstr "" -#: src/Module/Admin/Federation.php:142 src/Module/BaseAdmin.php:87 +#: src/Module/Admin/Federation.php:160 src/Module/BaseAdmin.php:87 msgid "Federation Statistics" msgstr "" -#: src/Module/Admin/Federation.php:146 +#: src/Module/Admin/Federation.php:164 #, php-format msgid "" "Currently this node is aware of %d nodes with %d registered users from the " @@ -8881,15 +8881,15 @@ msgstr "" msgid "Show all" msgstr "" -#: src/Module/OAuth/Authorize.php:53 +#: src/Module/OAuth/Authorize.php:54 msgid "Unsupported or missing response type" msgstr "" -#: src/Module/OAuth/Authorize.php:58 src/Module/OAuth/Token.php:58 +#: src/Module/OAuth/Authorize.php:59 src/Module/OAuth/Token.php:58 msgid "Incomplete request data" msgstr "" -#: src/Module/OAuth/Authorize.php:108 +#: src/Module/OAuth/Authorize.php:106 #, php-format msgid "" "Please copy the following authentication code into your application and " From 09c77e3774f520bb3feeebfdf05bf3d8e5e50734 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 15 Jun 2021 17:23:08 +0000 Subject: [PATCH 3/3] Updated messages.po --- view/lang/C/messages.po | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 4e0cd47c3..3a4997842 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.06-rc\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-06-13 11:02+0000\n" +"POT-Creation-Date: 2021-06-15 17:22+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4489,33 +4489,33 @@ msgstr "" msgid "Done. You can now login with your username and password" msgstr "" -#: src/Database/DBStructure.php:64 +#: src/Database/DBStructure.php:65 #, php-format msgid "The database version had been set to %s." msgstr "" -#: src/Database/DBStructure.php:77 +#: src/Database/DBStructure.php:78 #, php-format msgid "" "The post update is at version %d, it has to be at %d to safely drop the " "tables." msgstr "" -#: src/Database/DBStructure.php:89 +#: src/Database/DBStructure.php:90 msgid "No unused tables found." msgstr "" -#: src/Database/DBStructure.php:94 +#: src/Database/DBStructure.php:95 msgid "" "These tables are not used for friendica and will be deleted when you execute " "\"dbstructure drop -e\":" msgstr "" -#: src/Database/DBStructure.php:132 +#: src/Database/DBStructure.php:133 msgid "There are no tables on MyISAM or InnoDB with the Antelope file format." msgstr "" -#: src/Database/DBStructure.php:156 +#: src/Database/DBStructure.php:157 #, php-format msgid "" "\n" @@ -4523,20 +4523,20 @@ msgid "" "%s\n" msgstr "" -#: src/Database/DBStructure.php:159 +#: src/Database/DBStructure.php:160 msgid "Errors encountered performing database changes: " msgstr "" -#: src/Database/DBStructure.php:445 +#: src/Database/DBStructure.php:550 msgid "Another database update is currently running." msgstr "" -#: src/Database/DBStructure.php:449 +#: src/Database/DBStructure.php:554 #, php-format msgid "%s: Database update" msgstr "" -#: src/Database/DBStructure.php:749 +#: src/Database/DBStructure.php:854 #, php-format msgid "%s: updating %s table." msgstr ""