From: Michael Vogel <icarus@dabo.de>
Date: Sat, 17 Mar 2012 10:07:49 +0000 (+0100)
Subject: New bbcode element: "spoiler". Mail: Top post quotes are now embraced in "spoiler... 
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8a1f175df022e2fc2c2162aa314ea34454482d48;p=friendica.git

New bbcode element: "spoiler". Mail: Top post quotes are now embraced in "spoiler" elements
---

diff --git a/include/bbcode.php b/include/bbcode.php
index d69cb263f8..9fce895b8d 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -189,8 +189,18 @@ function bbcode($Text,$preserve_nl = false) {
 	// Check for [code] text
 	$Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text);
 
+	// Declare the format for [spoiler] layout
+	$SpoilerLayout = '<blockquote class="spoiler">$1</blockquote>';
+
+	// Check for [spoiler] text
+	// handle nested quotes
+	$endlessloop = 0;
+	while ((strpos($Text, "[/spoiler]") !== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20))
+		$Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism","$SpoilerLayout", $Text);
+
 	// Declare the format for [quote] layout
 	$QuoteLayout = '<blockquote>$1</blockquote>';
+
 	// Check for [quote] text
 	// handle nested quotes
 	$endlessloop = 0;
diff --git a/include/email.php b/include/email.php
index a3449a4249..43f04d7c20 100755
--- a/include/email.php
+++ b/include/email.php
@@ -74,7 +74,7 @@ function email_msg_headers($mbox,$uid) {
 }
 
 
-function email_get_msg($mbox,$uid) {
+function email_get_msg($mbox,$uid, $reply) {
 	$ret = array();
 
 	$struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null);
@@ -114,7 +114,7 @@ function email_get_msg($mbox,$uid) {
 	$ret['body'] = removegpg($ret['body']);
 	$msg = removesig($ret['body']);
 	$ret['body'] = $msg['body'];
-	$ret['body'] = convertquote($ret['body'], false);
+	$ret['body'] = convertquote($ret['body'], $reply);
 
 	if (trim($html) != '')
 		$ret['body'] = removelinebreak($ret['body']);
diff --git a/include/msgclean.php b/include/msgclean.php
index 284ad1ce4b..eabb47788a 100644
--- a/include/msgclean.php
+++ b/include/msgclean.php
@@ -13,7 +13,7 @@ function savereplace($pattern, $replace, $text)
 
 function unifyattributionline($message)
 {
-	$quotestr = array('quote', 'collapsed');
+	$quotestr = array('quote', 'spoiler');
 	foreach ($quotestr as $quote) {
 
 		$message = savereplace('/----- Original Message -----\s.*?From: "([^<"].*?)" <(.*?)>\s.*?To: (.*?)\s*?Cc: (.*?)\s*?Sent: (.*?)\s.*?Subject: ([^\n].*)\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
diff --git a/include/poller.php b/include/poller.php
index 3bc98e36ff..085e95a6ae 100755
--- a/include/poller.php
+++ b/include/poller.php
@@ -504,7 +504,12 @@ function poller_run($argv, $argc){
 							//$datarray['title'] = notags(trim($meta->subject));
 							$datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
 
-							$r = email_get_msg($mbox,$msg_uid);
+							// Is it  reply?
+							$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
+								(substr(strtolower($datarray['title']), 0, 3) == "re-") or
+								(raw_refs != ""));
+
+							$r = email_get_msg($mbox,$msg_uid, $reply);
 							if(! $r) {
 								logger("Mail: can't fetch msg ".$msg_uid);
 								continue;
diff --git a/include/quoteconvert.php b/include/quoteconvert.php
index 3aee93234f..2a6d28370a 100644
--- a/include/quoteconvert.php
+++ b/include/quoteconvert.php
@@ -124,7 +124,7 @@ function removetofu($message)
 	}
 
 	if ($quotestart != 0) {
-		$message = trim(substr($message, 0, $quotestart))."\n[collapsed]\n".substr($message, $quotestart+7, -8).'[/collapsed]';
+		$message = trim(substr($message, 0, $quotestart))."\n[spoiler]".substr($message, $quotestart+7, -8).'[/spoiler]';
 	}
 
 	return($message);
diff --git a/include/text.php b/include/text.php
index d34fd7fbee..bcd567a154 100644
--- a/include/text.php
+++ b/include/text.php
@@ -955,6 +955,25 @@ function prepare_body($item,$attach = false) {
 			$s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>'; 
 	}
 
+	// Look for spoiler
+	$spoilersearch = '<blockquote class="spoiler">';
+
+	// Remove line breaks before the spoiler
+	while ((strpos($s, "\n".$spoilersearch) !== false))
+		$s = str_replace("\n".$spoilersearch, $spoilersearch, $s);
+	while ((strpos($s, "<br />".$spoilersearch) !== false))
+		$s = str_replace("<br />".$spoilersearch, $spoilersearch, $s);
+
+	while ((strpos($s, $spoilersearch) !== false)) {
+
+		$pos = strpos($s, $spoilersearch);
+		$rnd = random_string(8);
+		$spoilerreplace = '<span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
+	                                '<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
+		//$s = str_replace($spoilersearch, $spoilerreplace, $s);
+		$s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
+	}
+
 	$prep_arr = array('item' => $item, 'html' => $s);
 	call_hooks('prepare_body_final', $prep_arr);