Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/vendor/ezyang/htmlpurifier/extras
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ezyang/htmlpurifier/extras')
-rw-r--r--vendor/ezyang/htmlpurifier/extras/ConfigDoc/HTMLXSLTProcessor.php91
-rw-r--r--vendor/ezyang/htmlpurifier/extras/FSTools.php164
-rw-r--r--vendor/ezyang/htmlpurifier/extras/FSTools/File.php141
-rw-r--r--vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.auto.php11
-rw-r--r--vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload-legacy.php15
-rw-r--r--vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload.php23
-rw-r--r--vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.php31
-rw-r--r--vendor/ezyang/htmlpurifier/extras/README32
8 files changed, 508 insertions, 0 deletions
diff --git a/vendor/ezyang/htmlpurifier/extras/ConfigDoc/HTMLXSLTProcessor.php b/vendor/ezyang/htmlpurifier/extras/ConfigDoc/HTMLXSLTProcessor.php
new file mode 100644
index 0000000..1cfec5d
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/ConfigDoc/HTMLXSLTProcessor.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * Decorator/extender XSLT processor specifically for HTML documents.
+ */
+class ConfigDoc_HTMLXSLTProcessor
+{
+
+ /**
+ * Instance of XSLTProcessor
+ */
+ protected $xsltProcessor;
+
+ public function __construct($proc = false)
+ {
+ if ($proc === false) $proc = new XSLTProcessor();
+ $this->xsltProcessor = $proc;
+ }
+
+ /**
+ * @note Allows a string $xsl filename to be passed
+ */
+ public function importStylesheet($xsl)
+ {
+ if (is_string($xsl)) {
+ $xsl_file = $xsl;
+ $xsl = new DOMDocument();
+ $xsl->load($xsl_file);
+ }
+ return $this->xsltProcessor->importStylesheet($xsl);
+ }
+
+ /**
+ * Transforms an XML file into compatible XHTML based on the stylesheet
+ * @param $xml XML DOM tree, or string filename
+ * @return string HTML output
+ * @todo Rename to transformToXHTML, as transformToHTML is misleading
+ */
+ public function transformToHTML($xml)
+ {
+ if (is_string($xml)) {
+ $dom = new DOMDocument();
+ $dom->load($xml);
+ } else {
+ $dom = $xml;
+ }
+ $out = $this->xsltProcessor->transformToXML($dom);
+
+ // fudges for HTML backwards compatibility
+ // assumes that document is XHTML
+ $out = str_replace('/>', ' />', $out); // <br /> not <br/>
+ $out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns
+
+ if (class_exists('Tidy')) {
+ // cleanup output
+ $config = array(
+ 'indent' => true,
+ 'output-xhtml' => true,
+ 'wrap' => 80
+ );
+ $tidy = new Tidy;
+ $tidy->parseString($out, $config, 'utf8');
+ $tidy->cleanRepair();
+ $out = (string) $tidy;
+ }
+
+ return $out;
+ }
+
+ /**
+ * Bulk sets parameters for the XSL stylesheet
+ * @param array $options Associative array of options to set
+ */
+ public function setParameters($options)
+ {
+ foreach ($options as $name => $value) {
+ $this->xsltProcessor->setParameter('', $name, $value);
+ }
+ }
+
+ /**
+ * Forward any other calls to the XSLT processor
+ */
+ public function __call($name, $arguments)
+ {
+ call_user_func_array(array($this->xsltProcessor, $name), $arguments);
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/FSTools.php b/vendor/ezyang/htmlpurifier/extras/FSTools.php
new file mode 100644
index 0000000..ce00763
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/FSTools.php
@@ -0,0 +1,164 @@
+<?php
+
+/**
+ * Filesystem tools not provided by default; can recursively create, copy
+ * and delete folders. Some template methods are provided for extensibility.
+ *
+ * @note This class must be instantiated to be used, although it does
+ * not maintain state.
+ */
+class FSTools
+{
+
+ private static $singleton;
+
+ /**
+ * Returns a global instance of FSTools
+ */
+ public static function singleton()
+ {
+ if (empty(FSTools::$singleton)) FSTools::$singleton = new FSTools();
+ return FSTools::$singleton;
+ }
+
+ /**
+ * Sets our global singleton to something else; useful for overloading
+ * functions.
+ */
+ public static function setSingleton($singleton)
+ {
+ FSTools::$singleton = $singleton;
+ }
+
+ /**
+ * Recursively creates a directory
+ * @param string $folder Name of folder to create
+ * @note Adapted from the PHP manual comment 76612
+ */
+ public function mkdirr($folder)
+ {
+ $folders = preg_split("#[\\\\/]#", $folder);
+ $base = '';
+ for($i = 0, $c = count($folders); $i < $c; $i++) {
+ if(empty($folders[$i])) {
+ if (!$i) {
+ // special case for root level
+ $base .= DIRECTORY_SEPARATOR;
+ }
+ continue;
+ }
+ $base .= $folders[$i];
+ if(!is_dir($base)){
+ $this->mkdir($base);
+ }
+ $base .= DIRECTORY_SEPARATOR;
+ }
+ }
+
+ /**
+ * Copy a file, or recursively copy a folder and its contents; modified
+ * so that copied files, if PHP, have includes removed
+ * @note Adapted from http://aidanlister.com/repos/v/function.copyr.php
+ */
+ public function copyr($source, $dest)
+ {
+ // Simple copy for a file
+ if (is_file($source)) {
+ return $this->copy($source, $dest);
+ }
+ // Make destination directory
+ if (!is_dir($dest)) {
+ $this->mkdir($dest);
+ }
+ // Loop through the folder
+ $dir = $this->dir($source);
+ while ( false !== ($entry = $dir->read()) ) {
+ // Skip pointers
+ if ($entry == '.' || $entry == '..') {
+ continue;
+ }
+ if (!$this->copyable($entry)) {
+ continue;
+ }
+ // Deep copy directories
+ if ($dest !== "$source/$entry") {
+ $this->copyr("$source/$entry", "$dest/$entry");
+ }
+ }
+ // Clean up
+ $dir->close();
+ return true;
+ }
+
+ /**
+ * Overloadable function that tests a filename for copyability. By
+ * default, everything should be copied; you can restrict things to
+ * ignore hidden files, unreadable files, etc. This function
+ * applies to copyr().
+ */
+ public function copyable($file)
+ {
+ return true;
+ }
+
+ /**
+ * Delete a file, or a folder and its contents
+ * @note Adapted from http://aidanlister.com/repos/v/function.rmdirr.php
+ */
+ public function rmdirr($dirname)
+ {
+ // Sanity check
+ if (!$this->file_exists($dirname)) {
+ return false;
+ }
+
+ // Simple delete for a file
+ if ($this->is_file($dirname) || $this->is_link($dirname)) {
+ return $this->unlink($dirname);
+ }
+
+ // Loop through the folder
+ $dir = $this->dir($dirname);
+ while (false !== $entry = $dir->read()) {
+ // Skip pointers
+ if ($entry == '.' || $entry == '..') {
+ continue;
+ }
+ // Recurse
+ $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
+ }
+
+ // Clean up
+ $dir->close();
+ return $this->rmdir($dirname);
+ }
+
+ /**
+ * Recursively globs a directory.
+ */
+ public function globr($dir, $pattern, $flags = NULL)
+ {
+ $files = $this->glob("$dir/$pattern", $flags);
+ if ($files === false) $files = array();
+ $sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR);
+ if ($sub_dirs === false) $sub_dirs = array();
+ foreach ($sub_dirs as $sub_dir) {
+ $sub_files = $this->globr($sub_dir, $pattern, $flags);
+ $files = array_merge($files, $sub_files);
+ }
+ return $files;
+ }
+
+ /**
+ * Allows for PHP functions to be called and be stubbed.
+ * @warning This function will not work for functions that need
+ * to pass references; manually define a stub function for those.
+ */
+ public function __call($name, $args)
+ {
+ return call_user_func_array($name, $args);
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/FSTools/File.php b/vendor/ezyang/htmlpurifier/extras/FSTools/File.php
new file mode 100644
index 0000000..6453a7a
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/FSTools/File.php
@@ -0,0 +1,141 @@
+<?php
+
+/**
+ * Represents a file in the filesystem
+ *
+ * @warning Be sure to distinguish between get() and write() versus
+ * read() and put(), the former operates on the entire file, while
+ * the latter operates on a handle.
+ */
+class FSTools_File
+{
+
+ /** Filename of file this object represents */
+ protected $name;
+
+ /** Handle for the file */
+ protected $handle = false;
+
+ /** Instance of FSTools for interfacing with filesystem */
+ protected $fs;
+
+ /**
+ * Filename of file you wish to instantiate.
+ * @note This file need not exist
+ */
+ public function __construct($name, $fs = false)
+ {
+ $this->name = $name;
+ $this->fs = $fs ? $fs : FSTools::singleton();
+ }
+
+ /** Returns the filename of the file. */
+ public function getName() {return $this->name;}
+
+ /** Returns directory of the file without trailing slash */
+ public function getDirectory() {return $this->fs->dirname($this->name);}
+
+ /**
+ * Retrieves the contents of a file
+ * @todo Throw an exception if file doesn't exist
+ */
+ public function get()
+ {
+ return $this->fs->file_get_contents($this->name);
+ }
+
+ /** Writes contents to a file, creates new file if necessary */
+ public function write($contents)
+ {
+ return $this->fs->file_put_contents($this->name, $contents);
+ }
+
+ /** Deletes the file */
+ public function delete()
+ {
+ return $this->fs->unlink($this->name);
+ }
+
+ /** Returns true if file exists and is a file. */
+ public function exists()
+ {
+ return $this->fs->is_file($this->name);
+ }
+
+ /** Returns last file modification time */
+ public function getMTime()
+ {
+ return $this->fs->filemtime($this->name);
+ }
+
+ /**
+ * Chmod a file
+ * @note We ignore errors because of some weird owner trickery due
+ * to SVN duality
+ */
+ public function chmod($octal_code)
+ {
+ return @$this->fs->chmod($this->name, $octal_code);
+ }
+
+ /** Opens file's handle */
+ public function open($mode)
+ {
+ if ($this->handle) $this->close();
+ $this->handle = $this->fs->fopen($this->name, $mode);
+ return true;
+ }
+
+ /** Closes file's handle */
+ public function close()
+ {
+ if (!$this->handle) return false;
+ $status = $this->fs->fclose($this->handle);
+ $this->handle = false;
+ return $status;
+ }
+
+ /** Retrieves a line from an open file, with optional max length $length */
+ public function getLine($length = null)
+ {
+ if (!$this->handle) $this->open('r');
+ if ($length === null) return $this->fs->fgets($this->handle);
+ else return $this->fs->fgets($this->handle, $length);
+ }
+
+ /** Retrieves a character from an open file */
+ public function getChar()
+ {
+ if (!$this->handle) $this->open('r');
+ return $this->fs->fgetc($this->handle);
+ }
+
+ /** Retrieves an $length bytes of data from an open data */
+ public function read($length)
+ {
+ if (!$this->handle) $this->open('r');
+ return $this->fs->fread($this->handle, $length);
+ }
+
+ /** Writes to an open file */
+ public function put($string)
+ {
+ if (!$this->handle) $this->open('a');
+ return $this->fs->fwrite($this->handle, $string);
+ }
+
+ /** Returns TRUE if the end of the file has been reached */
+ public function eof()
+ {
+ if (!$this->handle) return true;
+ return $this->fs->feof($this->handle);
+ }
+
+ public function __destruct()
+ {
+ if ($this->handle) $this->close();
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.auto.php b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.auto.php
new file mode 100644
index 0000000..4016d8a
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.auto.php
@@ -0,0 +1,11 @@
+<?php
+
+/**
+ * This is a stub include that automatically configures the include path.
+ */
+
+set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() );
+require_once 'HTMLPurifierExtras.php';
+require_once 'HTMLPurifierExtras.autoload.php';
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload-legacy.php b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload-legacy.php
new file mode 100644
index 0000000..d1485bf
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload-legacy.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @file
+ * Legacy autoloader for systems lacking spl_autoload_register
+ *
+ * Must be separate to prevent deprecation warning on PHP 7.2
+ */
+
+function __autoload($class)
+{
+ return HTMLPurifierExtras::autoload($class);
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload.php b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload.php
new file mode 100644
index 0000000..69c9095
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.autoload.php
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * @file
+ * Convenience file that registers autoload handler for HTML Purifier.
+ *
+ * @warning
+ * This autoloader does not contain the compatibility code seen in
+ * HTMLPurifier_Bootstrap; the user is expected to make any necessary
+ * changes to use this library.
+ */
+
+if (function_exists('spl_autoload_register')) {
+ spl_autoload_register(array('HTMLPurifierExtras', 'autoload'));
+ if (function_exists('__autoload')) {
+ // Be polite and ensure that userland autoload gets retained
+ spl_autoload_register('__autoload');
+ }
+} elseif (!function_exists('__autoload')) {
+ require dirname(__FILE__) . '/HTMLPurifierExtras.autoload-legacy.php';
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.php b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.php
new file mode 100644
index 0000000..35c2ca7
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/HTMLPurifierExtras.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * Meta-class for HTML Purifier's extra class hierarchies, similar to
+ * HTMLPurifier_Bootstrap.
+ */
+class HTMLPurifierExtras
+{
+
+ public static function autoload($class)
+ {
+ $path = HTMLPurifierExtras::getPath($class);
+ if (!$path) return false;
+ require $path;
+ return true;
+ }
+
+ public static function getPath($class)
+ {
+ if (
+ strncmp('FSTools', $class, 7) !== 0 &&
+ strncmp('ConfigDoc', $class, 9) !== 0
+ ) return false;
+ // Custom implementations can go here
+ // Standard implementation:
+ return str_replace('_', '/', $class) . '.php';
+ }
+
+}
+
+// vim: et sw=4 sts=4
diff --git a/vendor/ezyang/htmlpurifier/extras/README b/vendor/ezyang/htmlpurifier/extras/README
new file mode 100644
index 0000000..4bfece7
--- /dev/null
+++ b/vendor/ezyang/htmlpurifier/extras/README
@@ -0,0 +1,32 @@
+
+HTML Purifier Extras
+ The Method Behind The Madness!
+
+The extras/ folder in HTML Purifier contains--you guessed it--extra things
+for HTML Purifier. Specifically, these are two extra libraries called
+FSTools and ConfigSchema. They're extra for a reason: you don't need them
+if you're using HTML Purifier for normal usage: filtering HTML. However,
+if you're a developer, and would like to test HTML Purifier, or need to
+use one of HTML Purifier's maintenance scripts, chances are they'll need
+these libraries. Who knows: maybe you'll find them useful too!
+
+Here are the libraries:
+
+
+FSTools
+-------
+
+Short for File System Tools, this is a poor-man's object-oriented wrapper for
+the filesystem. It currently consists of two classes:
+
+- FSTools: This is a singleton that contains a manner of useful functions
+ such as recursive glob, directory removal, etc, as well as the ability
+ to call arbitrary native PHP functions through it like $FS->fopen(...).
+ This makes it a lot simpler to mock these filesystem calls for unit testing.
+
+- FSTools_File: This object represents a single file, and has almost any
+ method imaginable one would need.
+
+Check the files themselves for more information.
+
+ vim: et sw=4 sts=4