]> git.mxchange.org Git - friendica.git/blobdiff - mod/message.php
Move $pager and $page_offset out of App
[friendica.git] / mod / message.php
index 7377ba5e48a74d88210c51fbe31a0197ba617ba8..de2ee3cf0186cb6f0deebe9f269d411a1fe0369f 100644 (file)
@@ -5,6 +5,7 @@
 
 use Friendica\App;
 use Friendica\Content\Nav;
+use Friendica\Content\Pager;
 use Friendica\Content\Smilies;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
@@ -13,6 +14,7 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Mail;
+use Friendica\Module\Login;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy as ProxyUtils;
 use Friendica\Util\Temporal;
@@ -46,12 +48,6 @@ function message_init(App $a)
                '$baseurl' => System::baseUrl(true),
                '$base' => $base
        ]);
-
-       $end_tpl = get_markup_template('message-end.tpl');
-       $a->page['end'] .= replace_macros($end_tpl, [
-               '$baseurl' => System::baseUrl(true),
-               '$base' => $base
-       ]);
 }
 
 function message_post(App $a)
@@ -92,7 +88,7 @@ function message_post(App $a)
                $a->argc = 2;
                $a->argv[1] = 'new';
        } else {
-               goaway($a->cmd . '/' . $ret);
+               $a->internalRedirect($a->cmd . '/' . $ret);
        }
 }
 
@@ -103,7 +99,7 @@ function message_content(App $a)
 
        if (!local_user()) {
                notice(L10n::t('Permission denied.') . EOL);
-               return;
+               return Login::form();
        }
 
        $myprofile = System::baseUrl() . '/profile/' . $a->user['nickname'];
@@ -160,17 +156,28 @@ function message_content(App $a)
 
                // Now check how the user responded to the confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       goaway($_SESSION['return_url']);
+                       $a->internalRedirect('message');
                }
 
                $cmd = $a->argv[1];
                if ($cmd === 'drop') {
+                       $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]);
+                       if(!DBA::isResult($message)){
+                               info(L10n::t('Conversation not found.') . EOL);
+                               $a->internalRedirect('message');
+                       }
+
                        if (DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) {
                                info(L10n::t('Message deleted.') . EOL);
                        }
 
-                       //goaway(System::baseUrl(true) . '/message' );
-                       goaway($_SESSION['return_url']);
+                       $conversation = DBA::selectFirst('mail', ['id'], ['convid' => $message['convid'], 'uid' => local_user()]);
+                       if(!DBA::isResult($conversation)){
+                               info(L10n::t('Conversation removed.') . EOL);
+                               $a->internalRedirect('message');
+                       }
+
+                       $a->internalRedirect('message/' . $conversation['id'] );
                } else {
                        $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                intval($a->argv[2]),
@@ -184,8 +191,7 @@ function message_content(App $a)
                                        info(L10n::t('Conversation removed.') . EOL);
                                }
                        }
-                       //goaway(System::baseUrl(true) . '/message' );
-                       goaway($_SESSION['return_url']);
+                       $a->internalRedirect('message');
                }
        }
 
@@ -199,13 +205,6 @@ function message_content(App $a)
                        '$linkurl' => L10n::t('Please enter a link URL:')
                ]);
 
-               $tpl = get_markup_template('msg-end.tpl');
-               $a->page['end'] .= replace_macros($tpl, [
-                       '$baseurl' => System::baseUrl(true),
-                       '$nickname' => $a->user['nickname'],
-                       '$linkurl' => L10n::t('Please enter a link URL:')
-               ]);
-
                $preselect = isset($a->argv[2]) ? [$a->argv[2]] : [];
 
                $prename = $preurl = $preid = '';
@@ -267,7 +266,7 @@ function message_content(App $a)
        }
 
 
-       $_SESSION['return_url'] = $a->query_string;
+       $_SESSION['return_path'] = $a->query_string;
 
        if ($a->argc == 1) {
 
@@ -275,16 +274,18 @@ 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)) {
-                       $a->set_pager_total($r[0]['total']);
+                       $total = $r[0]['total'];
                }
 
-               $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']);
+               $pager = new Pager($a->query_string, $total);
+
+               $r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage());
 
                if (!DBA::isResult($r)) {
                        info(L10n::t('No messages.') . EOL);
@@ -293,7 +294,7 @@ function message_content(App $a)
 
                $o .= render_messages($r, 'mail_list.tpl');
 
-               $o .= paginate($a);
+               $o .= $pager->renderFull();
 
                return $o;
        }
@@ -344,13 +345,6 @@ function message_content(App $a)
                        '$linkurl' => L10n::t('Please enter a link URL:')
                ]);
 
-               $tpl = get_markup_template('msg-end.tpl');
-               $a->page['end'] .= replace_macros($tpl, [
-                       '$baseurl' => System::baseUrl(true),
-                       '$nickname' => $a->user['nickname'],
-                       '$linkurl' => L10n::t('Please enter a link URL:')
-               ]);
-
                $mails = [];
                $seen = 0;
                $unknown = false;
@@ -488,7 +482,7 @@ function render_messages(array $msg, $t)
                        '$id' => $rr['id'],
                        '$from_name' => $participants,
                        '$from_url' => Contact::magicLink($rr['url']),
-                       '$from_addr' => $contact['addr'],
+                       '$from_addr' => defaults($contact, 'addr', ''),
                        '$sparkle' => ' sparkle',
                        '$from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB),
                        '$subject' => $subject_e,