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

📄 class.tslib_pibase.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 4 页
字号:
	 * @return	mixed		The query build.	 * @access private	 * @deprecated		Use pi_exec_query() instead!	 */	function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)	{			// Begin Query:		if (!$query)	{				// Fetches the list of PIDs to select from.				// TypoScript property .pidList is a comma list of pids. If blank, current page id is used.				// TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select.			$pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);			if (is_array($mm_cat))	{				$query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).						' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).						(strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).						' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).						$this->cObj->enableFields($table).chr(10);	// This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!			} else {				$query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).						$this->cObj->enableFields($table).chr(10);	// This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!			}		}			// Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:		list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);		$TABLENAMES = trim(substr(trim($TABLENAMES),5));		$WHERE = trim($WHERE);			// Add '$addWhere'		if ($addWhere)	{$WHERE.=' '.$addWhere.chr(10);}			// Search word:		if ($this->piVars['sword'] && $this->internal['searchFieldList'])	{			$WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);		}		if ($count) {			$queryParts = array(				'SELECT' => 'count(*)',				'FROM' => $TABLENAMES,				'WHERE' => $WHERE,				'GROUPBY' => '',				'ORDERBY' => '',				'LIMIT' => ''			);		} else {				// Order by data:			if (!$orderBy && $this->internal['orderBy'])	{				if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))	{					$orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');				}			}				// Limit data:			$pointer = $this->piVars['pointer'];			$pointer = intval($pointer);			$results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);			$LIMIT = ($pointer*$results_at_a_time).','.$results_at_a_time;				// Add 'SELECT'			$queryParts = array(				'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),				'FROM' => $TABLENAMES,				'WHERE' => $WHERE,				'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),				'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),				'LIMIT' => $LIMIT			);		}		$query = $GLOBALS['TYPO3_DB']->SELECTquery (					$queryParts['SELECT'],					$queryParts['FROM'],					$queryParts['WHERE'],					$queryParts['GROUPBY'],					$queryParts['ORDERBY'],					$queryParts['LIMIT']				);		return $returnQueryArray ? $queryParts : $query;	}	/**	 * Executes a standard SELECT query for listing of records based on standard input vars from the 'browser' ($this->internal['results_at_a_time'] and $this->piVars['pointer']) and 'searchbox' ($this->piVars['sword'] and $this->internal['searchFieldList'])	 * Set $count to 1 if you wish to get a count(*) query for selecting the number of results.	 * Notice that the query will use $this->conf['pidList'] and $this->conf['recursive'] to generate a PID list within which to search for records.	 *	 * @param	string		The table name to make the query for.	 * @param	boolean		If set, you will get a "count(*)" query back instead of field selecting	 * @param	string		Additional WHERE clauses (should be starting with " AND ....")	 * @param	mixed		If an array, then it must contain the keys "table", "mmtable" and (optionally) "catUidList" defining a table to make a MM-relation to in the query (based on fields uid_local and uid_foreign). If not array, the query will be a plain query looking up data in only one table.	 * @param	string		If set, this is added as a " GROUP BY ...." part of the query.	 * @param	string		If set, this is added as a " ORDER BY ...." part of the query. The default is that an ORDER BY clause is made based on $this->internal['orderBy'] and $this->internal['descFlag'] where the orderBy field must be found in $this->internal['orderByList']	 * @param	string		If set, this is taken as the first part of the query instead of what is created internally. Basically this should be a query starting with "FROM [table] WHERE ... AND ...". The $addWhere clauses and all the other stuff is still added. Only the tables and PID selecting clauses are bypassed. May be deprecated in the future!	 * @return	pointer		SQL result pointer	 */	function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')	{		$queryParts = $this->pi_list_query($table,$count,$addWhere,$mm_cat,$groupBy,$orderBy,$query, TRUE);		return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);	}	/**	 * Returns the row $uid from $table	 * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())	 *	 * @param	string		The table name	 * @param	integer		The uid of the record from the table	 * @param	boolean		If $checkPage is set, it's required that the page on which the record resides is accessible	 * @return	array		If record is found, an array. Otherwise false.	 */	function pi_getRecord($table,$uid,$checkPage=0)	{		return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);	}	/**	 * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')	 *	 * @param	string		$pid_list is a comma list of page ids (if empty current page is used)	 * @param	integer		$recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list	 * @return	string		List of PID values (comma separated)	 */	function pi_getPidList($pid_list,$recursive=0)	{		if (!strcmp($pid_list,''))	$pid_list = $GLOBALS['TSFE']->id;		$recursive = t3lib_div::intInRange($recursive,0);		$pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));		$pid_list = array();		foreach($pid_list_arr as $val)	{			$val = t3lib_div::intInRange($val,0);			if ($val)	{				$_list = $this->cObj->getTreeList(-1*$val, $recursive);				if ($_list)		$pid_list[] = $_list;			}		}		return implode(',', $pid_list);	}	/**	 * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name	 *	 * @param	string		Table name to prepend	 * @param	string		List of fields where each element will be prepended with the table name given.	 * @return	string		List of fields processed.	 */	function pi_prependFieldsWithTable($table,$fieldList)	{		$list=t3lib_div::trimExplode(',',$fieldList,1);		$return=array();		while(list(,$listItem)=each($list))	{			$return[]=$table.'.'.$listItem;		}		return implode(',',$return);	}	/**	 * Will select all records from the "category table", $table, and return them in an array.	 *	 * @param	string		The name of the category table to select from.	 * @param	integer		The page from where to select the category records.	 * @param	string		Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!	 * @param	string		Optional GROUP BY field(s), if none, supply blank string.	 * @param	string		Optional ORDER BY field(s), if none, supply blank string.	 * @param	string		Optional LIMIT value ([begin,]max), if none, supply blank string.	 * @return	array		The array with the category records in.	 */	function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')	{		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(					'*',					$table,					'pid='.intval($pid).						$this->cObj->enableFields($table).' '.						$whereClause,	// whereClauseMightContainGroupOrderBy					$groupBy,					$orderBy,					$limit				);		$outArr = array();		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{			$outArr[$row['uid']] = $row;		}		$GLOBALS['TYPO3_DB']->sql_free_result($res);		return $outArr;	}	/***************************	 *	 * Various	 *	 **************************/	/**	 * Returns true if the piVars array has ONLY those fields entered that is set in the $fList (commalist) AND if none of those fields value is greater than $lowerThan field if they are integers.	 * Notice that this function will only work as long as values are integers.	 *	 * @param	string		List of fields (keys from piVars) to evaluate on	 * @param	integer		Limit for the values.	 * @return	boolean		Returns true (1) if conditions are met.	 */	function pi_isOnlyFields($fList,$lowerThan=-1)	{		$lowerThan = $lowerThan==-1 ? $this->pi_lowerThan : $lowerThan;		$fList = t3lib_div::trimExplode(',',$fList,1);		$tempPiVars = $this->piVars;		while(list(,$k)=each($fList))	{			if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)		unset($tempPiVars[$k]);		}		if (!count($tempPiVars))	return 1;	}	/**	 * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields	 * Used by ->pi_linkTP_keepPIvars	 * This is an advanced form of evaluation of whether a URL should be cached or not.	 *	 * @param	array		An array with piVars values to evaluate	 * @return	boolean		Returns true (1) if conditions are met.	 * @see pi_linkTP_keepPIvars()	 */	function pi_autoCache($inArray)	{		if (is_array($inArray))	{			reset($inArray);			while(list($fN,$fV)=each($inArray))	{				if (!strcmp($inArray[$fN],''))	{					unset($inArray[$fN]);				} elseif (is_array($this->pi_autoCacheFields[$fN]))	{					if (is_array($this->pi_autoCacheFields[$fN]['range'])							 && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])							 && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))	{								unset($inArray[$fN]);					}					if (is_array($this->pi_autoCacheFields[$fN]['list'])							 && in_array($inArray[$fN],$this->pi_autoCacheFields[$fN]['list']))	{								unset($inArray[$fN]);					}				}			}		}		if (!count($inArray))	return 1;	}	/**	 * Will process the input string with the parseFunc function from tslib_cObj based on configuration set in "lib.parseFunc_RTE" in the current TypoScript template.	 * This is useful for rendering of content in RTE fields where the transformation mode is set to "ts_css" or so.	 * Notice that this requires the use of "css_styled_content" to work right.	 *	 * @param	string		The input text string to process	 * @return	string		The processed string	 * @see tslib_cObj::parseFunc()	 */	function pi_RTEcssText($str)	{		$parseFunc = $GLOBALS['TSFE']->tmpl->setup['lib.']['parseFunc_RTE.'];		if (is_array($parseFunc))	$str = $this->cObj->parseFunc($str, $parseFunc);		return $str;	}	/*******************************	 *	 * FlexForms related functions	 *	 *******************************/	/**	 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.	 *	 * @param	string		Field name to convert	 * @return	void	 */	function pi_initPIflexForm($field='pi_flexform')	{			// Converting flexform data into array:		if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field])	{			$this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);			if (!is_array($this->cObj->data[$field]))	$this->cObj->data[$field]=array();		}	}	/**	 * Return value from somewhere inside a FlexForm structure	 *	 * @param	array		FlexForm data	 * @param	string		Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.	 * @param	string		Sheet pointer, eg. "sDEF"	 * @param	string		Language pointer, eg. "lDEF"	 * @param	string		Value pointer, eg. "vDEF"	 * @return	string		The content.	 */	function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')	{		$sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';		if (is_array($sheetArray))	{			return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);		}	}	/**	 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray	 *	 * @param	array		Multidimensiona array, typically FlexForm contents	 * @param	array		Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...)	 * @param	string		Value for outermost key, typ. "vDEF" depending on language.	 * @return	mixed		The value, typ. string.	 * @access private	 * @see pi_getFFvalue()	 */	function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)	{		$tempArr=$sheetArray;		foreach($fieldNameArr as $k => $v)	{			if (t3lib_div::testInt($v))	{				if (is_array($tempArr))	{					$c=0;					foreach($tempArr as $values)	{						if ($c==$v)	{							#debug($values);							$tempArr=$values;							break;						}						$c++;					}				}			} else {				$tempArr = $tempArr[$v];			}		}		return $tempArr[$value];	}}// NO extension of class - does not make sense here.?>

⌨️ 快捷键说明

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