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

📄 search.php

📁 一款基于PHP的网络日记程序。WikyBlog支持:多用户的 BLOG
💻 PHP
字号:
<?php//$lang checked// "hidden" and "deleted" files are removed from the search index so we don't have to join all_search and all_files tables..//		Question Now: How is it best to do a search restricted to a single user account? and still be able to use the full-text..//			.. this can probably wait!//		Advanced Search .. what does it look like// 		The boolean full-text search capability supports the following operators:// 		+// 		    A leading plus sign indicates that this word must be present in every row returned. // 		-// 		    A leading minus sign indicates that this word must not be present in any row returned. // 		    By default (when neither plus nor minus is specified) the word is optional, but the rows that contain it will be rated higher. This mimicks the behaviour of MATCH() ... AGAINST() without the IN BOOLEAN MODE modifier. // 		< >// 		    These two operators are used to change a word's contribution to the relevance value that is assigned to a row. The < operator decreases the contribution and the > operator increases it. See the example below. // 		( )// 		    Parentheses are used to group words into subexpressions. // 		~// 		    A leading tilde acts as a negation operator, causing the word's contribution to the row relevance to be negative. It's useful for marking noise words. A row that contains such a word will be rated lower than others, but will not be excluded altogether, as it would be with the - operator. // 		*// 		    An asterisk is the truncation operator. Unlike the other operators, it should be appended to the word, not prepended. // 		"// 		    The phrase, that is enclosed in double quotes ", matches only rows that contain this phrase literally, as it was typed. defined('WikyBlog') or die("Not an entry point...");if( !isset($GLOBALS['wbConfig']['search']) || !$GLOBALS['wbConfig']['search'] ){	message('ENABLE_SEARCH');	return;}$_GET += array('key'=>'','all'=>'','phrase'=>'','except'=>'','pre'=>'');//strip the coordinates if setif( isset($_GET['x']) ){	unset($_GET['x']);	unset($_GET['y']);}includeFile('search/all.php');	class searchSearch extends query{	var $classes;	var $placeholder;		function searchSearch(){		global $page,$dbInfo,$pageOwner;		global $lang,$wbTables;						//advanced search			if( !empty($_GET['all']) ){				$temp = $this->getWords($_GET['all']);				foreach($temp as $key){					$_GET['key'] .= ' +'.$key;				}			}			if( !empty($_GET['phrase']) ){				$_GET['key'] .= ' +"'.str_replace('"','',$_GET['phrase']).'"';			}			if( !empty($_GET['except']) ){				$temp = $this->getWords($_GET['except']);				foreach($temp as $key){					$_GET['key'] .= ' -'.$key;				}			}			if( !empty($_GET['pre']) ){				$temp = $this->getWords($_GET['pre']);				foreach($temp as $key){					$_GET['key'] .= $key.'* ';				}			}						// $this->placeholder = str_shuffle('W0I1K2Y3B4L5O6G7P8L9A0C1E2H3O4L5D6E7R8');		// $content = ' RIGHT(SUBSTR( content, 1, POSITION("'.wbDB::escape($_GET['key']).'" in content)+100),200) ';		// $position = ' POSITION("'.wbDB::escape($_GET['key']).'" in '.$content.') ';		// $selectText[] = ' INSERT('.$content.','.$position.',0,"'.$this->placeholder.'") as piece ';		// $this->query = dbInfoToQuery($where,$selectText);		// $this->orderBy();		// $this->limit();		//EVEN NEWER		//The words in the search		// $pattern = '#([a-zA-Z0-9_\']+)#S';		// preg_match_all($pattern,$_GET['key'],$matches,PREG_PATTERN_ORDER);						// message(showArray($matches[0]));		// $howMany = min(count($matches[0]),4);		// $length = ceil(200/$howMany);		// $temp = array();		// $i = 0;		// while($i < $howMany){		// 	$word = wbDB::escape($matches[0][$i]);		// 	$position = ' POSITION("'.$word.'" in `all_content`) ';		// 	$temp[] = ' RIGHT(SUBSTR( `all_content`, 1, POSITION("'.$word.'" in `all_content`)),'.$length.') ';		// 	$i++;		// }		// message(implode(', ',$temp));								//!!this isn't case-insensitive and doesn't work all that well!		// $contentSql = false;		// foreach($matches[0] as $word){		// 	$word = wbDB::escape($word);		// 	if( !$contentSql ){		// 		$position = ' POSITION("'.$word.'" in `all_content`) ';		// 		$contentSql = ' RIGHT( SUBSTRING( `all_content`, 1, POSITION("'.$word.'" in `all_content`)+50),200) ';		// 	}		// 	$contentSql = ' REPLACE('.$contentSql.',"'.$word.'","<b>'.$word.'</b>") ';		// }		// if( !$contentSql ){		// 	$contentSql = ' "" ';		// }				$contentSql = ' SUBSTRING( `all_content`, 1, 300) ';						$page->displayTitle = $lang['search:'].$_GET['key'];		$this->searchUrl = '/Special/'.$pageOwner['username'].'/Search';				$page->css2 =true;		$this->rowLimit = 10;				//$this->fields[--shown to user--] = --database column--		$this->fields[$lang['relevance']] = 'relevance'; //				$this->selectFrom = $wbTables['all_search'].' INNER JOIN '.$wbTables['all_files'].' USING(`file_id`) ';		$this->joinAllTo = $wbTables['all_search'];						//could we value the title more than the content with something like this?		//$match = ' ( MATCH(all_title) AGAINST("'.wbDB::escape($_GET['key']).'") + MATCH(all_title,all_content) AGAINST("'.wbDB::escape($_GET['key']).'")) ';		$match = 'MATCH(all_title,all_content) AGAINST("'.wbDB::escape($_GET['key']).'")';		$modified = $wbTables['all_files'].'.`modified` ';		$this->allSelect = array($match=>'relevance',$contentSql=>'formatted',$modified=>'modified');				$this->queryAllFiles();		$this->query .= ' AND MATCH(all_title,all_content) AGAINST("'.wbDB::escape($_GET['key']).'" IN BOOLEAN MODE) ';				//single user or all users		$this->allUsers = false;		$this->query .= ' AND '.$wbTables['all_files'].'.`owner_id` = "'.wbDB::escape($pageOwner['user_id']).'"';				$this->orderBy();		$label = $lang['search:'].$_GET['key'];				browseSearch3($this,$label);	}		// we only store certain characters in the all_search table	//	so we only want to search for these characters	function getWords(&$text){		$pattern = '#([a-zA-Z0-9_\']+)#';		preg_match_all($pattern,$text,$matches,PREG_PATTERN_ORDER);		$matches[0] = array_diff($matches[0],array(null,''));		return $matches[0];		//return implode(' ',$matches[0]);	}		function mysqlFetch(&$result){		return mysql_fetch_row($result);	}	function displayEmpty(){		parent::displayEmpty();		echo '<p> <br/> </p>';		echo searchSearch::searchForm();		return false;	}	function displayPre(){}		function displayPost(&$prev,&$pages,&$next,$listItems=null,$more=null){		echo '<p> <br/> </p>';		echo searchSearch::searchForm();		parent::displayPost($prev,$pages,$next,$listItems,$more);	}		function abbrevOutput(&$row,$i){		global $pageOwner,$lang;						$this->queryAllResult($row);				echo '<table><tr><td style="white-space:nowrap">';			//relevance			//y=(1600-(x-40)^2)^(1/2) add a little arc..  0 < x < 40			$row['relevance'] = $row['relevance']*2;			$x = min(40,(40*$row['relevance']/100));			$pos = pow(1600-pow($x-40,2),1/2);			//message($x.'::'.$y);						echo '<span title="'.number_format($pos,2).'%" class="wbRelevance" style="cursor:pointer">';				echo '<img src="'.wbLinks::getDir('/imgs/blank.gif').'" class="wbRelevancePos" alt="" align="absmiddle" border="0" height="4" width="'.ceil($pos).'">';			echo '<img src="'.wbLinks::getDir('/imgs/blank.gif').'" class="wbRelevanceNeg" alt="" align="absmiddle" border="0" height="4" width="'.(40-ceil($pos)).'">';			echo '</span> ';					echo '</td><td>';						echo '<span class="title">';			echo wbLinks::local($row['uniqLink'],toDisplay($row['dTitle']));			echo '</span>';			if( $this->allUsers ){				echo '<span class="sm"> (';				echo $row['owner'];				echo ') </span>';			}		echo '</td></tr>';		echo '<tr><td></td><td>';											echo $row['formatted'];								echo '<span class="sm" style="white-space:nowrap">';				$temp = $lang['view_source'];				if( hasPrivilege($row['flags'],$row['owner']) ){					$temp = $lang['edit'];				}				echo ' ... [ ';				echo wbLinks::local($row['uniqLink'].'?cmd=edit',$temp);				echo ' ]';				echo '</span>';											echo '</td></tr></table>';														echo ' &nbsp; <br/>';	}		function searchForm(){		global $page, $pageOwner,$lang;		$page->css2 = true;		$page->formMethod = 'GET';		$page->displayTitle = $lang['search'];						$_GET += array('key'=>'');				$t = '';		$t .= '<table class="WBtoolbar" border=0 >';		$t .= '<tr>';			$t .= '<td>For at least one of the words</td>';			$t .= '<td> <input type="text" name="key" value="'.htmlspecialchars($_GET['key']).'" size="30" />';			$t .= '</td><td>';			$t .= ' <input type="submit" name="search" value="'.$lang['search'].'" class="submit" /> ';			$t .= '</td></tr>';					$t .= '<tr>';			$t .= '<td>';			$t .= '</td>';			$t .= '<td>';			$t .= '</td><td>';			$t .= wbLinks::special('Search','advanced_search');			$t .= '</td></tr>';					//	'/Special/'.$pageOwner['username'].'/Search?adv=1';											$t .= '</table>';		$t .= '';		return $t;	}		function advancedForm(){		global $page, $pageOwner,$lang;		$page->css2 = true;		$page->formMethod = 'GET';		$page->displayTitle = $lang['search'];						$t = '';		$t .= '<table class="WBtoolbar" border=0 >';		$t .= '<tr>';			$t .= '<td>For at least one of the words</td>';			$t .= '<td> <input type="text" name="key" value="'.htmlspecialchars($_GET['key']).'" size="30" /> </td>';			$t .= '</tr>';					$t .= '<tr>';			$t .= '<td>For all of the words</td>';			$t .= '<td> <input type="text" name="all" value="'.htmlspecialchars($_GET['all']).'" size="30" /> </td>';			$t .= '</tr>';				$t .= '<tr>';			$t .= '<td>For the exact phrase</td>';			$t .= '<td> <input type="text" name="phrase" value="'.htmlspecialchars($_GET['phrase']).'" size="30" /> </td>';			$t .= '</tr>';					$t .= '<tr>';			$t .= '<td>Without the words</td>';			$t .= '<td> <input type="text" name="except" value="'.htmlspecialchars($_GET['except']).'" size="30" /> ';			$t .= '</td></tr>';					$t .= '<tr>';			$t .= '<td>For words beginning with</td>';			$t .= '<td> <input type="text" name="pre" value="'.htmlspecialchars($_GET['pre']).'" size="30" /> ';			$t .= '</td><td>';			$t .= ' <input type="submit" name="search" value="'.$lang['search'].'" class="submit" /> ';			$t .= '</td></tr>';			// 		$t .= '<tr><td>';// 			$t .= '</td><td style="text-align:right">';// 			//$t .= ' <input type="submit" name="search" value="'.$lang['search'].'" class="submit" /> ';// 			$t .= '</td></tr>';					$t .= '</table>';					return $t;					}}//					searchSearch////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////					Control Flow//global $page,$pageOwner,$dbObject,$dbObject,$lang,$pageOwner;	$dbObject->links[$lang['search']] = '/Special/'.$pageOwner['username'].'/Search';$dbObject->links['?'] = $lang['search'];if( isset($_GET['search']) ){	$page->formAction = '/Special/'.$pageOwner['username'].'/Search?'.arrayToBrowseString($_GET);	new searchSearch($_GET);}else{	$page->formAction = '/Special/'.$pageOwner['username'].'/Search';	$page->contentA[$lang['search']] = searchSearch::advancedForm();}// this function is in multiple files// similar to functions in adminConfig.php, specPreferences.phpfunction formSelect($name,$values,$selected=null){	$select = '<select name="'.$name.'">';	foreach($values as $key => $value){		if($key == $selected){			$focus = ' selected ';		}else{			$focus = '';		}		if( is_numeric($key) ){			$key = '';		}		$select .= '<option value="'.htmlspecialchars($key).'" '.$focus.'>'.$value.'</option>';	}	$select .= '</select>';	return $select;}

⌨️ 快捷键说明

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