]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
this is going to take some more debug before it can be roller out
[friendica.git] / include / conversation.php
old mode 100755 (executable)
new mode 100644 (file)
index 8ca484c..d830c8d
@@ -94,9 +94,9 @@ function localize_item(&$item){
                        
                }
                
-               $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
-               $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
-               if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
+               $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
+               $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
+               if ($Bphoto!="") $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
 
                $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
 
@@ -108,8 +108,8 @@ function localize_item(&$item){
                if(count($r)==0) return;
                $obj=$r[0];
                
-               $author  = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
-               $objauthor =  '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
+               $author  = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
+               $objauthor =  '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
                
                switch($obj['verb']){
                        case ACTIVITY_POST:
@@ -158,14 +158,28 @@ function localize_item(&$item){
                                $target = $r[0];
                                $Bname = $target['author-name'];
                                $Blink = $target['author-link'];
-                               $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
-                               $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
+                               $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
+                               $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
                                $P = '[url=' . $target['plink'] . ']' . t('post/item') . '[/url]';
                                $item['body'] = sprintf( t('%1$s marked %2$s\'s %3$s as favorite'), $A, $B, $P)."\n";
 
                        }
                }
        }
+       $matches = null;
+       if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
+               foreach($matches as $mtch) {
+                       if(! strpos($mtch[1],'zrl='))
+                               $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']);
+               }
+       }
+       // add zrl's to public images
+       if(preg_match_all('/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is',$item['body'],$matches,PREG_SET_ORDER)) {
+               foreach($matches as $mtch) {
+                               $item['body'] = str_replace($mtch[0],'[url=' . zrl($mtch[1] . '/photos/' . $mtch[2] . '/image/' . $mtch[3] ,true) . '][img' . $mtch[4] . ']h' . $mtch[5]  . '[/img][/url]',$item['body']);
+               }
+       }
+
 
 }
 
@@ -243,7 +257,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
        $threads = array();
        $threadsid = -1;
        
-       if(count($items)) {
+       if($items && count($items)) {
 
                if($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
 
@@ -271,24 +285,30 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                else
                                        $nickname = $a->user['nickname'];
                                
+                               // prevent private email from leaking.
+                               if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
+                                               continue;
                        
                                $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
                                if($item['author-link'] && (! $item['author-name']))
                                        $profile_name = $item['author-link'];
 
+
+
                                $sp = false;
                                $profile_link = best_link_url($item,$sp);
-                               if($sp)
-                                       $sparkle = ' sparkle';
                                if($profile_link === 'mailbox')
                                        $profile_link = '';
-
+                               if($sp)
+                                       $sparkle = ' sparkle';
+                               else
+                                       $profile_link = zrl($profile_link);                                     
 
                                $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
                                if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
                                        $profile_avatar = $a->contacts[$normalised]['thumb'];
                                else
-                                       $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
+                                       $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
 
                                $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                                call_hooks('render_location',$locate);
@@ -332,7 +352,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        'body' => template_escape($body),
                                        'text' => strip_tags(template_escape($body)),
                                        'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
-                                       'lock' => $lock,
                                        'location' => template_escape($location),
                                        'indent' => '',
                                        'owner_name' => template_escape($owner_name),
@@ -390,6 +409,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                        }
 
                        $comments_collapsed = false;
+                       $comments_seen = 0;
                        $comment_lastcollapsed = false;
                        $comment_firstcollapsed = false;
                        $blowhard = 0;
@@ -437,8 +457,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                else {
 
                                        // prevent private email reply to public conversation from leaking.
-                                       if($item['private'] && ! $threads[$threadsid]['private'])
-                                               continue;
+                                       if($item['network'] === NETWORK_MAIL && local_user() != $item['uid'])
+                                                       continue;
 
                                        $comments_seen ++;
                                        $comment_lastcollapsed  = false;
@@ -482,47 +502,67 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
                                                // On the network page, I am the owner. On the display page it will be the profile owner.
                                                // This will have been stored in $a->page_contact by our calling page.
-                                               // Put this person on the left of the wall-to-wall notice.
+                                               // Put this person as the wall owner of the wall-to-wall notice.
 
-                                               $owner_url = $a->page_contact['url'];
+                                               $owner_url = zrl($a->page_contact['url']);
                                                $owner_photo = $a->page_contact['thumb'];
                                                $owner_name = $a->page_contact['name'];
                                                $template = $wallwall;
                                                $commentww = 'ww';      
                                        }
-                                       if((! $item['wall']) && (strlen($item['owner-link'])) && (! link_compare($item['owner-link'],$item['author-link']))) {
 
-                                               // Could be anybody. 
-
-                                               $owner_url = $item['owner-link'];
-                                               $owner_photo = $item['owner-avatar'];
-                                               $owner_name = $item['owner-name'];
-                                               $template = $wallwall;
-                                               $commentww = 'ww';
-                                               // If it is our contact, use a friendly redirect link
-                                               if((link_compare($item['owner-link'],$item['url'])) 
-                                                       && ($item['network'] === 'dfrn')) {
-                                                       $owner_url = $redirect_url;
-                                                       $osparkle = ' sparkle';
+                                       if((! $item['wall']) && $item['owner-link']) {
+
+                                               $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link']));
+                                               $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link']));
+                                               $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']);
+                                               if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
+
+                                                       // The author url doesn't match the owner (typically the contact)
+                                                       // and also doesn't match the contact alias. 
+                                                       // The name match is a hack to catch several weird cases where URLs are 
+                                                       // all over the park. It can be tricked, but this prevents you from
+                                                       // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
+                                                       // well that it's the same Bob Smith. 
+
+                                                       // But it could be somebody else with the same name. It just isn't highly likely. 
+                                                       
+
+                                                       $owner_url = $item['owner-link'];
+                                                       $owner_photo = $item['owner-avatar'];
+                                                       $owner_name = $item['owner-name'];
+                                                       $template = $wallwall;
+                                                       $commentww = 'ww';
+                                                       // If it is our contact, use a friendly redirect link
+                                                       if((link_compare($item['owner-link'],$item['url'])) 
+                                                               && ($item['network'] === NETWORK_DFRN)) {
+                                                               $owner_url = $redirect_url;
+                                                               $osparkle = ' sparkle';
+                                                       }
+                                                       else
+                                                               $owner_url = zrl($owner_url);
                                                }
                                        }
                                }
 
                                $likebuttons = '';
-                               $shareable = ((($profile_owner == local_user()) &&  (! $item['private'])) ? true : false); //($mode != 'display') &&
+                               $shareable = ((($profile_owner == local_user()) &&  ((! $item['private']) || $item['network'] === NETWORK_FEED)) ? true : false); 
 
                                if($page_writeable) {
-                                       if($toplevelpost) {
+                                       if($toplevelpost) { 
                                                $likebuttons = array(
                                                        'like' => array( t("I like this \x28toggle\x29"), t("like")),
                                                        'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
                                                );
                                                if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
-                                       }
+                                       } 
 
+                                       $qc = $qcomment =  null;
 
-                                       $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
-                                       $qcomment = (($qc) ? explode("\n",$qc) : null);
+                                       if(in_array('qcomment',$a->plugins)) {
+                                               $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
+                                               $qcomment = (($qc) ? explode("\n",$qc) : null);
+                                       }
 
                                        if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
                                                $comment = replace_macros($cmnt_tpl,array(
@@ -538,16 +578,24 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                        '$myphoto' => $a->contact['thumb'],
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
+                                                       '$edbold' => t('Bold'),
+                                                       '$editalic' => t('Italic'),
+                                                       '$eduline' => t('Underline'),
+                                                       '$edquote' => t('Quote'),
+                                                       '$edcode' => t('Code'),
+                                                       '$edimg' => t('Image'),
+                                                       '$edurl' => t('Link'),
+                                                       '$edvideo' => t('Video'),
                                                        '$preview' => t('Preview'),
                                                        '$ww' => (($mode === 'network') ? $commentww : '')
                                                ));
                                        }
                                }
 
-                               $edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
-                                               ? array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"))
-                                               : False);
-
+                               if(local_user() && link_compare($a->contact['url'],$item['author-link']))
+                                       $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
+                               else
+                                       $edpost = false;
 
                                $drop = '';
                                $dropping = false;
@@ -580,7 +628,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                        'classtagger' => "",
                                                );
                                        }
-                                       $filer = t("file as");
+                                       $filer = t("save to folder");
                                }
 
 
@@ -596,27 +644,23 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                if($item['author-link'] && (! $item['author-name']))
                                        $profile_name = $item['author-link'];
 
-
                                $sp = false;
                                $profile_link = best_link_url($item,$sp);
-                               if($sp)
-                                       $sparkle = ' sparkle';
-
                                if($profile_link === 'mailbox')
                                        $profile_link = '';
+                               if($sp)
+                                       $sparkle = ' sparkle';
+                               else
+                                       $profile_link = zrl($profile_link);                                     
 
                                $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
                                if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
                                        $profile_avatar = $a->contacts[$normalised]['thumb'];
                                else
-                                       $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
-
-
-
+                                       $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb));
 
-
-                               $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
-                               $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
+                               $like    = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
+                               $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
 
                                $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                                call_hooks('render_location',$locate);
@@ -649,7 +693,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        // template to use to render item (wall, walltowall, search)
                                        'template' => $template,
                                        
-                                       'type' => implode("",array_slice(split("/",$item['verb']),-1)),
+                                       'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
                                        'tags' => $tags,
                                        'body' => template_escape($body),
                                        'text' => strip_tags(template_escape($body)),
@@ -698,7 +742,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
        }
 
        $page_template = get_markup_template("conversation.tpl");
-       $o .= replace_macros($page_template, array(
+       $o = replace_macros($page_template, array(
                '$baseurl' => $a->get_baseurl($ssl_state),
                '$mode' => $mode,
                '$user' => $a->user,
@@ -767,8 +811,10 @@ function item_photo_menu($item){
                $photos_link = $profile_link . "?url=photos";
                $profile_link = $profile_link . "?url=profile";
                $pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
+               $zurl = '';
        }
        else {
+               $profile_link = zrl($profile_link);
                if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
                        $cid = $item['contact-id'];
                }               
@@ -793,11 +839,11 @@ function item_photo_menu($item){
        }
 
        $menu = Array(
-               t("View status") => $status_link,
-               t("View profile") => $profile_link,
-               t("View photos") => $photos_link,               
-               t("View recent") => $posts_link, 
-               t("Edit contact") => $contact_url,
+               t("View Status") => $status_link,
+               t("View Profile") => $profile_link,
+               t("View Photos") => $photos_link,
+               t("Network Posts") => $posts_link, 
+               t("Edit Contact") => $contact_url,
                t("Send PM") => $pm_url,
        );
        
@@ -828,13 +874,19 @@ function like_puller($a,$item,&$arr,$mode) {
                        $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
                        $sparkle = ' class="sparkle" ';
                }
-               if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
-                       $arr[$item['parent'] . '-l'] = array();
-               if(! isset($arr[$item['parent']]))
-                       $arr[$item['parent']] = 1;
+               else
+                       $url = zrl($url);
+
+               if(! $item['thr-parent'])
+                       $item['thr-parent'] = $item['parent-uri'];
+
+               if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
+                       $arr[$item['thr-parent'] . '-l'] = array();
+               if(! isset($arr[$item['thr-parent']]))
+                       $arr[$item['thr-parent']] = 1;
                else    
-                       $arr[$item['parent']] ++;
-               $arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
+                       $arr[$item['thr-parent']] ++;
+               $arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
        }
        return;
 }}
@@ -896,9 +948,8 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$vidurl' => t("Please enter a video link/URL:"),
                '$audurl' => t("Please enter an audio link/URL:"),
                '$term' => t('Tag term:'),
-               '$fileas' => t('File as:'),
-               '$whereareu' => t('Where are you right now?'),
-               '$title' => t('Enter a title for this item') 
+               '$fileas' => t('Save to Folder:'),
+               '$whereareu' => t('Where are you right now?')
        ));
 
 
@@ -937,7 +988,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
        $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));        
 
        $o .= replace_macros($tpl,array(
-               '$return_path' => $a->cmd,
+               '$return_path' => $a->query_string,
                '$action' =>  $a->get_baseurl(true) . '/item',
                '$share' => (x($x,'button') ? $x['button'] : t('Share')),
                '$upload' => t('Upload photo'),
@@ -956,6 +1007,8 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$shortnoloc' => t('clear location'),
                '$title' => "",
                '$placeholdertitle' => t('Set title'),
+               '$category' => "",
+               '$placeholdercategory' => t('Categories (comma-separated list)'),
                '$wait' => t('Please wait'),
                '$permset' => t('Permission settings'),
                '$shortpermset' => t('permissions'),
@@ -1058,7 +1111,6 @@ function find_thread_parent_index($arr,$x) {
 }
 
 function render_location_google($item) {
-       $location = '';
        $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
        $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
        if($coord) {
@@ -1069,4 +1121,3 @@ function render_location_google($item) {
        }
        return $location;
 }
-