X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FMail.php;h=b47d4ac8e33c46b5d9358148c0088342031e808b;hb=df230126c937985fb74d4d3ea93a963fae4cd0b6;hp=d789d69de03749d5d9dc697dd73dd90143a2b0a7;hpb=b3e6a1d2832be024819328e51e9e1df4c25b560f;p=friendica.git diff --git a/src/Model/Mail.php b/src/Model/Mail.php index d789d69de0..b47d4ac8e3 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -1,17 +1,18 @@ 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; @@ -55,39 +56,38 @@ 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[0]['url'], strpos($contact[0]['url'], '://') + 3); + $recip_host = substr($contact['url'], strpos($contact['url'], '://') + 3); $recip_host = substr($recip_host, 0, strpos($recip_host, '/')); - $recip_handle = (($contact[0]['addr']) ? $contact[0]['addr'] : $contact[0]['nick'] . '@' . $recip_host); + $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; $fields = ['uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle, - 'created' => datetime_convert(), 'updated' => datetime_convert(), + '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; } @@ -96,29 +96,29 @@ class Mail } $post_id = null; - $success = dba::insert( + $success = DBA::insert( 'mail', [ 'uid' => local_user(), 'guid' => $guid, 'convid' => $convid, - 'from-name' => $me[0]['name'], - 'from-photo' => $me[0]['thumb'], - 'from-url' => $me[0]['url'], - `contact-id` => $recipient, - `title` => $subject, - `body` => $body, - `seen` => true, - `reply` => $reply, - `replied` => false, - `uri` => $uri, - `parent-uri` => $replyto, - `created` => datetime_convert() + 'from-name' => $me['name'], + 'from-photo' => $me['thumb'], + 'from-url' => $me['url'], + 'contact-id' => $recipient, + 'title' => $subject, + 'body' => $body, + 'seen' => 1, + 'reply' => $reply, + 'replied' => 0, + 'uri' => $uri, + 'parent-uri' => $replyto, + 'created' => DateTimeFormat::utcNow() ] ); if ($success) { - $post_id = dba::lastInsertId(); + $post_id = DBA::lastInsertId(); } /** @@ -142,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()]); } } } @@ -168,10 +168,10 @@ class Mail } if (!strlen($subject)) { - $subject = t('[no subject]'); + $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); @@ -180,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); @@ -193,36 +193,36 @@ class Mail $convid = null; $fields = ['uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle, - 'created' => datetime_convert(), 'updated' => datetime_convert(), + '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'], - `guid` => $guid, - `convid` => $convid, - `from-name` => $me['name'], - `from-photo` => $me['photo'], - `from-url` => $me['url'], - `contact-id` => 0, - `title` => $subject, - `body` => $body, - `seen` => false, - `reply` => false, - `replied` => false, - `uri` => $uri, - `parent-uri` => $replyto, - `created` => datetime_convert(), - `unknown` => true + 'uid' => $recipient['uid'], + 'guid' => $guid, + 'convid' => $convid, + 'from-name' => $me['name'], + 'from-photo' => $me['photo'], + 'from-url' => $me['url'], + 'contact-id' => 0, + 'title' => $subject, + 'body' => $body, + 'seen' => 0, + 'reply' => 0, + 'replied' => 0, + 'uri' => $uri, + 'parent-uri' => $replyto, + 'created' => DateTimeFormat::utcNow(), + 'unknown' => 1 ] );