]> git.mxchange.org Git - friendica.git/blobdiff - mod/message.php
Replace "notice" calls
[friendica.git] / mod / message.php
index e862a469bdae55262e9eef8f1cd02a2070cad0e5..d1231b7c5dcb0425a91feb61f0511c6be30674e5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -66,31 +66,31 @@ function message_init(App $a)
 function message_post(App $a)
 {
        if (!local_user()) {
-               notice(DI::l10n()->t('Permission denied.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                return;
        }
 
-       $replyto   = !empty($_REQUEST['replyto'])   ? Strings::escapeTags(trim($_REQUEST['replyto'])) : '';
-       $subject   = !empty($_REQUEST['subject'])   ? Strings::escapeTags(trim($_REQUEST['subject'])) : '';
-       $body      = !empty($_REQUEST['body'])      ? Strings::escapeHtml(trim($_REQUEST['body']))    : '';
-       $recipient = !empty($_REQUEST['recipient']) ? intval($_REQUEST['recipient'])                  : 0;
+       $replyto   = !empty($_REQUEST['replyto'])   ? trim($_REQUEST['replyto'])                   : '';
+       $subject   = !empty($_REQUEST['subject'])   ? trim($_REQUEST['subject'])                   : '';
+       $body      = !empty($_REQUEST['body'])      ? Strings::escapeHtml(trim($_REQUEST['body'])) : '';
+       $recipient = !empty($_REQUEST['recipient']) ? intval($_REQUEST['recipient'])               : 0;
 
        $ret = Mail::send($recipient, $body, $subject, $replyto);
        $norecip = false;
 
        switch ($ret) {
                case -1:
-                       notice(DI::l10n()->t('No recipient selected.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('No recipient selected.'));
                        $norecip = true;
                        break;
                case -2:
-                       notice(DI::l10n()->t('Unable to locate contact information.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate contact information.'));
                        break;
                case -3:
-                       notice(DI::l10n()->t('Message could not be sent.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Message could not be sent.'));
                        break;
                case -4:
-                       notice(DI::l10n()->t('Message collection failure.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Message collection failure.'));
                        break;
        }
 
@@ -108,11 +108,11 @@ function message_content(App $a)
        Nav::setSelected('messages');
 
        if (!local_user()) {
-               notice(DI::l10n()->t('Permission denied.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                return Login::form();
        }
 
-       $myprofile = DI::baseUrl() . '/profile/' . $a->getNickname();
+       $myprofile = DI::baseUrl() . '/profile/' . $a->getLoggedInUserNickname();
 
        $tpl = Renderer::getMarkupTemplate('mail_head.tpl');
        if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new') {
@@ -143,12 +143,12 @@ function message_content(App $a)
                if ($cmd === 'drop') {
                        $message = DBA::selectFirst('mail', ['convid'], ['id' => DI::args()->getArgv()[2], 'uid' => local_user()]);
                        if(!DBA::isResult($message)){
-                               notice(DI::l10n()->t('Conversation not found.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Conversation not found.'));
                                DI::baseUrl()->redirect('message');
                        }
 
                        if (!DBA::delete('mail', ['id' => DI::args()->getArgv()[2], 'uid' => local_user()])) {
-                               notice(DI::l10n()->t('Message was not deleted.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Message was not deleted.'));
                        }
 
                        $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => local_user()]);
@@ -158,15 +158,12 @@ function message_content(App $a)
 
                        DI::baseUrl()->redirect('message/' . $conversation['id'] );
                } else {
-                       $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(DI::args()->getArgv()[2]),
-                               intval(local_user())
-                       );
-                       if (DBA::isResult($r)) {
-                               $parent = $r[0]['parent-uri'];
+                       $parentmail = DBA::selectFirst('mail', ['parent-uri'], ['id' => DI::args()->getArgv()[2], 'uid' => local_user()]);
+                       if (DBA::isResult($parentmail)) {
+                               $parent = $parentmail['parent-uri'];
 
                                if (!DBA::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) {
-                                       notice(DI::l10n()->t('Conversation was not removed.'));
+                                       DI::sysmsg()->addNotice(DI::l10n()->t('Conversation was not removed.'));
                                }
                        }
                        DI::baseUrl()->redirect('message');
@@ -179,7 +176,7 @@ function message_content(App $a)
                $tpl = Renderer::getMarkupTemplate('msg-header.tpl');
                DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
                        '$baseurl' => DI::baseUrl()->get(true),
-                       '$nickname' => $a->getNickname(),
+                       '$nickname' => $a->getLoggedInUserNickname(),
                        '$linkurl' => DI::l10n()->t('Please enter a link URL:')
                ]);
 
@@ -215,21 +212,14 @@ function message_content(App $a)
 
                $o .= $header;
 
-               $total = 0;
-               $r = q("SELECT count(*) AS `total`, ANY_VALUE(`created`) AS `created` FROM `mail`
-                       WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `created` DESC",
-                       intval(local_user())
-               );
-               if (DBA::isResult($r)) {
-                       $total = $r[0]['total'];
-               }
+               $total = DBA::count('mail', ['uid' => local_user()], ['distinct' => true, 'expression' => 'parent-uri']);
 
                $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
 
                $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage());
 
                if (!DBA::isResult($r)) {
-                       notice(DI::l10n()->t('No messages.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('No messages.'));
                        return $o;
                }
 
@@ -285,14 +275,14 @@ function message_content(App $a)
                }
 
                if (!DBA::isResult($messages)) {
-                       notice(DI::l10n()->t('Message not available.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Message not available.'));
                        return $o;
                }
 
                $tpl = Renderer::getMarkupTemplate('msg-header.tpl');
                DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
                        '$baseurl' => DI::baseUrl()->get(true),
-                       '$nickname' => $a->getNickname(),
+                       '$nickname' => $a->getLoggedInUserNickname(),
                        '$linkurl' => DI::l10n()->t('Please enter a link URL:')
                ]);
 
@@ -318,7 +308,7 @@ function message_content(App $a)
                        $body_e = BBCode::convertForUriId($message['uri-id'], $message['body']);
                        $to_name_e = $message['name'];
 
-                       $contact = Contact::getByURL($message['from-url'], false, ['thumb', 'addr', 'id', 'avatar']);
+                       $contact = Contact::getByURL($message['from-url'], false, ['thumb', 'addr', 'id', 'avatar', 'url']);
                        $from_photo = Contact::getThumb($contact);
 
                        $mails[] = [
@@ -431,7 +421,7 @@ function render_messages(array $msg, $t)
        $tpl = Renderer::getMarkupTemplate($t);
        $rslt = '';
 
-       $myprofile = DI::baseUrl() . '/profile/' . $a->getNickname();
+       $myprofile = DI::baseUrl() . '/profile/' . $a->getLoggedInUserNickname();
 
        foreach ($msg as $rr) {
                if ($rr['unknown']) {
@@ -450,7 +440,7 @@ function render_messages(array $msg, $t)
                        continue;
                }
 
-               $contact = Contact::getByURL($rr['url'], false, ['thumb', 'addr', 'id', 'avatar']);
+               $contact = Contact::getByURL($rr['url'], false, ['thumb', 'addr', 'id', 'avatar', 'url']);
                $from_photo = Contact::getThumb($contact);
 
                $rslt .= Renderer::replaceMacros($tpl, [