1
1
Fork 0

bbcode: New element "share" for shared content

mail: Now mails connected via subject line if there isn't an appropriate header.
vier: Improvents to the theme so that shared messages are looking fine
This commit is contained in:
Michael Vogel 2012-12-17 03:01:40 +01:00
parent d253d59668
commit 9c0de28622
4 changed files with 110 additions and 8 deletions

View file

@ -155,6 +155,9 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
// $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism",
// "[url]$1[/url]\n[img]$2[/img]", $Text); // "[url]$1[/url]\n[img]$2[/img]", $Text);
// Remove the avatar picture since that isn't looking good on the other side
//$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 // Convert it to HTML - don't try oembed
$Text = bbcode($Text, $preserve_nl, false); $Text = bbcode($Text, $preserve_nl, false);

View file

@ -206,7 +206,59 @@ function bb_replace_images($body, $images) {
return $newbody; return $newbody;
}} }}
function bb_ShareAttributes($match) {
$attributes = $match[1];
$author = "";
preg_match("/author='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$author = $matches[1];
preg_match('/author="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$author = $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];
$avatar = "";
preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$avatar = $matches[1];
preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$avatar = $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];
$headline = '<div class="shared_header">';
if ($avatar != "")
$headline .= '<img src="'.$avatar.'" height="32" width="32" >';
$headline .= sprintf(t('<span><a href="%s">%s</a> wrote the following <a href="%s">post</a>:</span>'), $profile, $author, $link);
$headline .= "</div>";
$text = "<br />".$headline.'<blockquote class="shared_content">'.trim($match[2])."</blockquote>";
return($text);
}
// BBcode 2 HTML was written by WAY2WEB.net // BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendica - Mike Macgirvin // extended to work with Mistpark/Friendica - Mike Macgirvin
@ -248,6 +300,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = str_replace("<", "&lt;", $Text); $Text = str_replace("<", "&lt;", $Text);
$Text = str_replace(">", "&gt;", $Text); $Text = str_replace(">", "&gt;", $Text);
// remove some newlines before the general conversion
$Text = preg_replace("/\s?\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","[share$1]$2[/share]",$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);
// Convert new line chars to html <br /> tags // Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up // nlbr seems to be hopelessly messed up
@ -271,7 +330,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// Perform URL Search // Perform URL Search
$Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text); $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
if ($tryoembed) if ($tryoembed)
$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text); $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
@ -422,7 +481,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// [img]pathtoimage[/img] // [img]pathtoimage[/img]
$Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text); $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
// Shared content
$Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$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="' . 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); $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

@ -2,6 +2,13 @@
require_once("boot.php"); require_once("boot.php");
function RemoveReply($subject) {
while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:")))
$subject = trim(substr($subject, 4));
return($subject);
}
function onepoll_run(&$argv, &$argc){ function onepoll_run(&$argv, &$argc){
global $a, $db; global $a, $db;
@ -367,10 +374,6 @@ function onepoll_run(&$argv, &$argc){
// $datarray['parent-uri'] = $r[0]['uri']; // $datarray['parent-uri'] = $r[0]['uri'];
} }
if(! x($datarray,'parent-uri'))
$datarray['parent-uri'] = $datarray['uri'];
// Decoding the header // Decoding the header
$subject = imap_mime_header_decode($meta->subject); $subject = imap_mime_header_decode($meta->subject);
$datarray['title'] = ""; $datarray['title'] = "";
@ -385,11 +388,26 @@ function onepoll_run(&$argv, &$argc){
//$datarray['title'] = notags(trim($meta->subject)); //$datarray['title'] = notags(trim($meta->subject));
$datarray['created'] = datetime_convert('UTC','UTC',$meta->date); $datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
// Is it reply? // Is it a reply?
$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
(substr(strtolower($datarray['title']), 0, 3) == "re-") or (substr(strtolower($datarray['title']), 0, 3) == "re-") or
(raw_refs != "")); (raw_refs != ""));
// Remove Reply-signs in the subject
$datarray['title'] = RemoveReply($datarray['title']);
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
if(!x($datarray,'parent-uri') and $reply) {
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE MATCH (`title`) AGAINST ('".'"%s"'."' IN BOOLEAN MODE) ORDER BY `created` DESC LIMIT 1",
besc(protect_sprintf($datarray['title'])));
if(count($r))
$datarray['parent-uri'] = $r[0]['parent-uri'];
}
if(! x($datarray,'parent-uri'))
$datarray['parent-uri'] = $datarray['uri'];
$r = email_get_msg($mbox,$msg_uid, $reply); $r = email_get_msg($mbox,$msg_uid, $reply);
if(! $r) { if(! $r) {
logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']); logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']);

View file

@ -313,6 +313,27 @@
cursor: url('lock.cur'), pointer; cursor: url('lock.cur'), pointer;
} }
.shared_header {
height: 32px;
color: #999;
border-top: 1px solid #D2D2D2;
padding-top: 16px;
margin-top: 16px;
}
.shared_header img {
float: left;
}
.shared_header span {
margin-left: 9px;
}
blockquote.shared_content {
margin-left: 32px;
color: #000;
border: none;
}
#contact-edit-links ul { #contact-edit-links ul {
list-style: none; list-style: none;
@ -793,7 +814,7 @@ aside {
padding: 0px 10px 0px 20px; padding: 0px 10px 0px 20px;
border-right: 1px solid #D2D2D2; border-right: 1px solid #D2D2D2;
background-color: #ECECF2; background-color: #ECECF2;
font-size: 13px; font-size: 14px;
/* background: #F1F1F1; */ /* background: #F1F1F1; */
} }
aside .vcard .fn { aside .vcard .fn {