]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Mostly some checks in order to avoid Notices; 1 real bugfix in /mod/network.php
[friendica.git] / include / conversation.php
index 35abb29ca58e216a25fadf846f19997ed284ec4f..bd9b11bee6b141aef57ec20cd5af00dca7faefbe 100755 (executable)
@@ -4,6 +4,33 @@
  * Render actions localized
  */
 function localize_item(&$item){
+
+       $Text = $item['body'];
+
+
+       // find private image (w/data url) if present and convert image 
+       // link to a magic-auth redirect.
+
+       $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/' . $item['contact-id'] 
+                       . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]' ;
+
+               $Text = preg_replace($search,$replace,$Text);
+
+               if(strlen($saved_image))
+                       $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]',$Text);
+       }
+
        $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
        if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){
 
@@ -210,7 +237,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
        $alike = array();
        $dlike = array();
-       
+       $o = "";
        
        // array with html for each thread (parent+comments)
        $threads = array();
@@ -346,7 +373,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                $comments[$item['parent']] = 1;
                                        else
                                                $comments[$item['parent']] += 1;
-                               }
+                               } elseif(! x($comments,$item['parent'])) 
+                                       $comments[$item['parent']] = 0; // avoid notices later on
                        }
 
                        // map all the like/dislike activities for each parent item 
@@ -381,6 +409,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                $toplevelprivate = false;
 
                                // Take care of author collapsing and comment collapsing
+                               // (author collapsing is currently disabled)
                                // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
                                // If there are more than two comments, squash all but the last 2.
                        
@@ -388,7 +417,9 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        $toplevelprivate = (($toplevelpost && $item['private']) ? true : false);
                                        $item_writeable = (($item['writable'] || $item['self']) ? true : false);
 
-                                       /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
+                                       // DISABLED
+                                       /*
+                                       if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
                                                $blowhard_count ++;
                                                if($blowhard_count == 3) {
                                                        $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] 
@@ -402,7 +433,9 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                if($blowhard_count >= 3)
                                                        $o .= '</div>';
                                                $blowhard_count = 0;
-                                       }*/
+                                       }
+                                       // END DISABLED
+                                       */
 
                                        $comments_seen = 0;
                                        $comments_collapsed = false;
@@ -414,7 +447,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                }
                                else {
                                        // prevent private email from leaking into public conversation
-                                       if((! $toplevelpost) && (! toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
+                                       if((! $toplevelpost) && (! $toplevelprivate) && ($item['private']) && ($profile_owner != local_user()))
                                                continue;
                                        $comments_seen ++;
                                }       
@@ -489,7 +522,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                }
 
                                $likebuttons = '';
-                               $shareable = ((($profile_owner == local_user()) && ($mode != 'display') && (! $item['private'])) ? true : false);
+                               $shareable = ((($profile_owner == local_user()) &&  (! $item['private'])) ? true : false); //($mode != 'display') &&
 
                                if($page_writeable) {
                                        if($toplevelpost) {
@@ -500,6 +533,10 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                if ($shareable) $likebuttons['share'] = array( t('Share this'), t('share'));
                                        }
 
+
+                                       $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(
                                                        '$return_path' => '', 
@@ -507,6 +544,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                                        '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
                                                        '$id' => $item['item_id'],
                                                        '$parent' => $item['parent'],
+                                                       '$qcomment' => $qcomment,
                                                        '$profile_uid' =>  $profile_owner,
                                                        '$mylink' => $a->contact['url'],
                                                        '$mytitle' => t('This is you'),
@@ -609,14 +647,12 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        if ($tag!="") $tags[] = bbcode($tag);
                                }
 
-
                                // Build the HTML
 
                                $body = prepare_body($item,true);
-                               
 
                                $tmp_item = replace_macros($template,array(
-                                       '$type' => implode("",array_slice(split("/",$item['verb']),-1)),
+                                       '$type' => implode("",array_slice(explode("/",$item['verb']),-1)),
                                        '$tags' => $tags,
                                        '$body' => template_escape($body),
                                        '$id' => $item['item_id'],
@@ -821,7 +857,7 @@ function format_like($cnt,$arr,$type,$id) {
 }}
 
 
-function status_editor($a,$x, $notes_cid = 0) {
+function status_editor($a,$x, $notes_cid = 0, $popup=false) {
 
        $o = '';
                
@@ -885,8 +921,8 @@ function status_editor($a,$x, $notes_cid = 0) {
 
        $o .= replace_macros($tpl,array(
                '$return_path' => $a->cmd,
-               '$action' => 'item',
-               '$share' => (($x['button']) ? $x['button'] : t('Share')),
+               '$action' =>  $a->get_baseurl().'/item',
+               '$share' => (x($x,'button') ? $x['button'] : t('Share')),
                '$upload' => t('Upload photo'),
                '$shortupload' => t('upload photo'),
                '$attach' => t('Attach file'),
@@ -924,6 +960,12 @@ function status_editor($a,$x, $notes_cid = 0) {
                '$preview' => t('Preview'),
        ));
 
+
+       if ($popup==true){
+               $o = '<div id="jot-popup" style="display: none;">'.$o.'</div>';
+               
+       }
+
        return $o;
 }
 
@@ -945,8 +987,8 @@ function conv_sort($arr,$order) {
                usort($parents,'sort_thr_commented');
 
        if(count($parents))
-               foreach($parents as $x) 
-                       $x['children'] = array();
+               foreach($parents as $i=>$_x) 
+                       $parents[$i]['children'] = array();
 
        foreach($arr as $x) {
                if($x['id'] != $x['parent']) {