CC-1695 Remove Campcaster Studio and make install easier
Fixed references to files for new directory structure for the backend stuff.
This commit is contained in:
parent
fe724b7814
commit
2ece374513
319 changed files with 75 additions and 357 deletions
226
3rd_party/php/pear/XML/Beautifier/Renderer.php
vendored
Normal file
226
3rd_party/php/pear/XML/Beautifier/Renderer.php
vendored
Normal file
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* XML_Beautifier/Renderer
|
||||
*
|
||||
* XML Beautifier's Rendere
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version CVS: $Id: Renderer.php,v 1.6 2008/08/24 19:44:14 ashnazg Exp $
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Renderer base class for XML_Beautifier
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version Release: 1.2.0
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
*/
|
||||
class XML_Beautifier_Renderer
|
||||
{
|
||||
/**
|
||||
* options
|
||||
* @var array
|
||||
*/
|
||||
var $_options = array();
|
||||
|
||||
/**
|
||||
* create a new renderer
|
||||
*
|
||||
* @param array $options for the serialization
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function XML_Beautifier_Renderer($options = array())
|
||||
{
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the XML tokens
|
||||
*
|
||||
* @param array $tokens XML tokens
|
||||
*
|
||||
* @return string XML document
|
||||
* @access public
|
||||
* @abstract
|
||||
*/
|
||||
function serialize($tokens)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* normalize the XML tree
|
||||
*
|
||||
* When normalizing an XML tree, adjacent data sections
|
||||
* are combined to one data section.
|
||||
*
|
||||
* @param array $tokens XML tree as returned by the tokenizer
|
||||
*
|
||||
* @return array XML tree
|
||||
* @access public
|
||||
*/
|
||||
function normalize($tokens)
|
||||
{
|
||||
$tmp = array();
|
||||
foreach ($tokens as $token) {
|
||||
array_push($tmp, $this->_normalizeToken($token));
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* normalize one element in the XML tree
|
||||
*
|
||||
* This method will combine all data sections of an element.
|
||||
*
|
||||
* @param array $token token array
|
||||
*
|
||||
* @return array $struct
|
||||
* @access private
|
||||
*/
|
||||
function _normalizeToken($token)
|
||||
{
|
||||
if ((isset($token["children"]))
|
||||
&& !is_array($token["children"])
|
||||
|| empty($token["children"])
|
||||
) {
|
||||
return $token;
|
||||
}
|
||||
|
||||
$children = $token["children"];
|
||||
$token["children"] = array();
|
||||
$cnt = count($children);
|
||||
$currentMode = 0;
|
||||
for ($i = 0; $i < $cnt; $i++ ) {
|
||||
// no data section
|
||||
if ($children[$i]["type"] != XML_BEAUTIFIER_CDATA
|
||||
&& $children[$i]["type"] != XML_BEAUTIFIER_CDATA_SECTION
|
||||
) {
|
||||
$children[$i] = $this->_normalizeToken($children[$i]);
|
||||
|
||||
$currentMode = 0;
|
||||
array_push($token["children"], $children[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* remove whitespace
|
||||
*/
|
||||
if ($this->_options['removeLineBreaks'] == true) {
|
||||
$children[$i]['data'] = trim($children[$i]['data']);
|
||||
if ($children[$i]['data'] == '') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($currentMode == $children[$i]["type"]) {
|
||||
$tmp = array_pop($token["children"]);
|
||||
|
||||
if ($children[$i]['data'] != '') {
|
||||
if ($tmp['data'] != ''
|
||||
&& $this->_options['removeLineBreaks'] == true
|
||||
) {
|
||||
$tmp['data'] .= ' ';
|
||||
}
|
||||
$tmp["data"] .= $children[$i]["data"];
|
||||
}
|
||||
array_push($token["children"], $tmp);
|
||||
} else {
|
||||
array_push($token["children"], $children[$i]);
|
||||
}
|
||||
|
||||
$currentMode = $children[$i]["type"];
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* indent a text block consisting of several lines
|
||||
*
|
||||
* @param string $text textblock
|
||||
* @param integer $depth depth to indent
|
||||
* @param boolean $trim trim the lines
|
||||
*
|
||||
* @return string indented text block
|
||||
* @access private
|
||||
*/
|
||||
function _indentTextBlock($text, $depth, $trim = false)
|
||||
{
|
||||
$indent = $this->_getIndentString($depth);
|
||||
$tmp = explode("\n", $text);
|
||||
$cnt = count($tmp);
|
||||
$xml = '';
|
||||
for ($i = 0; $i < $cnt; $i++ ) {
|
||||
if ($trim) {
|
||||
$tmp[$i] = trim($tmp[$i]);
|
||||
}
|
||||
if ($tmp[$i] == '') {
|
||||
continue;
|
||||
}
|
||||
$xml .= $indent.$tmp[$i].$this->_options["linebreak"];
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string that is used for indentation in a specific depth
|
||||
*
|
||||
* This depends on the option 'indent'.
|
||||
*
|
||||
* @param integer $depth nesting level
|
||||
*
|
||||
* @return string indent string
|
||||
* @access private
|
||||
*/
|
||||
function _getIndentString($depth)
|
||||
{
|
||||
if ($depth > 0) {
|
||||
return str_repeat($this->_options["indent"], $depth);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
?>
|
313
3rd_party/php/pear/XML/Beautifier/Renderer/Plain.php
vendored
Normal file
313
3rd_party/php/pear/XML/Beautifier/Renderer/Plain.php
vendored
Normal file
|
@ -0,0 +1,313 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* XML_Beautifier
|
||||
*
|
||||
* XML Beautifier's Plain Renderer
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version CVS: $Id: Plain.php,v 1.7 2008/08/24 19:44:14 ashnazg Exp $
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* XML_Util is needed to create the tags
|
||||
*/
|
||||
require_once 'XML/Util.php';
|
||||
|
||||
/**
|
||||
* Renderer base class
|
||||
*/
|
||||
require_once XML_BEAUTIFIER_INCLUDE_PATH . '/Renderer.php';
|
||||
|
||||
/**
|
||||
* Basic XML Renderer for XML Beautifier
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version Release: 1.2.0
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
* @todo option to specify inline tags
|
||||
* @todo option to specify treatment of whitespace in data sections
|
||||
*/
|
||||
class XML_Beautifier_Renderer_Plain extends XML_Beautifier_Renderer
|
||||
{
|
||||
/**
|
||||
* Serialize the XML tokens
|
||||
*
|
||||
* @param array $tokens XML tokens
|
||||
*
|
||||
* @return string XML document
|
||||
* @access public
|
||||
*/
|
||||
function serialize($tokens)
|
||||
{
|
||||
$tokens = $this->normalize($tokens);
|
||||
|
||||
$xml = '';
|
||||
$cnt = count($tokens);
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
$xml .= $this->_serializeToken($tokens[$i]);
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* serialize a token
|
||||
*
|
||||
* This method does the actual beautifying.
|
||||
*
|
||||
* @param array $token structure that should be serialized
|
||||
*
|
||||
* @return mixed
|
||||
* @access private
|
||||
* @todo split this method into smaller methods
|
||||
*/
|
||||
function _serializeToken($token)
|
||||
{
|
||||
switch ($token["type"]) {
|
||||
|
||||
/*
|
||||
* serialize XML Element
|
||||
*/
|
||||
case XML_BEAUTIFIER_ELEMENT:
|
||||
$indent = $this->_getIndentString($token["depth"]);
|
||||
|
||||
// adjust tag case
|
||||
if ($this->_options["caseFolding"] === true) {
|
||||
switch ($this->_options["caseFoldingTo"]) {
|
||||
case "uppercase":
|
||||
$token["tagname"] = strtoupper($token["tagname"]);
|
||||
$token["attribs"] =
|
||||
array_change_key_case($token["attribs"], CASE_UPPER);
|
||||
break;
|
||||
case "lowercase":
|
||||
$token["tagname"] = strtolower($token["tagname"]);
|
||||
$token["attribs"] =
|
||||
array_change_key_case($token["attribs"], CASE_LOWER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_options["multilineTags"] == true) {
|
||||
$attIndent = $indent . str_repeat(" ",
|
||||
(2+strlen($token["tagname"])));
|
||||
} else {
|
||||
$attIndent = null;
|
||||
}
|
||||
|
||||
// check for children
|
||||
switch ($token["contains"]) {
|
||||
|
||||
// contains only CData or is empty
|
||||
case XML_BEAUTIFIER_CDATA:
|
||||
case XML_BEAUTIFIER_EMPTY:
|
||||
if (sizeof($token["children"]) >= 1) {
|
||||
$data = $token["children"][0]["data"];
|
||||
} else {
|
||||
$data = '';
|
||||
}
|
||||
|
||||
if (strstr($data, "\n")) {
|
||||
$data = "\n"
|
||||
. $this->_indentTextBlock($data, $token['depth']+1, true);
|
||||
}
|
||||
|
||||
$xml = $indent
|
||||
. XML_Util::createTag($token["tagname"],
|
||||
$token["attribs"], $data, null, XML_UTIL_REPLACE_ENTITIES,
|
||||
$this->_options["multilineTags"], $attIndent)
|
||||
. $this->_options["linebreak"];
|
||||
break;
|
||||
// contains mixed content
|
||||
default:
|
||||
$xml = $indent . XML_Util::createStartElement($token["tagname"],
|
||||
$token["attribs"], null, $this->_options["multilineTags"],
|
||||
$attIndent) . $this->_options["linebreak"];
|
||||
|
||||
$cnt = count($token["children"]);
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
$xml .= $this->_serializeToken($token["children"][$i]);
|
||||
}
|
||||
$xml .= $indent . XML_Util::createEndElement($token["tagname"])
|
||||
. $this->_options["linebreak"];
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* serialize CData
|
||||
*/
|
||||
case XML_BEAUTIFIER_CDATA:
|
||||
if ($token["depth"] > 0) {
|
||||
$xml = str_repeat($this->_options["indent"], $token["depth"]);
|
||||
} else {
|
||||
$xml = "";
|
||||
}
|
||||
|
||||
$xml .= XML_Util::replaceEntities($token["data"])
|
||||
. $this->_options["linebreak"];
|
||||
break;
|
||||
|
||||
/*
|
||||
* serialize CData section
|
||||
*/
|
||||
case XML_BEAUTIFIER_CDATA_SECTION:
|
||||
if ($token["depth"] > 0) {
|
||||
$xml = str_repeat($this->_options["indent"], $token["depth"]);
|
||||
} else {
|
||||
$xml = "";
|
||||
}
|
||||
|
||||
$xml .= '<![CDATA['.$token["data"].']]>' . $this->_options["linebreak"];
|
||||
break;
|
||||
|
||||
/*
|
||||
* serialize entity
|
||||
*/
|
||||
case XML_BEAUTIFIER_ENTITY:
|
||||
if ($token["depth"] > 0) {
|
||||
$xml = str_repeat($this->_options["indent"], $token["depth"]);
|
||||
} else {
|
||||
$xml = "";
|
||||
}
|
||||
$xml .= "&".$token["name"].";".$this->_options["linebreak"];
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
* serialize Processing instruction
|
||||
*/
|
||||
case XML_BEAUTIFIER_PI:
|
||||
$indent = $this->_getIndentString($token["depth"]);
|
||||
|
||||
$xml = $indent."<?".$token["target"].$this->_options["linebreak"]
|
||||
. $this->_indentTextBlock(rtrim($token["data"]), $token["depth"])
|
||||
. $indent."?>".$this->_options["linebreak"];
|
||||
break;
|
||||
|
||||
/*
|
||||
* comments
|
||||
*/
|
||||
case XML_BEAUTIFIER_COMMENT:
|
||||
$lines = count(explode("\n", $token["data"]));
|
||||
|
||||
/*
|
||||
* normalize comment, i.e. combine it to one
|
||||
* line and remove whitespace
|
||||
*/
|
||||
if ($this->_options["normalizeComments"] && $lines > 1) {
|
||||
$comment = preg_replace("/\s\s+/s", " ",
|
||||
str_replace("\n", " ", $token["data"]));
|
||||
$lines = 1;
|
||||
} else {
|
||||
$comment = $token["data"];
|
||||
}
|
||||
|
||||
/*
|
||||
* check for the maximum length of one line
|
||||
*/
|
||||
if ($this->_options["maxCommentLine"] > 0) {
|
||||
if ($lines > 1) {
|
||||
$commentLines = explode("\n", $comment);
|
||||
} else {
|
||||
$commentLines = array($comment);
|
||||
}
|
||||
|
||||
$comment = "";
|
||||
for ($i = 0; $i < $lines; $i++) {
|
||||
if (strlen($commentLines[$i])
|
||||
<= $this->_options["maxCommentLine"]
|
||||
) {
|
||||
$comment .= $commentLines[$i];
|
||||
continue;
|
||||
}
|
||||
$comment .= wordwrap($commentLines[$i],
|
||||
$this->_options["maxCommentLine"]);
|
||||
if ($i != ($lines-1)) {
|
||||
$comment .= "\n";
|
||||
}
|
||||
}
|
||||
$lines = count(explode("\n", $comment));
|
||||
}
|
||||
|
||||
$indent = $this->_getIndentString($token["depth"]);
|
||||
|
||||
if ($lines > 1) {
|
||||
$xml = $indent . "<!--" . $this->_options["linebreak"]
|
||||
. $this->_indentTextBlock($comment, $token["depth"]+1, true)
|
||||
. $indent . "-->" . $this->_options["linebreak"];
|
||||
} else {
|
||||
$xml = $indent . sprintf("<!-- %s -->", trim($comment))
|
||||
. $this->_options["linebreak"];
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* xml declaration
|
||||
*/
|
||||
case XML_BEAUTIFIER_XML_DECLARATION:
|
||||
$indent = $this->_getIndentString($token["depth"]);
|
||||
$xml = $indent . XML_Util::getXMLDeclaration($token["version"],
|
||||
$token["encoding"], $token["standalone"]);
|
||||
break;
|
||||
|
||||
/*
|
||||
* xml declaration
|
||||
*/
|
||||
case XML_BEAUTIFIER_DT_DECLARATION:
|
||||
$xml = $token["data"];
|
||||
break;
|
||||
|
||||
/*
|
||||
* all other elements
|
||||
*/
|
||||
case XML_BEAUTIFIER_DEFAULT:
|
||||
default:
|
||||
$xml = XML_Util::replaceEntities($token["data"]);
|
||||
break;
|
||||
}
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
?>
|
456
3rd_party/php/pear/XML/Beautifier/Tokenizer.php
vendored
Normal file
456
3rd_party/php/pear/XML/Beautifier/Tokenizer.php
vendored
Normal file
|
@ -0,0 +1,456 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* XML_Beautifier/Tokenizer
|
||||
*
|
||||
* XML Beautifier package's Tokenizer
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version CVS: $Id: Tokenizer.php,v 1.10 2008/08/24 19:44:14 ashnazg Exp $
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* XML_Parser is needed to parse the document
|
||||
*/
|
||||
require_once 'XML/Parser.php';
|
||||
|
||||
/**
|
||||
* Tokenizer for XML_Beautifier
|
||||
*
|
||||
* This class breaks an XML document in seperate tokens
|
||||
* that will be rendered by an XML_Beautifier renderer.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Beautifier
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version Release: 1.2.0
|
||||
* @link http://pear.php.net/package/XML_Beautifier
|
||||
* @todo tokenize DTD
|
||||
* @todo check for xml:space attribute
|
||||
*/
|
||||
class XML_Beautifier_Tokenizer extends XML_Parser
|
||||
{
|
||||
/**
|
||||
* current depth
|
||||
* @var integer
|
||||
* @access private
|
||||
*/
|
||||
var $_depth = 0;
|
||||
|
||||
/**
|
||||
* stack for all found elements
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_struct = array();
|
||||
|
||||
/**
|
||||
* current parsing mode
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_mode = "xml";
|
||||
|
||||
/**
|
||||
* indicates, whether parser is in cdata section
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $_inCDataSection = false;
|
||||
|
||||
/**
|
||||
* Tokenize a document
|
||||
*
|
||||
* @param string $document filename or XML document
|
||||
* @param boolean $isFile flag to indicate whether
|
||||
* the first parameter is a file
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function tokenize($document, $isFile = true)
|
||||
{
|
||||
$this->folding = false;
|
||||
$this->XML_Parser();
|
||||
$this->_resetVars();
|
||||
|
||||
if ($isFile === true) {
|
||||
$this->setInputFile($document);
|
||||
$result = $this->parse();
|
||||
} else {
|
||||
$result = $this->parseString($document);
|
||||
}
|
||||
|
||||
if ($this->isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $this->_struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start element handler for XML parser
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $element XML element
|
||||
* @param array $attribs attributes of XML tag
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function startHandler($parser, $element, $attribs)
|
||||
{
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_ELEMENT,
|
||||
"tagname" => $element,
|
||||
"attribs" => $attribs,
|
||||
"contains" => XML_BEAUTIFIER_EMPTY,
|
||||
"depth" => $this->_depth++,
|
||||
"children" => array()
|
||||
);
|
||||
|
||||
array_push($this->_struct, $struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* End element handler for XML parser
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $element element
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function endHandler($parser, $element)
|
||||
{
|
||||
$struct = array_pop($this->_struct);
|
||||
if ($struct["depth"] > 0) {
|
||||
$parent = array_pop($this->_struct);
|
||||
array_push($parent["children"], $struct);
|
||||
$parent["contains"] = $parent["contains"] | XML_BEAUTIFIER_ELEMENT;
|
||||
array_push($this->_struct, $parent);
|
||||
} else {
|
||||
array_push($this->_struct, $struct);
|
||||
}
|
||||
$this->_depth--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for character data
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $cdata CDATA
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function cdataHandler($parser, $cdata)
|
||||
{
|
||||
if ((string)$cdata === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->_inCDataSection === true) {
|
||||
$type = XML_BEAUTIFIER_CDATA_SECTION;
|
||||
} else {
|
||||
$type = XML_BEAUTIFIER_CDATA;
|
||||
}
|
||||
|
||||
$struct = array(
|
||||
"type" => $type,
|
||||
"data" => $cdata,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
$this->_appendToParent($struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for processing instructions
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $target target
|
||||
* @param string $data data
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function piHandler($parser, $target, $data)
|
||||
{
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_PI,
|
||||
"target" => $target,
|
||||
"data" => $data,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
$this->_appendToParent($struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for external entities
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $open_entity_names entity name
|
||||
* @param string $base ?? (unused?)
|
||||
* @param string $system_id ?? (unused?)
|
||||
* @param string $public_id ?? (unused?)
|
||||
*
|
||||
* @return bool
|
||||
* @access protected
|
||||
* @todo revisit parameter signature... doesn't seem to be correct
|
||||
* @todo PEAR CS - need to shorten arg list for 85-char rule
|
||||
*/
|
||||
function entityrefHandler($parser, $open_entity_names, $base, $system_id, $public_id)
|
||||
{
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_ENTITY,
|
||||
"name" => $open_entity_names,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
$this->_appendToParent($struct);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for all other stuff
|
||||
*
|
||||
* @param object $parser XML parser object
|
||||
* @param string $data data
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function defaultHandler($parser, $data)
|
||||
{
|
||||
switch ($this->_mode) {
|
||||
case "xml":
|
||||
$this->_handleXMLDefault($data);
|
||||
break;
|
||||
case "doctype":
|
||||
$this->_handleDoctype($data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handler for all data inside the doctype declaration
|
||||
*
|
||||
* @param string $data data
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
* @todo improve doctype parsing to split the declaration into seperate tokens
|
||||
*/
|
||||
function _handleDoctype($data)
|
||||
{
|
||||
if (eregi(">", $data)) {
|
||||
$last = $this->_getLastToken();
|
||||
if ($last["data"] == "]" ) {
|
||||
$this->_mode = "xml";
|
||||
}
|
||||
}
|
||||
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_DT_DECLARATION,
|
||||
"data" => $data,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
$this->_appendToParent($struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* handler for all default XML data
|
||||
*
|
||||
* @param string $data data
|
||||
*
|
||||
* @return bool
|
||||
* @access private
|
||||
*/
|
||||
function _handleXMLDefault($data)
|
||||
{
|
||||
if (strncmp("<!--", $data, 4) == 0) {
|
||||
|
||||
/*
|
||||
* handle comment
|
||||
*/
|
||||
$regs = array();
|
||||
eregi("<!--(.+)-->", $data, $regs);
|
||||
$comment = trim($regs[1]);
|
||||
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_COMMENT,
|
||||
"data" => $comment,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
} elseif ($data == "<![CDATA[") {
|
||||
/*
|
||||
* handle start of cdata section
|
||||
*/
|
||||
$this->_inCDataSection = true;
|
||||
$struct = null;
|
||||
|
||||
} elseif ($data == "]]>") {
|
||||
/*
|
||||
* handle end of cdata section
|
||||
*/
|
||||
$this->_inCDataSection = false;
|
||||
$struct = null;
|
||||
|
||||
} elseif (strncmp("<?", $data, 2) == 0) {
|
||||
/*
|
||||
* handle XML declaration
|
||||
*/
|
||||
preg_match_all('/([a-zA-Z_]+)="((?:\\\.|[^"\\\])*)"/', $data, $match);
|
||||
$cnt = count($match[1]);
|
||||
$attribs = array();
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
$attribs[$match[1][$i]] = $match[2][$i];
|
||||
}
|
||||
|
||||
if (!isset($attribs["version"])) {
|
||||
$attribs["version"] = "1.0";
|
||||
}
|
||||
if (!isset($attribs["encoding"])) {
|
||||
$attribs["encoding"] = "UTF-8";
|
||||
}
|
||||
if (!isset($attribs["standalone"])) {
|
||||
$attribs["standalone"] = true;
|
||||
} else {
|
||||
if ($attribs["standalone"] === 'yes') {
|
||||
$attribs["standalone"] = true;
|
||||
} else {
|
||||
$attribs["standalone"] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_XML_DECLARATION,
|
||||
"version" => $attribs["version"],
|
||||
"encoding" => $attribs["encoding"],
|
||||
"standalone" => $attribs["standalone"],
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
} elseif (eregi("^<!DOCTYPE", $data)) {
|
||||
$this->_mode = "doctype";
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_DT_DECLARATION,
|
||||
"data" => $data,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
|
||||
} else {
|
||||
/*
|
||||
* handle all other data
|
||||
*/
|
||||
$struct = array(
|
||||
"type" => XML_BEAUTIFIER_DEFAULT,
|
||||
"data" => $data,
|
||||
"depth" => $this->_depth
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_null($struct)) {
|
||||
$this->_appendToParent($struct);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* append a struct to the last struct on the stack
|
||||
*
|
||||
* @param array $struct structure to append
|
||||
*
|
||||
* @return bool
|
||||
* @access private
|
||||
*/
|
||||
function _appendToParent($struct)
|
||||
{
|
||||
if ($this->_depth > 0) {
|
||||
$parent = array_pop($this->_struct);
|
||||
array_push($parent["children"], $struct);
|
||||
$parent["contains"] = $parent["contains"] | $struct["type"];
|
||||
array_push($this->_struct, $parent);
|
||||
return true;
|
||||
}
|
||||
array_push($this->_struct, $struct);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the last token
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _getLastToken()
|
||||
{
|
||||
$parent = array_pop($this->_struct);
|
||||
if (isset($parent["children"]) && is_array($parent["children"])) {
|
||||
$last = array_pop($parent["children"]);
|
||||
array_push($parent["children"], $last);
|
||||
} else {
|
||||
$last = $parent;
|
||||
}
|
||||
array_push($this->_struct, $parent);
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* reset all used object properties
|
||||
*
|
||||
* This method is called before parsing a new document
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function _resetVars()
|
||||
{
|
||||
$this->_depth = 0;
|
||||
$this->_struct = array();
|
||||
$this->_mode = "xml";
|
||||
$this->_inCDataSection = false;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue