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

📄 cb.xml.domit.php

📁 最受欢迎的Joomla社区用户管理收费插件 - Commnity Builder 1.2 RC2。 Community Builder suite (CB) extends the Joomla!
💻 PHP
📖 第 1 页 / 共 2 页
字号:
			$this->$name = array();		// Create the child object itself		$classname = get_class( $this );		$child = new $classname( null, null, false, null, false, $name, $attrs );		// Add the reference of it to the end of an array member named for the elements name:		array_unshift( $this->$name, $child );		// Add the reference to the children array member:		array_unshift( $this->_children, $child );		return $child;	}	/**	 * Return a well-formed XML string based on SimpleXML element	 *	 * @param  string  $filename  filename to write to if not returning xml	 * @param  int     $_level    no public access: level for indentation	 * @return string             if no $filename, otherwise null	 */	function asXML( $filename = null, $_level = 0 ) {		$out = "\n".str_repeat("\t", $_level).'<'.$this->_name;		//For each attribute, add attr="value"		foreach($this->_attributes as $attr => $value)			$out .= ' '.$attr.'="'.htmlspecialchars($value).'"';		//If there are no children and it contains no data, end it off with a />		if(empty($this->_children) && empty($this->_data))			$out .= " />";		else		{			//If there are children			if(!empty($this->_children))			{				//Close off the start tag				$out .= '>';				//For each child, call the asXML function (this will ensure that all children are added recursively)				foreach($this->_children as $child)					$out .= $child->asXML( null, $_level + 1 );				//Add the newline and indentation to go along with the close tag				$out .= "\n".str_repeat("\t", $_level);			}			//If there is data, close off the start tag and add the data			elseif(!empty($this->_data))				$out .= '>'. htmlspecialchars($this->_data);			//Add the end tag			$out .= '</'.$this->_name.'>';		}		if ( ( $_level != 0 ) || ( $filename === null ) ) {			return $out;		} else {			file_put_contents( $filename, $out );			return null;		}	}}/** * Helper Class to load SimpleXMLElement in PHP < 5.1.3 * * @author Beat * @copyright Beat 2007 * @licence allowed for free use within CB and for CB plugins */class SimpleXML_Helper{	/** Document element	* @var FixedSimpleXML $document */	var $document = null;	/** The XML parser	 * @var resource */	var $_parser = null;	/** parsing helper	* @var array of array */	var $_stack = array();	/**	 * Constructor.	 */	function SimpleXML_Helper( &$firstElement, $data, $options = null, $data_is_url = false, $ns = null, $is_prefix = false ) {		if ( strlen( $data ) > 64000 ) {			// DOMIT XML parser can be very very very memory-hungry on PHP < 5.1.3 on large files:			if ( ( ! is_callable( 'ini_get_all' ) ) || in_array( 'memory_limit', array_keys( ini_get_all() ) ) ) {				$memMax			=	trim( @ini_get( 'memory_limit' ) );				if ( $memMax ) {					$last			=	strtolower( $memMax{strlen( $memMax ) - 1} );					switch( $last ) {						case 'g':							$memMax	*=	1024;						case 'm':							$memMax	*=	1024;						case 'k':							$memMax	*=	1024;					}					if ( $memMax < 64000000 ) {						@ini_set( 'memory_limit', '64M' );					}					if ( $memMax < 96000000 ) {						@ini_set( 'memory_limit', '96M' );					}					if ( $memMax < 128000000 ) {						@ini_set( 'memory_limit', '128M' );					}					if ( $memMax < 196000000 ) {						@ini_set( 'memory_limit', '196M' );					}				}			}		}		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. 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");			}						$this->_parser = null;		} else {						//Create the parser resource and make sure both versions of PHP autodetect the format			$this->_parser = xml_parser_create('');				// check parser resource			xml_set_object($this->_parser, $this);			xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 0);				//Set the handlers			xml_set_element_handler($this->_parser, '_startElement', '_endElement');			xml_set_character_data_handler($this->_parser, '_characterData');		}		// set the first element		$this->document[0]	=&	$firstElement;/*$mem0 = memory_get_usage();echo "Memory: " . $mem0 ."\n";$time = microtime(true);*/		// load the XML data and generate tree		if ( $data_is_url ) {			if ( ! $this->loadFile( $data ) ) {				echo "XML file " . $data . " load error.";				exit();			}		} else {			if ( ! $this->loadString( $data ) ) {				echo "XML string load error.";				exit();			}		}/*$time2 = microtime(true) - $time;echo "Time function calls: " . $time2 ."\n";$mem1 = memory_get_usage();echo "Memory used additional: " . ($mem1 - $mem0) ."\n";$mem0 = $mem1;*/	}	 /**	 * Interprets a string of XML into an object	 *	 * This function will take the well-formed xml string data and return an object of class	 * FixedSimpleXML with properties containing the data held within the xml document.	 * If any errors occur, it returns FALSE.	 *	 * @param string  Well-formed xml string data	 * @return boolean	 */	function loadString( $string ) {		$this->_parse( $string );		return true;	}	 /**	 * Interprets an XML file into an object	 *	 * @param string  Path to xml file containing a well-formed XML document	 * @return boolean True if successful, false if file empty	 */	function loadFile( $path ) {		if ( file_exists( $path ) ) {			//Get the XML document loaded into a variable			$xml = trim( file_get_contents($path) );			if ( $xml == '' ) {				return false;			} else {				$this->_parse( $xml );				unset( $xml );				return true;			}		} else {			return false;		}	}	/**	 * Returns all attributes of the DOMIT element in an array	 *	 * @param DOMIT_Lite_Element $element	 * @return array of string	 */	function _domitGetAttributes( &$element ) {		$attributesArray = array();				//get a reference to the attributes list / named node map (don't forget the ampersand!)		$attrList =& $element->attributes;		if ( $attrList !== null && is_array( $attrList ) && ( count( $attrList ) > 0 ) ) {			//iterate through the list			foreach ($attrList as $k => $currAttr ) {				$attributesArray[$k] = $currAttr;			}		}		return $attributesArray;	}	/**	 * Recursively parses XML using DOMIT	 *	 * @param unknown_type $element	 */	function _domitParse( &$element ) {		if ( $element->nodeName != '#text' ) {			$this->_startElement( null, $element->nodeName, $this->_domitGetAttributes( $element ) );			if ( $element->hasChildNodes() ) {				$myChildNodes = $element->childNodes;				//get the total number of childNodes for the document element				$numChildren = $element->childCount;				//iterate through the collection				for ($i = 0; $i < $numChildren; $i++) {					//get a reference to the i childNode					$currentNode = $myChildNodes[$i];					// recurse					$this->_domitParse( $currentNode );				}			}			$this->_endElement( null, $element->nodeName );		} else {			$this->_characterData( null, $element->nodeValue );		}	}	/**	 * Start parsing an XML document	 *	 * Parses an XML document. The handlers for the configured events are called as many times as necessary.	 *	 * @param  string $data to parse	 */	function _parse($data = '') {		if ( $this->_parser === null ) {			$xml					=&	new DOMIT_Lite_Document();			$success				=	$xml->parseXML( $data );			if ($success) {				//gets a reference to the root element of the cd collection				$myDocumentElement	=&	$xml->documentElement;				$this->_domitParse( $myDocumentElement );				$this->document		=	$this->document[0];			}		} else {			if ( xml_parse( $this->_parser, $data ) ) {				$this->document		=	$this->document[0];			} else {				//Error handling				$this->_handleError( xml_get_error_code( $this->_parser ),									 xml_get_current_line_number( $this->_parser ),									 xml_get_current_column_number( $this->_parser ) );			}			xml_parser_free($this->_parser);		}	}	/**	 * Handles an XML parsing error	 *	 * @param int $code XML Error Code	 * @param int $line Line on which the error happened	 * @param int $col Column on which the error happened	 */	function _handleError($code, $line, $col) {		echo 'XML Parsing Error at '.$line.':'.$col.'. Error '.$code.': '.xml_error_string($code);	}	/**	 * Gets the current direct parent	 *	 * @return FixedSimpleXML  object	 */	function & _getStackElement() {		$return =& $this;		foreach($this->_stack as $stack) {			$return =& $return->{$stack[0]}[$stack[1]];			// equivalent to:			//list( $n, $k ) = $stack;			//$return	=	$return->{$n}[$k];		}		return $return;	}	/**	 * Handler function for the start of a tag	 *	 * @param resource $parser	 * @param string $name	 * @param array $attrs	 */	function _startElement( $parser, $name, $attrs = array() ) {		//Check to see if tag is root-level		if (count($this->_stack) == 0) {			// start out the stack with the document tag			$this->_stack = array( array ( 'document', 0 ) );			$this->document[0]->_name		=	$name;			$this->document[0]->_attributes	=	$attrs;		} else {			//If it isn't root level, use the stack to find the parent			 //Get the name which points to the current direct parent, relative to $this			$parent			=&	$this->_getStackElement();			//Add the child			$parent->addChildWithAttr( $name, null, null, $attrs );			//Update the stack			$this->_stack[]	=	array( $name, ( count( $parent->$name ) - 1 ) );		}	}	/**	 * Handler function for the end of a tag	 *	 * @param resource $parser	 * @param string $name	 */	function _endElement( $parser, $name ) {		//Update stack by removing the end value from it as the parent		array_pop($this->_stack);	}	/**	 * Handler function for the character data within a tag	 *	 * @param resource $parser	 * @param string $data	 */	function _characterData( $parser, $data ) {		//Get the reference to the current parent object		$tag =& $this->_getStackElement();		//Assign data to it		$tag->_data .= $data;	}}?>

⌨️ 快捷键说明

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