From a1a6b6a06087834fd7f23f924f1ce119f601624d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 27 Apr 2009 17:39:59 -0400 Subject: [PATCH] Remove trailing whitespace. Signed-off-by: Edward Z. Yang --- XHTMLCompiler.php | 30 +++++++------- XHTMLCompiler/DOMFilter.php | 22 +++++------ XHTMLCompiler/Directory.php | 34 ++++++++-------- XHTMLCompiler/Exception.php | 8 ++-- XHTMLCompiler/File.php | 24 ++++++------ XHTMLCompiler/FilterManager.php | 72 +++++++++++++++++----------------- XHTMLCompiler/PHP.php | 22 +++++------ XHTMLCompiler/Page.php | 74 +++++++++++++++++------------------ XHTMLCompiler/RSSFeed.php | 24 ++++++------ XHTMLCompiler/TextFilter.php | 4 +- XHTMLCompiler/TextFilter/Fragment.php | 6 +-- functions.php | 16 ++++---- htaccess.php | 20 +++++----- 13 files changed, 178 insertions(+), 178 deletions(-) diff --git a/XHTMLCompiler.php b/XHTMLCompiler.php index 8717ee9..ec13215 100644 --- a/XHTMLCompiler.php +++ b/XHTMLCompiler.php @@ -5,17 +5,17 @@ */ class XHTMLCompiler { - + // SINGLETON FUNCTIONALITY - + /** Private instance of singleton */ private static $_instance; - + /** Private constructor, prevents other people from making it */ private function __construct() { $this->loadConf(); } - + /** Retrieves the single instance of the object */ static public function getInstance() { if(is_null(self::$_instance)) { @@ -23,7 +23,7 @@ class XHTMLCompiler } return self::$_instance; } - + /** * Overloads the instance with another one, usually a mock object * @param Object substitute for XHTMLCompiler @@ -31,12 +31,12 @@ class XHTMLCompiler static public function setInstance($stub) { self::$_instance = $stub; } - + // REGISTRY FUNCTIONALITY - + /** Private instance of PHP wrapper */ private static $_PHPWrapperInstance; - + /** Retrieves the single instance of the PHP wrapper */ static public function getPHPWrapper() { if(is_null(self::$_PHPWrapperInstance)) { @@ -44,7 +44,7 @@ class XHTMLCompiler } return self::$_PHPWrapperInstance; } - + /** * Overloads the instance with another one, usually a mock object * @param Object substitute for XHTMLCompiler @@ -52,24 +52,24 @@ class XHTMLCompiler static public function setPHPWrapper($stub) { self::$_PHPWrapperInstance = $stub; } - + // PLUGIN/CONFIGURATION FUNCTIONALITY - + protected $configKeys = array('allowed_dirs', 'directory_index', 'indexed_dirs', 'web_path', 'web_domain', 'viewvc_url', 'svn_headurl_munge', 'debug', 'error_xsl', 'admin_email', 'from_email', 'error_log', 'error_mute', 'configdoc', 'smtp_transport', 'dsn'); protected $config = array(); protected $filterManager; - + public function loadConf() { $filters = new XHTMLCompiler_FilterManager(); require 'config.default.php'; // defaults - + // user configuration if (file_exists($f = dirname(__FILE__) . '/conf/config.php')) require $f; if (file_exists($f = dirname(__FILE__) . '/config.php')) require $f; - + $this->config = compact($this->configKeys); $this->filterManager = $filters; } @@ -78,5 +78,5 @@ class XHTMLCompiler return $this->config[$key]; } public function getFilterManager() {return $this->filterManager;} - + } diff --git a/XHTMLCompiler/DOMFilter.php b/XHTMLCompiler/DOMFilter.php index a4a5140..8621004 100644 --- a/XHTMLCompiler/DOMFilter.php +++ b/XHTMLCompiler/DOMFilter.php @@ -5,7 +5,7 @@ */ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter { - + /** * If set, DOMFilter will allocate a namespace for the filter * and assign it to this prefix. @@ -13,17 +13,17 @@ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter * allocated for the core namespaces. */ protected $prefix; - + /** * Allocated namespace for the filter, or default 'xc' one. */ protected $ns; - + /** * Lookup of namespace shortcuts to full namespace names. */ protected $nsLookup; - + /** * List of attributes the extension adds to the generic xc namespace, * helps prevent naming conflicts. @@ -32,8 +32,8 @@ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter public function getXCAttributesDefined() { return $this->xcAttr; } - - + + /** * Defines a filter that processes a DOMDocument. * @note Return is not used as objects are passed "by reference", and @@ -43,7 +43,7 @@ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter * @param $manager Currently running XHTMLCompiler_FilterManager */ abstract public function process(DOMDocument $dom, $page, $manager); - + /** * Performs common initialization of DOM and XPath * @note This must be called before you can use any of the convenience @@ -68,18 +68,18 @@ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter } $this->nsLookup = $ns; } - + /** * XPath object for the current DOM (private: use query() to use it) * @todo Implement all member functions for this */ private $xpath; - + /** * Current DOMDocument (private: use the instance passed to you via parameter) */ private $dom; - + /** * Querys a DOM with an XPath expression * @param $expr XPath expression to evaluate @@ -90,7 +90,7 @@ abstract class XHTMLCompiler_DOMFilter extends XHTMLCompiler_Filter if (!$context) return $this->xpath->query($expr); return $this->xpath->query($expr, $context); } - + /** * Retrieves a namespaced attribute from an element, and then deletes it. * @note This is best for proprietary attributes that, once you grab diff --git a/XHTMLCompiler/Directory.php b/XHTMLCompiler/Directory.php index af668b3..61f0963 100644 --- a/XHTMLCompiler/Directory.php +++ b/XHTMLCompiler/Directory.php @@ -5,20 +5,20 @@ */ class XHTMLCompiler_Directory { - + /** Location of directory this object represents, w/o trailing slash */ protected $name; - + /** Non-blank location of directory, safe for directory handling functions */ protected $safeName; - + /** * Path to directory you wish to instantiate. */ public function __construct($name) { $xc = XHTMLCompiler::getInstance(); $php = XHTMLCompiler::getPHPWrapper(); - + $name = str_replace('\\', '/', $name); // normalize \ to / $l = strlen($name) - 1; // index of last character if ($l >= 0 && $name[$l] == '/') $name = substr($name, 0, $l); // truncate trailing slash @@ -30,7 +30,7 @@ class XHTMLCompiler_Directory $this->name = $name; $this->safeName = $safe_name; } - + /** * Returns name of directory without trailing slash * @note This function works in all cases, but can be slightly @@ -38,7 +38,7 @@ class XHTMLCompiler_Directory * a filename (compare index.html versus ./index.html) */ public function getName() {return $this->safeName;} - + /** * Returns name of directory with trailing slash, prepared for * a filename to be appended (s = slash, it is NOT safe) @@ -51,7 +51,7 @@ class XHTMLCompiler_Directory public function getSName() { return ($this->name === '') ? '' : $this->name . '/'; } - + /** * Recursively scans directory for files * @return Tree of files in the directory, file => size @@ -60,7 +60,7 @@ class XHTMLCompiler_Directory $dir = new RecursiveDirectoryIterator($this->safeName); $tree = array(); $dirs = array(array($dir, &$tree)); - + for($i = 0; $i < count($dirs); ++$i) { $d =& $dirs[$i][0]; // current directory iterator $tier =& $dirs[$i][1]; // current directory tree to write to @@ -76,13 +76,13 @@ class XHTMLCompiler_Directory } } } - - return $tree; + + return $tree; } - + /** * Scans directory recursively for files with a certain file extension - * @param $ext_match Extension with period to look for, cannot have + * @param $ext_match Extension with period to look for, cannot have * more than one period within it * @return List of matching files, with fully qualified relative * paths (not tree format) @@ -108,10 +108,10 @@ class XHTMLCompiler_Directory } return $ret; } - + /** * Scans just the current directory for files matching extension - * @param $ext_match Extension with period to look for, cannot have + * @param $ext_match Extension with period to look for, cannot have * more than one period within it * @return List of matching files */ @@ -126,7 +126,7 @@ class XHTMLCompiler_Directory } return $ret; } - + /** * Scans directory for files with matching extension * @param $ext_match File extension to match @@ -154,7 +154,7 @@ class XHTMLCompiler_Directory $dir = realpath($this->safeName); if ($dir[strlen($dir)-1] == '/') $dir = substr($dir, 0, -1); $ok = false; - + foreach ($allowed_dirs as $allowed_dir => $recursive) { $allowed_dir = $php->realpath($allowed_dir); // factor out! if (!is_string($allowed_dir)) continue; @@ -170,5 +170,5 @@ class XHTMLCompiler_Directory } return $ok; } - + } diff --git a/XHTMLCompiler/Exception.php b/XHTMLCompiler/Exception.php index 469f8ba..2fdbb96 100644 --- a/XHTMLCompiler/Exception.php +++ b/XHTMLCompiler/Exception.php @@ -10,7 +10,7 @@ class XHTMLCompiler_Exception extends Exception * In-depth HTML message on the nature of the error. */ protected $details; - + /** * @param $code HTTP status code you wish to return * @param $message Brief title of the error @@ -20,9 +20,9 @@ class XHTMLCompiler_Exception extends Exception parent::__construct($message, $code); $this->details = $details; } - + /** Returns details of exception */ public function getDetails() {return $this->details;} - - + + } diff --git a/XHTMLCompiler/File.php b/XHTMLCompiler/File.php index 13e6348..011fbeb 100644 --- a/XHTMLCompiler/File.php +++ b/XHTMLCompiler/File.php @@ -5,10 +5,10 @@ */ class XHTMLCompiler_File { - + /** Filename of file this object represents */ protected $name; - + /** * Filename of file you wish to instantiate. * @note This file need not exist @@ -16,17 +16,17 @@ class XHTMLCompiler_File public function __construct($name) { $this->name = $name; } - + /** * Returns the filename of the file. */ public function getName() {return $this->name;} - + /** * Returns directory of the file without trailing slash */ public function getDirectory() {return dirname($this->name);} - + /** * Retrieves the contents of a file * @todo Throw an exception if file doesn't exist @@ -34,7 +34,7 @@ class XHTMLCompiler_File public function get() { return file_get_contents($this->name); } - + /** * Writes contents to a file, creates new file if necessary * @param $contents String contents to write to file @@ -42,14 +42,14 @@ class XHTMLCompiler_File public function write($contents) { file_put_contents($this->name, $contents); } - + /** * Deletes the file */ public function delete() { unlink($this->name); } - + /** * Returns true if file exists and is a file. */ @@ -57,19 +57,19 @@ class XHTMLCompiler_File $php = XHTMLCompiler::getPHPWrapper(); return $php->isFile($this->name); } - + /** * Returns last file modification time */ public function getMTime() { return filemtime($this->name); } - + /** Returns the last inode modifiation time */ public function getCTime() { return filectime($this->name); } - + /** * Chmod a file * @note We ignore errors because of some weird owner trickery due @@ -78,7 +78,7 @@ class XHTMLCompiler_File public function chmod($octal_code) { @chmod($this->name, $octal_code); } - + /** * Touches a file. */ diff --git a/XHTMLCompiler/FilterManager.php b/XHTMLCompiler/FilterManager.php index a7c75fd..4aad0e2 100644 --- a/XHTMLCompiler/FilterManager.php +++ b/XHTMLCompiler/FilterManager.php @@ -5,16 +5,16 @@ */ class XHTMLCompiler_FilterManager { - + protected $preTextFilters = array(); protected $postTextFilters = array(); protected $DOMFilters = array(); protected $Markup = array('xhtml' => true); protected $xcAttr = array(); - + protected $errors = array(); protected $deps = array(); - + /** * Adds a pre-processing text filter to the queue. * @note Filters added here are run before the document is @@ -31,7 +31,7 @@ class XHTMLCompiler_FilterManager } return $this->preTextFilters[$n] = $filter; } - + /** * Adds a post-processing text filter to the queue. * @note Filters added here are run after the document has been @@ -50,7 +50,7 @@ class XHTMLCompiler_FilterManager } return $this->postTextFilters[$n] = $filter; } - + /** * Adds a DOM-processing filter to the queue * @param $filter XHTMLCompiler_DOMFilter @@ -84,7 +84,7 @@ class XHTMLCompiler_FilterManager public function getMarkup() { return $this->Markup; } - + /** * If filter is string, load the filter based on a few guesses * @param $filter String or object filter @@ -103,21 +103,21 @@ class XHTMLCompiler_FilterManager } return $filter; } - + /** Returns the dependency array accumulated from the filter run */ public function getDeps() {return $this->deps;} - + /** Adds a file to the dependency list */ public function addDependency($filename) { $this->deps[$filename] = filemtime($filename); } - + /** - * Accepts a page's text and turns it into its DOM representation. + * Accepts a page's text and turns it into its DOM representation. * Text, initial validation and XIncludes will be processed before * returning. DOM filters will *not* be processed. * @param $text String text to be processed - * @param + * @param */ public function parse($text, $page) { $markup = $this->Markup[$page->getSourceExt()]; @@ -133,43 +133,43 @@ class XHTMLCompiler_FilterManager foreach ($this->preTextFilters as $filter) { $text = $filter->process($text, $page, $this); } - + // generate the DOM $this->setupXMLCatalog(); $dom = $this->createDOM($text); - + $this->analyzeInternalSubset($dom); - + // validate the document to force the entities to be resolved, // we don't actually care about the errors set_error_handler(array($this, 'muteErrorHandler')); $dom->validate(); restore_error_handler(); - + $this->analyzeXIncludes($dom); $dom->xinclude(); - + return $dom; } - + /** * Accepts a page's text (usually XHTML) and processes it. * @param $text String text to be processed * @param $page XHTMLCompiler_Page representing currently processed page */ public function process($text, $page) { - + $dom = $this->parse($text, $page); - + // run DOM filters foreach ($this->DOMFilters as $filter) { $filter->setup($dom); $filter->process($dom, $page, $this); } - + // translate back to text $text = $dom->saveXML(); - + // remove all non-default namespace declarations, may change, // but for now embedded XML namespaces are not cross-browser friendly $text = preg_replace('/ xmlns:.+?=".+?"/', '', $text); @@ -184,7 +184,7 @@ class XHTMLCompiler_FilterManager array('XHTMLCompiler_FilterManager', 'cdataCallback'), $text ); - + // replace any redundant xmlns sections, although they are // valid they interfere with DTD validation $text = preg_replace( @@ -192,7 +192,7 @@ class XHTMLCompiler_FilterManager '$1', $text ); - + // okay, now finally do validation, and let the errors get // spit out if there are some collect parse errors set_error_handler(array($this, 'validationErrorHandler')); @@ -203,26 +203,26 @@ class XHTMLCompiler_FilterManager $this->buildErrors($dom); $text = $dom->saveXML(); } - + return $text; } - + public static function cdataCallback($matches) { return htmlspecialchars($matches[1], ENT_NOQUOTES, 'UTF-8'); } - + /** * Temporary error handler to use when validating a document */ public function validationErrorHandler($n, $text) { $this->errors[] = $text; } - + /** * Handler that mutes all errors */ public function muteErrorHandler($n, $t) {} - + /** * Sets up an XML catalog to speed up entity resolution */ @@ -232,7 +232,7 @@ class XHTMLCompiler_FilterManager if ($catalog[1] == ':') $catalog = substr($catalog, 2); // remove drive putenv('XML_CATALOG_FILES=' . $catalog); } - + /** * Creates a reasonable well default configured DOM * @param string $xml XML to load DOM with @@ -242,16 +242,16 @@ class XHTMLCompiler_FilterManager $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->resolveExternals = true; - + // todo: somehow, collect information on which entity files // are being added to the document, and add to xc-deps. $dom->substituteEntities = true; // allows for custom entities too! - + if ($text !== false) $dom->loadXML($text); - + return $dom; } - + /** * Analyzes the internal subset of a DOM, registering any file * entity definitions as dependencies @@ -275,7 +275,7 @@ class XHTMLCompiler_FilterManager } } } - + /** * Analyzes a documents XIncludes and registers necessary dependencies. * Make sure you call this before calling $dom->xinclude @@ -296,7 +296,7 @@ class XHTMLCompiler_FilterManager $this->analyzeInternalSubset($sub_dom); } } - + /** * Adds validation errors to the output document as a message */ @@ -320,5 +320,5 @@ class XHTMLCompiler_FilterManager $warning->appendChild($list); $body->insertBefore($warning, $body->childNodes->item(0)); } - + } diff --git a/XHTMLCompiler/PHP.php b/XHTMLCompiler/PHP.php index 3c88166..4095d9c 100644 --- a/XHTMLCompiler/PHP.php +++ b/XHTMLCompiler/PHP.php @@ -10,27 +10,27 @@ */ class XHTMLCompiler_PHP { - + /** Sends an HTTP header, equivalent to header() */ public function header() { $args = func_get_args(); call_user_func_array('header', $args); } - + /** Sends HTTP headers to indicate output is XML **/ public function headerXML() { $this->header('Content-type: application/xml'); } - + /** Outputs text, equivalent to echo */ public function paint($text) { echo $text; } - + /** Retrieves the relative URI with which the page was requested. */ public function getRequestURI() {return $_SERVER['REQUEST_URI'];} - + /** Retrieves the relative URI which denotes the frontend PHP file */ public function getPHPSelf() {return $_SERVER['PHP_SELF'];} - + /** Retrieves a parameter from GET superglobal, does magic quote cleaning */ public function getGVal($key) { if (!isset($_GET[$key])) return false; @@ -40,13 +40,13 @@ class XHTMLCompiler_PHP if (is_string($val) && get_magic_quotes_gpc()) $val = stripslashes($val); return $val; } - + /** Returns true if passed filename is directory */ public function isDir($dir) {return is_dir($dir);} - + /** Returns true if passed filename is file */ public function isFile($file) {return is_file($file);} - + /** * Resolves a relative path into an absolute one * @note This also normalizes Windows backslashes into forward slashes @@ -56,8 +56,8 @@ class XHTMLCompiler_PHP if ($path === false) return false; return str_replace('\\', '/', $path); } - + /** Returns HTTP status code server was originally going to send */ public function getRedirectStatus() {return (int) getenv("REDIRECT_STATUS");} - + } diff --git a/XHTMLCompiler/Page.php b/XHTMLCompiler/Page.php index 4f0ce0f..1132df9 100644 --- a/XHTMLCompiler/Page.php +++ b/XHTMLCompiler/Page.php @@ -7,12 +7,12 @@ */ class XHTMLCompiler_Page { - + /** * Filename identifier of this page without extension */ protected $pathStem; - + /** * File extension of the source file * @note Previously, this parameter could only be xhtml, but since we've @@ -25,20 +25,20 @@ class XHTMLCompiler_Page protected $cacheExt = 'html'; /** File extension of dependency files */ protected $depsExt = 'xc-deps'; - + /** Instance of XHTMLCompiler_File for source file */ protected $source; /** Instance of XHTMLCompiler_File for cache file */ protected $cache; /** Instance of XHTMLCompiler_File for dependency file */ protected $deps; - + /** Instance of XHTMLCompiler_Directory for all of the above files*/ protected $dir; - + /** Array of attributes about this file. Currently used by News/NewsLinker */ public $attr = array(); - + /** * Constructs a page object, validates filename for correctness * @param $path String path filename, can be from untrusted source @@ -49,11 +49,11 @@ class XHTMLCompiler_Page * @todo Factor out allowed_directories realpath'ing to config class */ public function __construct($path, $mute = false) { - + $xc = XHTMLCompiler::getInstance(); $php = XHTMLCompiler::getPHPWrapper(); $markup = $xc->getFilterManager()->getMarkup(); - + // test file extension $info = pathinfo($path); if ( @@ -66,7 +66,7 @@ class XHTMLCompiler_Page 'File extension cannot be processed by XHTML Compiler, check for faulty .htaccess rules.'); } - + // test for directory's existence and resolve to real path $dir = $info['dirname']; if ($dir == '.') $dir .= '/'; @@ -77,17 +77,17 @@ class XHTMLCompiler_Page path and try again.' ); } if ($dir[strlen($dir)-1] == '/') $dir = substr($dir, 0, -1); - + $dirObj = new XHTMLCompiler_Directory($dir); $ok = $dirObj->isAllowed(); if (!$ok) throw new XHTMLCompiler_Exception(403, 'Forbidden directory', 'Requested directory is forbidden to XHTML Compiler; try accessing it directly or check for faulty .htaccess rules.'); - + // cannot use pathinfo, since PATHINFO_FILENAME is PHP 5.2.0 $this->pathStem = substr($path, 0, strrpos($path, '.')); - + // setup the files foreach ($markup as $ext => $impl) { $this->source = new XHTMLCompiler_File($this->pathStem . '.' . $ext); @@ -96,9 +96,9 @@ class XHTMLCompiler_Page } $this->cache = new XHTMLCompiler_File($this->pathStem . '.' . $this->cacheExt); $this->deps = new XHTMLCompiler_File($this->pathStem . '.' . $this->depsExt); - + $this->dir = new XHTMLCompiler_Directory(dirname($this->pathStem)); - + if (!$mute && !$this->source->exists()) { // Apache may have redirected to an ErrorDocument which got directed // via mod_rewrite to us, in that case, output the corresponding @@ -108,9 +108,9 @@ class XHTMLCompiler_Page throw new XHTMLCompiler_Exception($code, 'Page not found', 'Requested page not found; check the URL in your address bar.'); } } - + // Note: Do not use this functions internally inside the class - + /** Returns path stem, full filename without file extension */ public function getPathStem() { return $this->pathStem; } /** Returns relative path to cache */ @@ -127,12 +127,12 @@ class XHTMLCompiler_Page public function getDirSName() { return $this->dir->getSName(); } /** Returns how deep from the root the file is */ public function getDepth() { return substr_count($this->getSourcePath(), '/'); } - + /** Normalizes a relative path as if it were from this page's directory */ public function normalizePath($path) { return $this->getDirName() . '/' . $path; } - + /** * Returns a fully formed web path with web domain to the file. This path * is valid anywhere on the web. @@ -145,7 +145,7 @@ class XHTMLCompiler_Page } return 'http://' . $domain . $this->getAbsolutePath(); } - + /** * Returns a fully formed absolute web path valid anywhere on the * current domain to the cached file. @@ -158,21 +158,21 @@ class XHTMLCompiler_Page if (strncmp($name, './', 2) === 0) $name = substr($name, 1); return $xc->getConf('web_path') . $name; } - + /** Returns contents of the cache/served file */ public function getCache() { return $this->cache->get(); } /** Returns contents of the source file */ public function getSource() { return $this->source->get(); } - + /** Reports whether or not cache file exists and is a file */ public function isCacheExistent() { return $this->cache->exists(); } /** Reports whether or not source file exists and is a file */ public function isSourceExistent() { return $this->source->exists(); } - + /** Removes the cache file, forcing this page to be re-updated as if it were newly added.*/ public function purge() { return $this->cache->delete(); } - + /** * Reports whether or not the cache is stale by comparing the file * modification times between the source file and the cache file. @@ -194,14 +194,14 @@ class XHTMLCompiler_Page } return false; } - + /** * Writes text to the cache file, overwriting any previous contents * and creating the cache file if it doesn't exist. * @param $contents String contents to write to cache */ public function writeCache($contents) {$this->cache->write($contents);} - + /** * Attempts to display contents from the cache, otherwise returns false * @return True if successful, false if not. @@ -220,7 +220,7 @@ class XHTMLCompiler_Page } return false; } - + /** * Generates the final version of a page from the source file and writes * it to the cache. @@ -240,7 +240,7 @@ class XHTMLCompiler_Page $this->deps->write(serialize($deps)); return $contents; } - + /** * Displays the page, either from cache or fresh regeneration. */ @@ -256,14 +256,14 @@ class XHTMLCompiler_Page } echo $ret; } - + /** * Retrieves the Git_Repo that represents this page. */ public function getRepo() { return new Git_Repo($this->source->getDirectory()); } - + /** * Retrieves the filename relative to the Git repository root. */ @@ -278,7 +278,7 @@ class XHTMLCompiler_Page ) ); } - + /** * Retrieves the log that represents this page. */ @@ -287,9 +287,9 @@ class XHTMLCompiler_Page $repo = $this->getRepo(); return $repo->log('master', array($this->getGitPath()), array_merge(array('follow' => true), $kwargs)); } - + // this is metadata stuff that needs to be moved and cached - + /** * Retrieves the DateTime this page was created, according to Git's logs. * If no logs are present, use filectime(), which isn't totally accurate @@ -309,7 +309,7 @@ class XHTMLCompiler_Page $time = substr($source, $p, strpos($source, '"', $p) - $p); return new DateTime($time); } - + $repo = $this->getRepo(); // This is extremely memory inefficient, but I can't figure out // how to get Git to limit the commits (-n) without undoing @@ -325,7 +325,7 @@ class XHTMLCompiler_Page $this->setTimezone($date); return $date; } - + /** * Retrieves the DateTime this page was last updated, according to Git's logs, * otherwise according to filemtime. @@ -343,7 +343,7 @@ class XHTMLCompiler_Page $this->setTimezone($date); return $date; } - + /** * Touches the source file, meaning that any files that depend on this * file should be regenerated. XHTML Compiler knows, however, @@ -353,7 +353,7 @@ class XHTMLCompiler_Page public function touch() { $this->source->touch(); } - + /** * Sets our default timezone to a date object; especially useful if it * was initialized with an @ isgn. @@ -361,5 +361,5 @@ class XHTMLCompiler_Page private function setTimezone($date) { $date->setTimezone(new DateTimeZone(date_default_timezone_get())); } - + } diff --git a/XHTMLCompiler/RSSFeed.php b/XHTMLCompiler/RSSFeed.php index 088d821..2fb9167 100644 --- a/XHTMLCompiler/RSSFeed.php +++ b/XHTMLCompiler/RSSFeed.php @@ -5,13 +5,13 @@ */ class XHTMLCompiler_RSSFeed { - + /** Internal DOM that represents the feed */ protected $doc; - + /** Convenient reference to channel node in $this->doc */ protected $channel; - + /** * @param $title Title of the feed * @param $path Fully-formed webpath to feed @@ -21,14 +21,14 @@ class XHTMLCompiler_RSSFeed public function __construct($title, $path, $description = null, $lang = null) { $this->doc = new DOMDocument('1.0', 'UTF-8'); $this->doc->formatOutput = true; - + $rss = $this->doc->createElement('rss'); $rss->setAttribute('version', '2.0'); $this->doc->appendChild($rss); - + $channel = $this->doc->createElement('channel'); $rss->appendChild($channel); - + $channel->appendChild($this->doc->createElement('title', $title)); $channel->appendChild($this->doc->createElement('link', $path)); if ($lang) { @@ -44,10 +44,10 @@ class XHTMLCompiler_RSSFeed $channel->appendChild( $this->doc->createElement('generator', 'XHTML Compiler') ); - + $this->channel = $channel; } - + /** * Adds a news item to the RSS feed * @param $link Link to relevant article @@ -58,15 +58,15 @@ class XHTMLCompiler_RSSFeed public function addItem($link, $title, $date, $body) { $item = $this->doc->createElement('item'); $this->channel->appendChild($item); - + $body = preg_replace("/\s+/", ' ', $body); - + if ($title) $item->appendChild($this->doc->createElement('title', htmlspecialchars($title))); $item->appendChild($this->doc->createElement('pubDate', $date)); $item->appendChild($this->doc->createElement('description', htmlspecialchars($body))); $item->appendChild($this->doc->createElement('link', htmlspecialchars($link))); } - + /** * Saves RSS feed to path * @param $path Path to save feed to @@ -75,5 +75,5 @@ class XHTMLCompiler_RSSFeed $this->doc->save($path); chmod($path, 0644); } - + } diff --git a/XHTMLCompiler/TextFilter.php b/XHTMLCompiler/TextFilter.php index 8d38ae5..00f5d17 100644 --- a/XHTMLCompiler/TextFilter.php +++ b/XHTMLCompiler/TextFilter.php @@ -5,7 +5,7 @@ */ abstract class XHTMLCompiler_TextFilter extends XHTMLCompiler_Filter { - + /** * Defines a filter that processes string text. * @param $text String text to process @@ -16,5 +16,5 @@ abstract class XHTMLCompiler_TextFilter extends XHTMLCompiler_Filter * solution would not work. */ abstract public function process($text, $page, $manager); - + } diff --git a/XHTMLCompiler/TextFilter/Fragment.php b/XHTMLCompiler/TextFilter/Fragment.php index f6a0944..8767fcf 100644 --- a/XHTMLCompiler/TextFilter/Fragment.php +++ b/XHTMLCompiler/TextFilter/Fragment.php @@ -7,14 +7,14 @@ */ class XHTMLCompiler_TextFilter_Fragment extends XHTMLCompiler_TextFilter { - + var $name = 'Fragment'; - + public function process($text, $page, $manager) { if (strpos($text, '') === false) return $text; preg_match('/(.+?)<\/body>/s', $text, $matches); file_put_contents($page->getPathStem() . '.frag', $matches[1]); return $text; } - + } diff --git a/functions.php b/functions.php index 7d869d5..1b23dd6 100644 --- a/functions.php +++ b/functions.php @@ -98,7 +98,7 @@ function xhtmlcompiler_exception_handler(Exception $e) { } $error_xsl = $xc->getConf('error_xsl'); - + // extract information out of exception if ($e instanceof XHTMLCompiler_Exception) { $code = $e->getCode(); @@ -109,21 +109,21 @@ function xhtmlcompiler_exception_handler(Exception $e) { $title = false; $details = $e->getMessage(); } - + // send appropriate response code $default = set_response_code($code); - + // munge the title if (!$title) $title = $default; else $title = $code . ' ' . $title; - + // build a error document $page = new DOMDocument('1.0', 'utf-8'); $error = $page->createElement('error'); $page->appendChild($error); $error->appendChild($page->createElement('code', $code)); $error->appendChild($page->createElement('title', $title)); $error->appendChild($page->createElement('base', $xc->getConf('web_path'))); - + // details (in HTML) if ($details) { $html = $page->createDocumentFragment(); @@ -132,7 +132,7 @@ function xhtmlcompiler_exception_handler(Exception $e) { $details_dom->appendChild($html); $error->appendChild($details_dom); } - + // debug if ($xc->getConf('debug')) { $debug = $page->createElement('debug'); @@ -141,13 +141,13 @@ function xhtmlcompiler_exception_handler(Exception $e) { $debug->appendChild($page->createElement('line', $e->getLine())); $error->appendChild($debug); } - + // generate and output html $xslt_processor = new ConfigDoc_HTMLXSLTProcessor(); $xslt_processor->importStylesheet(dirname(__FILE__) . '/../' . $error_xsl); $html = $xslt_processor->transformToHTML($page); $php->paint($html); - + } diff --git a/htaccess.php b/htaccess.php index daae71d..45fab73 100644 --- a/htaccess.php +++ b/htaccess.php @@ -17,7 +17,7 @@ $identifier_end = '# END xhtml-compiler/main.php mod_rewrite'; $identifier_here = '# HERE xhtml-compiler/main.php mod_rewrite'; if (file_exists('.htaccess')) { - + // do time check $files_to_check = array( '.htaccess.in', @@ -28,9 +28,9 @@ if (file_exists('.htaccess')) { 'xhtml-compiler/htaccess.php', 'redirects.txt', ); - + $mtime_htaccess = filemtime('.htaccess'); - + $no_changes_needed = true; foreach ($files_to_check as $file) { if (file_exists($file) && filemtime($file) > $mtime_htaccess) { @@ -38,20 +38,20 @@ if (file_exists('.htaccess')) { break; } } - + if ($no_changes_needed) { throw new XHTMLCompiler_Exception(503, false, 'No changes detected in xhtml-compiler/config.php, xhtml-compiler/config.default.php or xhtml-compiler/htaccess.php.'); } - + if (!file_exists('.htaccess.in')) { $contents = file_get_contents('.htaccess'); } else { $contents = file_get_contents('.htaccess.in'); } - + // do writeability check if ( ( @@ -63,7 +63,7 @@ if (file_exists('.htaccess')) { throw new XHTMLCompiler_Exception(503, false, 'Pre-existing htaccess not configured to accept new rules'); } - + // replace old rules with new set $regex = '/' . @@ -71,9 +71,9 @@ if (file_exists('.htaccess')) { '.+?' . preg_quote($identifier_end, '/') . '/s'; - + $contents = preg_replace($regex, $identifier_here, $contents); - + } else { $contents = $identifier_here; } @@ -110,7 +110,7 @@ foreach ($allowed_dirs as $dir => $recursive) { $len = strlen($dir); $slash = (!$len || $dir[$len-1] === '/') ? '' : '/'; $dir_exp = preg_quote($dir) . $slash . $r; - + if (is_array($indexed_dirs)) { $intercept = isset($indexed_dirs[$dir]) ? $indexed_dirs[$dir] : true; } else { -- 2.11.4.GIT