]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/FriendSuggest.php
Merge pull request #10544 from annando/router-lock
[friendica.git] / src / Module / FriendSuggest.php
index 027a43b36d608b87923aba9564d168d160a21ea9..a53d47c481ea4c51ceedb8e7d011ad08ea4a32aa 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module;
 
@@ -21,7 +40,7 @@ class FriendSuggest extends BaseModule
 {
        public static function init(array $parameters = [])
        {
-               if (! local_user()) {
+               if (!local_user()) {
                        throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
                }
        }
@@ -50,13 +69,13 @@ class FriendSuggest extends BaseModule
                $note = Strings::escapeHtml(trim($_POST['note'] ?? ''));
 
                $suggest = DI::fsuggest()->insert([
-                       'uid' => local_user(),
-                       'cid' => $cid,
-                       'name' => $contact['name'],
-                       'url' => $contact['url'],
+                       'uid'     => local_user(),
+                       'cid'     => $cid,
+                       'name'    => $contact['name'],
+                       'url'     => $contact['url'],
                        'request' => $contact['request'],
-                       'photo' => $contact['avatar'],
-                       'note' => $note,
+                       'photo'   => $contact['avatar'],
+                       'note'    => $note,
                        'created' => DateTimeFormat::utcNow()
                ]);
 
@@ -75,8 +94,16 @@ class FriendSuggest extends BaseModule
                        DI::baseUrl()->redirect();
                }
 
-               $stmtContacts = ContactModel::select(['id', 'name'], [
-                       '`uid` = ? AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND NOT `deleted` AND `notify` != "" AND `id` != ? AND `networks` = ?',
+               $contacts = ContactModel::selectToArray(['id', 'name'], [
+                       '`uid` = ? 
+                       AND `id` != ? 
+                       AND `network` = ? 
+                       AND NOT `self` 
+                       AND NOT `blocked` 
+                       AND NOT `pending` 
+                       AND NOT `archive` 
+                       AND NOT `deleted` 
+                       AND `notify` != ""',
                        local_user(),
                        $cid,
                        Protocol::DFRN,
@@ -84,14 +111,14 @@ class FriendSuggest extends BaseModule
 
                $formattedContacts = [];
 
-               while ($contact = DI::dba()->fetch($stmtContacts)) {
+               foreach ($contacts as $contact) {
                        $formattedContacts[$contact['id']] = $contact['name'];
                }
 
                $tpl = Renderer::getMarkupTemplate('fsuggest.tpl');
                return Renderer::replaceMacros($tpl, [
-                       '$contact_id' => $cid,
-                       '$fsuggest_title' => DI::l10n()->t('Suggest Friends'),
+                       '$contact_id'      => $cid,
+                       '$fsuggest_title'  => DI::l10n()->t('Suggest Friends'),
                        '$fsuggest_select' => [
                                'suggest',
                                DI::l10n()->t('Suggest a friend for %s', $contact['name']),
@@ -99,7 +126,7 @@ class FriendSuggest extends BaseModule
                                '',
                                $formattedContacts,
                        ],
-                       '$submit' => DI::l10n()->t('Submit'),
+                       '$submit'          => DI::l10n()->t('Submit'),
                ]);
        }
 }