X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=6c3f13477fdf4cd16371e504d6a8baedc26be032;hb=bfca7f47ef1f986ea8515d23c3c1962c7fe3a298;hp=d0ced1d18a2c73119b1ac372c8087a46a7e42c85;hpb=7614d35cadb274a48434a61cdab205ca120462a3;p=friendica.git diff --git a/include/conversation.php b/include/conversation.php index d0ced1d18a..6c3f13477f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1,30 +1,91 @@ $new_body, 'images' => $saved_image); +}} + +if(! function_exists('item_redir_and_replace_images')) { +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'; + $replace = '[url=' . z_path() . '/redir/' . $cid + . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/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); + + $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); + $cnt++; + } + return $newbody; +}} + + + /** * 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); - } + $extracted = item_extract_images($item['body']); + if($extracted['images']) + $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']); $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; if ($item['verb']=== ACTIVITY_LIKE || $item['verb']=== ACTIVITY_DISLIKE){ @@ -173,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) { @@ -180,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']; + } + + } @@ -432,7 +505,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { continue; $toplevelpost = (($item['id'] == $item['parent']) ? true : false); - $toplevelprivate = false; + // Take care of author collapsing and comment collapsing // (author collapsing is currently disabled) @@ -440,7 +513,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // If there are more than two comments, squash all but the last 2. if($toplevelpost) { - $toplevelprivate = (($toplevelpost && $item['private']) ? true : false); + $item_writeable = (($item['writable'] || $item['self']) ? true : false); $comments_seen = 0; @@ -485,7 +558,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; - $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) + $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) ? t('Private Message') : false); @@ -546,16 +619,16 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { } $likebuttons = ''; - $shareable = ((($profile_owner == local_user()) && ((! $item['private']) || $item['network'] === NETWORK_FEED)) ? true : false); + $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? 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;