]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
allow comments on other folks wall-to-wall postings
[friendica.git] / include / conversation.php
index ee8e73cebe5d67750f7db4947151961b20e8db0c..ceef63a9927d83da75d1b675bfc27150fcfc7d7a 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+require_once("include/bbcode.php");
+
+
 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
 // is identical to the code in mod/message.php for 'item_extract_images' and
 // 'item_redir_and_replace_images'
@@ -51,19 +54,27 @@ 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';
+       $cnt = 1;
+       $pos = get_bb_tag_pos($origbody, 'url', 1);
+       while($pos !== false && $cnt < 1000) {
+
+               $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
                $replace = '[url=' . z_path() . '/redir/' . $cid 
-                          . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
+                          . '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/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);
+               $newbody .= substr($origbody, 0, $pos['start']['open']);
+               $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
+               $origbody = substr($origbody, $pos['end']['close']);
+               if($origbody === false)
+                       $origbody = '';
 
-               $process_part = preg_replace($search, $replace, $process_part);
-               $newbody = $newbody . $process_part;
+               $subject = preg_replace($search, $replace, $subject);
+               $newbody .= $subject;
+
+               $cnt++;
+               $pos = get_bb_tag_pos($origbody, 'url', 1);
        }
-       $newbody = $newbody . $origbody;
+       $newbody .= $origbody;
 
        $cnt = 0;
        foreach($images as $image) {
@@ -205,6 +216,20 @@ function localize_item(&$item){
                $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
 
        }
+       if (stristr($item['verb'],ACTIVITY_MOOD)) {
+               $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
+               if(! $verb)
+                       return;
+
+               $Aname = $item['author-name'];
+               $Alink = $item['author-link'];
+               $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
+               
+               $txt = t('%1$s is currently %2$s');
+
+               $item['body'] = sprintf($txt, $A, t($verb));
+       }
+
     if ($item['verb']===ACTIVITY_TAG){
                $r = q("SELECT * from `item`,`contact` WHERE 
                `item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
@@ -279,10 +304,10 @@ function localize_item(&$item){
        }
 
        // 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']);
-               }
+       $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
+       if(preg_match($photo_pattern,$item['body'])) {
+               $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5'  . '[/img][/url]';
+               $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']);
        }
 
        // add sparkle links to appropriate permalinks
@@ -321,7 +346,7 @@ function count_descendants($item) {
  * Recursively prepare a thread for HTML
  */
 
-function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $alike, $dlike, $thread_level=1) {
+function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $alike, $dlike, $previewing, $thread_level=1) {
        $result = array();
 
        $wall_template = 'wall_thread.tpl';
@@ -369,12 +394,34 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
                $thumb = $item['thumb'];
                $indent = '';
                $osparkle = '';
+               $visiting = false;
                $lastcollapsed = false;
                $firstcollapsed = false;
                $total_children += count_descendants($item);
 
                $toplevelpost = (($item['id'] == $item['parent']) ? true : false);
+
+
+               if($item['uid'] == local_user())
+                       $dropping = true;
+               elseif(is_array($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $visitor) {
+                               if($visitor['cid'] == $item['contact-id']) {
+                                       $dropping = true;
+                                       $visiting = true;
+                                       break;
+                               }
+                       }
+               }
+
                $item_writeable = (($item['writable'] || $item['self']) ? true : false);
+
+               // This will allow us to comment on wall-to-wall items owned by our friends
+               // and community forums even if somebody else wrote the post. 
+
+               if($visiting && $mode == 'profile')
+                       $item_writeable = true;
+
                $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
                $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
                        || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
@@ -386,8 +433,6 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
                        $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
                else
                        $edpost = false;
-               if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
-                       $dropping = true;
 
                $drop = array(
                        'dropping' => $dropping,
@@ -508,6 +553,13 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
                        }
                }
 
+               if(intval(get_config('system','thread_allow')) && $a->theme_thread_allow) {
+                       $comments_threaded = true;
+               }
+               else {
+                       $comments_threaded = false;
+               }
+
                if($page_writeable) {
                        $buttons = array(
                                'like' => array( t("I like this \x28toggle\x29"), t("like")),
@@ -524,7 +576,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
                                        $qcomment = (($qc) ? explode("\n",$qc) : null);
                                }
                                $comment = replace_macros($cmnt_tpl,array(
-                                       '$return_path' => '', 
+                                       '$return_path' => '',
+                                       '$threaded' => $comments_threaded, 
                                        '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
                                        '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
                                        '$id' => $item['item_id'],
@@ -618,7 +671,7 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
 
                $item_result['children'] = array();
                if(count($item['children'])) {
-                       $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, $alike, $dlike, ($thread_level + 1));
+                       $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, $alike, $dlike, $previewing, ($thread_level + 1));
                }
                $item_result['private'] = $item['private'];
                $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : '');
@@ -868,7 +921,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                }
                        }
 
-                       $threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode,  $profile_owner, $alike, $dlike);
+                       $threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode,  $profile_owner, $alike, $dlike, $previewing);
                }
        }