X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fmessage.php;h=f9c5c29ec773a934f3795453c8c6a15b257848f3;hb=738cb4ace6cb3dc4a78320577ffbdb3cdb773132;hp=ddd5d03d6667255d2d143cb5363a00d34bdc3493;hpb=e3584daef9c7801bce8d504152c5ccbd3ab492b4;p=friendica.git diff --git a/mod/message.php b/mod/message.php index ddd5d03d66..f9c5c29ec7 100644 --- a/mod/message.php +++ b/mod/message.php @@ -10,11 +10,13 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\ACL; use Friendica\Core\L10n; use Friendica\Core\System; -use Friendica\Database\DBM; +use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Mail; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Temporal; +use Friendica\Module\Login; require_once 'include/conversation.php'; @@ -45,12 +47,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) @@ -91,7 +87,7 @@ function message_post(App $a) $a->argc = 2; $a->argv[1] = 'new'; } else { - goaway($_SESSION['return_url']); + goaway($a->cmd . '/' . $ret); } } @@ -102,14 +98,29 @@ 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']; $tpl = get_markup_template('mail_head.tpl'); + if ($a->argc > 1 && $a->argv[1] == 'new') { + $button = [ + 'label' => L10n::t('Discard'), + 'url' => '/message', + 'sel' => 'close', + ]; + } else { + $button = [ + 'label' => L10n::t('New Message'), + 'url' => '/message/new', + 'sel' => 'new', + 'accesskey' => 'm', + ]; + } $header = replace_macros($tpl, [ '$messages' => L10n::t('Messages'), + '$button' => $button, ]); if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { @@ -118,7 +129,7 @@ function message_content(App $a) } // Check if we should do HTML-based delete confirmation - if ($_REQUEST['confirm']) { + if (!empty($_REQUEST['confirm'])) { //
can't take arguments in its "action" parameter // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); @@ -143,33 +154,43 @@ function message_content(App $a) } // Now check how the user responded to the confirmation query - if ($_REQUEST['canceled']) { - goaway($_SESSION['return_url']); + if (!empty($_REQUEST['canceled'])) { + goaway('/message'); } $cmd = $a->argv[1]; if ($cmd === 'drop') { - if (dba::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) { + $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]); + if(!DBA::isResult($message)){ + info(L10n::t('Conversation not found.') . EOL); + goaway('/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); + goaway('/message'); + } + + goaway('/message/' . $conversation['id'] ); } else { $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $parent = $r[0]['parent-uri']; $convid = $r[0]['convid']; - if (dba::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) { + if (DBA::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) { info(L10n::t('Conversation removed.') . EOL); } } - //goaway(System::baseUrl(true) . '/message' ); - goaway($_SESSION['return_url']); + goaway('/message' ); } } @@ -183,13 +204,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 = ''; @@ -199,21 +213,21 @@ function message_content(App $a) intval(local_user()), intval($a->argv[2]) ); - if (!DBM::is_result($r)) { + if (!DBA::isResult($r)) { $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval(local_user()), - dbesc(normalise_link(base64_decode($a->argv[2]))) + DBA::escape(normalise_link(base64_decode($a->argv[2]))) ); } - if (!DBM::is_result($r)) { + if (!DBA::isResult($r)) { $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1", intval(local_user()), - dbesc(base64_decode($a->argv[2])) + DBA::escape(base64_decode($a->argv[2])) ); } - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $prename = $r[0]['name']; $preurl = $r[0]['url']; $preid = $r[0]['id']; @@ -264,13 +278,13 @@ function message_content(App $a) intval(local_user()) ); - if (DBM::is_result($r)) { - $a->set_pager_total($r[0]['total']); + if (DBA::isResult($r)) { + $a->setPagerTotal($r[0]['total']); } $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if (!DBM::is_result($r)) { + if (!DBA::isResult($r)) { info(L10n::t('No messages.') . EOL); return $o; } @@ -292,14 +306,14 @@ function message_content(App $a) intval(local_user()), intval($a->argv[1]) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $contact_id = $r[0]['contact-id']; $convid = $r[0]['convid']; - $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri'])); + $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", DBA::escape($r[0]['parent-uri'])); if ($convid) $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ", - dbesc($r[0]['parent-uri']), + DBA::escape($r[0]['parent-uri']), intval($convid) ); @@ -308,14 +322,16 @@ function message_content(App $a) WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC", intval(local_user()) ); + } else { + $messages = false; } - if (!count($messages)) { + if (!DBA::isResult($messages)) { notice(L10n::t('Message not available.') . EOL); return $o; } $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d", - dbesc($r[0]['parent-uri']), + DBA::escape($r[0]['parent-uri']), intval(local_user()) ); @@ -326,13 +342,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; @@ -371,7 +380,7 @@ function message_content(App $a) 'from_url' => $from_url, 'from_addr' => $contact['addr'], 'sparkle' => $sparkle, - 'from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB), + 'from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB), 'subject' => $subject_e, 'body' => $body_e, 'delete' => L10n::t('Delete message'), @@ -470,9 +479,9 @@ 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' => proxy_url($from_photo, false, PROXY_SIZE_THUMB), + '$from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB), '$subject' => $subject_e, '$delete' => L10n::t('Delete conversation'), '$body' => $body_e,