- logger('Facebook post: original msg=' . $msg, LOGGER_DATA);
-
- // make links readable before we strip the code
-
- // unless it's a dislike - just send the text as a comment
-
- // if($b['verb'] == ACTIVITY_DISLIKE)
- // $msg = trim(strip_tags(bbcode($msg)));
-
- // Old code
- /*$search_str = $a->get_baseurl() . '/search';
-
- if(preg_match("/\[url=(.*?)\](.*?)\[\/url\]/is",$msg,$matches)) {
-
- // don't use hashtags for message link
-
- if(strpos($matches[2],$search_str) === false) {
- $link = $matches[1];
- if(substr($matches[2],0,5) != '[img]')
- $linkname = $matches[2];
- }
- }
-
- // strip tag links to avoid link clutter, this really should be
- // configurable because we're losing information
-
- $msg = preg_replace("/\#\[url=(.*?)\](.*?)\[\/url\]/is",'#$2',$msg);
-
- // provide the link separately for normal links
- $msg = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/is",'$2 $1',$msg);
-
- if(preg_match("/\[img\](.*?)\[\/img\]/is",$msg,$matches))
- $image = $matches[1];
-
- $msg = preg_replace("/\[img\](.*?)\[\/img\]/is", t('Image: ') . '$1', $msg);
-
- if((strpos($link,z_root()) !== false) && (! $image))
- $image = $a->get_baseurl() . '/images/friendica-64.jpg';
-
- $msg = trim(strip_tags(bbcode($msg)));*/
-
- // New code
-
- // Looking for the first image
- $image = '';
- if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches))
- $image = $matches[3];
-
- if ($image == '')
- if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
- $image = $matches[1];
-
- // When saved into the database the content is sent through htmlspecialchars
- // That means that we have to decode all image-urls
- $image = htmlspecialchars_decode($image);
-
- // Checking for a bookmark element
- $body = $b['body'];
- if (strpos($body, "[bookmark") !== false) {
- // splitting the text in two parts:
- // before and after the bookmark
- $pos = strpos($body, "[bookmark");
- $body1 = substr($body, 0, $pos);
- $body2 = substr($body, $pos);
-
- // Removing the bookmark and all quotes after the bookmark
- // they are mostly only the content after the bookmark.
- $body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2);
- $body2 = preg_replace("/\[quote\=([^\]]*)\](.*?)\[\/quote\]/ism",'',$body2);
- $body2 = preg_replace("/\[quote\](.*?)\[\/quote\]/ism",'',$body2);
-
- $body = $body1.$body2;
- }
-
- // Convert recycle signs
- $body = str_replace("\t", " ", $body);
- // recycle 1
- $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n\t$2:\t", $body);
- // recycle 2 (Test)
- $recycle = html_entity_decode("◌ ", ENT_QUOTES, 'UTF-8');
- $body = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', "\n\t$2:\t", $body);
-
- // share element
- $body = preg_replace_callback("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]/ism","fbpost_ShareAttributes", $body);
-
- $bodyparts = explode("\t", $body);
- // Doesn't help with multiple repeats - the problem has to be solved later
- if (sizeof($bodyparts) == 3) {
- $html = bbcode($bodyparts[2], false, false);
- $test = trim(html2plain($html, 0, true));
-
- if (trim($bodyparts[0]) == "")
- $body = trim($bodyparts[2]);
- else if (trim($test) == "")
- $body = trim($bodyparts[0]);
- else
- $body = trim($bodyparts[0])."\n\n".trim($bodyparts[1])."[quote]".trim($bodyparts[2])."[/quote]";
- } else
- $body = str_replace("\t", "", $body);
-
- // At first convert the text to html
- $html = bbcode($body, false, false);
-
- // Then convert it to plain text
- $msg = trim($b['title']." \n\n".html2plain($html, 0, true));