X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FMail.php;h=b47d4ac8e33c46b5d9358148c0088342031e808b;hb=8c75c26361a836e6f281c550d577c2f8a11b579b;hp=b2e9e1a48734770b4b2ec5a0b9fcf05287eb0eda;hpb=dad58e0f6fdff5e1ff8a002bb31119a38f08268b;p=friendica.git diff --git a/src/Model/Mail.php b/src/Model/Mail.php index b2e9e1a487..b47d4ac8e3 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -6,14 +6,13 @@ namespace Friendica\Model; use Friendica\Core\L10n; +use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Core\Worker; -use Friendica\Database\DBM; +use Friendica\Database\DBA; +use Friendica\Model\Photo; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; -use dba; - -require_once 'include/dba.php'; /** * Class to handle private messages @@ -30,7 +29,7 @@ class Mail */ public static function send($recipient = 0, $body = '', $subject = '', $replyto = '') { - $a = get_app(); + $a = \get_app(); if (!$recipient) { return -1; @@ -40,14 +39,14 @@ class Mail $subject = L10n::t('[no subject]'); } - $me = dba::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]); - $contact = dba::selectFirst('contact', [], ['id' => $recipient, 'uid' => local_user()]); + $me = DBA::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]); + $contact = DBA::selectFirst('contact', [], ['id' => $recipient, 'uid' => local_user()]); if (!(count($me) && (count($contact)))) { return -2; } - $guid = get_guid(32); + $guid = System::createUUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $convid = 0; @@ -57,16 +56,15 @@ class Mail if (strlen($replyto)) { $reply = true; - $r = q("SELECT `convid` FROM `mail` WHERE `uid` = %d AND (`uri` = '%s' OR `parent-uri` = '%s') LIMIT 1", - intval(local_user()), - dbesc($replyto), - dbesc($replyto) - ); - if (DBM::is_result($r)) { - $convid = $r[0]['convid']; + $condition = ["`uid` = ? AND (`uri` = ? OR `parent-uri` = ?)", + local_user(), $replyto, $replyto]; + $mail = DBA::selectFirst('mail', ['convid'], $condition); + if (DBA::isResult($mail)) { + $convid = $mail['convid']; } } + $convuri = ''; if (!$convid) { // create a new conversation $recip_host = substr($contact['url'], strpos($contact['url'], '://') + 3); @@ -75,7 +73,7 @@ class Mail $recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host); $sender_handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); - $conv_guid = get_guid(32); + $conv_guid = System::createUUID(); $convuri = $recip_handle . ':' . $conv_guid; $handles = $recip_handle . ';' . $sender_handle; @@ -83,13 +81,13 @@ class Mail $fields = ['uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle, 'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(), 'subject' => $subject, 'recips' => $handles]; - if (dba::insert('conv', $fields)) { - $convid = dba::lastInsertId(); + if (DBA::insert('conv', $fields)) { + $convid = DBA::lastInsertId(); } } if (!$convid) { - logger('send message: conversation not found.'); + Logger::log('send message: conversation not found.'); return -4; } @@ -98,7 +96,7 @@ class Mail } $post_id = null; - $success = dba::insert( + $success = DBA::insert( 'mail', [ 'uid' => local_user(), @@ -120,7 +118,7 @@ class Mail ); if ($success) { - $post_id = dba::lastInsertId(); + $post_id = DBA::lastInsertId(); } /** @@ -144,7 +142,7 @@ class Mail } $image_uri = substr($image, strrpos($image, '/') + 1); $image_uri = substr($image_uri, 0, strpos($image_uri, '-')); - dba::update('photo', ['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]); + Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]); } } } @@ -173,7 +171,7 @@ class Mail $subject = L10n::t('[no subject]'); } - $guid = get_guid(32); + $guid = System::createUUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $me = Probe::uri($replyto); @@ -182,7 +180,7 @@ class Mail return -2; } - $conv_guid = get_guid(32); + $conv_guid = System::createUUID(); $recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); @@ -197,16 +195,16 @@ class Mail $fields = ['uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle, 'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(), 'subject' => $subject, 'recips' => $handles]; - if (dba::insert('conv', $fields)) { - $convid = dba::lastInsertId(); + if (DBA::insert('conv', $fields)) { + $convid = DBA::lastInsertId(); } if (!$convid) { - logger('send message: conversation not found.'); + Logger::log('send message: conversation not found.'); return -4; } - dba::insert( + DBA::insert( 'mail', [ 'uid' => $recipient['uid'],