aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ezyang/htmlpurifier/extras/FSTools/File.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/extras/FSTools/File.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/extras/FSTools/File.php')
-rw-r--r--vendor/ezyang/htmlpurifier/extras/FSTools/File.php141
1 files changed, 141 insertions, 0 deletions
diff --git a/vendor/ezyang/htmlpurifier/extras/FSTools/File.php b/vendor/ezyang/htmlpurifier/extras/FSTools/File.php
new file mode 100644
index 000000000..6453a7a45
--- /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