X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fmessage.php;h=e2380fdb5c5c7d5504588fba97b86f937c2d5a80;hb=57fe36e9a3e414b21544335dad4484193edc36ae;hp=c1b2d989e9651a0e147added038373a8c19ff4a3;hpb=dc366bf1f7b5b7b0fc1c1a86772783074b301993;p=friendica.git diff --git a/mod/message.php b/mod/message.php index c1b2d989e9..e2380fdb5c 100644 --- a/mod/message.php +++ b/mod/message.php @@ -6,14 +6,17 @@ use Friendica\App; use Friendica\Content\Nav; use Friendica\Content\Smilies; +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; -require_once 'include/acl_selectors.php'; require_once 'include/conversation.php'; function message_init(App $a) @@ -89,7 +92,7 @@ function message_post(App $a) $a->argc = 2; $a->argv[1] = 'new'; } else { - goaway($_SESSION['return_url']); + goaway($a->cmd . '/' . $ret); } } @@ -106,8 +109,23 @@ function message_content(App $a) $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')) { @@ -116,7 +134,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); @@ -139,52 +157,33 @@ function message_content(App $a) '$cancel' => L10n::t('Cancel'), ]); } + // 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') { - $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[2]), - intval(local_user()) - ); - if ($r) { + 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']); + + goaway('/message' ); } 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']; - $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ", - dbesc($parent), - intval(local_user()) - ); - - // remove diaspora conversation pointer - // Actually if we do this, we can never receive another reply to that conversation, - // as we will never again have the info we need to re-create it. - // We'll just have to orphan it. - //if ($convid) { - // q("delete from conv where id = %d limit 1", - // intval($convid) - // ); - //} - - if ($r) { + 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' ); } } @@ -205,7 +204,7 @@ function message_content(App $a) '$linkurl' => L10n::t('Please enter a link URL:') ]); - $preselect = isset($a->argv[2]) ? [$a->argv[2]] : false; + $preselect = isset($a->argv[2]) ? [$a->argv[2]] : []; $prename = $preurl = $preid = ''; @@ -214,34 +213,34 @@ 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']; $preselect = [$preid]; } else { - $preselect = false; + $preselect = []; } } $prefill = $preselect ? $prename : ''; // the ugly select box - $select = contact_select('messageto', 'message-to-select', $preselect, 4, true, false, false, 10); + $select = ACL::getMessageContactSelectHTML('messageto', 'message-to-select', $preselect, 4, 10); $tpl = get_markup_template('prv_message.tpl'); $o .= replace_macros($tpl, [ @@ -249,7 +248,6 @@ function message_content(App $a) '$to' => L10n::t('To:'), '$showinputs' => 'true', '$prefill' => $prefill, - '$autocomp' => $autocomp, '$preid' => $preid, '$subject' => L10n::t('Subject:'), '$subjtxt' => x($_REQUEST, 'subject') ? strip_tags($_REQUEST['subject']) : '', @@ -280,13 +278,13 @@ function message_content(App $a) intval(local_user()) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $a->set_pager_total($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; } @@ -308,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) ); @@ -324,19 +322,19 @@ 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()) ); - require_once("include/bbcode.php"); - $tpl = get_markup_template('msg-header.tpl'); $a->page['htmlhead'] .= replace_macros($tpl, [ '$baseurl' => System::baseUrl(true), @@ -361,11 +359,8 @@ function message_content(App $a) if ($message['from-url'] == $myprofile) { $from_url = $myprofile; $sparkle = ''; - } elseif ($message['contact-id'] != 0) { - $from_url = 'redir/' . $message['contact-id']; - $sparkle = ' sparkle'; } else { - $from_url = $message['from-url'] . "?zrl=" . urlencode($myprofile); + $from_url = Contact::magicLink($message['from-url']); $sparkle = ' sparkle'; } @@ -376,7 +371,7 @@ function message_content(App $a) $from_name_e = $message['from-name']; $subject_e = $message['title']; - $body_e = Smilies::replace(bbcode($message['body'])); + $body_e = Smilies::replace(BBCode::convert($message['body'])); $to_name_e = $message['name']; $contact = Contact::getDetailsByURL($message['from-url']); @@ -392,13 +387,13 @@ 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'), 'to_name' => $to_name_e, - 'date' => Temporal::convert($message['created'], date_default_timezone_get(), 'UTC', 'D, d M Y - g:i A'), - 'ago' => relative_date($message['created']), + 'date' => DateTimeFormat::local($message['created'], L10n::t('D, d M Y - g:i A')), + 'ago' => Temporal::getRelativeDate($message['created']), ]; $seen = $message['seen']; @@ -490,16 +485,16 @@ function render_messages(array $msg, $t) $rslt .= replace_macros($tpl, [ '$id' => $rr['id'], '$from_name' => $participants, - '$from_url' => (($rr['network'] === NETWORK_DFRN) ? 'redir/' . $rr['contact-id'] : $rr['url']), - '$from_addr' => $contact['addr'], + '$from_url' => Contact::magicLink($rr['url']), + '$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, '$to_name' => $to_name_e, - '$date' => Temporal::convert($rr['mailcreated'], date_default_timezone_get(), 'UTC', L10n::t('D, d M Y - g:i A')), - '$ago' => relative_date($rr['mailcreated']), + '$date' => DateTimeFormat::local($rr['mailcreated'], L10n::t('D, d M Y - g:i A')), + '$ago' => Temporal::getRelativeDate($rr['mailcreated']), '$seen' => $rr['mailseen'], '$count' => L10n::tt('%d message', '%d messages', $rr['count']), ]);