mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-03 05:11:52 +00:00
Tidy up Phorum extension. Add svn:ignore, add img to the default list of allowed tags (for smileys), improve naming convention, move loading code out of main namespace, and add reset. Probably the last thing to do before this is feature complete is to have a WYSIWYG flag that turns on escaping for edit posts.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1270 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
2e7e411491
commit
148681d1b0
@ -9,7 +9,7 @@ $config->set('HTML', 'Allowed',
|
||||
// common semantic markup
|
||||
'del,ins,strong,em,'.
|
||||
// commmon presentational markup
|
||||
's,strike,sub,sup,u,br,tt,div[class],'. // div because bbcode [quote] uses it
|
||||
's,strike,sub,sup,u,br,tt,div[class],img[src|alt|title|class],'. // div because bbcode [quote] uses it, img for smileys
|
||||
// uncommon semantic markup
|
||||
'abbr[title],acronym[title],caption,code,dfn,cite,kbd,var,'.
|
||||
// lists
|
||||
|
@ -18,39 +18,10 @@
|
||||
|
||||
if(!defined('PHORUM')) exit;
|
||||
|
||||
// load library
|
||||
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 '<strong>Error:</strong> No migration path specified for HTML Purifier, please check
|
||||
<tt>modes/htmlpurifier/migrate.bbcode.php</tt> for instructions on
|
||||
how to migrate from your previous markup language.';
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purifies a data array
|
||||
*/
|
||||
function phorum_htmlpurifier($data)
|
||||
function phorum_htmlpurifier_format($data)
|
||||
{
|
||||
$PHORUM = $GLOBALS["PHORUM"];
|
||||
|
||||
@ -58,7 +29,13 @@ function phorum_htmlpurifier($data)
|
||||
$cache_serial = $PHORUM['mod_htmlpurifier']['body_cache_serial'];
|
||||
|
||||
foreach($data as $message_id => $message){
|
||||
if(isset($message['body'])){
|
||||
if(isset($message['body'])) {
|
||||
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 (
|
||||
isset($message['meta']['body_cache']) &&
|
||||
@ -120,8 +97,11 @@ function phorum_htmlpurifier($data)
|
||||
*/
|
||||
function phorum_htmlpurifier_posting($message) {
|
||||
$PHORUM = $GLOBALS["PHORUM"];
|
||||
$purifier =& HTMLPurifier::getInstance();
|
||||
$message['meta']['body_cache'] = $purifier->purify($message['body']);
|
||||
$fake_data = array($message);
|
||||
// this is a temporary attribute
|
||||
$fake_data[0]['meta']['htmlpurifier_light'] = true; // only purify, please
|
||||
list($changed_message) = phorum_hook('format', $fake_data);
|
||||
$message['meta']['body_cache'] = $changed_message['body'];
|
||||
$message['meta']['body_cache_serial'] = $PHORUM['mod_htmlpurifier']['body_cache_serial'];
|
||||
return $message;
|
||||
}
|
||||
@ -137,29 +117,56 @@ function phorum_htmlpurifier_quote($array) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that our format hook is processed last
|
||||
* Ensure that our format hook is processed last. Also, loads the library.
|
||||
* @credits <http://secretsauce.phorum.org/snippets/make_bbcode_last_formatter.php.txt>
|
||||
*/
|
||||
function phorum_htmlpurifier_common() {
|
||||
global $PHORUM;
|
||||
|
||||
if (! isset($PHORUM['hooks']['format']['mods'])) return;
|
||||
require_once (dirname(__FILE__).'/htmlpurifier/HTMLPurifier.auto.php');
|
||||
|
||||
$hp_idx = null;
|
||||
$last_idx = null;
|
||||
foreach ($PHORUM['hooks']['format']['mods'] as $idx => $mod) {
|
||||
if ($mod == 'htmlpurifier') $hp_idx = $idx;
|
||||
$last_idx = $idx;
|
||||
$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 '<strong>Error:</strong> No migration path specified for HTML Purifier, please check
|
||||
<tt>modes/htmlpurifier/migrate.bbcode.php</tt> for instructions on
|
||||
how to migrate from your previous markup language.';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($hp_idx !== null && $hp_idx != $last_idx) {
|
||||
// see if our hooks need to be bubbled to the end
|
||||
phorum_htmlpurifier_bubble_hook('format');
|
||||
|
||||
$hp_mod = array_splice($PHORUM['hooks']['format']['mods'], $hp_idx, 1);
|
||||
$PHORUM['hooks']['format']['mods'][] = $hp_mod;
|
||||
|
||||
$hp_func = array_splice($PHORUM['hooks']['format']['funcs'], $hp_idx, 1);
|
||||
$PHORUM['hooks']['format']['funcs'][] = $hp_func;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
hook: format|phorum_htmlpurifier
|
||||
hook: format|phorum_htmlpurifier_format
|
||||
hook: quote|phorum_htmlpurifier_quote
|
||||
hook: posting_custom_action|phorum_htmlpurifier_posting
|
||||
hook: common|phorum_htmlpurifier_common
|
||||
|
@ -32,6 +32,10 @@ $directives = array(
|
||||
'Output.TidyFormat',
|
||||
);
|
||||
|
||||
if (isset($_POST['reset'])) {
|
||||
unset($PHORUM['mod_htmlpurifier']['config']);
|
||||
}
|
||||
|
||||
// instantiate $config object
|
||||
$config_exists = file_exists(dirname(__FILE__) . '/config.php');
|
||||
if ($config_exists || !isset($PHORUM['mod_htmlpurifier']['config'])) {
|
||||
@ -51,7 +55,7 @@ if(!empty($_POST)){
|
||||
echo "Cannot update settings, <code>mods/htmlpurifier/config.php</code> already exists. To change
|
||||
settings, edit that file. To use the web form, delete that file.<br />";
|
||||
} else {
|
||||
$config->mergeArrayFromForm($_POST, 'config', $directives);
|
||||
if (!isset($_POST['reset'])) $config->mergeArrayFromForm($_POST, 'config', $directives);
|
||||
$PHORUM['mod_htmlpurifier']['config'] = $config->getAll();
|
||||
if(!phorum_db_update_settings(array("mod_htmlpurifier"=>$PHORUM["mod_htmlpurifier"]))){
|
||||
$error="Database error while updating settings.";
|
||||
@ -115,6 +119,8 @@ if ($config_exists) {
|
||||
|
||||
$frm->addMessage($warning);
|
||||
|
||||
$frm->addrow('Reset to defaults:', $frm->checkbox("reset", "1", "", false));
|
||||
|
||||
// hack to include extra styling
|
||||
echo '<style type="text/css">' . $htmlpurifier_form->getCSS() . '
|
||||
.hp-config {margin-left:auto;margin-right:auto;}
|
||||
|
Loading…
Reference in New Issue
Block a user