]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/FriendSuggest.php
Merge remote-tracking branch 'upstream/develop' into api4
[friendica.git] / src / Module / FriendSuggest.php
index b2a76300a443587909ef277691b5c8eec1118e48..b0456377f1c53d8ed76f29996d3b9f81300ec12d 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;
 
@@ -19,16 +38,16 @@ use Friendica\Worker\Delivery;
  */
 class FriendSuggest extends BaseModule
 {
-       public static function init(array $parameters = [])
+       public function init()
        {
                if (!local_user()) {
                        throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
                }
        }
 
-       public static function post(array $parameters = [])
+       public function post()
        {
-               $cid = intval($parameters['contact']);
+               $cid = intval($this->parameters['contact']);
 
                // We do query the "uid" as well to ensure that it is our contact
                if (!DI::dba()->exists('contact', ['id' => $cid, 'uid' => local_user()])) {
@@ -49,25 +68,24 @@ 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'],
-                       'request' => $contact['request'],
-                       'photo'   => $contact['avatar'],
-                       'note'    => $note,
-                       'created' => DateTimeFormat::utcNow()
-               ]);
+               $suggest = DI::fsuggest()->save(DI::fsuggestFactory()->createNew(
+                       local_user(),
+                       $cid,
+                       $contact['name'],
+                       $contact['url'],
+                       $contact['request'],
+                       $contact['avatar'],
+                       $note
+               ));
 
                Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, $suggest->id);
 
                info(DI::l10n()->t('Friend suggestion sent.'));
        }
 
-       public static function content(array $parameters = [])
+       public function content(): string
        {
-               $cid = intval($parameters['contact']);
+               $cid = intval($this->parameters['contact']);
 
                $contact = DI::dba()->selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
                if (empty($contact)) {
@@ -75,8 +93,16 @@ class FriendSuggest extends BaseModule
                        DI::baseUrl()->redirect();
                }
 
-               $contacts = ContactModel::selectToArray(['id', 'name'], [
-                       '`uid` = ? AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND NOT `deleted` AND `notify` != "" AND `id` != ? AND `network` = ?',
+               $suggestableContacts = 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,8 +110,8 @@ class FriendSuggest extends BaseModule
 
                $formattedContacts = [];
 
-               foreach ($contacts as $contact) {
-                       $formattedContacts[$contact['id']] = $contact['name'];
+               foreach ($suggestableContacts as $suggestableContact) {
+                       $formattedContacts[$suggestableContact['id']] = $suggestableContact['name'];
                }
 
                $tpl = Renderer::getMarkupTemplate('fsuggest.tpl');