X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fwallmessage.php;h=d4988aa0cae385a7a73bb007d4bc64ebb49edf05;hb=6b03ee29229e1c56e1ba71fb3ff062fa4f1ce51a;hp=cf1bca9cb9d9dc2b8e6e437bbb271750414f6ae3;hpb=0c0abd923822994d808273ed60c149d34b49a76f;p=friendica.git diff --git a/mod/wallmessage.php b/mod/wallmessage.php index cf1bca9cb9..d4988aa0ca 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -26,6 +26,8 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Mail; use Friendica\Model\Profile; +use Friendica\Model\User; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; function wallmessage_post(App $a) { @@ -36,35 +38,27 @@ function wallmessage_post(App $a) { return; } - $subject = (!empty($_REQUEST['subject']) ? Strings::escapeTags(trim($_REQUEST['subject'])) : ''); - $body = (!empty($_REQUEST['body']) ? Strings::escapeHtml(trim($_REQUEST['body'])) : ''); + $subject = trim($_REQUEST['subject'] ?? ''); + $body = Strings::escapeHtml(trim($_REQUEST['body'] ?? '')); - $recipient = ((DI::args()->getArgc() > 1) ? Strings::escapeTags(DI::args()->getArgv()[1]) : ''); + $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : ''); if ((! $recipient) || (! $body)) { return; } - $r = q("select * from user where nickname = '%s' limit 1", - DBA::escape($recipient) - ); - - if (! DBA::isResult($r)) { - Logger::log('wallmessage: no recipient'); + $user = User::getByNickname($recipient); + if (empty($r)) { + Logger::notice('wallmessage: no recipient'); return; } - $user = $r[0]; - - if (! intval($user['unkmail'])) { + if (!$user['unkmail']) { notice(DI::l10n()->t('Permission denied.')); return; } - $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", - intval($user['uid']) - ); - - if ($r[0]['total'] > $user['cntunkmail']) { + $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]); + if ($total > $user['cntunkmail']) { notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); return; } @@ -104,28 +98,21 @@ function wallmessage_content(App $a) { return; } - $r = q("select * from user where nickname = '%s' limit 1", - DBA::escape($recipient) - ); + $user = User::getByNickname($recipient); - if (! DBA::isResult($r)) { + if (empty($user)) { notice(DI::l10n()->t('No recipient.')); - Logger::log('wallmessage: no recipient'); + Logger::notice('wallmessage: no recipient'); return; } - $user = $r[0]; - - if (!intval($user['unkmail'])) { + if (!$user['unkmail']) { notice(DI::l10n()->t('Permission denied.')); return; } - $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", - intval($user['uid']) - ); - - if ($r[0]['total'] > $user['cntunkmail']) { + $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]); + if ($total > $user['cntunkmail']) { notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])); return; }