]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
some testbubble stuff
[friendica.git] / include / conversation.php
index b44d4acd6e94acbed8a105c8939b5b00cd8c3899..f4740688cd9b0775336f30cfa8433b69e62e0da3 100755 (executable)
@@ -4,6 +4,28 @@
  * Render actions localized
  */
 function localize_item(&$item){
+
+       $Text = $item['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/' . $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){
 
@@ -157,6 +179,7 @@ function localize_item(&$item){
  * that are based on unique features of the calling module.
  *
  */
+ if(!function_exists('conversation')){
 function conversation(&$a, $items, $mode, $update, $preview = false) {
 
        require_once('bbcode.php');
@@ -204,8 +227,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
        $items = $cb['items'];
 
        $cmnt_tpl    = get_markup_template('comment_item.tpl');
-       $tpl         = get_markup_template('wall_item.tpl');
-       $wallwall    = get_markup_template('wallwall_item.tpl');
+       $tpl         = 'wall_item.tpl';
+       $wallwall    = 'wallwall_item.tpl';
        $hide_comments_tpl = get_markup_template('hide_comments.tpl');
 
        $alike = array();
@@ -223,7 +246,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                        // "New Item View" on network page or search page results 
                        // - just loop through the items and format them minimally for display
 
-                       $tpl = get_markup_template('search_item.tpl');
+                       //$tpl = get_markup_template('search_item.tpl');
+                       $tpl = 'search_item.tpl';
 
                        foreach($items as $item) {
                                $threadsid++;
@@ -289,43 +313,46 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
                                $body = prepare_body($item,true);
                                
-                               $tmp_item = replace_macros($tpl,array(
-                                       '$id' => (($preview) ? 'P0' : $item['item_id']),
-                                       '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
-                                       '$profile_url' => $profile_link,
-                                       '$item_photo_menu' => item_photo_menu($item),
-                                       '$name' => template_escape($profile_name),
-                                       '$sparkle' => $sparkle,
-                                       '$lock' => $lock,
-                                       '$thumb' => $profile_avatar,
-                                       '$title' => template_escape($item['title']),
-                                       '$body' => 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),
-                                       '$owner_url' => $owner_url,
-                                       '$owner_photo' => $owner_photo,
-                                       '$plink' => get_plink($item),
-                                       '$edpost' => false,
-                                       '$isstarred' => $isstarred,
-                                       '$star' => $star,
-                                       '$drop' => $drop,
-                                       '$vote' => $likebuttons,
-                                       '$like' => '',
-                                       '$dislike' => '',
-                                       '$comment' => '',
-                                       '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
-                                       '$previewing' => $previewing,
-                                       '$wait' => t('Please wait'),
-                               ));
+                               //$tmp_item = replace_macros($tpl,array(
+                               $tmp_item = array(
+                                       'template' => $tpl,
+                                       'id' => (($preview) ? 'P0' : $item['item_id']),
+                                       'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
+                                       'profile_url' => $profile_link,
+                                       'item_photo_menu' => item_photo_menu($item),
+                                       'name' => template_escape($profile_name),
+                                       'sparkle' => $sparkle,
+                                       'lock' => $lock,
+                                       'thumb' => $profile_avatar,
+                                       'title' => template_escape($item['title']),
+                                       '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),
+                                       'owner_url' => $owner_url,
+                                       'owner_photo' => $owner_photo,
+                                       'plink' => get_plink($item),
+                                       'edpost' => false,
+                                       'isstarred' => $isstarred,
+                                       'star' => $star,
+                                       'drop' => $drop,
+                                       'vote' => $likebuttons,
+                                       'like' => '',
+                                       'dislike' => '',
+                                       'comment' => '',
+                                       'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
+                                       'previewing' => $previewing,
+                                       'wait' => t('Please wait'),
+                               );
 
                                $arr = array('item' => $item, 'output' => $tmp_item);
                                call_hooks('display_item', $arr);
 
                                $threads[$threadsid]['id'] = $item['item_id'];
-                               $threads[$threadsid]['html'] .= $arr['output'];
+                               $threads[$threadsid]['items'] = array($arr['output']);
 
                        }
 
@@ -358,6 +385,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                        }
 
                        $comments_collapsed = false;
+                       $comment_lastcollapsed = false;
+                       $comment_firstcollapsed = false;
                        $blowhard = 0;
                        $blowhard_count = 0;
 
@@ -381,6 +410,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 +418,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,21 +434,27 @@ 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;
+                                       $comment_lastcollapsed  = false;
+                                       $comment_firstcollapsed = false;
                                        
                                        $threadsid++;
                                        $threads[$threadsid]['id'] = $item['item_id'];
-                                       $threads[$threadsid]['html'] = "";
+                                       $threads[$threadsid]['items'] = array();
 
                                }
                                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 ++;
+                                       $comment_lastcollapsed  = false;
+                                       $comment_firstcollapsed = false;
                                }       
 
                                $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
@@ -424,23 +462,17 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
 
                                if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
-                                       if(! $comments_collapsed) {
 
-                                               // IMPORTANT: the closing </div> in the hide_comments template
-                                               // is supplied below in code. 
-
-                                               $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array(
-                                                       '$id' => $item['parent'],
-                                                       '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),
-                                                               $comments[$item['parent']]),
-                                                       '$display' => 'none',
-                                                       '$hide_text' => t('show more')
-                                               ));
+                                       if (!$comments_collapsed){
+                                               $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] );
+                                               $threads[$threadsid]['hide_text'] = t('show more');
                                                $comments_collapsed = true;
+                                               $comment_firstcollapsed = true;
                                        }
                                }
                                if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
-                                       $threads[$threadsid]['html'] .= '</div>';
+
+                                       $comment_lastcollapsed = true;
                                }
 
                                $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
@@ -500,6 +532,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 +543,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,68 +646,75 @@ 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,
+                               $tmp_item = array(
+                                       // collapse comments in template. I don't like this much...
+                                       'comment_firstcollapsed' => $comment_firstcollapsed,
+                                       'comment_lastcollapsed' => $comment_lastcollapsed,
+                                       // template to use to render item (wall, walltowall, search)
+                                       'template' => $template,
+                                       
+                                       'type' => implode("",array_slice(split("/",$item['verb']),-1)),
+                                       'tags' => $tags,
+                                       'body' => template_escape($body),
+                                       'text' => strip_tags(template_escape($body)),
+                                       'id' => $item['item_id'],
+                                       'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
+                                       'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
+                                       'to' => t('to'),
+                                       'wall' => t('Wall-to-Wall'),
+                                       'vwall' => t('via Wall-To-Wall:'),
+                                       'profile_url' => $profile_link,
+                                       'item_photo_menu' => item_photo_menu($item),
+                                       'name' => template_escape($profile_name),
+                                       'thumb' => $profile_avatar,
+                                       'osparkle' => $osparkle,
+                                       'sparkle' => $sparkle,
+                                       'title' => template_escape($item['title']),
+                                       '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' => $indent,
+                                       'owner_url' => $owner_url,
+                                       'owner_photo' => $owner_photo,
+                                       'owner_name' => template_escape($owner_name),
+                                       'plink' => get_plink($item),
+                                       'edpost' => $edpost,
+                                       'isstarred' => $isstarred,
+                                       'star' => $star,
+                                       'drop' => $drop,
+                                       'vote' => $likebuttons,
+                                       'like' => $like,
+                                       'dislike' => $dislike,
+                                       'comment' => $comment,
+                                       'previewing' => $previewing,
+                                       'wait' => t('Please wait'),
 
-                               $tmp_item = replace_macros($template,array(
-                                       '$type' => implode("",array_slice(split("/",$item['verb']),-1)),
-                                       '$tags' => $tags,
-                                       '$body' => template_escape($body),
-                                       '$id' => $item['item_id'],
-                                       '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
-                                       '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
-                                       '$to' => t('to'),
-                                       '$wall' => t('Wall-to-Wall'),
-                                       '$vwall' => t('via Wall-To-Wall:'),
-                                       '$profile_url' => $profile_link,
-                                       '$item_photo_menu' => item_photo_menu($item),
-                                       '$name' => template_escape($profile_name),
-                                       '$thumb' => $profile_avatar,
-                                       '$osparkle' => $osparkle,
-                                       '$sparkle' => $sparkle,
-                                       '$title' => template_escape($item['title']),
-                                       '$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' => $indent,
-                                       '$owner_url' => $owner_url,
-                                       '$owner_photo' => $owner_photo,
-                                       '$owner_name' => template_escape($owner_name),
-                                       '$plink' => get_plink($item),
-                                       '$edpost' => $edpost,
-                                       '$isstarred' => $isstarred,
-                                       '$star' => $star,
-                                       '$drop' => $drop,
-                                       '$vote' => $likebuttons,
-                                       '$like' => $like,
-                                       '$dislike' => $dislike,
-                                       '$comment' => $comment,
-                                       '$previewing' => $previewing,
-                                       '$wait' => t('Please wait'),
-
-                               ));
+                               );
 
 
                                $arr = array('item' => $item, 'output' => $tmp_item);
                                call_hooks('display_item', $arr);
 
-                               $threads[$threadsid]['html'] .= $arr['output'];
+                               $threads[$threadsid]['items'][] = $arr['output'];
                        }
                }
        }
 
-
        $page_template = get_markup_template("conversation.tpl");
        $o .= replace_macros($page_template, array(
+               '$baseurl' => $a->get_baseurl(),
+               '$mode' => $mode,
+               '$user' => $a->user,
                '$threads' => $threads,
                '$dropping' => ($dropping?t('Delete Selected Items'):False),
        ));
 
        return $o;
-} 
+}}
 
 function best_link_url($item,&$sparkle) {