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

📄 class.em_xmlhandler.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	}	/**	 * Parses content of mirrors.xml into a suitable array	 *	 * @param	string		XML data file to parse	 * @return	string		HTLML output informing about result	 */	function parseExtensionsXML($filename) {		$parser = xml_parser_create();		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'utf-8');		xml_set_element_handler($parser, array(&$this,'startElement'), array(&$this,'endElement'));		xml_set_character_data_handler($parser, array(&$this,'characterData'));		$fp = gzopen($filename, 'rb');		if (!$fp)	{			$content.= 'Error opening XML extension file "'.$filename.'"';			return $content;		}		$string = gzread($fp, 0xffff);	// Read 64KB		$this->revCatArr = array();		$idx = 0;		foreach ($this->emObj->defaultCategories['cat'] as $catKey => $tmp)	{			$this->revCatArr[$catKey] = $idx++;		}		$this->revStateArr = array();		$idx = 0;		foreach ($this->emObj->states as $state => $tmp)	{			$this->revStateArr[$state] = $idx++;		}		$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_extensions', '1=1');		$extcount = 0;		@ini_set('pcre.backtrack_limit', 500000);		do	{			if (preg_match('/.*(<extension\s+extensionkey="[^"]+">.*<\/extension>)/suU', $string, $match))	{				// Parse content:				if (!xml_parse($parser, $match[0], 0)) {					$content.= 'Error in XML parser while decoding extensions XML file. Line '.xml_get_current_line_number($parser).': '.xml_error_string(xml_get_error_code($parser));					$error = true;					break;				}				$this->storeXMLResult();				$this->extXMLResult = array();				$extcount++;				$string = substr($string, strlen($match[0]));			} elseif(function_exists('preg_last_error') && preg_last_error())	{				$errorcodes = array(					0 => 'PREG_NO_ERROR',					1 => 'PREG_INTERNAL_ERROR',					2 => 'PREG_BACKTRACK_LIMIT_ERROR',					3 => 'PREG_RECURSION_LIMIT_ERROR',					4 => 'PREG_BAD_UTF8_ERROR'				);				$content.= 'Error in regular expression matching, code: '.$errorcodes[preg_last_error()].'<br />See <a href="http://www.php.net/manual/en/function.preg-last-error.php" target="_blank">http://www.php.net/manual/en/function.preg-last-error.php</a>';				$error = true;				break;			} else	{				if(gzeof($fp)) break; // Nothing more can be read				$string .= gzread($fp, 0xffff);	// Read another 64KB			}		} while (true);		xml_parser_free($parser);		gzclose($fp);		if(!$error) {			$content.= '<p>The extensions list has been updated and now contains '.$extcount.' extension entries.</p>';		}		return $content;	} 	function storeXMLResult()	{		foreach ($this->extXMLResult as $extkey => $extArr)	{			$max = -1;			$maxrev = -1;			$last = '';			$lastrev = '';			$usecat = '';			$usetitle = '';			$usestate = '';			$useauthorcompany = '';			$useauthorname = '';			$verArr = array();			foreach ($extArr['versions'] as $version => $vArr)	{				$iv = $this->emObj->makeVersion($version, 'int');				if ($vArr['title']&&!$usetitle)	{					$usetitle = $vArr['title'];				}				if ($vArr['state']&&!$usestate)	{					$usestate = $vArr['state'];				}				if ($vArr['authorcompany']&&!$useauthorcompany)	{					$useauthorcompany = $vArr['authorcompany'];				}				if ($vArr['authorname']&&!$useauthorname)	{					$useauthorname = $vArr['authorname'];				}				$verArr[$version] = $iv;				if ($iv>$max)	{					$max = $iv;					$last = $version;					if ($vArr['title'])	{						$usetitle = $vArr['title'];					}					if ($vArr['state'])	{						$usestate = $vArr['state'];					}					if ($vArr['authorcompany'])	{						$useauthorcompany = $vArr['authorcompany'];					}					if ($vArr['authorname'])	{						$useauthorname = $vArr['authorname'];					}					$usecat = $vArr['category'];				}				if ($vArr['reviewstate'] && ($iv>$maxrev))	{					$maxrev = $iv;					$lastrev = $version;				}			}			if (!strlen($usecat))	{				$usecat = 4;		// Extensions without a category end up in "misc"			} else	{				if (isset($this->revCatArr[$usecat]))	{					$usecat = $this->revCatArr[$usecat];				} else	{					$usecat = 4;		// Extensions without a category end up in "misc"				}			}			if (isset($this->revStateArr[$usestate]))	{				$usestate = $this->revCatArr[$usestate];			} else	{				$usestate = 999;		// Extensions without a category end up in "misc"			}			foreach ($extArr['versions'] as $version => $vArr)	{				$vArr['version'] = $version;				$vArr['intversion'] = $verArr[$version];				$vArr['extkey'] = $extkey;				$vArr['alldownloadcounter'] = $extArr['downloadcounter'];				$vArr['dependencies'] = serialize($vArr['dependencies']);				$vArr['category'] = $usecat;				$vArr['title'] = $usetitle;				if ($version==$last)	{					$vArr['lastversion'] = 1;				}				if ($version==$lastrev)	{					$vArr['lastreviewedversion'] = 1;				}				$vArr['state'] = isset($this->revStateArr[$vArr['state']])?$this->revStateArr[$vArr['state']]:$usestate;	// 999 = not set category				$GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_extensions', $vArr);			}		}	}	/**	 * Parses content of mirrors.xml into a suitable array	 *	 * @param	string		$string: XML data to parse	 * @return	string		HTLML output informing about result	 */	function parseMirrorsXML($string) {		global $TYPO3_CONF_VARS;		// Create parser:		$parser = xml_parser_create();		$vals = array();		$index = array();		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);		if ((double)phpversion()>=5)	{			$preg_result = array();			preg_match('/^[[:space:]]*<\?xml[^>]*encoding[[:space:]]*=[[:space:]]*"([^"]*)"/',substr($string,0,200),$preg_result);			$theCharset = $preg_result[1] ? $preg_result[1] : ($TYPO3_CONF_VARS['BE']['forceCharset'] ? $TYPO3_CONF_VARS['BE']['forceCharset'] : 'iso-8859-1');			xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $theCharset);  // us-ascii / utf-8 / iso-8859-1		}		// Parse content:		xml_parse_into_struct($parser, $string, $vals, $index);		// If error, return error message:		if (xml_get_error_code($parser))	{			$line = xml_get_current_line_number($parser);			$error = xml_error_string(xml_get_error_code($parser));			xml_parser_free($parser);			return 'Error in XML parser while decoding mirrors XML file. Line '.$line.': '.$error;		} else  {			// Init vars:			$stack = array(array());			$stacktop = 0;			$mirrornumber = 0;			$current=array();			$tagName = '';			$documentTag = '';			// Traverse the parsed XML structure:			foreach($vals as $val) {				// First, process the tag-name (which is used in both cases, whether "complete" or "close")				$tagName = ($val['tag']=='mirror' && $val['type']=='open') ? '__plh' : $val['tag'];				if (!$documentTag)	$documentTag = $tagName;				// Setting tag-values, manage stack:				switch($val['type'])	{					case 'open':		// If open tag it means there is an array stored in sub-elements. Therefore increase the stackpointer and reset the accumulation array:						$current[$tagName] = array();	// Setting blank place holder						$stack[$stacktop++] = $current;						$current = array();						break;					case 'close':	// If the tag is "close" then it is an array which is closing and we decrease the stack pointer.					$oldCurrent = $current;					$current = $stack[--$stacktop];					end($current);	// Going to the end of array to get placeholder key, key($current), and fill in array next:					if($tagName=='mirror') {						unset($current['__plh']);						$current[$oldCurrent['host']] = $oldCurrent;					} else {						$current[key($current)] = $oldCurrent;					}					unset($oldCurrent);					break;					case 'complete':	// If "complete", then it's a value. If the attribute "base64" is set, then decode the value, otherwise just set it.					$current[$tagName] = (string)$val['value']; // Had to cast it as a string - otherwise it would be evaluate false if tested with isset()!!					break;				}			}			return $current[$tagName];		}	}	/**	 * Parses content of *-l10n.xml into a suitable array	 *	 * @param	string		$string: XML data to parse	 * @return	array		Array representation of XML data	 */	function parseL10nXML($string) {		// Create parser:		$parser = xml_parser_create();		$vals = array();		$index = array();		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);		// Parse content:		xml_parse_into_struct($parser, $string, $vals, $index);		// If error, return error message:		if (xml_get_error_code($parser))	{			$line = xml_get_current_line_number($parser);			$error = xml_error_string(xml_get_error_code($parser));			debug($error);			xml_parser_free($parser);			return 'Error in XML parser while decoding l10n XML file. Line '.$line.': '.$error;		} else  {			// Init vars:			$stack = array(array());			$stacktop = 0;			$mirrornumber = 0;			$current=array();			$tagName = '';			$documentTag = '';			// Traverse the parsed XML structure:			foreach($vals as $val) {				// First, process the tag-name (which is used in both cases, whether "complete" or "close")				$tagName = ($val['tag']=='languagepack' && $val['type']=='open') ? $val['attributes']['language'] : $val['tag'];				if (!$documentTag)	$documentTag = $tagName;				// Setting tag-values, manage stack:				switch($val['type'])	{					case 'open':		// If open tag it means there is an array stored in sub-elements. Therefore increase the stackpointer and reset the accumulation array:						$current[$tagName] = array();	// Setting blank place holder						$stack[$stacktop++] = $current;						$current = array();						break;					case 'close':	// If the tag is "close" then it is an array which is closing and we decrease the stack pointer.					$oldCurrent = $current;					$current = $stack[--$stacktop];					end($current);	// Going to the end of array to get placeholder key, key($current), and fill in array next:					$current[key($current)] = $oldCurrent;					unset($oldCurrent);					break;					case 'complete':	// If "complete", then it's a value. If the attribute "base64" is set, then decode the value, otherwise just set it.					$current[$tagName] = (string)$val['value']; // Had to cast it as a string - otherwise it would be evaluate false if tested with isset()!!					break;				}			}			return $current[$tagName];		}	}}?>

⌨️ 快捷键说明

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