X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Ffsuggest.php;h=58bb11670070bbf22ceeee11fa1ede56c97b766c;hb=41663c7592abe55a958632c3a48265e0a8544d2b;hp=0d088c02c8652abca44cd6788566b7dc9b6d9495;hpb=b958a0702f688cbec70064467dafa1754d04784c;p=friendica.git diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 0d088c02c8..58bb116700 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -2,12 +2,17 @@ /** * @file mod/fsuggest.php */ + use Friendica\App; +use Friendica\Core\ACL; +use Friendica\Core\L10n; use Friendica\Core\Worker; -use Friendica\Database\DBM; - -function fsuggest_post(App $a) { +use Friendica\Database\DBA; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\Strings; +function fsuggest_post(App $a) +{ if (! local_user()) { return; } @@ -18,70 +23,58 @@ 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 (! DBM::is_result($r)) { - notice( t('Contact not found.') . EOL); + $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) { + if ($new_contact) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($new_contact), intval(local_user()) ); - if (DBM::is_result($r)) { - - $x = q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`) + if (DBA::isResult($r)) { + 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), - dbesc($r[0]['name']), - dbesc($r[0]['url']), - dbesc($r[0]['request']), - dbesc($r[0]['photo']), - dbesc($hash), - dbesc(datetime_convert()) + DBA::escape($contact['name']), + DBA::escape($contact['url']), + DBA::escape($contact['request']), + DBA::escape($contact['photo']), + DBA::escape($hash), + DBA::escape(DateTimeFormat::utcNow()) ); $r = q("SELECT `id` FROM `fsuggest` WHERE `note` = '%s' AND `uid` = %d LIMIT 1", - dbesc($hash), + DBA::escape($hash), intval(local_user()) ); - if (DBM::is_result($r)) { - $fsuggest_id = $r[0]['id']; + if (DBA::isResult($r)) { + $fsuggest_id = $contact['id']; q("UPDATE `fsuggest` SET `note` = '%s' WHERE `id` = %d AND `uid` = %d", - dbesc($note), + DBA::escape($note), intval($fsuggest_id), intval(local_user()) ); Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', $fsuggest_id); } - info( t('Friend suggestion sent.') . EOL); + info(L10n::t('Friend suggestion sent.') . EOL); } - } - - } - - function fsuggest_content(App $a) { - require_once 'include/acl_selectors.php'; - if (! local_user()) { - notice(t('Permission denied.') . EOL); + notice(L10n::t('Permission denied.') . EOL); return; } @@ -91,32 +84,26 @@ 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 (! DBM::is_result($r)) { - notice(t('Contact not found.') . EOL); + $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 = '