]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Mail.php
Use Model\Photo as much as possible
[friendica.git] / src / Model / Mail.php
index 37ebd123aa46082abf5fc297ea95950c20870e2f..b47d4ac8e33c46b5d9358148c0088342031e808b 100644 (file)
@@ -6,14 +6,14 @@
 namespace Friendica\Model;
 
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\Model\Photo;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 
-require_once 'include/dba.php';
-
 /**
  * Class to handle private messages
  */
@@ -29,7 +29,7 @@ class Mail
         */
        public static function send($recipient = 0, $body = '', $subject = '', $replyto = '')
        {
-               $a = get_app();
+               $a = \get_app();
 
                if (!$recipient) {
                        return -1;
@@ -46,7 +46,7 @@ class Mail
                        return -2;
                }
 
-               $guid = System::createGUID(32);
+               $guid = System::createUUID();
                $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid;
 
                $convid = 0;
@@ -56,13 +56,11 @@ 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()),
-                               DBA::escape($replyto),
-                               DBA::escape($replyto)
-                       );
-                       if (DBA::isResult($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'];
                        }
                }
 
@@ -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 = System::createGUID(32);
+                       $conv_guid = System::createUUID();
                        $convuri = $recip_handle . ':' . $conv_guid;
 
                        $handles = $recip_handle . ';' . $sender_handle;
@@ -89,7 +87,7 @@ class Mail
                }
 
                if (!$convid) {
-                       logger('send message: conversation not found.');
+                       Logger::log('send message: conversation not found.');
                        return -4;
                }
 
@@ -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 = System::createGUID(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 = System::createGUID(32);
+               $conv_guid = System::createUUID();
 
                $recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
 
@@ -202,7 +200,7 @@ class Mail
                }
 
                if (!$convid) {
-                       logger('send message: conversation not found.');
+                       Logger::log('send message: conversation not found.');
                        return -4;
                }