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

📄 inc_arcbook_view.php

📁 强大的PHP内容管理系统尽量不要让站长把时间都花费在为您修正说明上。压缩包解压
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
require_once(dirname(__FILE__)."/config_base.php");
require_once(DEDEINC."/inc_channel_unit_functions.php");
require_once(DEDEINC."/pub_dedetag.php");
require_once(DEDEINC."/inc_bookfunctions.php");
/******************************************************
//Copyright 2004-2006 by DedeCms.com itprato
//本类的用途是用于连载频道的内容浏览
******************************************************/
@set_time_limit(0);
class BookView
{
	var $dsql;
	var $dtp;
	var $InitType;
	var $CatalogID;
	var $BookID;
	var $ContentID;
	var $ChapterID;
	var $BookType;
	var $PageNo;
	var $TotalPage;
	var $TotalResult;
	var $PageSize;
	var $CacheArray;
	var $PreNext;
	var $Keys;
	//-------------------------------
	//php5构造函数
	//-------------------------------
	function __construct($rsid=0,$inittype='catalog',$kws='')
 	{
 		global $cfg_basedir,$PubFields;
 		$this->CacheArray = Array();
 		$this->PreNext = Array();
 		$this->InitType = $inittype;
	  $this->CatalogID = 0;;
	  $this->BookID = 0;
	  $this->ContentID = 0;
	  $this->ChapterID = 0;
	  $this->TotalResult = -1;
	  $this->BookType = 'story';
	  if(is_array($kws)) $this->Keys = $kws;
	  else $this->Keys = Array();

 		$this->dsql = new DedeSql(false);
 		$this->dtp = new DedeTagParse();
 		$this->dtp->SetNameSpace("dede","{","}");
 		$this->Fields['id'] = $rsid;
 		$this->Fields['position'] = '';
 		$this->Fields['title'] = '';
 		//设置一些全局参数的值
 		foreach($PubFields as $k=>$v) $this->Fields[$k] = $v;

 		$this->MakeFirst($inittype,$rsid);

 		//如果分类有上级栏目,获取其信息
 		$this->Fields['pclassname'] = '';
 		if($inittype!='index' && $inittype!='search')
 		{
 		  if($this->Fields['pid']>0){
 			  $row = $this->dsql->GetOne("Select classname From #@__story_catalog where id='{$this->Fields['pid']}' ");
 			  $this->Fields['pclassname'] = $row['classname'];
 		  }
 		  $this->Fields['fulltitle'] = $this->Fields['title'];
 		  if($this->Fields['pclassname']!=''){
 			  $this->Fields['fulltitle'] = $this->Fields['fulltitle']." - ".$this->Fields['pclassname'];
 		  }
    }
  }
  //php4构造函数
 	//---------------------------
 	function BookView($rsid=0,$inittype='catalog',$kws='')
 	{
 		$this->__construct($rsid,$inittype);
 	}

 	/*---------------------------
 	//根据初始化的类型获取filed值,并载入模板
 	--------------------------*/
 	function MakeFirst($inittype,$rsid)
 	{
 		global $cfg_basedir,$PubFields;
 		//列表
 		if($inittype=='catalog')
 		{
 			$this->CatalogID = $rsid;
 			$row = $this->dsql->GetOne("Select * From #@__story_catalog where id='$rsid' ");
 			foreach($row as $k=>$v) if(ereg('[^0-9]',$k)) $this->Fields[$k] = $v;
 			unset($row);
 			$this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_list.htm');
 			$this->Fields['title'] = $this->Fields['classname'];
 			$this->Fields['catid'] = $this->Fields['id'];
 			$this->Fields['bcatid'] = $this->Fields['pid'];
 			$this->Fields['position'] = $this->GetPosition($this->Fields['catid'],$this->Fields['bcatid']);
 		}
 		//图书
 		else if($inittype=='book')
 		{
 			$this->BookID = $rsid;
 			$row = $this->dsql->GetOne("Select c.classname,c.pid,bk.* From #@__story_books bk left join #@__story_catalog c on c.id=bk.catid where bk.id='$rsid' ");
 		  foreach($row as $k=>$v) if(ereg('[^0-9]',$k)) $this->Fields[$k] = $v;
 		  unset($row);
 		  $this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_book.htm');
 		  $this->Fields['title'] = $this->Fields['bookname'];
 		  $this->CatalogID = $this->Fields['catid'];
 		  if($this->Fields['status']==1) $this->Fields['status']='已完成连载';
 			else $this->Fields['status']='连载中...';
 			$this->Fields['position'] = $this->GetPosition($this->Fields['catid'],$this->Fields['bcatid']);
 		}
 		//内容
 		else if($inittype=='content')
 		{
 			$this->ContentID = $rsid;
 			$nquery = "Select c.classname,c.pid,ct.*,cp.chaptername,cp.chapnum
 			From #@__story_content ct
 			left join #@__story_catalog c on c.id=ct.catid
 			left join #@__story_chapter cp on cp.id=ct.chapterid
 			where ct.id='$rsid' ";
 			$row = $this->dsql->GetOne($nquery,MYSQL_ASSOC);
 			if(!is_array($row)) {showmsg('内容不存在','javascript:;');exit();}
 		  $this->ChapterID = $row['chapterid'];
 		  $this->BookID = $row['bookid'];
 		  $this->Fields['bookurl'] = GetBookUrl($row['bookid'],$row['bookname']);
 		  foreach($row as $k=>$v) if(ereg('[^0-9]',$k)) $this->Fields[$k] = $v;
 		  unset($row);
 		  if($this->Fields['booktype']==1) $this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_photo.htm');
 		  else $this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_story.htm');
 		  $this->Fields['position'] = $this->GetPosition($this->Fields['catid'],$this->Fields['bcatid']);
 		  $row = $this->dsql->GetOne("Select freenum From #@__story_books where id='{$this->Fields['bookid']}' ");
 		  $this->Fields['freenum'] = $row['freenum'];
 		  $this->Fields['body'] = GetBookText($this->Fields['id']);
 		  $this->Fields['bookid'] = $this->BookID;
 		}
 		//封面
 		else if($inittype=='index')
 		{
 			$this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_index.htm');
 		}
 		//搜索界面
 		else if($inittype=='search')
 		{
 			if($this->Keys['id']>0) $this->CatalogID = $this->Keys['id'];
 			$this->dtp->LoadTemplet($cfg_basedir.$PubFields['templetdef'].'/books_search.htm');
 		}
 	}

 	//-------------------------------
 	//解析固定模板标记
 	//-----------------------------
 	function ParseTempletsFirst()
 	{
 		if( !is_array($this->dtp->CTags) ) return 0;
 	  foreach($this->dtp->CTags as $tagid=>$ctag)
 		{
 			$tagname = $ctag->GetTagName();
 		  //字段
 		  if($tagname=='field')
 		  {
 		  	if(isset($this->Fields[$ctag->GetAtt('name')])) $this->dtp->Assign($tagid,$this->Fields[$ctag->GetAtt('name')]);
 				else $this->dtp->Assign($tagid,"");
 		  }
 		  //章节信息
 		  else if($tagname=='chapter')
 		  {
 		  	$this->dtp->Assign($tagid, $this->GetChapterList($this->BookID, $ctag->GetInnerText()) );
 		  }
 		  //栏目信息
 		  else if($tagname=='catalog')
 		  {
 		  	$pid = 0;
 		  	if($ctag->GetAtt('type')=='son') $pid = $this->Fields['catid'];
 		  	$this->dtp->Assign($tagid, $this->GetCatalogList($pid,$ctag->GetInnerText()));
 		  }
 		  //当前图书的最新章节
 		  else if($tagname=='newcontent')
 		  {
 		  	if($ctag->GetAtt('bookid')=='') $bid = $this->BookID;
 		  	if(empty($bid)) $this->dtp->Assign($tagid,'');
 		  	else $this->dtp->Assign($tagid, $this->GetNewContentLink($bid,$ctag->GetInnerText()));
 		  }
 		  //指定记录的图书
 		  else if($tagname=='booklist')
 		  {
 		  	if($ctag->GetAtt('catid')!='') $catid = $ctag->GetAtt('catid');
 		  	else $catid = $this->CatalogID;
 		  	$this->dtp->Assign($tagid,
 		  	    $this->GetBookList(
 		  	       $ctag->GetAtt('row'),
 		  	       $ctag->GetAtt('booktype'),
 		  	       $ctag->GetAtt('titlelen'),
 		  	       $ctag->GetAtt('orderby'),
 		  	       $catid,$this->BookID,
 		  	       $ctag->GetAtt('author'),0,
 		  	       $ctag->GetInnerText(),0,
 		  	       $ctag->GetAtt('imgwidth'),
 		  	       $ctag->GetAtt('imgheight')
 		  	    )
 		  	);
 		  }
 		  //指定记录的章节
 		  else if($tagname=='contentlist')
 		  {
 		  	$this->dtp->Assign($tagid,
 		  	    $this->GetBookList(
 		  	       $ctag->GetAtt('row'),
 		  	       $ctag->GetAtt('booktype'),
 		  	       $ctag->GetAtt('titlelen'),
 		  	       'lastpost',$ctag->GetAtt('catid'),0,
 		  	       '',1,$ctag->GetInnerText()
 		  	    )
 		  	);
 		 }
 		 else if($tagname=='prenext'){
 		  	$this->dtp->Assign($tagid, $this->GetPreNext($ctag->GetAtt('get')));
 		 }

 		 }//End Foreach
 	}


 	//---------------------
 	//解析动态标签
 	//即是指和页码相关的标记
 	//---------------------
 	function ParseDmFields($mtype,$pageno)
 	{
 		if(empty($pageno)) $this->PageNo = 1;
 	  else $this->PageNo=$pageno;
 	  $ctag = $this->dtp->GetTag('list');
 		//先处理 list 标记,因为这个标记包含统计信息
 		$this->dtp->AssignName('list',
 		  	  $this->GetBookList(
 		  	      0,
 		  	      $ctag->GetAtt('booktype'),
 		  	      $ctag->GetAtt('titlelen'),
 		  	      $ctag->GetAtt('orderby'),
 		  	      $this->CatalogID,0,'',-1,
 		  	      $ctag->GetInnerText(),
 		  	      $ctag->GetAtt('pagesize'),
 		  	      $ctag->GetAtt('imgwidth'),
 		  	      $ctag->GetAtt('imgheight')
 		  	  )
 		);

 		//其它动态标记
 	  foreach($this->dtp->CTags as $tagid=>$ctag)
 		{
 			 $tagname = $ctag->GetTagName();
 		   if($tagname=='pagelist'){
 		   	  if($mtype=='dm') $this->dtp->Assign($tagid,$this->GetPageListDM($ctag->GetAtt('listsize'),$ctag->GetAtt('listitem')) );
 		   }
 		}

 	}

 	//------------------
 	//生成HTML(仅图书,内容页因为考虑到收费图书问题,不生成HTML)
 	//$isclose 是是否关闭数据库,
 	//由于mysql每PHP进程只需关闭一次mysql连接,因此在批量更新HTML的时候此选项应该用 false
 	//------------------
 	function MakeHtml($isclose=true)
 	{
 	  global $cfg_basedir;
 	  $bookdir = GetBookUrl($this->Fields['id'],$this->Fields['bookname'],1);
 	  $bookurl = GetBookUrl($this->Fields['id'],$this->Fields['bookname']);
 	  if(!is_dir($cfg_basedir.$bookdir)) CreateDir($bookdir);
 	  $this->ParseTempletsFirst();
 	  $fp = fopen($cfg_basedir.$bookurl,'w');
 		fwrite($fp,$this->dtp->GetResult());
 		fclose($fp);
 		if($isclose) $this->Close();
 		//if($displaysucc) echo "<a href='{$bookurl}' target='_blank'>创建或更新'{$this->Fields['bookname']}'的HTML成功!</a><br />\r\n";
 		return $bookurl;
 	}

 	//------------------
 	//显示内容
 	//------------------
 	function Display()
 	{
 	  global $PageNo;
 	  $this->ParseTempletsFirst();
 	  if($this->InitType=='catalog' || $this->InitType=='search'){
 	     $this->ParseDmFields('dm',$PageNo);
 	  }
 		$this->dtp->Display();
 		$this->Close();
 	}

 	//------------------
 	//获得指定条件的图书列表
 	//-------------------
 	function GetBookList($num=12,$booktype='-1',$titlelen=24,$orderby='lastpost',$catid=0,$bookid=0,$author='',$getcontent=0,$innertext='',$pagesize=0,$imgwidth=90,$imgheight=110)
 	{
 		global $cfg_cmspath;
 		if(empty($num)) $num = 12;
 		if($booktype=='') $booktype = -1;
 		if(empty($titlelen)) $titlelen = 24;
 		if(empty($orderby)) $orderby = 'lastpost';
 		if(empty($bookid)) $bookid = 0;
 		$addquery = '';
 		if(empty($innertext)){
 			  //普通图书列表
 			  if($getcontent==0) $innertext = GetSysTemplets('book_booklist.htm');
 			  //分页图书列表
 			  else if($getcontent==-1) $innertext = GetSysTemplets('book_booklist_m.htm');
 			  //最新章节列表
 			  else $innertext = GetSysTemplets('book_contentlist.htm');
 		}
 		if($booktype!=-1) $addquery .= " And b.booktype='{$booktype}' ";
 		if($bookid>0) $addquery .= " And b.id<>'{$bookid}' ";
 		if($orderby=='commend'){
 			$addquery .= " And b.iscommend=1 ";
 			$orderby = 'lastpost';
 		}
 		if($catid>0){
 			$addquery .= " And (b.catid='$catid' Or b.bcatid='$catid') ";
 		}

 		//分页、搜索列表选项
 		if($getcontent==-1)
 		{
 		  if(empty($pagesize)) $this->PageSize = 20;
 		  else $this->PageSize = $pagesize;
 			$limitnum = ($this->PageSize * ($this->PageNo-1)).','.$this->PageSize;
 		}
 		else{
 			$limitnum = $num;
 		}

 		if(!empty($this->Keys['author'])) $author = $this->Keys['author'];

 		if(!empty($author)){
 			$addquery .= " And b.author like '$author' ";
 		}

 		//关键字条件
 		if(!empty($this->Keys['keyword'])){
 			$keywords = explode(' ',$this->Keys['keyword']);
 			$keywords = array_unique($keywords);
 			if(count($keywords)>0) $addquery .= " And (";
 			foreach($keywords as $v) $addquery .= " CONCAT(b.author,b.bookname,b.keywords) like '%$v%' OR";
 			$addquery = ereg_replace(" OR$","",$addquery);
 			$addquery .= ")";
 		}

 		$clist = '';
 		$query = "Select SQL_CALC_FOUND_ROWS b.id,b.catid,b.ischeck,b.booktype,b.iscommend,b.click,b.bookname,b.lastpost,
 		b.author,b.memberid,b.litpic,b.pubdate,b.weekcc,b.monthcc,b.description,c.classname,c.classname as typename,c.booktype as catalogtype
 		From #@__story_books b left join #@__story_catalog c on c.id=b.catid
 		where b.postnum>0 And b.ischeck>0 $addquery order by b.{$orderby} desc limit $limitnum";
 		$this->dsql->SetQuery($query);
 		$this->dsql->Execute();

 		//统计记录数
 		if($this->TotalResult==-1 && $getcontent==-1)
 		{
 		  $row = $this->dsql->GetOne("SELECT FOUND_ROWS() as dd ");
		  $this->TotalResult = $row['dd'];
		  $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
		}

 		$ndtp = new DedeTagParse();

⌨️ 快捷键说明

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