+// Escpecially for Diaspora (there mustn't be links in the share information)
+function bb_ShareAttributesDiaspora($match) {
+
+ $attributes = $match[2];
+
+ $author = "";
+ preg_match("/author='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+
+ preg_match('/author="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $author = $matches[1];
+
+ $profile = "";
+ preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ $posted = "";
+// preg_match("/posted='(.*?)'/ism", $attributes, $matches);
+// if ($matches[1] != "")
+// $posted = " ".date("Y-m-d H:i", strtotime($matches[1]));
+//
+// preg_match('/posted="(.*?)"/ism', $attributes, $matches);
+// if ($matches[1] != "")
+// $posted = " ".date("Y-m-d H:i", strtotime($matches[1]));
+
+ $userid = GetProfileUsername($profile,$author);
+
+ $headline = '<div class="shared_header">';
+ $headline .= '<span><b>'.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$userid.':</b></span>';
+ //$headline .= sprintf(t('<span><b>'.
+ // html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').
+ // '<a href="%s" target="_blank">%s</a>%s:</b></span>'), $profile, $userid, $posted);
+ $headline .= "</div>";
+
+ $text = trim($match[1]);
+
+ if ($text != "")
+ $text .= "<hr />";
+
+ $text .= $headline.'<blockquote class="shared_content">'.trim($match[3])."</blockquote><br />";
+ //$text .= $headline."<br />".trim($match[3])."<br />";
+
+ return($text);
+}
+
+// Optimized for Libertree, Wordpress, Tumblr, ...
+function bb_ShareAttributesForExport($match) {
+
+ $attributes = $match[2];
+
+ $author = "";
+ preg_match("/author='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+
+ preg_match('/author="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $author = $matches[1];
+
+ $profile = "";
+ preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ $link = "";
+ preg_match("/link='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $link = $matches[1];
+
+ preg_match('/link="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $link = $matches[1];
+
+ if ($link == "")
+ $link = $profile;
+
+ $userid = GetProfileUsername($profile,$author);
+
+ $headline = '<div class="shared_header">';
+ $headline .= sprintf(t('<span><b>'.
+ html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').
+ '<a href="%s" target="_blank">%s</a>%s:</b></span>'), $link, $userid, $posted);
+ $headline .= "</div>";
+
+ $text = trim($match[1]);
+
+ if ($text != "")
+ $text .= "<hr />";
+
+ $text .= $headline.'<blockquote class="shared_content">'.trim($match[3])."</blockquote><br />";
+
+ return($text);
+}
+
+// Still in use?
+function bb_ShareAttributesSimple($match) {
+
+ $attributes = $match[1];
+
+ $author = "";
+ preg_match("/author='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+
+ preg_match('/author="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $author = $matches[1];
+
+ $profile = "";
+ preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ $userid = GetProfileUsername($profile,$author);
+
+ $text = "<br />".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' <a href="'.$profile.'">'.$userid."</a>: <br />»".$match[2]."«";
+
+ return($text);
+}
+
+// Used for text exports (Twitter, Facebook, Google+)
+function bb_ShareAttributesSimple2($match) {
+
+ $attributes = $match[1];
+
+ $author = "";
+ preg_match("/author='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
+
+ preg_match('/author="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $author = $matches[1];
+
+ $profile = "";
+ preg_match("/profile='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[1];
+
+ preg_match('/profile="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $profile = $matches[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').' '.$userid.": <br />".$match[2];
+
+ return($text);
+}
+
+function GetProfileUsername($profile, $username) {
+
+ $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1@twitter.com", $profile);
+ if ($twitter != $profile)
+ return($username." (".$twitter.")");
+
+ $gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile);
+ if ($gplus != $profile)
+ return($username." (".$gplus.")");
+
+ $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile);
+ if ($friendica != $profile)
+ return($username." (".$friendica.")");
+
+ $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile);
+ if ($diaspora != $profile)
+ return($username." (".$diaspora.")");
+
+ $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile);
+ if ($StatusnetHost != $profile) {
+ $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
+ if ($StatusnetUser != $profile) {
+ $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
+ $user = json_decode($UserData);
+ if ($user)
+ return($username." (".$user->screen_name."@".$StatusnetHost.")");
+ }
+ }
+
+ // 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) {
+ $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) {
+ $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);
+}
+
+function bb_CleanPictureLinks($text) {
+ $text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_CleanPictureLinksSub', $text);
+ return ($text);
+}
+