X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=mod%2Fmessage.php;h=178d99bba5fb0383d7958bf712f95283152a2fc6;hb=5f89cb09234bc79aab2be93778609b344239c3da;hp=b8236641a9c749a765fee383aba4c5d7db925896;hpb=facca43e2de1c3c30a34f38bbe7025b7216db13f;p=friendica.git diff --git a/mod/message.php b/mod/message.php index b8236641a9..178d99bba5 100644 --- a/mod/message.php +++ b/mod/message.php @@ -1,10 +1,35 @@ t('New Message'), + 'url' => $a->get_baseurl(true) . '/message/new', + 'sel'=> ($a->argv[1] == 'new'), + ); + + $tpl = get_markup_template('message_side.tpl'); + $a->page['aside'] = replace_macros($tpl, array( + '$tabs'=>$tabs, + '$new'=>$new, + )); + $base = $a->get_baseurl(); + $head_tpl = get_markup_template('message-head.tpl'); + $a->page['htmlhead'] .= replace_macros($head_tpl,array( + '$baseurl' => $a->get_baseurl(true), + '$base' => $base + )); + $end_tpl = get_markup_template('message-end.tpl'); + $a->page['end'] .= replace_macros($end_tpl,array( + '$baseurl' => $a->get_baseurl(true), + '$base' => $base + )); + } function message_post(&$a) { @@ -14,207 +39,379 @@ function message_post(&$a) { return; } - $replyto = notags(trim($_POST['replyto'])); - $recipient = intval($_POST['messageto']); - $subject = notags(trim($_POST['subject'])); - $body = escape_tags(trim($_POST['body'])); + $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : ''); + $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : ''); + $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); + $recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto']) : 0 ); - if(! $recipient) { - notice( t('No recipient selected.') . EOL ); - return; + // Work around doubled linefeeds in Tinymce 3.5b2 + +/* $plaintext = intval(get_pconfig(local_user(),'system','plaintext') && !feature_enabled(local_user(),'richtext')); + if(! $plaintext) { + $body = fix_mce_lf($body); + }*/ + $plaintext = intval(!feature_enabled(local_user(),'richtext')); + if(! $plaintext) { + $body = fix_mce_lf($body); + } + + $ret = send_message($recipient, $body, $subject, $replyto); + $norecip = false; + + switch($ret){ + case -1: + notice( t('No recipient selected.') . EOL ); + $norecip = true; + break; + case -2: + notice( t('Unable to locate contact information.') . EOL ); + break; + case -3: + notice( t('Message could not be sent.') . EOL ); + break; + case -4: + notice( t('Message collection failure.') . EOL ); + break; + default: + info( t('Message sent.') . EOL ); } - $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", - intval($_SESSION['uid']) - ); - $contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($recipient), - intval($_SESSION['uid']) - ); + // fake it to go back to the input form if no recipient listed - if(! (count($me) && (count($contact)))) { - notice( t('Unable to locate contact information.') . EOL ); - return; + if($norecip) { + $a->argc = 2; + $a->argv[1] = 'new'; } + else + goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']); - $hash = random_string(); - $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . $_SESSION['uid'] . ':' . $hash ; - - if(! strlen($replyto)) - $replyto = $uri; - - $r = q("INSERT INTO `mail` ( `uid`, `from-name`, `from-photo`, `from-url`, - `contact-id`, `title`, `body`, `delivered`, `seen`, `replied`, `uri`, `parent-uri`, `created`) - VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )", - intval($_SESSION['uid']), - dbesc($me[0]['name']), - dbesc($me[0]['thumb']), - dbesc($me[0]['url']), - intval($recipient), - dbesc($subject), - dbesc($body), - 0, - 1, - 0, - dbesc($uri), - dbesc($replyto), - datetime_convert() - ); - $r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1", - dbesc($uri), - intval($_SESSION['uid']) - ); - if(count($r)) - $post_id = $r[0]['id']; +} - $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php'); - - if($post_id) { - proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"mail\" \"$post_id\" &", - array(),$foo)); - notice( t('Message sent.') . EOL ); +// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' +// is identical to the code in include/conversation.php +if(! function_exists('item_extract_images')) { +function item_extract_images($body) { + + $saved_image = array(); + $orig_body = $body; + $new_body = ''; + + $cnt = 0; + $img_start = strpos($orig_body, '[img'); + $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); + $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); + while(($img_st_close !== false) && ($img_end !== false)) { + + $img_st_close++; // make it point to AFTER the closing bracket + $img_end += $img_start; + + if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + // This is an embedded image + + $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); + $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; + + $cnt++; + } + else + $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); + + $orig_body = substr($orig_body, $img_end + strlen('[/img]')); + + if($orig_body === false) // in case the body ends on a closing image tag + $orig_body = ''; + + $img_start = strpos($orig_body, '[img'); + $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); + $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); + } + + $new_body = $new_body . $orig_body; + + return array('body' => $new_body, 'images' => $saved_image); +}} + +if(! function_exists('item_redir_and_replace_images')) { +function item_redir_and_replace_images($body, $images, $cid) { + + $origbody = $body; + $newbody = ''; + + for($i = 0; $i < count($images); $i++) { + $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; + $replace = '[url=' . z_path() . '/redir/' . $cid + . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; + + $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]'); + $process_part = substr($origbody, 0, $img_end); + $origbody = substr($origbody, $img_end); + + $process_part = preg_replace($search, $replace, $process_part); + $newbody = $newbody . $process_part; } - else { - notice( t('Message could not be sent.') . EOL ); + $newbody = $newbody . $origbody; + + $cnt = 0; + foreach($images as $image) { + // We're depending on the property of 'foreach' (specified on the PHP website) that + // it loops over the array starting from the first element and going sequentially + // to the last element + $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody); + $cnt++; } - return; -} + return $newbody; +}} + + function message_content(&$a) { + $o = ''; + nav_set_selected('messages'); + if(! local_user()) { notice( t('Permission denied.') . EOL); return; } - $myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname']; - + $myprofile = $a->get_baseurl(true) . '/profile/' . $a->user['nickname']; - $tpl = file_get_contents('view/mail_head.tpl'); + $tpl = get_markup_template('mail_head.tpl'); $header = replace_macros($tpl, array( '$messages' => t('Messages'), - '$inbox' => t('Inbox'), - '$outbox' => t('Outbox'), - '$new' => t('New Message') + '$tab_content' => $tab_content )); - if(($a->argc == 3) && ($a->argv[1] == 'drop' || $a->argv[1] == 'dropconv')) { + if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { if(! intval($a->argv[2])) return; + + // Check if we should do HTML-based delete confirmation + if($_REQUEST['confirm']) { + //