X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FMail.php;h=2d304e55f8b92142544fd65781a424af44b56880;hb=44ac0275ab3d42c661594d052e9346a9f238141e;hp=ae30859be1849632df70bac1cbe96ad2ebf94e0d;hpb=d5623d28d5833c93dd5e47d11ed9edb24b19e488;p=friendica.git diff --git a/src/Model/Mail.php b/src/Model/Mail.php index ae30859be1..2d304e55f8 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -1,47 +1,53 @@ 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; @@ -51,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 = array('uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle, - 'created' => datetime_convert(), 'updated' => datetime_convert(), - 'subject' => $subject, 'recips' => $handles); - if (dba::insert('conv', $fields)) { - $convid = dba::lastInsertId(); + $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 (!$convid) { - logger('send message: conversation not found.'); + Logger::log('send message: conversation not found.'); return -4; } @@ -92,27 +97,29 @@ class Mail } $post_id = null; - $result = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`, - `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`) - VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )", - intval(local_user()), - dbesc($guid), - intval($convid), - dbesc($me[0]['name']), - dbesc($me[0]['thumb']), - dbesc($me[0]['url']), - intval($recipient), - dbesc($subject), - dbesc($body), - 1, - intval($reply), - 0, - dbesc($uri), - dbesc($replyto), - datetime_convert() + $success = DBA::insert( + 'mail', + [ + 'uid' => local_user(), + 'guid' => $guid, + 'convid' => $convid, + '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 ($result) { - $post_id = dba::lastInsertId(); + + if ($success) { + $post_id = DBA::lastInsertId(); } /** @@ -136,13 +143,7 @@ class Mail } $image_uri = substr($image, strrpos($image, '/') + 1); $image_uri = substr($image_uri, 0, strpos($image_uri, '-')); - q("UPDATE `photo` SET `allow_cid` = '%s' - WHERE `resource-id` = '%s' AND `album` = '%s' AND `uid` = %d ", - dbesc('<' . $recipient . '>'), - dbesc($image_uri), - dbesc( t('Wall Photos')), - intval(local_user()) - ); + Photo::update(['allow-cid' => '<' . $recipient . '>'], ['resource-id' => $image_uri, 'album' => 'Wall Photos', 'uid' => local_user()]); } } } @@ -155,17 +156,26 @@ class Mail } } - function send_wallmessage($recipient = '', $body = '', $subject = '', $replyto = '') + /** + * @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(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); @@ -174,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); @@ -186,37 +196,38 @@ class Mail $handles = $recip_handle . ';' . $sender_handle; $convid = null; - $fields = array('uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle, - 'created' => datetime_convert(), 'updated' => datetime_convert(), - 'subject' => $subject, 'recips' => $handles); - if (dba::insert('conv', $fields)) { - $convid = dba::lastInsertId(); + $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 (!$convid) { - logger('send message: conversation not found.'); + Logger::log('send message: conversation not found.'); return -4; } - q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`, - `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`) - VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )", - intval($recipient['uid']), - dbesc($guid), - intval($convid), - dbesc($me['name']), - dbesc($me['photo']), - dbesc($me['url']), - 0, - dbesc($subject), - dbesc($body), - 0, - 0, - 0, - dbesc($uri), - dbesc($replyto), - datetime_convert(), - 1 + 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' => 0, + 'reply' => 0, + 'replied' => 0, + 'uri' => $uri, + 'parent-uri' => $replyto, + 'created' => DateTimeFormat::utcNow(), + 'unknown' => 1 + ] ); return 0;