⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb.xml.domit.php

📁 最受欢迎的Joomla社区用户管理收费插件 - Commnity Builder 1.2 RC2。 Community Builder suite (CB) extends the Joomla!
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/*** Precise emulation of PHP SimpleXMLElement in PHP < 5.1.3* @version $Id:$* @author Beat* @copyright (C) 2007 Beat and Lightning MultiCom SA, 1009 Pully, Switzerland* @license Lightning Proprietary. See licence. Allowed for free use within CB and for CB plugins.*/// Check to ensure this file is within the rest of the frameworkif ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }if( defined('JXML_TEST_DOMIT') || ! function_exists( 'xml_parser_create' ) ) {	global $_CB_framework;	$domitPath = $_CB_framework->getCfg('absolute_path') . '/includes/domit/xml_domit_lite_include.php';	if ( file_exists( $domitPath ) ) {		require_once( $domitPath );	} else {		die("<font color='red'>". $_CB_framework->getCfg( 'absolute_path' ) . "/includes/domit/ does not exist! This is normal with mambo 4.5.0 and 4.6.1 and php 4 without xml parser library binded. Community Builder needs this library for handling plugins.<br />  You Must Manually do the following:<br /> 1.) create " . $_CB_framework->getCfg( 'absolute_path' ) . "/includes/domit/ directory <br /> 2.) chmod it to 777 <br /> 3.) copy corresponding content of a mambo 4.5.2 directory.</font><br /><br />\n");	}}/** * Class to emulate precisely PHP SimpleXMLElement in PHP < 5.1.3 * * @author Beat * @copyright Beat 2007 * @licence allowed for free use within CB and for CB plugins */class FixedSimpleXML {	/** Attributes of this element	* @var array of string */	var $_attributes	=	array();	/** The name of the element	* @var string */	var $_name			=	'';	/** The data the element contains	* @var string */	var $_data			=	'';	/** The parent of the element	* @var FixedSimpleXML */	var $_parent		=	null;	/** Array of references to the objects of all direct children of this XML object	* @var array of FixedSimpleXML */	var $_children		=	array();		/**	 * Constructor, creates tree and parses XML	 * All parameters are equivalent to PHP 5 SimpleXML, except last 2	 *	 * @param  string          $data	 * @param  int             $options	 * @param  boolean         $data_is_url	 * @param  string          $ns	 * @param  boolean         $is_prefix	 * @param  string          $name         used internally to creat tree:  name	 * @param  array           $attrs        used internally to create tree: attributes	 * @return FixedSimpleXML	 */	function FixedSimpleXML( $data, $options = null, $data_is_url = false, $ns = null, $is_prefix = false, $name = null, $attrs = array() )	{		if ( $data ) {			$this->_xmlHelper		=&	new SimpleXML_Helper( $this,  $data, $options, $data_is_url, $ns, $is_prefix );		} else {			//Make the keys of the attr array lower case, and store the value			$this->_attributes		=	$attrs;				// array_change_key_case($attrs, CASE_LOWER);			$this->_name			=	$name;		}	}	/**	 * Get an element in the document by / separated path	 * or FALSE	 *	 * @param	string	$path	The / separated path to the element	 * @return	CBSimpleXMLElement or FALSE	 */	function & getElementByPath( $path ) {		$parts				=	explode( '/', trim($path, '/') );		$tmp				=&	$this;		foreach ($parts as $node) {			$found			=	false;			foreach ( $tmp->_children as $k => $child ) {				if ($child->_name == $node) {					$tmp	=&	$tmp->_children[$k];					$found	=	true;					break;				}			}			if ( ! $found ) break;		}		if ( $found ) {			return $tmp;		} else {			$false			=	false;			return $false;		}	}	/**	 * Get the name of the element	 *	 * @return string	 */	function name() {		return $this->_name;	}	/**	 * Get the an attribute of the element	 *	 * @param  string  $attribute  The name of the attribute	 * @return mixed   string      If an attribute is given will return the attribute if it exist.	 *                 boolean     Null if attribute is given but doesn't exist	 * 				   array       If no attribute is given will return the complete attributes array	 */	function attributes( $attribute = null ) {		if( ! isset( $attribute ) ) {			return $this->_attributes;		}		return ( isset( $this->_attributes[$attribute] ) ? $this->_attributes[$attribute] : null );	}	/**	 * Get the data of the element	 *	 * @return string	 */	function data( ) {		return $this->_data;	}	/**	 * Set the data of the element	 * WARNING: Not PHP SimpleXML compatible	 *	 * @param	string $data	 * @return string	 */	function setData( $data ) {		$this->_data	=	$data;	}	/**	 * Get the children of the element	 *	 * @return array FixedSimpleXML	 * 	 */	function & children( ) {		return $this->_children;	}	 /**	 * Adds an attribute to the element, override if it already exists	 *	 * @param string $name	 * @param array  $attrs	 */	function addAttribute( $name, $value ) {		$this->_attributes[$name]	=	$value;	}	/**	 * Searches this SimpleXML node for children matching the XPath path.	 * Implements a usefull subset of the syntax of http://www.w3.org/TR/xpath:	 *	 * Abreviated syntax: works:	   * para  selects the para element children of the context node	   * *     selects all element children of the context node	   * para[1]		selects the first para child of the context node	   * * / para		selects all para grandchildren of the context node ( space added around / to not break comment	   * /doc/chapter[5]/section[2]		selects the second section of the fifth chapter of the doc	   * chapter//para					selects the para element descendants of the chapter element children of the context node	   * //olist/item	selects all the item elements in the same document as the context node that have an olist parent	   * .				selects the context node	   * .//para		selects the para element descendants of the context node	   * ..				selects the parent of the context node	   * para[@type="warning"]			selects all para children of the context node that have a type attribute with value warning	   * para[@type="warning"][5]		selects the fifth para child of the context node that has a type attribute with value warning	   * para[5][@type="warning"]		selects the fifth para child of the context node if that child has a type attribute with value warning	   * chapter[title="Introduction"]	selects the chapter children of the context node that have one or more title children with string-value equal to Introduction	 * DOES NOT WORK yet:	   * //para			selects all the para descendants of the document root and thus selects all para elements in the same document as the context node	   * //para									selects all descendant para elements that are the first para children of their parents	   * div//para								select all para descendants of div children	   * para[last()]							selects the last para child of the context node	   * chapter[title]							selects the chapter children of the context node that have one or more title children	   * employee[@secretary and @assistant]	selects all the employee children of the context node that have both a secretary attribute and an assistant attribute	 *	 * @param  string  $basePath	 * @return array|boolean     array of SimpleXMLElement objects or FALSE in case of an error.	 */	function xpath ( $basePath ) {		$path				=	$basePath;	    if ( empty( $path ) ) {	    	return array();	    } elseif ( substr( $path , -1) === '/' ) {			return false;			 // If ends with '/' then wrong		}		$nodesList			=	array( &$this );		$recurse			=	false;		$absoluteMode		=	( $path[0] == '/' );		if ( $absoluteMode ) {			$node			=	$this;			while ( $node->_parent ) {				$node		=	$node->_parent;			}			$path			=	substr( $path, 1 );			if ( ( $path != '' ) && ( $path[0] == '/' ) ) {				$recurse	=	true;						//TBD				$path		=	substr( $path, 1 );			}			$nodesList		=	array( &$node );		}		$xpa				=	explode( '/', $path );		if ( $absoluteMode && ! $recurse ) {			$xpb			=	array_shift( $xpa );			if ( ! in_array( $xpb, array( '*', $node->name() ) ) ) {				return array();			}		}		foreach ( $xpa as $xpb ) {			$xpc					=	explode( '::', $xpb, 2 );			if ( count( $xpc ) == 1 ) {				if ( $xpb == '.' ) {					// ./					$nodesList		=	array( &$this );				} elseif ( $xpb == '..' ) {					// ../					$new			=	array();					foreach ( $nodesList as $n ) {						if ( $n->_parent && ! in_array( $n->_parent, $new ) ) {							$new[]	=	$n->_parent;						}					}					$nodesList		=	$new;				} elseif ( ( $xpb == '*' ) || ( $xpb == '' ) ) {			//TBD to check: maybe this case is included below already...					// */ or /					$new			=	array();					foreach ( $nodesList as $n ) {						foreach ( $n->children() as $nn ) {							$new[]	=	$nn;						}					}					$nodesList		=	$new;				} else {					// tag or tag[a] or tag[a][b]					$matches		=	null;					$result			=	preg_match_all( "/^([^\\[\\]]*)*?(?:\\[([^\\[\\]]*)\\])?(?:\\[([^\\[\\]]*)\\])?\$/", $xpb, $matches );					if ( $result ) {						// tag or tag[a] or tag[a][b]						// $matches = array( 0 => "tag[b][c]", 1 => "tag", 2 => "b", 3 => "c" );						if ( $matches[2][0] ) {							$matchesB	=	null;								$resultB	=	preg_match_all( "/^@([^=]+)=([\"'])(.+)\\2\$/", $matches[2][0], $matchesB );							// $matchesB = array( 0 => '@attr="val"', 1 => 'attr', 2 => '"', 3 => 'val' );						}						if ( $matches[3][0] ) {							$matchesC	=	null;								$resultC	=	preg_match_all( "/^@([^=]+)=([\"'])(.+)\\2\$/", $matches[3][0], $matchesC );							// $matchesC = array( 0 => '@attr="val"', 1 => 'attr', 2 => '"', 3 => 'val' );						}						$new			=	array();						foreach ( $nodesList as $n ) {							// tag , tag[1], tag[1][@attr="val"], tag[@attr="val"], tag[@attr="val"][1]  ( where tag can be '*' or '' or tag )							$counterA		=	0;							$counterB		=	0;							foreach ( $n->children() as $nn ) {								if ( in_array( $matches[1][0], array( '*', '', $nn->name() ) ) ) {									if ( is_numeric( $matches[2][0] ) ) {										if ( ++$counterA < $matches[2][0] ) {											continue;										} elseif ( $counterA > $matches[2][0] ) {											break;										}									} elseif ( $matches[2][0] ) {										if ( ! ( ( ! $resultB ) || ( $resultB && ( $nn->attributes( $matchesB[1][0] ) == $matchesB[3][0] ) ) ) ) {											continue;										}									}									// second [ ]:									if ( is_numeric( $matches[3][0] ) ) {										if ( ++$counterB < $matches[3][0] ) {											continue;										} elseif ( $counterB > $matches[3][0] ) {											break;										}									} elseif ( $matches[3][0] ) {										if ( ! ( ( ! $resultC ) || ( $resultC && ( $nn->attributes( $matchesC[1][0] ) == $matchesC[3][0] ) ) ) ) {											continue;										}									}									$new[]	=	$nn;								}							}						}						$nodesList		=	$new;					} else {						trigger_error( sprintf( 'Error in xpath( %s ): illegal subexpression: %s ', $basePath , $xpb), E_USER_WARNING );					}				}			} else {		// ( count( $xpc ) == 2 ) {				//TBD: for now just trigger an error:				trigger_error( sprintf( 'Unsuported in CB xpath( %s ): unabreviated syntax subexpression: %s ', $basePath , $xpb), E_USER_WARNING );			}		}		return $nodesList;	}	/**	 * Adds a direct child to the element	 *	 * @param string $name	 * @param string $value	 * @param string $nameSpace	 * @param array  $attrs	 * @return FixedSimpleXML the child	 */	function &addChildWithAttr( $name, $value, $nameSpace = null, $attrs = array() ) {		// If there is no array already set for the tag name being added, create an empty array for it:		if( ! isset( $this->$name ) ) {			$this->$name	=	array();		}		// Create the child object itself:		$classname			=	get_class( $this );		$child				=&	new $classname( null, null, false, null, false, $name, $attrs );		$child->_data		=	$value;		// Add the parent:		$child->_parent		=&	$this;		// Add the reference of it to the end of an array member named for the elements name:		$this->{$name}[]	=&	$child;		// Add the reference to the children array member:		$this->_children[]	=&	$child;		return $child;	}	/**	 * Remove a specific child from the tree	 *	 * @param FixedSimpleXML $child  the child	 */	function removeChild( &$child ) {		$name = $child->name();		for ( $i = 0, $n = count( $this->_children ); $i < $n; $i++ ) {			if ( $this->_children[$i] == $child ) {				unset( $this->_children[$i] );			}		}		for ( $i = 0, $n = count( $this->{$name} ); $i < $n; $i++ ) {			if ( $this->{$name}[$i] == $child ) {				unset( $this->{$name}[$i] );			}		}		$this->_children	=	array_values( $this->_children );		$this->{$name}		=	array_values($this->{$name});		unset( $child );	}	/**	 * Adds a direct child to the element prepended as first child	 * WARNING: Not PHP SimpleXML compatible	 *	 * @param string $name	 * @param array  $attrs	 * @return FixedSimpleXML  the child	 */	function & prependChild( $name, $attrs ) {		// If there is no array already set for the tag name being added, create an empty array for it:		if(!isset($this->$name))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -