X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FModel%2FMail.php;h=2d304e55f8b92142544fd65781a424af44b56880;hb=9f11476ca09c128e4489f702895f699b8158acc8;hp=d5105ac21ce118a05bdb752dcf14b686020172f1;hpb=753996c86f0ddc3aa54c3fbd52a66626d89933aa;p=friendica.git diff --git a/src/Model/Mail.php b/src/Model/Mail.php index d5105ac21c..2d304e55f8 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -1,17 +1,17 @@ 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 +57,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 +97,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'], + 'from-name' => $me['name'], + 'from-photo' => $me['thumb'], + 'from-url' => $me['url'], 'contact-id' => $recipient, 'title' => $subject, 'body' => $body, - 'seen' => true, + 'seen' => 1, 'reply' => $reply, - 'replied' => false, + 'replied' => 0, 'uri' => $uri, 'parent-uri' => $replyto, - 'created' => datetime_convert() + 'created' => DateTimeFormat::utcNow() ] ); if ($success) { - $post_id = dba::lastInsertId(); + $post_id = DBA::lastInsertId(); } /** @@ -142,7 +143,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()]); } } } @@ -156,22 +157,25 @@ class Mail } /** - * @param string $recipient recipient, default empty + * @param array $recipient recipient, default empty * @param string $body message body, default empty * @param string $subject message subject, default empty * @param string $replyto reply to, default empty + * @return int + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException */ - public static function sendWall($recipient = '', $body = '', $subject = '', $replyto = '') + public static function sendWall(array $recipient = [], $body = '', $subject = '', $replyto = '') { if (!$recipient) { return -1; } 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 +184,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,18 +197,18 @@ 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'], @@ -216,13 +220,13 @@ class Mail 'contact-id' => 0, 'title' => $subject, 'body' => $body, - 'seen' => false, - 'reply' => false, - 'replied' => false, + 'seen' => 0, + 'reply' => 0, + 'replied' => 0, 'uri' => $uri, 'parent-uri' => $replyto, - 'created' => datetime_convert(), - 'unknown' => true + 'created' => DateTimeFormat::utcNow(), + 'unknown' => 1 ] );