/** * Converts text / HTML to BBC * * What it does: * - protects certain tags from conversion * - strips original message from the reply if possible * - If the email is html based, this will convert basic html tags to bbc tags * - If the email is plain text it will convert it to html based on markdown text * conventions and then that will be converted to bbc. * * @uses Html2BBC.class.php for the html to bbc conversion * @uses markdown.php for text to html conversions * @package Maillist * @param string $text * @param boolean $html */ function pbe_email_to_bbc($text, $html) { // Define some things that need to be converted/modified, outside normal html or markup $tags = array('~\\*\\*(.*)\\*\\*~isUe' => '\'**\'.ltrim(\'$1\').\'**\'', '~<\\*>~i' => '<*>', '~-{20,}~' => '<hr>', '~#([0-9a-fA-F]{4,6}\\b)~' => '#$1'); // We are starting with HTML, our goal is to convert the best parts of it to BBC, if ($html) { // Convert the email-HTML to BBC $text = preg_replace(array_keys($tags), array_values($tags), $text); require_once SUBSDIR . '/Html2BBC.class.php'; $bbc_converter = new Html_2_BBC($text); $text = $bbc_converter->get_bbc(); // Run our parsers, as defined in the ACP, to remove the original "replied to" message // before we do any more work. $text_save = $text; $result = pbe_parse_email_message($text); // If we have no message left after running the parser, then they may have replied // below and/or inside the original message. People like this should not be allowed // to use the net, or be forced to read their own messed up emails if (empty($result) || trim(strip_tags(pbe_filter_email_message($text))) === '') { $text = $text_save; } } else { // Run the parser to try and remove common mail clients "reply to" stuff $text_save = $text; $result = pbe_parse_email_message($text); // Bottom feeder? If we have no message they could have replied below the original message if (empty($result) || trim(strip_tags(pbe_filter_email_message($text))) === '') { $text = $text_save; } // Set a gmail flag for special quote processing since its quotes are strange $gmail = (bool) preg_match('~<div class="gmail_quote">~i', $text); // Attempt to fix textual ('>') quotes so we also fix wrapping issues first! $text = pbe_fix_email_quotes($text, $html && !$gmail); // Convert this (markup) text to html $text = preg_replace(array_keys($tags), array_values($tags), $text); require_once EXTDIR . '/markdown/markdown.php'; $text = Markdown($text); // Convert any resulting HTML created by markup style text in the email to BBC require_once SUBSDIR . '/Html2BBC.class.php'; $bbc_converter = new Html_2_BBC($text, false); $text = $bbc_converter->get_bbc(); } // Some tags often end up as just empty tags - remove those. $emptytags = array('~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~(\\n){3,}~si' => "\n\n"); $text = preg_replace(array_keys($emptytags), array_values($emptytags), $text); return $text; }
/** * Converts text / HTML to BBC * * What it does: * - protects certain tags from conversion * - strips original message from the reply if possible * - If the email is html based, this will convert basic html tags to bbc tags * - If the email is plain text it will convert it to html based on markdown text * conventions and then that will be converted to bbc. * * @uses Html2BBC.class.php for the html to bbc conversion * @uses markdown.php for text to html conversions * @package Maillist * @param string $text * @param boolean $html */ function pbe_email_to_bbc($text, $html) { // Define some things that need to be converted/modified, outside normal html or markup $tags = array('~\\*\\*\\s?(.*?)\\*\\*~is' => '**$1**', '~<\\*>~i' => '<*>', '~-{20,}~' => '<hr>', '~#([0-9a-fA-F]{4,6}\\b)~' => '#$1'); // We are starting with HTML, our goal is to convert the best parts of it to BBC, if ($html) { // upfront pre-process $tags, mostly for the email template strings $text = preg_replace(array_keys($tags), array_values($tags), $text); // Run the parsers on the html $text = pbe_run_parsers($text); // Convert the email-HTML to BBC require_once SUBSDIR . '/Html2BBC.class.php'; $bbc_converter = new Html_2_BBC($text); $bbc_converter->skip_tags(array('font', 'span')); $bbc_converter->skip_styles(array('font-family', 'font-size', 'color')); $text = $bbc_converter->get_bbc(); } else { // Run the parser to try and remove common mail clients "reply to" stuff $text = pbe_run_parsers($text); // Set a gmail flag for special quote processing since its quotes are strange $gmail = (bool) preg_match('~<div class="gmail_quote">~i', $text); // Attempt to fix textual ('>') quotes so we also fix wrapping issues first! $text = pbe_fix_email_quotes($text, $html && !$gmail); $text = str_replace(array('[quote]', '[/quote]'), array('>blockquote>', '>/blockquote>'), $text); // Convert this (markup) text to html $text = preg_replace(array_keys($tags), array_values($tags), $text); require_once EXTDIR . '/markdown/markdown.php'; $text = Markdown($text); $text = str_replace(array('>blockquote>', '>/blockquote>'), array('<blockquote>', '</blockquote>'), $text); // Convert any resulting HTML created by markup style text in the email to BBC require_once SUBSDIR . '/Html2BBC.class.php'; $bbc_converter = new Html_2_BBC($text, false); $text = $bbc_converter->get_bbc(); } // Some tags often end up as just empty tags - remove those. $emptytags = array('~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~\\[[bisu]\\]\\s*\\[/[bisu]\\]~' => '', '~(\\n){3,}~si' => "\n\n"); $text = preg_replace(array_keys($emptytags), array_values($emptytags), $text); return $text; }