$message){ if(isset($message['body'])) { if ($message_id) { // we're dealing with a real message, not a fake, so // there a number of shortcuts that can be taken if (isset($message['meta']['htmlpurifier_light'])) { // format hook was called outside of Phorum's normal // functions, do the abridged purification $data[$message_id]['body'] = $purifier->purify($message['body']); continue; } if (!empty($PHORUM['args']['purge'])) { // purge the cache, must be below the following if unset($message['meta']['body_cache']); } if ( isset($message['meta']['body_cache']) && isset($message['meta']['body_cache_serial']) && $message['meta']['body_cache_serial'] == $cache_serial ) { // cached version is present, bail out early $data[$message_id]['body'] = base64_decode($message['meta']['body_cache']); continue; } } // migration might edit this array, that's why it's defined // so early $updated_message = array(); // create the $body variable if ( $message_id && // message must be real to migrate !isset($message['meta']['body_cache_serial']) ) { // perform migration $fake_data = array(); list($signature, $edit_message) = phorum_htmlpurifier_remove_sig_and_editmessage($message); $fake_data[$message_id] = $message; $fake_data = phorum_htmlpurifier_migrate($fake_data); $body = $fake_data[$message_id]['body']; $body = str_replace("", '', $body); $updated_message['body'] = $body; // save it in $body .= $signature . $edit_message; // add it back in } else { // reverse Phorum's pre-processing $body = $message['body']; // order is important $body = str_replace("\n", "\n", $body); $body = str_replace(array('<','>','&'), array('<','>','&'), $body); if (!$message_id && defined('PHORUM_CONTROL_CENTER')) { // we're in control.php, so it was double-escaped $body = str_replace(array('<','>','&', '"'), array('<','>','&','"'), $body); } } $body = $purifier->purify($body); // dynamically update the cache (MUST BE DONE HERE!) // this is inefficient because it's one db call per // cache miss, but once the cache is in place things are // a lot zippier. if ($message_id) { // make sure it's not a fake id $updated_message['meta'] = $message['meta']; $updated_message['meta']['body_cache'] = base64_encode($body); $updated_message['meta']['body_cache_serial'] = $cache_serial; phorum_db_update_message($message_id, $updated_message); } // must not get overloaded until after we cache it, otherwise // we'll inadvertently change the original text $data[$message_id]['body'] = $body; } } return $data; } // ----------------------------------------------------------------------- // This is fragile code, copied from read.php:359. It will break if // that is changed /** * Generates a signature based on a message array */ function phorum_htmlpurifier_generate_sig($row) { $phorum_sig = ''; if(isset($row["user"]["signature"]) && isset($row['meta']['show_signature']) && $row['meta']['show_signature']==1){ $phorum_sig=trim($row["user"]["signature"]); if(!empty($phorum_sig)){ $phorum_sig="\n\n$phorum_sig"; } } return $phorum_sig; } /** * Generates an edit message based on a message array */ function phorum_htmlpurifier_generate_editmessage($row) { $PHORUM = $GLOBALS['PHORUM']; $editmessage = ''; if(isset($row['meta']['edit_count']) && $row['meta']['edit_count'] > 0) { $editmessage = str_replace ("%count%", $row['meta']['edit_count'], $PHORUM["DATA"]["LANG"]["EditedMessage"]); $editmessage = str_replace ("%lastedit%", phorum_date($PHORUM["short_date"],$row['meta']['edit_date']), $editmessage); $editmessage = str_replace ("%lastuser%", $row['meta']['edit_username'], $editmessage); $editmessage="\n\n\n\n$editmessage"; } return $editmessage; } // End fragile code // ----------------------------------------------------------------------- /** * Removes the signature and edit message from a message * @param $row Message passed by reference */ function phorum_htmlpurifier_remove_sig_and_editmessage(&$row) { // attempt to remove the Phorum's pre-processing: // we must not process the signature or editmessage $signature = phorum_htmlpurifier_generate_sig($row); $editmessage = phorum_htmlpurifier_generate_editmessage($row); $row['body'] = strtr($row['body'], array($signature => '', $editmessage => '')); return array($signature, $editmessage); } /** * Indicate that data is fully HTML and not from migration, invalidate * previous caches * @note This function used to generate the actual cache entries, but * since there's data missing that must be deferred to the first read */ function phorum_htmlpurifier_posting($message) { $PHORUM = $GLOBALS["PHORUM"]; unset($message['meta']['body_cache']); // invalidate the cache $message['meta']['body_cache_serial'] = $PHORUM['mod_htmlpurifier']['body_cache_serial']; return $message; } /** * Overload quoting mechanism to prevent default, mail-style quote from happening */ function phorum_htmlpurifier_quote($array) { $PHORUM = $GLOBALS["PHORUM"]; $purifier =& HTMLPurifier::getInstance(); $text = $purifier->purify($array[1]); return "
\n$text\n
"; } /** * Ensure that our format hook is processed last. Also, loads the library. * @credits */ function phorum_htmlpurifier_common() { require_once (dirname(__FILE__).'/htmlpurifier/HTMLPurifier.auto.php'); $config_exists = file_exists(dirname(__FILE__) . '/config.php'); if ($config_exists || !isset($PHORUM['mod_htmlpurifier']['config'])) { $config = HTMLPurifier_Config::createDefault(); include(dirname(__FILE__) . '/config.default.php'); if ($config_exists) { include(dirname(__FILE__) . '/config.php'); } } else { // used cached version that was constructed from web interface $config = HTMLPurifier_Config::create($PHORUM['mod_htmlpurifier']['config']); } HTMLPurifier::getInstance($config); // increment revision.txt if you want to invalidate the cache $GLOBALS['PHORUM']['mod_htmlpurifier']['body_cache_serial'] = $config->getSerial(); // load migration if (file_exists(dirname(__FILE__) . '/migrate.php')) { include(dirname(__FILE__) . '/migrate.php'); } else { echo 'Error: No migration path specified for HTML Purifier, please check modes/htmlpurifier/migrate.bbcode.php for instructions on how to migrate from your previous markup language.'; exit; } // see if our hooks need to be bubbled to the end phorum_htmlpurifier_bubble_hook('format'); } function phorum_htmlpurifier_bubble_hook($hook) { global $PHORUM; $our_idx = null; $last_idx = null; if (!isset($PHORUM['hooks'][$hook]['mods'])) return; foreach ($PHORUM['hooks'][$hook]['mods'] as $idx => $mod) { if ($mod == 'htmlpurifier') $our_idx = $idx; $last_idx = $idx; } list($mod) = array_splice($PHORUM['hooks'][$hook]['mods'], $our_idx, 1); $PHORUM['hooks'][$hook]['mods'][] = $mod; list($func) = array_splice($PHORUM['hooks'][$hook]['funcs'], $our_idx, 1); $PHORUM['hooks'][$hook]['funcs'][] = $func; } /** * Pre-emptively performs purification if it looks like a WYSIWYG editor * is being used */ function phorum_htmlpurifier_before_editor($message) { if (!empty($GLOBALS['PHORUM']['mod_htmlpurifier']['wysiwyg'])) { if (!empty($message['body'])) { $body = $message['body']; // de-entity-ize contents $body = str_replace(array('<','>','&'), array('<','>','&'), $body); $purifier =& HTMLPurifier::getInstance(); $body = $purifier->purify($message['body']); // re-entity-ize contents $body = htmlspecialchars($body, ENT_QUOTES, $GLOBALS['PHORUM']['DATA']['CHARSET']); } } return $message; } function phorum_htmlpurifier_editor_after_subject() { // don't show this message if it's a WYSIWYG editor, since it will // then be handled automatically if (!empty($GLOBALS['PHORUM']['mod_htmlpurifier']['wysiwyg'])) return; ?> HTML input is on. Make sure you escape all HTML and angled-brackets with &lt; and &gt; (you can also use CDATA tags, simply wrap the suspect text with <![CDATA[text]]>. Paragraphs will only be applied to double-spaces; single-spaces will not generate <br> tags.