require_once("include/oembed.php");
require_once('include/event.php');
+function bb_rearrange_link($shared) {
+ if ($shared[1] != "type-link")
+ return($shared[0]);
+
+ $newshare = trim($shared[2]);
+ $newshare = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $newshare);
+
+ if (!strpos($shared[0], "[bookmark"))
+ $newshare = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $newshare, 1);
+
+ preg_match("/\[img\](.*?)\[\/img\]/ism", $newshare, $matches);
+
+ if ($matches) {
+ $newshare = str_replace($matches[0], '', $newshare);
+ $newshare = "[img]".$matches[1]."[/img]\n".$newshare;
+ }
+
+ $search = array("\n\n", "\n ", " \n");
+ $replace = array("\n", "\n", "\n");
+ do {
+ $oldtext = $newshare;
+ $newshare = str_replace($search, $replace, $newshare);
+ } while ($oldtext != $newshare);
+
+ $newshare = "[class=type-link]".$newshare."[/class]";
+
+ return($newshare);
+}
+
function bb_remove_share_information($Text) {
$Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism","bb_cleanup_share",$Text);
return($Text);
if (strpos($shared[1],$title) !== false)
$title = "";
- if (strpos($shared[1],$link) !== false)
- $link = "";
+// if (strpos($shared[1],$link) !== false)
+// $link = "";
$text = trim($shared[1]);
$userid = GetProfileUsername($profile,$author);
- $text = "<br />".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' <a href="'.$profile.'">'.$userid."</a>: <br />".$match[2];
+ //$text = "<br />".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' <a href="'.$profile.'">'.$userid."</a>: <br />".$match[2];
+ $text = "<br />".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.": <br />".$match[2];
return($text);
}
}
}
- // To-Do: Better check for pumpio
- $pumpio = preg_replace("=https?://([^/]*).*/(\w*)=ism", "$2@$1", $profile);
- if ($pumpio != $profile)
- return($username." (".$pumpio.")");
+ // pumpio (http://host.name/user)
+ $rest = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$3", $profile);
+ if ($rest == "") {
+ $pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "*$2@$1*", $profile);
+ if ($pumpio != $profile)
+ return($username." (".$pumpio.")");
+ }
return($username);
}
function bb_RemovePictureLinks($match) {
- $ch = @curl_init($match[1]);
- @curl_setopt($ch, CURLOPT_NOBODY, true);
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
- @curl_exec($ch);
- $curl_info = @curl_getinfo($ch);
-
- if (substr($curl_info["content_type"], 0, 6) == "image/")
- $text = "[url=".$match[1]."]".$match[1]."[/url]";
- else {
- $text = "[url=".$match[2]."]".$match[2]."[/url]";
-
- // if its not a picture then look if its a page that contains a picture link
- require_once("include/network.php");
-
- $body = fetch_url($match[1]);
-
- $doc = new DOMDocument();
- @$doc->loadHTML($body);
- $xpath = new DomXPath($doc);
- $list = $xpath->query("//meta[@name]");
- foreach ($list as $node) {
- $attr = array();
-
- if ($node->attributes->length)
- foreach ($node->attributes as $attribute)
- $attr[$attribute->name] = $attribute->value;
-
- if (strtolower($attr["name"]) == "twitter:image")
- $text = "[url=".$attr["content"]."]".$attr["content"]."[/url]";
+ $text = Cache::get($match[1]);
+
+ if(is_null($text)){
+ $ch = @curl_init($match[1]);
+ @curl_setopt($ch, CURLOPT_NOBODY, true);
+ @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
+ @curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+
+ if (substr($curl_info["content_type"], 0, 6) == "image/")
+ $text = "[url=".$match[1]."]".$match[1]."[/url]";
+ else {
+ $text = "[url=".$match[2]."]".$match[2]."[/url]";
+
+ // if its not a picture then look if its a page that contains a picture link
+ require_once("include/network.php");
+
+ $body = fetch_url($match[1]);
+
+ $doc = new DOMDocument();
+ @$doc->loadHTML($body);
+ $xpath = new DomXPath($doc);
+ $list = $xpath->query("//meta[@name]");
+ foreach ($list as $node) {
+ $attr = array();
+
+ if ($node->attributes->length)
+ foreach ($node->attributes as $attribute)
+ $attr[$attribute->name] = $attribute->value;
+
+ if (strtolower($attr["name"]) == "twitter:image")
+ $text = "[url=".$attr["content"]."]".$attr["content"]."[/url]";
+ }
}
+ Cache::set($match[1],$text);
}
-
return($text);
}
function bb_CleanPictureLinksSub($match) {
- $ch = @curl_init($match[1]);
- @curl_setopt($ch, CURLOPT_NOBODY, true);
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
- @curl_exec($ch);
- $curl_info = @curl_getinfo($ch);
-
- // if its a link to a picture then embed this picture
- if (substr($curl_info["content_type"], 0, 6) == "image/")
- $text = "[img]".$match[1]."[/img]";
- else {
- $text = "[img]".$match[2]."[/img]";
-
- // if its not a picture then look if its a page that contains a picture link
- require_once("include/network.php");
-
- $body = fetch_url($match[1]);
-
- $doc = new DOMDocument();
- @$doc->loadHTML($body);
- $xpath = new DomXPath($doc);
- $list = $xpath->query("//meta[@name]");
- foreach ($list as $node) {
- $attr = array();
-
- if ($node->attributes->length)
- foreach ($node->attributes as $attribute)
- $attr[$attribute->name] = $attribute->value;
-
- if (strtolower($attr["name"]) == "twitter:image")
- $text = "[img]".$attr["content"]."[/img]";
+ $text = Cache::get($match[1]);
+
+ if(is_null($text)){
+ $ch = @curl_init($match[1]);
+ @curl_setopt($ch, CURLOPT_NOBODY, true);
+ @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
+ @curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+
+ // if its a link to a picture then embed this picture
+ if (substr($curl_info["content_type"], 0, 6) == "image/")
+ $text = "[img]".$match[1]."[/img]";
+ else {
+ $text = "[img]".$match[2]."[/img]";
+
+ // if its not a picture then look if its a page that contains a picture link
+ require_once("include/network.php");
+
+ $body = fetch_url($match[1]);
+
+ $doc = new DOMDocument();
+ @$doc->loadHTML($body);
+ $xpath = new DomXPath($doc);
+ $list = $xpath->query("//meta[@name]");
+ foreach ($list as $node) {
+ $attr = array();
+
+ if ($node->attributes->length)
+ foreach ($node->attributes as $attribute)
+ $attr[$attribute->name] = $attribute->value;
+
+ if (strtolower($attr["name"]) == "twitter:image")
+ $text = "[img]".$attr["content"]."[/img]";
+ }
}
+ Cache::set($match[1],$text);
}
-
return($text);
}
$Text = preg_replace("/\n\[code\]/ism", "[code]", $Text);
$Text = preg_replace("/\[\/code\]\n/ism", "[/code]", $Text);
+ // Rearrange shared links
+ if (get_config("system", "rearrange_shared_links") AND (!$simplehtml OR $tryoembed))
+ $Text = preg_replace_callback("(\[class=(.*?)\](.*?)\[\/class\])ism","bb_rearrange_link",$Text);
+
// when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
if (!$tryoembed)
$Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);