aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ezyang/htmlpurifier/maintenance/rename-config.php
diff options
context:
space:
mode:
authorKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2017-03-18 17:50:05 +0100
committerKlaus Weidenbach <Klaus.Weidenbach@gmx.net>2017-03-26 00:41:27 +0100
commitf718e2b0db0fe3477212a8dd6c3ec067f4432862 (patch)
tree8dfbd3b3d4bdcd967b50f1ee4655440bcdef5bb8 /vendor/ezyang/htmlpurifier/maintenance/rename-config.php
parent2115eb26a7fd2ca937286bd4e98ab74c7d6e9525 (diff)
downloadvolse-hubzilla-f718e2b0db0fe3477212a8dd6c3ec067f4432862.tar.gz
volse-hubzilla-f718e2b0db0fe3477212a8dd6c3ec067f4432862.tar.bz2
volse-hubzilla-f718e2b0db0fe3477212a8dd6c3ec067f4432862.zip
:arrow_up: Update HTML Purifier library.
Updated HTML Purifier from 4.6.0 to 4.9.2 with better PHP7 compatibility. Used composer to manage this library.
Diffstat (limited to 'vendor/ezyang/htmlpurifier/maintenance/rename-config.php')
-rw-r--r--vendor/ezyang/htmlpurifier/maintenance/rename-config.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/ezyang/htmlpurifier/maintenance/rename-config.php b/vendor/ezyang/htmlpurifier/maintenance/rename-config.php
new file mode 100644
index 000000000..6e59e2a79
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/maintenance/rename-config.php
@@ -0,0 +1,84 @@
+#!/usr/bin/php
+<?php
+
+chdir(dirname(__FILE__));
+require_once 'common.php';
+require_once '../library/HTMLPurifier.auto.php';
+assertCli();
+
+/**
+ * @file
+ * Renames a configuration directive. This involves renaming the file,
+ * adding an alias, and then regenerating the cache. You still have to
+ * manually go through and fix any calls to the directive.
+ * @warning This script doesn't handle multi-stringhash files.
+ */
+
+$argv = $_SERVER['argv'];
+if (count($argv) < 3) {
+ echo "Usage: {$argv[0]} OldName NewName\n";
+ exit(1);
+}
+
+chdir('../library/HTMLPurifier/ConfigSchema/schema');
+
+$old = $argv[1];
+$new = $argv[2];
+
+if (!file_exists("$old.txt")) {
+ echo "Cannot move undefined configuration directive $old\n";
+ exit(1);
+}
+
+if ($old === $new) {
+ echo "Attempting to move to self, aborting\n";
+ exit(1);
+}
+
+if (file_exists("$new.txt")) {
+ echo "Cannot move to already defined directive $new\n";
+ exit(1);
+}
+
+$file = "$old.txt";
+$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
+$interchange = new HTMLPurifier_ConfigSchema_Interchange();
+$builder->buildFile($interchange, $file);
+$contents = file_get_contents($file);
+
+if (strpos($contents, "\r\n") !== false) {
+ $nl = "\r\n";
+} elseif (strpos($contents, "\r") !== false) {
+ $nl = "\r";
+} else {
+ $nl = "\n";
+}
+
+// replace name with new name
+$contents = str_replace($old, $new, $contents);
+
+if ($interchange->directives[$old]->aliases) {
+ $pos_alias = strpos($contents, 'ALIASES:');
+ $pos_ins = strpos($contents, $nl, $pos_alias);
+ if ($pos_ins === false) $pos_ins = strlen($contents);
+ $contents =
+ substr($contents, 0, $pos_ins) . ", $old" . substr($contents, $pos_ins);
+ file_put_contents($file, $contents);
+} else {
+ $lines = explode($nl, $contents);
+ $insert = false;
+ foreach ($lines as $n => $line) {
+ if (strncmp($line, '--', 2) === 0) {
+ $insert = $n;
+ break;
+ }
+ }
+ if (!$insert) {
+ $lines[] = "ALIASES: $old";
+ } else {
+ array_splice($lines, $insert, 0, "ALIASES: $old");
+ }
+ file_put_contents($file, implode($nl, $lines));
+}
+
+rename("$old.txt", "$new.txt") || exit(1);