]> git.mxchange.org Git - friendica.git/blobdiff - mod/fsuggest.php
Storing the protocol while following a contact
[friendica.git] / mod / fsuggest.php
index 8fc0f07deef7b8b6becee9cd7f2d2a849c6cfbf7..58bb11670070bbf22ceeee11fa1ede56c97b766c 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Strings;
 
 function fsuggest_post(App $a)
 {
@@ -22,21 +23,17 @@ function fsuggest_post(App $a)
 
        $contact_id = intval($a->argv[1]);
 
-       $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-               intval($contact_id),
-               intval(local_user())
-       );
-       if (! DBA::isResult($r)) {
+       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+       if (! DBA::isResult($contact)) {
                notice(L10n::t('Contact not found.') . EOL);
                return;
        }
-       $contact = $r[0];
 
        $new_contact = intval($_POST['suggest']);
 
-       $hash = random_string();
+       $hash = Strings::getRandomHex();
 
-       $note = escape_tags(trim($_POST['note']));
+       $note = Strings::escapeHtml(trim(defaults($_POST, 'note', '')));
 
        if ($new_contact) {
                $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -44,14 +41,14 @@ function fsuggest_post(App $a)
                        intval(local_user())
                );
                if (DBA::isResult($r)) {
-                       $x = q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`)
+                       q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`)
                                VALUES ( %d, %d, '%s','%s','%s','%s','%s','%s')",
                                intval(local_user()),
                                intval($contact_id),
-                               DBA::escape($r[0]['name']),
-                               DBA::escape($r[0]['url']),
-                               DBA::escape($r[0]['request']),
-                               DBA::escape($r[0]['photo']),
+                               DBA::escape($contact['name']),
+                               DBA::escape($contact['url']),
+                               DBA::escape($contact['request']),
+                               DBA::escape($contact['photo']),
                                DBA::escape($hash),
                                DBA::escape(DateTimeFormat::utcNow())
                        );
@@ -60,7 +57,7 @@ function fsuggest_post(App $a)
                                intval(local_user())
                        );
                        if (DBA::isResult($r)) {
-                               $fsuggest_id = $r[0]['id'];
+                               $fsuggest_id = $contact['id'];
                                q("UPDATE `fsuggest` SET `note` = '%s' WHERE `id` = %d AND `uid` = %d",
                                        DBA::escape($note),
                                        intval($fsuggest_id),
@@ -87,16 +84,11 @@ function fsuggest_content(App $a)
 
        $contact_id = intval($a->argv[1]);
 
-       $r = q(
-               "SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-               intval($contact_id),
-               intval(local_user())
-       );
-       if (! DBA::isResult($r)) {
+       $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
+       if (! DBA::isResult($contact)) {
                notice(L10n::t('Contact not found.') . EOL);
                return;
        }
-       $contact = $r[0];
 
        $o = '<h3>' . L10n::t('Suggest Friends') . '</h3>';