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

📄 class.tslib_search.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
				$sword = implode(' ',$a_sword);	// re-build $sword			} else {					// There are no double-quotes around the value. Looking for next (space) or special char.				ereg('^[^ '.$this->quotemeta($specchars).']*',$sword,$reg);				$word = ereg_replace($delchars.'$','',trim($reg[0]));		// Delete $delchars at end of string				$value[] = $word;				$sword = trim(ereg_replace('^'.$this->quotemeta($reg[0]),'',$sword));			}		}		return $value;	}	/**	 * Local version of quotemeta. This is the same as the PHP function	 * but the vertical line, |, and minus, -, is also escaped with a slash.	 *	 * @param	string		String to pass through quotemeta()	 * @return	string		Return value	 */	function quotemeta($str)	{		$str = str_replace('|','\|',quotemeta($str));		#$str = str_replace('-','\-',$str);		// Breaks "-" which should NOT have a slash before it inside of [ ] in a regex.		return $str;	}	/**	 * This creates the search-query.	 * In TypoScript this is used for searching only records not hidden, start/endtimed and fe_grouped! (enable-fields, see tt_content)	 * Sets $this->queryParts	 *	 * @param	string		$endClause is some extra conditions that the search must match.	 * @return	boolean		Returns true no matter what - sweet isn't it!	 * @access private	 * @see	tslib_cObj::SEARCHRESULT()	 */	function build_search_query($endClause) {		if (is_array($this->tables))	{			$tables = $this->tables;			$primary_table = '';				// Primary key table is found.			foreach($tables as $key => $val)	{				if ($tables[$key]['primary_key'])	{$primary_table = $key;}			}			if ($primary_table) {					// Initialize query parts:				$this->queryParts = array(					'SELECT' => '',					'FROM' => '',					'WHERE' => '',					'GROUPBY' => '',					'ORDERBY' => '',					'LIMIT' => '',				);					// Find tables / field names to select:				$fieldArray = array();				$tableArray = array();				foreach($tables as $key => $val)	{					$tableArray[] = $key;					$resultfields = $tables[$key]['resultfields'];					if (is_array($resultfields))	{						foreach($resultfields as $key2 => $val2)	{							$fieldArray[] = $key.'.'.$val2;						}					}				}				$this->queryParts['SELECT'] = implode(',',$fieldArray);				$this->queryParts['FROM'] = implode(',',$tableArray);					// Set join WHERE parts:				$whereArray = array();				$primary_table_and_key = $primary_table.'.'.$tables[$primary_table]['primary_key'];				$primKeys = Array();				foreach($tables as $key => $val)	{					$fkey = $tables[$key]['fkey'];					if ($fkey)	{						 $primKeys[] = $key.'.'.$fkey.'='.$primary_table_and_key;					}				}				if (count($primKeys))	{					$whereArray[] = '('.implode(' OR ',$primKeys).')';				}					// Additional where clause:				if (trim($endClause))	{					$whereArray[] = trim($endClause);				}					// Add search word where clause:				$query_part = $this->build_search_query_for_searchwords();				if (!$query_part)	{					$query_part = '(0!=0)';				}				$whereArray[] = '('.$query_part.')';					// Implode where clauses:				$this->queryParts['WHERE'] = implode(' AND ',$whereArray);					// Group by settings:				if ($this->group_by)	{					if ($this->group_by == 'PRIMARY_KEY')	{						$this->queryParts['GROUPBY'] = $primary_table_and_key;					} else {						$this->queryParts['GROUPBY'] = $this->group_by;					}				}			}		}	}	/**	 * Creates the part of the SQL-sentence, that searches for the search-words ($this->sword_array)	 *	 * @return	string		Part of where class limiting result to the those having the search word.	 * @access private	 */	function build_search_query_for_searchwords()	{		if (is_array($this->sword_array))	{			$main_query_part = array();			foreach($this->sword_array as $key => $val)	{				$s_sword = $this->sword_array[$key]['sword'];					// Get subQueryPart				$sub_query_part = array();				$this->listOfSearchFields='';				foreach($this->tables as $key3 => $val3)	{					$searchfields = $this->tables[$key3]['searchfields'];					if (is_array($searchfields))	{						foreach($searchfields as $key2 => $val2)	{							$this->listOfSearchFields.= $key3.'.'.$val2.',';							$sub_query_part[] = $key3.'.'.$val2.' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($s_sword, $key3).'%\'';						}					}				}				if (count($sub_query_part))	{					$main_query_part[] = $this->sword_array[$key]['oper'];					$main_query_part[] = '('.implode(' OR ',$sub_query_part).')';				}			}			if (count($main_query_part))	{				unset($main_query_part[0]);	// Remove first part anyways.				return implode(' ',$main_query_part);			}		}	}	/**	 * This returns an SQL search-operator (eg. AND, OR, NOT) translated from the current localized set of operators (eg. in danish OG, ELLER, IKKE).	 *	 * @param	string		The possible operator to find in the internal operator array.	 * @return	string		If found, the SQL operator for the localized input operator.	 * @access private	 */	function get_operator($operator)	{		$operator = trim($operator);		$op_array = $this->operator_translate_table;		reset ($op_array);		if ($this->operator_translate_table_caseinsensitive)	{			$operator = strtolower($operator);	// case-conversion is charset insensitive, but it doesn't spoil anything if input string AND operator table is already converted		}		while (list($key,$val) = each($op_array))	{			$item = $op_array[$key][0];			if ($this->operator_translate_table_caseinsensitive)	{				$item = strtolower($item);	// See note above.			}			if ($operator==$item)	{				return $op_array[$key][1];			}		}	}	/**	 * Counts the results and sets the result in $this->res_count	 *	 * @return	boolean		True, if $this->query was found	 */	function count_query() {		if (is_array($this->queryParts))	{			$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($this->queryParts['SELECT'], $this->queryParts['FROM'], $this->queryParts['WHERE'], $this->queryParts['GROUPBY']);		    $this->res_count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);			return TRUE;		}	}	/**	 * Executes the search, sets result pointer in $this->result	 *	 * @return	boolean		True, if $this->query was set and query performed	 */	function execute_query() {		if (is_array($this->queryParts))	{	        $this->result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($this->queryParts);			return TRUE;		}	}	/**	 * Returns URL-parameters with the current search words.	 * Used when linking to result pages so that search words can be highlighted.	 *	 * @return	string		URL-parameters with the searchwords	 */	function get_searchwords()	{		$SWORD_PARAMS = '';		if (is_array($this->sword_array))	{			foreach($this->sword_array as $key => $val)	{				$SWORD_PARAMS.= '&sword_list[]='.rawurlencode($val['sword']);			}		}		return $SWORD_PARAMS;	}	/**	 * Returns an array with the search words in	 *	 * @return	array		IF the internal sword_array contained search words it will return these, otherwise "void"	 */	function get_searchwordsArray()	{		if (is_array($this->sword_array))	{			foreach($this->sword_array as $key => $val)	{				$swords[] = $val['sword'];			}		}		return $swords;	}}if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_search.php'])	{	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_search.php']);}?>

⌨️ 快捷键说明

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