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

📄 class.em_xmlhandler.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* ***************************************************************  Copyright notice**  (c) 2006 Karsten Dambekalns <karsten@typo3.org>*  All rights reserved**  This script is part of the TYPO3 project. The TYPO3 project is*  free software; you can redistribute it and/or modify*  it under the terms of the GNU General Public License as published by*  the Free Software Foundation; either version 2 of the License, or*  (at your option) any later version.**  The GNU General Public License can be found at*  http://www.gnu.org/copyleft/gpl.html.*  A copy is found in the textfile GPL.txt and important notices to the license*  from the author is found in LICENSE.txt distributed with these scripts.***  This script is distributed in the hope that it will be useful,*  but WITHOUT ANY WARRANTY; without even the implied warranty of*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*  GNU General Public License for more details.**  This copyright notice MUST APPEAR in all copies of the script!***************************************************************//** * XML handling class for the TYPO3 Extension Manager. * * It contains methods for handling the XML files involved with the EM, * such as the list of extension mirrors and the list of available extensions. * * @author Karsten Dambekalns <karsten@typo3.org> * @package TYPO3 * @subpackage EM */class SC_mod_tools_em_xmlhandler {	/**	 * Holds the parsed XML from extensions.xml.gz	 * @see parseExtensionsXML()	 *	 * @var array	 */	var $emObj;	var $extXMLResult = array();	var $extensionsXML = array();	var $reviewStates = null;	var $useUnchecked = false;	var $useObsolete = false;	/**	 * Reduces the entries in $this->extensionsXML to the latest version per extension and removes entries not matching the search parameter	 *	 * @param	string		$search	The list of extensions is reduced to entries matching this. If empty, the full list is returned.	 * @param	string		$owner	If set only extensions of that user are fetched	 * @param	string		$order	A field to order the result by	 * @param	boolean		$allExt	If set also unreviewed and obsolete extensions are shown	 * @param	boolean		$allVer	If set returns all version of an extension, otherwise only the last	 * @param	integer		$offset	Offset to return result from (goes into LIMIT clause)	 * @param	integer		$limit	Maximum number of entries to return (goes into LIMIT clause)	 * @return	void	 */	function searchExtensionsXML($search, $owner='', $order='', $allExt=false, $allVer=false, $offset=0, $limit=500)	{		$where = '1=1';		if ($search)	{			$where.= ' AND extkey LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($GLOBALS['TYPO3_DB']->escapeStrForLike($search, 'cache_extensions'), 'cache_extensions').'%\'';		}		if ($owner)	{			$where.= ' AND ownerusername='.$GLOBALS['TYPO3_DB']->fullQuoteStr($owner, 'cache_extensions');		}		if (strlen($owner) || $this->useUnchecked || $allExt)	{				// show extensions without review or that have passed review			$where.= ' AND reviewstate >= 0';		} else {				// only display extensions that have passed review			$where.= ' AND reviewstate > 0';		}		if (!$this->useObsolete && !$allExt)	{			$where.= ' AND state!=5';		// 5 == obsolete		}		switch ($order)	{			case 'author_company':				$forder = 'authorname, authorcompany';			break;			case 'state':				$forder = 'state';			break;			case 'cat':			default:				$forder = 'category';			break;		}		$order = $forder.', title';		if (!$allVer)	{			if ($this->useUnchecked)	{				$where .= ' AND lastversion>0';			} else	{				$where .= ' AND lastreviewedversion>0';			}		}		$this->catArr = array();		$idx = 0;		foreach ($this->emObj->defaultCategories['cat'] as $catKey => $tmp)	{			$this->catArr[$idx] = $catKey;			$idx++;		}		$this->stateArr = array();		$idx = 0;		foreach ($this->emObj->states as $state => $tmp)	{			$this->stateArr[$idx] = $state;			$idx++;		}			// Fetch count		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*) as cnt', 'cache_extensions', $where);		$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);		$this->matchingCount = $row['cnt'];		$GLOBALS['TYPO3_DB']->sql_free_result($res);		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'cache_extensions', $where, '', $order, $offset.','.$limit);		$this->extensionsXML = array();		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{			$row['category'] = $this->catArr[$row['category']];			$row['state'] = $this->stateArr[$row['state']];			if (!is_array($this->extensionsXML[$row['extkey']]))	{				$this->extensionsXML[$row['extkey']] = array();				$this->extensionsXML[$row['extkey']]['downloadcounter'] = $row['alldownloadcounter'];			}			if (!is_array($this->extensionsXML[$row['extkey']]['versions']))	{				$this->extensionsXML[$row['extkey']]['versions'] = array(); 			}			$row['dependencies'] = unserialize($row['dependencies']);			$this->extensionsXML[$row['extkey']]['versions'][$row['version']] = $row; 		}		$GLOBALS['TYPO3_DB']->sql_free_result($res); 	}	function countExtensions() {		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('extkey', 'cache_extensions', '1=1', 'extkey');		$cnt = $GLOBALS['TYPO3_DB']->sql_num_rows($res);		$GLOBALS['TYPO3_DB']->sql_free_result($res);		return $cnt; 	}	/**	 * Loads the pre-parsed extension list	 *	 * @return	boolean		true on success, false on error	 */	function loadExtensionsXML() {		$this->searchExtensionsXML('', '', '', true);	}	/**	 * Frees the pre-parsed extension list	 *	 * @return	void	 */	function freeExtensionsXML() {		unset($this->extensionsXML);		$this->extensionsXML = array();	}	/**	 * Removes all extension with a certain state from the list	 *	 * @param	array		&$extensions	The "versions" subpart of the extension list	 * @return	void	 */	function removeObsolete(&$extensions) {		if($this->useObsolete) return;		reset($extensions);		while (list($version, $data) = each($extensions)) {			if($data['state']=='obsolete')			unset($extensions[$version]);		}	}	/**	 * Returns the reviewstate of a specific extension-key/version	 *	 * @param	string		$extKey	 * @param	string		$version: ...	 * @return	integer		Review state, if none is set 0 is returned as default.	 */	function getReviewState($extKey, $version) {		$where = 'extkey='.$GLOBALS['TYPO3_DB']->fullQuoteStr($extKey, 'cache_extensions').' AND version='.$GLOBALS['TYPO3_DB']->fullQuoteStr($version, 'cache_extensions');		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('reviewstate', 'cache_extensions', $where);		if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{			return $row['reviewstate']; 		}		$GLOBALS['TYPO3_DB']->sql_free_result($res);		return 0;	}	/**	 * Removes all extension versions from $extensions that have a reviewstate<1, unless explicitly allowed	 *	 * @param	array		&$extensions	The "versions" subpart of the extension list	 * @return	void	 */	function checkReviewState(&$extensions) {		if ($this->useUnchecked) return;		reset($extensions);		while (list($version, $data) = each($extensions)) {			if($data['reviewstate']<1)				unset($extensions[$version]);		}	}	/**	 * Removes all extension versions from the list of available extensions that have a reviewstate<1, unless explicitly allowed	 *	 * @return	void	 */	function checkReviewStateGlobal() {		if($this->useUnchecked) return;		reset($this->extensionsXML);		while (list($extkey, $data) = each($this->extensionsXML)) {			while (list($version, $vdata) = each($data['versions'])) {				if($vdata['reviewstate']<1) unset($this->extensionsXML[$extkey]['versions'][$version]);			}			if(!count($this->extensionsXML[$extkey]['versions'])) unset($this->extensionsXML[$extkey]);		}	}	/**	 * ***************PARSING METHODS***********************	 */	/**	 * Enter description here...	 *	 * @param	unknown_type		$parser	 * @param	unknown_type		$name	 * @param	unknown_type		$attrs	 * @return	[type]		...	 */	function startElement($parser, $name, $attrs) {		switch($name) {			case 'extensions':			break;			case 'extension':			$this->currentExt = $attrs['extensionkey'];			break;			case 'version':			$this->currentVersion = $attrs['version'];			$this->extXMLResult[$this->currentExt]['versions'][$this->currentVersion] = array();			break;			default:			$this->currentTag = $name;		}	}	/**	 * Enter description here...	 *	 * @param	unknown_type		$parser	 * @param	unknown_type		$name	 * @return	[type]		...	 */	function endElement($parser, $name) {		switch($name) {			case 'extension':			unset($this->currentExt);			break;			case 'version':			unset($this->currentVersion);			break;			default:			unset($this->currentTag);		}	}	/**	 * Enter description here...	 *	 * @param	unknown_type		$parser	 * @param	unknown_type		$data	 * @return	[type]		...	 */	function characterData($parser, $data) {		if(isset($this->currentTag)) {			if(!isset($this->currentVersion) && $this->currentTag == 'downloadcounter') {				$this->extXMLResult[$this->currentExt]['downloadcounter'] = trim($data);			} elseif($this->currentTag == 'dependencies') {				$data = @unserialize($data);				if(is_array($data)) {					$dep = array();					foreach($data as $v) {						$dep[$v['kind']][$v['extensionKey']] = $v['versionRange'];					}					$this->extXMLResult[$this->currentExt]['versions'][$this->currentVersion]['dependencies'] = $dep;				}			} elseif($this->currentTag == 'reviewstate') {					$this->reviewStates[$this->currentExt][$this->currentVersion] = (int)trim($data);					$this->extXMLResult[$this->currentExt]['versions'][$this->currentVersion]['reviewstate'] = (int)trim($data);			} else {				$this->extXMLResult[$this->currentExt]['versions'][$this->currentVersion][$this->currentTag] .= trim($data);			}		}

⌨️ 快捷键说明

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