Merge pull request #900 from annando/master

Beautifiying export of shared posts to other networks
This commit is contained in:
Tobias Diekershoff 2014-01-18 22:23:59 -08:00
commit aa22598b80
3 changed files with 195 additions and 13 deletions

View file

@ -133,6 +133,10 @@ function diaspora_ol($s) {
function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
// Since Diaspora is creating a summary for links, this function removes them before posting
if ($fordiaspora)
$Text = bb_remove_share_information($Text);
// Re-enabling the converter again.
// The bbcode parser now handles youtube-links (and the other stuff) correctly.
// Additionally the html code is now fixed so that lists are now working.
@ -159,7 +163,10 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
//$Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);
// Convert it to HTML - don't try oembed
$Text = bbcode($Text, $preserve_nl, false);
if ($fordiaspora)
$Text = bbcode($Text, $preserve_nl, false, 3);
else
$Text = bbcode($Text, $preserve_nl, false, 4);
// Now convert HTML to Markdown
$md = new Markdownify(false, false, false);

View file

@ -1,8 +1,48 @@
<?php
require_once("include/oembed.php");
require_once('include/event.php');
function bb_remove_share_information($Text) {
$Text = preg_replace_callback("((.*?)\[class=(.*?)\](.*?)\[\/class\])ism","bb_cleanup_share",$Text);
return($Text);
}
function bb_cleanup_share($shared) {
if ($shared[2] != "type-link")
return($shared[3]);
if (!preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$shared[3], $bookmark))
return($shared[3]);
$title = "";
$link = "";
if (isset($bookmark[2][0]))
$title = $bookmark[2][0];
if (isset($bookmark[1][0]))
$link = $bookmark[1][0];
if (strpos($shared[1],$title) !== false)
$title = "";
if (strpos($shared[1],$link) !== false)
$link = "";
$text = trim($shared[1]);
if (($text == "") AND ($title != "") AND ($link == ""))
$text .= "\n\n".trim($title);
if (($link != "") AND ($title != ""))
$text .= "\n[url=".trim($link)."]".trim($title)."[/url]";
elseif (($link != ""))
$text .= "\n".trim($link);
return(trim($text));
}
function bb_cleanstyle($st) {
return "<span style=\"".cleancss($st[1]).";\">".$st[2]."</span>";
}
@ -291,6 +331,112 @@ function bb_ShareAttributes($match) {
return($text);
}
// 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("&#x2672; ", ENT_QUOTES, 'UTF-8').$userid.':</b></span>';
//$headline .= sprintf(t('<span><b>'.
// html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').
// '<a href="%s" target="external-link">%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("&#x2672; ", ENT_QUOTES, 'UTF-8').
'<a href="%s" target="external-link">%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];
@ -319,6 +465,8 @@ function bb_ShareAttributesSimple($match) {
return($text);
}
// Used for text exports (Twitter, Facebook, Google+)
function bb_ShareAttributesSimple2($match) {
$attributes = $match[1];
@ -349,17 +497,22 @@ function bb_ShareAttributesSimple2($match) {
}
function GetProfileUsername($profile, $username) {
$friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile);
if ($friendica != $profile)
return($friendica." (".$username.")");
$diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile);
if ($diaspora != $profile)
return($diaspora." (".$username.")");
$twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1@twitter.com", $profile);
if ($twitter != $profile)
return($twitter." (".$username.")");
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) {
@ -368,10 +521,15 @@ function GetProfileUsername($profile, $username) {
$UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
$user = json_decode($UserData);
if ($user)
return($user->screen_name."@".$StatusnetHost." (".$username.")");
return($username." (".$user->screen_name."@".$StatusnetHost.")");
}
}
// To-Do: Better check for pumpio
$pumpio = preg_replace("=https?://([^/]*).*/(\w*)=ism", "$2@$1", $profile);
if ($pumpio != $profile)
return($username." (".$pumpio.")");
return($username);
}
@ -630,6 +788,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple",$Text);
elseif ($simplehtml == 2)
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple2",$Text);
elseif ($simplehtml == 3)
$Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesDiaspora",$Text);
elseif ($simplehtml == 4)
$Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesForExport",$Text);
$Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
$Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);

View file

@ -1127,6 +1127,18 @@ border-bottom: 1px solid #D2D2D2;
display: table;
width: 745px;
}
.wall-item-content hr {
background: none repeat scroll 0% 0% rgb(221, 221, 221);
color: rgb(221, 221, 221);
clear: both;
float: none;
width: 100%;
height: 0.1em;
/* margin: 0px 0px 1.45em; */
border: medium none;
}
.wall-item-container .wall-item-item, .wall-item-container .wall-item-bottom {
display: table-row;
}
@ -2135,7 +2147,8 @@ blockquote {
}
.oembed {
font-size: large;
/* font-size: large; */
font-size: larger;
font-weight: bold;
}