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

📄 arc.searchview.class.php

📁 这是matlab的一个小程序
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
if(!defined('DEDEINC'))
{
	exit("Request Error!");
}
require_once(DEDEINC."/typelink.class.php");
require_once(DEDEINC."/dedetag.class.php");
require_once(DEDEINC."/splitword.class.php");
require_once(DEDEINC."/taglib/hotwords.lib.php");
require_once(DEDEINC."/taglib/channel.lib.php");

//Copyright 2004-2006 by DedeCms.com itprato
//本类的用途是用于文档搜索
@set_time_limit(0);

//搜索类
class SearchView
{
	var $dsql;
	var $dtp;
	var $dtp2;
	var $TypeID;
	var $TypeLink;
	var $PageNo;
	var $TotalPage;
	var $TotalResult;
	var $PageSize;
	var $ChannelType;
	var $TempInfos;
	var $Fields;
	var $PartView;
	var $StartTime;
	var $Keywords;
	var $OrderBy;
	var $SearchType;
	var $KType;
	var $Keyword;
	var $SearchMax;
	var $SearchMaxRc;
	var $SearchTime;
	var $AddSql;
	var $RsFields;

	//php5构造函数
	function __construct($typeid,$keyword,$orderby,$achanneltype="all",
	$searchtype='',$starttime=0,$upagesize=20,$kwtype=1)
	{
		global $cfg_search_max,$cfg_search_maxrc,$cfg_search_time;
		if(empty($upagesize))
		{
			$upagesize = 10;
		}
		$this->TypeID = $typeid;
		$this->Keyword = $keyword;
		$this->OrderBy = $orderby;
		$this->KType = $kwtype;
		$this->PageSize = $upagesize;
		$this->StartTime = $starttime;
		$this->ChannelType = $achanneltype;
		$this->SearchMax = $cfg_search_max;
		$this->SearchMaxRc = $cfg_search_maxrc;
		$this->SearchTime = $cfg_search_time;
		$this->RsFields = '';
		if($searchtype=="")
		{
			$this->SearchType = "titlekeyword";
		}
		else
		{
			$this->SearchType = $searchtype;
		}
		$this->dsql = $GLOBALS['dsql'];
		$this->dtp = new DedeTagParse();
		$this->dtp->refObj = $this;
		$this->dtp->SetNameSpace("dede","{","}");
		$this->dtp2 = new DedeTagParse();
		$this->dtp2->SetNameSpace("field","[","]");
		$this->TypeLink = new TypeLink($typeid);
		$this->Keywords = $this->GetKeywords($keyword);

		//设置一些全局参数的值
		foreach($GLOBALS['PubFields'] as $k=>$v)
		{
			$this->Fields[$k] = $v;
		}
		$this->CountRecord();
		$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
		if(!file_exists($tempfile)||!is_file($tempfile))
		{
			echo "模板文件不存在,无法解析!";
			exit();
		}
		$this->dtp->LoadTemplate($tempfile);
		$this->TempInfos['tags'] = $this->dtp->CTags;
		$this->TempInfos['source'] = $this->dtp->SourceString;
		if($this->PageSize=="")
		{
			$this->PageSize = 20;
		}
		$this->TotalPage = ceil($this->TotalResult/$this->PageSize);
		if($this->PageNo==1)
		{
			$this->dsql->ExecuteNoneQuery("Update `#@__search_keywords` set result='".$this->TotalResult."' where keyword='".addslashes($keyword)."'; ");
		}

	}

	//php4构造函数
	function SearchView($typeid,$keyword,$orderby,$achanneltype="all",
	$searchtype="",$starttime=0,$upagesize=20,$kwtype=1)
	{
		$this->__construct($typeid,$keyword,$orderby,$achanneltype,$searchtype,$starttime,$upagesize,$kwtype);
	}

	//关闭相关资源
	function Close()
	{
	}

	//获得关键字的分词结果,并保存到数据库
	function GetKeywords($keyword)
	{
		$keyword = cn_substr($keyword,50);
		$row = $this->dsql->GetOne("Select spwords From `#@__search_keywords` where keyword='".addslashes($keyword)."'; ");
		if(!is_array($row))
		{
			if(strlen($keyword)>7)
			{
				$sp = new SplitWord();
				$keywords = $sp->SplitRMM($keyword);
				$sp->Clear();
				$keywords = ereg_replace("[ ]{1,}"," ",trim($keywords));
			}
			else
			{
				$keywords = $keyword;
			}
			$inquery = "INSERT INTO `#@__search_keywords`(`keyword`,`spwords`,`count`,`result`,`lasttime`)
          VALUES ('".addslashes($keyword)."', '".addslashes($keywords)."', '1', '0', '".time()."'); ";
			$this->dsql->ExecuteNoneQuery($inquery);
		}
		else
		{
			$this->dsql->ExecuteNoneQuery("Update `#@__search_keywords` set count=count+1,lasttime='".time()."' where keyword='".addslashes($keyword)."'; ");
			$keywords = $row['spwords'];
		}
		return $keywords;
	}

	//获得关键字SQL
	function GetKeywordSql()
	{
		$ks = explode(' ',$this->Keywords);
		$kwsql = '';
		$kwsqls = array();
		foreach($ks as $k)
		{
			$k = trim($k);
			if(strlen($k)<2)
			{
				continue;
			}
			if(ord($k[0])>0x80 && strlen($k)<3)
			{
				continue;
			}
			$k = addslashes($k);
			if($this->SearchType=="title")
			{
				$kwsqls[] = " arc.title like '%$k%' ";
			}
			else
			{
				$kwsqls[] = " CONCAT(arc.title,' ',arc.writer,' ',arc.keywords) like '%$k%' ";
			}
		}
		if(!isset($kwsqls[0]))
		{
			return '';
		}
		else
		{
			if($this->KType==1)
			{
				$kwsql = join(' OR ',$kwsqls);
			}
			else
			{
				$kwsql = join(' And ',$kwsqls);
			}
			return $kwsql;
		}
	}

	//获得相关的关键字
	function GetLikeWords($num=8)
	{
		$ks = explode(' ',$this->Keywords);
		$lsql = '';
		foreach($ks as $k)
		{
			$k = trim($k);
			if(strlen($k)<2)
			{
				continue;
			}
			if(ord($k[0])>0x80 && strlen($k)<3)
			{
				continue;
			}
			$k = addslashes($k);
			if($lsql=='')
			{
				$lsql = $lsql." CONCAT(spwords,' ') like '%$k %' ";
			}
			else
			{
				$lsql = $lsql." Or CONCAT(spwords,' ') like '%$k %' ";
			}
		}
		if($lsql=='')
		{
			return '';
		}
		else
		{
			$likeword = '';
			$lsql = "(".$lsql.") And Not(keyword like '".addslashes($this->Keyword)."') ";
			$this->dsql->SetQuery("Select keyword,count From `#@__search_keywords` where $lsql order by lasttime desc limit 0,$num; ");
			$this->dsql->Execute('l');
			while($row=$this->dsql->GetArray('l'))
			{
				if($row['count']>1000)
				{
					$fstyle=" style='font-size:11pt;color:red'";
				}
				else if($row['count']>300)
				{
					$fstyle=" style='font-size:10pt;color:green'";
				}
				else
				{
					$style = "";
				}
				$likeword .= " <a href='search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'".$style."><u>".$row['keyword']."</u></a> ";
			}
			return $likeword;
		}
	}

	//加粗关键字
	function GetRedKeyWord($fstr)
	{
		$ks = explode(' ',$this->Keywords);
		$kwsql = '';
		foreach($ks as $k)
		{
			$k = trim($k);
			if($k=='')
			{
				continue;
			}
			if(ord($k[0])>0x80 && strlen($k)<3)
			{
				continue;
			}
			$fstr = str_replace($k,"<font color='red'>$k</font>",$fstr);
		}
		return $fstr;
	}

	//统计列表里的记录
	function CountRecord()
	{
		$this->TotalResult = -1;
		if(isset($GLOBALS['TotalResult']))
		{
			$this->TotalResult = $GLOBALS['TotalResult'];
		}
		if(isset($GLOBALS['PageNo']))
		{
			$this->PageNo = $GLOBALS['PageNo'];
		}
		else
		{
			$this->PageNo = 1;
		}
		$ksql = $this->GetKeywordSql();
		$ksqls = array();
		if($this->StartTime > 0)
		{
			$ksqls = " arc.senddate>'".$this->StartTime."' ";
		}
		if($this->TypeID > 0)
		{
			$ksqls[] = " typeid in (".GetSonIds($this->TypeID).") ";
		}
		if($this->ChannelType > 0)
		{
			$ksqls[] = " arc.channel='".$this->ChannelType."'";
		}
		$ksqls[] = " arc.arcrank > -1 ";
		$this->AddSql = ($ksql=='' ? join(' And ',$ksqls) : join(' And ',$ksqls)." And ($ksql)" );
		$cquery = "Select * From `#@__archives` arc where ".$this->AddSql;
		$hascode = md5($cquery);
		$row = $this->dsql->GetOne("Select * From `#@__arccache` where `md5hash`='".$hascode."' ");
		$uptime = time();
		if(is_array($row) && time()-$row['uptime'] < 3600 * 24)
		{
			$aids = explode(',', $row['cachedata']);
			$this->TotalResult = count($aids)-1;
			$this->RsFields = $row['cachedata'];
		}
		else
		{
			if($this->TotalResult==-1)
			{
				$this->dsql->SetQuery($cquery);
				$this->dsql->execute();
				$aidarr = array();
				$aidarr[] = 0;
				while($row = $this->dsql->getarray())
				{
					$aidarr[] = $row['id'];
				}
				$nums = count($aidarr)-1;
				$aids = implode(',', $aidarr);
				$delete = "Delete From `#@__arccache` where uptime<".(time() - 3600 * 24);
				$this->dsql->SetQuery($delete);
				$this->dsql->executenonequery();
				$insert = "insert into `#@__arccache` (`md5hash`, `uptime`, `cachedata`)
				 values('$hascode', '$uptime', '$aids')";
				$this->dsql->SetQuery($insert);
				$this->dsql->executenonequery();
				$this->TotalResult = $nums;
			}
		}
	}

	//显示列表
	function Display()
	{
		foreach($this->dtp->CTags as $tagid=>$ctag)
		{
			$tagname = $ctag->GetName();
			if($tagname=="list")
			{
				$limitstart = ($this->PageNo-1) * $this->PageSize;
				$row = $this->PageSize;
				if(trim($ctag->GetInnerText())=="")
				{
					$InnerText = GetSysTemplets("list_fulllist.htm");
				}
				else
				{
					$InnerText = trim($ctag->GetInnerText());
				}
				$this->dtp->Assign($tagid,
				$this->GetArcList($limitstart,
				$row,
				$ctag->GetAtt("col"),
				$ctag->GetAtt("titlelen"),

⌨️ 快捷键说明

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