diff --git a/plugins/phorum/htmlpurifier.php b/plugins/phorum/htmlpurifier.php
index af6ff532..4654c65d 100644
--- a/plugins/phorum/htmlpurifier.php
+++ b/plugins/phorum/htmlpurifier.php
@@ -26,8 +26,6 @@
// all, which ain't happening. It's slower, it takes up more space, but
// at least it won't get mutilated
-if(!defined('PHORUM')) exit;
-
/**
* Purifies a data array
*/
@@ -201,19 +199,10 @@ function phorum_htmlpurifier_quote($array) {
*/
function phorum_htmlpurifier_common() {
- require_once (dirname(__FILE__).'/htmlpurifier/HTMLPurifier.auto.php');
+ require_once(dirname(__FILE__).'/htmlpurifier/HTMLPurifier.auto.php');
+ require(dirname(__FILE__).'/init-config.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']);
- }
+ $config = phorum_htmlpurifier_get_config();
HTMLPurifier::getInstance($config);
// increment revision.txt if you want to invalidate the cache
diff --git a/plugins/phorum/init-config.php b/plugins/phorum/init-config.php
new file mode 100644
index 00000000..c279f67d
--- /dev/null
+++ b/plugins/phorum/init-config.php
@@ -0,0 +1,27 @@
+$PHORUM["mod_htmlpurifier"]));
- $offset = 1;
-} elseif (!empty($_GET['migrate-sigs']) && $PHORUM['mod_htmlpurifier']['migrate-sigs']) {
- $offset = (int) $_GET['migrate-sigs'];
-}
-
-// lower this setting if you're getting time outs/out of memory
-$increment = 100;
-
-if ($offset) do {
- require_once 'migrate.php';
+if ($offset = phorum_htmlpurifier_migrate_sigs_check()) {
// migrate signatures
- // do this in batches so we don't run out of time/space
- $end = $offset + $increment;
- $user_ids = array();
- for ($i = $offset; $i < $end; $i++) {
- $user_ids[] = $i;
- }
- $userinfos = phorum_db_user_get_fields($user_ids, 'signature');
- foreach ($userinfos as $i => $user) {
- if (empty($user['signature'])) continue;
- $sig = $user['signature'];
- // perform standard Phorum processing on the sig
- $sig = str_replace(array("&","<",">"), array("&","<",">"), $sig);
- $sig = preg_replace("/<((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%]+?)>/i", "$1", $sig);
- // prepare fake data to pass to migration function
- $fake_data = array(array("author"=>"", "email"=>"", "subject"=>"", 'body' => $sig));
- list($fake_message) = phorum_htmlpurifier_migrate($fake_data);
- $user['signature'] = $fake_message['body'];
- if (!phorum_user_save($user)) {
- exit('Error while saving user data');
- }
- }
- unset($userinfos); // free up memory
-
- // query for highest ID in database
- $type = $PHORUM['DBCONFIG']['type'];
- if ($type == 'mysql') {
- $conn = phorum_db_mysql_connect();
- $sql = "select MAX(user_id) from {$PHORUM['user_table']}";
- $res = mysql_query($sql, $conn);
- $row = mysql_fetch_row($res);
- $top_id = (int) $row[0];
- } elseif ($type == 'mysqli') {
- $conn = phorum_db_mysqli_connect();
- $sql = "select MAX(user_id) from {$PHORUM['user_table']}";
- $res = mysqli_query($conn, $sql);
- $row = mysqli_fetch_row($res);
- $top_id = (int) $row[0];
- } else {
- exit('Unrecognized database!');
- }
-
- $offset += $increment;
- if ($offset > $top_id) { // test for end condition
- echo 'Migration finished';
- $PHORUM['mod_htmlpurifier']['migrate-sigs'] = false;
- phorum_db_update_settings(array("mod_htmlpurifier"=>$PHORUM["mod_htmlpurifier"]));
- continue;
- }
- $host = $_SERVER['HTTP_HOST'];
- $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
- $extra = 'admin.php?module=modsettings&mod=htmlpurifier&migrate-sigs=' . $offset;
- // relies on output buffering to work
- header("Location: http://$host$uri/$extra");
- exit;
-} while (0);
-
-if(!empty($_POST) && !$offset){
+ phorum_htmlpurifier_migrate_sigs($offset);
+} elseif(!empty($_POST)){
// save settings
- if ($config_exists) {
- echo "Cannot update settings, mods/htmlpurifier/config.php
already exists. To change
- settings, edit that file. To use the web form, delete that file.
";
- } else {
- 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.";
- } else {
- echo "Settings Updated
";
- }
- }
+ phorum_htmlpurifier_save_settings();
}
-// warning that's used by both messages
-$warning = "
- Warning: Changing HTML Purifier's configuration will invalidate
- the cache. Expect to see a flurry of database activity after you change
- any of these settings.
-";
+phorum_htmlpurifier_show_migrate_sigs_form();
+echo '
';
+phorum_htmlpurifier_show_form();
-if ($config_exists) {
- // clear out mod_htmlpurifier for housekeeping
- phorum_db_update_settings(array("mod_htmlpurifier"=>$PHORUM["mod_htmlpurifier"]));
-
- // politely tell user how to edit settings manually
-?>
-
- A config.php file exists in your mods/htmlpurifier/ - directory. This file contains your custom configuration: in order to - change it, please navigate to that file and edit it accordingly. -
-- To use the web interface, delete config.php (or rename it to - config.php.bak). -
-- -
-hidden("module", "modsettings"); - $frm_migrate->hidden("mod", "htmlpurifier"); - $frm_migrate->hidden("migrate-sigs", "1"); - $frm_migrate->addbreak("Migrate user signatures to HTML"); - $frm_migrate->addMessage('This operation will migrate your users signatures - to HTML. This process is irreversible and must only be performed once. - Type in yes in the confirmation field to migrate.'); - if (!file_exists(dirname(__FILE__) . '/migrate.php')) { - $frm_migrate->addMessage('Migration file does not exist, cannot migrate signatures. - Please check migrate.bbcode.php on how to create an appropriate file.'); - } else { - $frm_migrate->addrow('Confirm:', $frm_migrate->text_box("confirmation", "")); - } - $frm_migrate->show(); - - echo 'Click on directive links to read what each option does - (links do not open in new windows).
-For more flexibility (for instance, you want to edit the full - range of configuration directives), you can create a config.php - file in your mods/htmlpurifier/ directory. Doing so will, - however, make the web configuration interface unavailable.
'); - - require_once 'HTMLPurifier/Printer/ConfigForm.php'; - $htmlpurifier_form = new HTMLPurifier_Printer_ConfigForm('config', 'http://htmlpurifier.org/live/configdoc/plain.html#%s'); - $htmlpurifier_form->setTextareaDimensions(23, 7); // widen a little, since we have space - - $frm->addMessage($htmlpurifier_form->render($config, $directives, false)); - - $frm->addMessage($warning); - - $frm->addrow('Reset to defaults:', $frm->checkbox("reset", "1", "", false)); - - // hack to include extra styling - echo ''; - $js = $htmlpurifier_form->getJavaScript(); - echo ''; - - $frm->show(); - -} diff --git a/plugins/phorum/settings/form.php b/plugins/phorum/settings/form.php new file mode 100644 index 00000000..b957b8d2 --- /dev/null +++ b/plugins/phorum/settings/form.php @@ -0,0 +1,79 @@ +hidden("module", "modsettings"); + $frm->hidden("mod", "htmlpurifier"); // this is the directory name that the Settings file lives in + + if (!empty($error)){ + echo "$errorClick on directive links to read what each option does + (links do not open in new windows).
+For more flexibility (for instance, you want to edit the full + range of configuration directives), you can create a config.php + file in your mods/htmlpurifier/ directory. Doing so will, + however, make the web configuration interface unavailable.
'); + + require_once 'HTMLPurifier/Printer/ConfigForm.php'; + $htmlpurifier_form = new HTMLPurifier_Printer_ConfigForm('config', 'http://htmlpurifier.org/live/configdoc/plain.html#%s'); + $htmlpurifier_form->setTextareaDimensions(23, 7); // widen a little, since we have space + + $frm->addMessage($htmlpurifier_form->render( + $config, $PHORUM['mod_htmlpurifier']['directives'], false)); + + $frm->addMessage("Warning: Changing HTML Purifier's configuration will invalidate + the cache. Expect to see a flurry of database activity after you change + any of these settings."); + + $frm->addrow('Reset to defaults:', $frm->checkbox("reset", "1", "", false)); + + // hack to include extra styling + echo ''; + $js = $htmlpurifier_form->getJavaScript(); + echo ''; + + $frm->show(); +} + +function phorum_htmlpurifier_show_config_info() { + global $PHORUM; + + // update mod_htmlpurifier for housekeeping + phorum_htmlpurifier_commit_settings(); + + // politely tell user how to edit settings manually +?> ++ A config.php file exists in your mods/htmlpurifier/ + directory. This file contains your custom configuration: in order to + change it, please navigate to that file and edit it accordingly. +
++ To use the web interface, delete config.php (or rename it to + config.php.bak). +
++ Warning: Changing HTML Purifier's configuration will invalidate + the cache. Expect to see a flurry of database activity after you change + any of these settings. +
+hidden("module", "modsettings"); + $frm->hidden("mod", "htmlpurifier"); + $frm->hidden("migrate-sigs", "1"); + $frm->addbreak("Migrate user signatures to HTML"); + $frm->addMessage('This operation will migrate your users signatures + to HTML. This process is irreversible and must only be performed once. + Type in yes in the confirmation field to migrate.'); + if (!file_exists(dirname(__FILE__) . '/../migrate.php')) { + $frm->addMessage('Migration file does not exist, cannot migrate signatures. + Please check migrate.bbcode.php on how to create an appropriate file.'); + } else { + $frm->addrow('Confirm:', $frm->text_box("confirmation", "")); + } + $frm->show(); +} + diff --git a/plugins/phorum/settings/migrate-sigs.php b/plugins/phorum/settings/migrate-sigs.php new file mode 100644 index 00000000..7896be36 --- /dev/null +++ b/plugins/phorum/settings/migrate-sigs.php @@ -0,0 +1,85 @@ +$PHORUM["mod_htmlpurifier"])); + $offset = 1; + } elseif (!empty($_GET['migrate-sigs']) && $PHORUM['mod_htmlpurifier']['migrate-sigs']) { + $offset = (int) $_GET['migrate-sigs']; + } + return $offset; +} + +function phorum_htmlpurifier_migrate_sigs($offset) { + global $PHORUM; + + if(!$offset) return; // bail out quick of $offset == 0 + + @set_time_limit(0); // attempt to let this run + $increment = $PHORUM['mod_htmlpurifier']['migrate-sigs-increment']; + + require_once(dirname(__FILE__) . '/../migrate.php'); + // migrate signatures + // do this in batches so we don't run out of time/space + $end = $offset + $increment; + $user_ids = array(); + for ($i = $offset; $i < $end; $i++) { + $user_ids[] = $i; + } + $userinfos = phorum_db_user_get_fields($user_ids, 'signature'); + foreach ($userinfos as $i => $user) { + if (empty($user['signature'])) continue; + $sig = $user['signature']; + // perform standard Phorum processing on the sig + $sig = str_replace(array("&","<",">"), array("&","<",">"), $sig); + $sig = preg_replace("/<((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%]+?)>/i", "$1", $sig); + // prepare fake data to pass to migration function + $fake_data = array(array("author"=>"", "email"=>"", "subject"=>"", 'body' => $sig)); + list($fake_message) = phorum_htmlpurifier_migrate($fake_data); + $user['signature'] = $fake_message['body']; + if (!phorum_user_save($user)) { + exit('Error while saving user data'); + } + } + unset($userinfos); // free up memory + + // query for highest ID in database + $type = $PHORUM['DBCONFIG']['type']; + if ($type == 'mysql') { + $conn = phorum_db_mysql_connect(); + $sql = "select MAX(user_id) from {$PHORUM['user_table']}"; + $res = mysql_query($sql, $conn); + $row = mysql_fetch_row($res); + $top_id = (int) $row[0]; + } elseif ($type == 'mysqli') { + $conn = phorum_db_mysqli_connect(); + $sql = "select MAX(user_id) from {$PHORUM['user_table']}"; + $res = mysqli_query($conn, $sql); + $row = mysqli_fetch_row($res); + $top_id = (int) $row[0]; + } else { + exit('Unrecognized database!'); + } + + $offset += $increment; + if ($offset > $top_id) { // test for end condition + echo 'Migration finished'; + $PHORUM['mod_htmlpurifier']['migrate-sigs'] = false; + phorum_htmlpurifier_commit_settings(); + return true; + } + $host = $_SERVER['HTTP_HOST']; + $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); + $extra = 'admin.php?module=modsettings&mod=htmlpurifier&migrate-sigs=' . $offset; + // relies on output buffering to work + header("Location: http://$host$uri/$extra"); + exit; + +} diff --git a/plugins/phorum/settings/save.php b/plugins/phorum/settings/save.php new file mode 100644 index 00000000..a08b8314 --- /dev/null +++ b/plugins/phorum/settings/save.php @@ -0,0 +1,23 @@ +mods/htmlpurifier/config.php already exists. To change + settings, edit that file. To use the web form, delete that file.