]> git.mxchange.org Git - friendica.git/blobdiff - mod/message.php
email autocomplete
[friendica.git] / mod / message.php
old mode 100755 (executable)
new mode 100644 (file)
index 949e561..8cfa025
@@ -4,20 +4,7 @@ require_once('include/acl_selectors.php');
 require_once('include/message.php');
 
 function message_init(&$a) {
-       $tabs = array(
-       /*
-               array(
-                       'label' => t('All'),
-                       'url'=> $a->get_baseurl(true) . '/message',
-                       'sel'=> ($a->argc == 1),
-               ),
-               array(
-                       'label' => t('Sent'),
-                       'url' => $a->get_baseurl(true) . '/message/sent',
-                       'sel'=> ($a->argv[1] == 'sent'),
-               ),
-       */
-       );
+       $tabs = array();
        $new = array(
                'label' => t('New Message'),
                'url' => $a->get_baseurl(true) . '/message/new',
@@ -29,6 +16,25 @@ function message_init(&$a) {
                '$tabs'=>$tabs,
                '$new'=>$new,
        ));
+       $base = $a->get_baseurl();
+
+       $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/jquery.autocomplete-min.js" ></script>';
+       $a->page['htmlhead'] .= <<< EOT
+
+<script>$(document).ready(function() { 
+       var a; 
+       a = $("#recip").autocomplete({ 
+               serviceUrl: '$base/acl',
+               width: 350,
+               onSelect: function(value,data) {
+                       $("#recip-complete").val(data);
+               }                       
+       });
+
+}); 
+
+</script>
+EOT;
        
 }
 
@@ -48,8 +54,7 @@ function message_post(&$a) {
 
        $plaintext = intval(get_pconfig(local_user(),'system','plaintext'));
        if(! $plaintext) {
-               $body = str_replace("\r\n","\n",$body);
-               $body = str_replace("\n\n","\n",$body);
+               $body = fix_mce_lf($body);
        }
        
        $ret = send_message($recipient, $body, $subject, $replyto);
@@ -94,10 +99,6 @@ function message_content(&$a) {
 
        $myprofile = $a->get_baseurl(true) . '/profile/' . $a->user['nickname'];
 
-
-
-
-
        $tpl = get_markup_template('mail_head.tpl');
        $header = replace_macros($tpl, array(
                '$messages' => t('Messages'),
@@ -172,11 +173,34 @@ function message_content(&$a) {
        
                $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
        
+
+               $prename = $preurl = $preid = '';
+
+               if($preselect) {
+                       $r = q("select name, url, id from contact where uid = %d and id = %d limit 1",
+                               intval(local_user()),
+                               intval($a->argv[2])
+                       );
+                       if(count($r)) {
+                               $prename = $r[0]['name'];
+                               $preurl = $r[0]['url'];
+                               $preid = $r[0]['id'];
+                       }
+               }        
+
+               $prefill = (($preselect) ? $prename . ' [' . $preurl . ']' : '');
+
+               // the ugly select box
+               
                $select = contact_select('messageto','message-to-select', $preselect, 4, true, false, false, 10);
+
                $tpl = get_markup_template('prv_message.tpl');
                $o .= replace_macros($tpl,array(
                        '$header' => t('Send Private Message'),
                        '$to' => t('To:'),
+                       '$prefill' => $prefill,
+                       '$autocomp' => $autocomp,
+                       '$preid' => $preid,
                        '$subject' => t('Subject:'),
                        '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
                        '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
@@ -192,17 +216,14 @@ function message_content(&$a) {
                return $o;
        }
 
-       if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
+       if($a->argc == 1) {
+
+               // list messages
 
                $o .= $header;
                
-               if($a->argc == 2)
-                       $eq = sprintf( "AND `from-url` = '%s'", dbesc($myprofile)); 
-               else
-                       $eq = '';
-
                $r = q("SELECT count(*) AS `total` FROM `mail` 
-                       WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
+                       WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `created` DESC",
                        intval(local_user()),
                        dbesc($myprofile)
                );
@@ -213,7 +234,7 @@ function message_content(&$a) {
                        `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb` , `contact`.`network`,
                        count( * ) as count
                        FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id` 
-                       WHERE `mail`.`uid` = %d  $eq GROUP BY `parent-uri` ORDER BY `mailcreated` DESC  LIMIT %d , %d ",
+                       WHERE `mail`.`uid` = %d GROUP BY `parent-uri` ORDER BY `mailcreated` DESC  LIMIT %d , %d ",
                        intval(local_user()),
                        //
                        intval($a->pager['start']),
@@ -226,9 +247,13 @@ function message_content(&$a) {
 
                $tpl = get_markup_template('mail_list.tpl');
                foreach($r as $rr) {
-                       if ($rr['from-url'] == $myprofile){
+                       if($rr['unknown']) {
+                               $partecipants = sprintf( t("Unknown sender - %s"),$rr['from-name']);
+                       }
+                       elseif (link_compare($rr['from-url'],$myprofile)){
                                $partecipants = sprintf( t("You and %s"), $rr['name']);
-                       } else {
+                       }
+                       else {
                                $partecipants = sprintf( t("%s and You"), $rr['from-name']);
                        }
                        
@@ -237,7 +262,7 @@ function message_content(&$a) {
                                '$from_name' => $partecipants,
                                '$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl(true) . '/redir/' . $rr['contact-id'] : $rr['url']),
                                '$sparkle' => ' sparkle',
-                               '$from_photo' => $rr['thumb'],
+                               '$from_photo' => (($rr['thumb']) ? $rr['thumb'] : $rr['from-photo']),
                                '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
                                '$delete' => t('Delete conversation'),
                                '$body' => template_escape($rr['body']),
@@ -300,7 +325,11 @@ function message_content(&$a) {
 
                $mails = array();
                $seen = 0;
+               $unknown = false;
+
                foreach($messages as $message) {
+                       if($message['unknown'])
+                               $unknown = true;
                        if($message['from-url'] == $myprofile) {
                                $from_url = $myprofile;
                                $sparkle = '';
@@ -309,6 +338,29 @@ function message_content(&$a) {
                                $from_url = $a->get_baseurl(true) . '/redir/' . $message['contact-id'];
                                $sparkle = ' sparkle';
                        }
+
+
+                       $Text = $message['body'];
+                       $saved_image = '';
+                       $img_start = strpos($Text,'[img]data:');
+                       $img_end = strpos($Text,'[/img]');
+
+                       if($img_start !== false && $img_end !== false && $img_end > $img_start) {
+                               $start_fragment = substr($Text,0,$img_start);
+                               $img_start += strlen('[img]');
+                               $saved_image = substr($Text,$img_start,$img_end - $img_start);
+                               $end_fragment = substr($Text,$img_end + strlen('[/img]'));              
+                               $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
+                               $search = '/\[url\=(.*?)\]\[!#saved_image#!\]\[\/url\]' . '/is';
+                               $replace = '[url=' . z_path() . '/redir/' . $message['contact-id'] 
+                                       . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
+
+                               $Text = preg_replace($search,$replace,$Text);
+
+                       if(strlen($saved_image))
+                               $message['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
+                       }
+
                        $mails[] = array(
                                'id' => $message['id'],
                                'from_name' => template_escape($message['from-name']),
@@ -326,7 +378,7 @@ function message_content(&$a) {
                }
                $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
                $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
-               
+                       
 
                $tpl = get_markup_template('mail_display.tpl');
                $o = replace_macros($tpl, array(
@@ -334,7 +386,8 @@ function message_content(&$a) {
                        '$thread_subject' => $message['title'],
                        '$thread_seen' => $seen,
                        '$delete' =>  t('Delete conversation'),
-                       
+                       '$canreply' => (($unknown) ? false : '1'),
+                       '$unknown_text' => t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."),                        
                        '$mails' => $mails,
                        
                        // reply