From 9c0de2862203619ebf52f8046c3ceee6d175ac83 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 17 Dec 2012 03:01:40 +0100 Subject: [PATCH] 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 --- include/bb2diaspora.php | 3 ++ include/bbcode.php | 64 +++++++++++++++++++++++++++++++++++++-- include/onepoll.php | 28 ++++++++++++++--- view/theme/vier/style.css | 23 +++++++++++++- 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 75fe1ef35d..ffe6b3b970 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -155,6 +155,9 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", // "[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 $Text = bbcode($Text, $preserve_nl, false); diff --git a/include/bbcode.php b/include/bbcode.php index d83fe6c12f..b3f6aa826b 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -206,7 +206,59 @@ function bb_replace_images($body, $images) { 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 = '
'; + + if ($avatar != "") + $headline .= ''; + + $headline .= sprintf(t('%s wrote the following post:'), $profile, $author, $link); + + $headline .= "
"; + + $text = "
".$headline.'
'.trim($match[2])."
"; + + return($text); +} // BBcode 2 HTML was written by WAY2WEB.net // extended to work with Mistpark/Friendica - Mike Macgirvin @@ -248,6 +300,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = str_replace("<", "<", $Text); $Text = str_replace(">", ">", $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
tags // nlbr seems to be hopelessly messed up @@ -271,7 +330,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Perform URL Search - $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); if ($tryoembed) $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text); @@ -422,7 +481,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // [img]pathtoimage[/img] $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . t('Image/photo') . '', $Text); - + // Shared content + $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); diff --git a/include/onepoll.php b/include/onepoll.php index a50d234e22..68d7873ecb 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -2,6 +2,13 @@ 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){ global $a, $db; @@ -367,10 +374,6 @@ function onepoll_run(&$argv, &$argc){ // $datarray['parent-uri'] = $r[0]['uri']; } - - if(! x($datarray,'parent-uri')) - $datarray['parent-uri'] = $datarray['uri']; - // Decoding the header $subject = imap_mime_header_decode($meta->subject); $datarray['title'] = ""; @@ -385,11 +388,26 @@ function onepoll_run(&$argv, &$argc){ //$datarray['title'] = notags(trim($meta->subject)); $datarray['created'] = datetime_convert('UTC','UTC',$meta->date); - // Is it reply? + // Is it a reply? $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or (substr(strtolower($datarray['title']), 0, 3) == "re-") or (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); if(! $r) { logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf[0]['user']); diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index f41b70bbbc..6a0cbb2850 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -313,6 +313,27 @@ 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 { list-style: none; @@ -793,7 +814,7 @@ aside { padding: 0px 10px 0px 20px; border-right: 1px solid #D2D2D2; background-color: #ECECF2; - font-size: 13px; + font-size: 14px; /* background: #F1F1F1; */ } aside .vcard .fn {