]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
rev update
[friendica.git] / include / conversation.php
index 4fea52c9c7a556a1733f4071b6dc4fcbcd726309..546e27db67fa772985493f09a4e65cf3b04e88f5 100644 (file)
@@ -22,10 +22,10 @@ function item_extract_images($body) {
                if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
                        // This is an embedded image
 
-                       $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - $img_start);
-                       $cnt++;
-
+                       $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
                        $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
+
+                       $cnt++;
                }
                else
                        $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
@@ -48,25 +48,31 @@ function item_extract_images($body) {
 if(! function_exists('item_redir_and_replace_images')) {
 function item_redir_and_replace_images($body, $images, $cid) {
 
-       $newbody = $body;
+       $origbody = $body;
+       $newbody = '';
 
        for($i = 0; $i < count($images); $i++) {
                $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is';
                $replace = '[url=' . z_path() . '/redir/' . $cid 
                           . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ;
 
-               $newbody = preg_replace($search, $replace, $newbody);
+               $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);
+
+               $process_part = preg_replace($search, $replace, $process_part);
+               $newbody = $newbody . $process_part;
        }
+       $newbody = $newbody . $origbody;
 
        $cnt = 0;
        foreach($images as $image) {
                // We're depending on the property of 'foreach' (specified on the PHP website) that
                // it loops over the array starting from the first element and going sequentially
                // to the last element
-               $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '[img]' . $image . '[/img]', $newbody);
+               $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
                $cnt++;
        }
-
        return $newbody;
 }}
 
@@ -228,6 +234,7 @@ function localize_item(&$item){
                                $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) {
@@ -235,6 +242,17 @@ function localize_item(&$item){
                }
        }
 
+       // add sparkle links to appropriate permalinks
+
+       $x = stristr($item['plink'],'/display/');
+       if($x) {
+               $sparkle = false;
+               $y = best_link_url($item,$sparkle,true);
+               if(strstr($y,'/redir/'))
+                       $item['plink'] = $y . '?f=&url=' . $item['plink'];
+       } 
+
+
 
 }
 
@@ -754,7 +772,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        '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'])),
+                                       'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner-name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
                                        'to' => t('to'),
                                        'wall' => t('Wall-to-Wall'),
                                        'vwall' => t('via Wall-To-Wall:'),