From 8a1f175df022e2fc2c2162aa314ea34454482d48 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 17 Mar 2012 11:07:49 +0100 Subject: [PATCH 1/6] New bbcode element: "spoiler". Mail: Top post quotes are now embraced in "spoiler" elements --- include/bbcode.php | 10 ++++++++++ include/email.php | 4 ++-- include/msgclean.php | 2 +- include/poller.php | 7 ++++++- include/quoteconvert.php | 2 +- include/text.php | 19 +++++++++++++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) 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 = '
$1
'; + + // 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 = '
$1
'; + // 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 .= '
' . t('Filed under:') . ' ' . $x . '
'; } + // Look for spoiler + $spoilersearch = '
'; + + // Remove line breaks before the spoiler + while ((strpos($s, "\n".$spoilersearch) !== false)) + $s = str_replace("\n".$spoilersearch, $spoilersearch, $s); + while ((strpos($s, "
".$spoilersearch) !== false)) + $s = str_replace("
".$spoilersearch, $spoilersearch, $s); + + while ((strpos($s, $spoilersearch) !== false)) { + + $pos = strpos($s, $spoilersearch); + $rnd = random_string(8); + $spoilerreplace = ''.sprintf(t('Click to open/close')).''. + '