arc.sglistview.class.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. <?php if(!defined('DEDEINC'))exit('Request Error!');
  2. /**
  3. * 单表模型列表视图类
  4. *
  5. * @version $Id: arc.sglistview.class.php 1 15:48 2010年7月7日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. @set_time_limit(0);
  12. require_once(DEDEINC."/arc.partview.class.php");
  13. /**
  14. * 单表模型列表视图类
  15. *
  16. * @package SgListView
  17. * @subpackage DedeCMS.Libraries
  18. * @link http://www.dedecms.com
  19. */
  20. class SgListView
  21. {
  22. var $dsql;
  23. var $dtp;
  24. var $dtp2;
  25. var $TypeID;
  26. var $TypeLink;
  27. var $PageNo;
  28. var $TotalPage;
  29. var $TotalResult;
  30. var $PageSize;
  31. var $ChannelUnit;
  32. var $ListType;
  33. var $Fields;
  34. var $PartView;
  35. var $addSql;
  36. var $IsError;
  37. var $CrossID;
  38. var $IsReplace;
  39. var $AddTable;
  40. var $ListFields;
  41. var $searchArr;
  42. var $sAddTable;
  43. /**
  44. * php5构造函数
  45. *
  46. * @access public
  47. * @param int $typeid 栏目ID
  48. * @param array $searchArr 检索数组
  49. * @return void
  50. */
  51. function __construct($typeid,$searchArr=array())
  52. {
  53. global $dsql;
  54. $this->TypeID = $typeid;
  55. $this->dsql = $dsql;
  56. $this->CrossID = '';
  57. $this->IsReplace = false;
  58. $this->IsError = false;
  59. $this->dtp = new DedeTagParse();
  60. $this->dtp->SetRefObj($this);
  61. $this->sAddTable = false;
  62. $this->dtp->SetNameSpace("dede","{","}");
  63. $this->dtp2 = new DedeTagParse();
  64. $this->dtp2->SetNameSpace("field","[","]");
  65. $this->TypeLink = new TypeLink($typeid);
  66. $this->searchArr = $searchArr;
  67. if(!is_array($this->TypeLink->TypeInfos))
  68. {
  69. $this->IsError = true;
  70. }
  71. if(!$this->IsError)
  72. {
  73. $this->ChannelUnit = new ChannelUnit($this->TypeLink->TypeInfos['channeltype']);
  74. $this->Fields = $this->TypeLink->TypeInfos;
  75. $this->Fields['id'] = $typeid;
  76. $this->Fields['position'] = $this->TypeLink->GetPositionLink(true);
  77. $this->Fields['title'] = preg_replace("/[<>]/", " / ", $this->TypeLink->GetPositionLink(false));
  78. //获得附加表和列表字段信息
  79. $this->AddTable = $this->ChannelUnit->ChannelInfos['addtable'];
  80. $listfield = trim($this->ChannelUnit->ChannelInfos['listfields']);
  81. $this->ListFields = explode(',', $listfield);
  82. //设置一些全局参数的值
  83. foreach($GLOBALS['PubFields'] as $k=>$v) $this->Fields[$k] = $v;
  84. $this->Fields['rsslink'] = $GLOBALS['cfg_cmsurl']."/data/rss/".$this->TypeID.".xml";
  85. //设置环境变量
  86. SetSysEnv($this->TypeID,$this->Fields['typename'],0,'','list');
  87. $this->Fields['typeid'] = $this->TypeID;
  88. //获得交叉栏目ID
  89. if($this->TypeLink->TypeInfos['cross']>0 && $this->TypeLink->TypeInfos['ispart']==0)
  90. {
  91. $selquery = '';
  92. if($this->TypeLink->TypeInfos['cross']==1)
  93. {
  94. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$this->Fields['typename']}' AND id<>'{$this->TypeID}' AND topid<>'{$this->TypeID}' ";
  95. }
  96. else
  97. {
  98. $this->Fields['crossid'] = preg_replace("/[^0-9,]/", '', trim($this->Fields['crossid']));
  99. if($this->Fields['crossid']!='')
  100. {
  101. $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id IN({$this->Fields['crossid']}) AND id<>{$this->TypeID} AND topid<>{$this->TypeID} ";
  102. }
  103. }
  104. if($selquery!='')
  105. {
  106. $this->dsql->SetQuery($selquery);
  107. $this->dsql->Execute();
  108. while($arr = $this->dsql->GetArray())
  109. {
  110. $this->CrossID .= ($this->CrossID=='' ? $arr['id'] : ','.$arr['id']);
  111. }
  112. }
  113. }
  114. }//!error
  115. }
  116. //php4构造函数
  117. function SgListView($typeid,$searchArr=array()){
  118. $this->__construct($typeid,$searchArr);
  119. }
  120. //关闭相关资源
  121. function Close()
  122. {
  123. }
  124. /**
  125. * 统计列表里的记录
  126. *
  127. * @access public
  128. * @return void
  129. */
  130. function CountRecord()
  131. {
  132. global $cfg_list_son;
  133. //统计数据库记录
  134. $this->TotalResult = -1;
  135. if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
  136. if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
  137. else $this->PageNo = 1;
  138. $this->addSql = " arc.arcrank > -1 ";
  139. //栏目id条件
  140. if(!empty($this->TypeID))
  141. {
  142. if($cfg_list_son=='N')
  143. {
  144. if($this->CrossID=='') $this->addSql .= " AND (arc.typeid='".$this->TypeID."') ";
  145. else $this->addSql .= " AND (arc.typeid IN({$this->CrossID},{$this->TypeID})) ";
  146. }
  147. else
  148. {
  149. if($this->CrossID=='') $this->addSql .= " AND (arc.typeid IN (".GetSonIds($this->TypeID,$this->Fields['channeltype']).") ) ";
  150. else $this->addSql .= " AND (arc.typeid IN (".GetSonIds($this->TypeID,$this->Fields['channeltype']).",{$this->CrossID}) ) ";
  151. }
  152. }
  153. $naddQuery = '';
  154. //地区与信息类型条件
  155. if(count($this->searchArr) > 0)
  156. {
  157. if(!empty($this->searchArr['nativeplace']))
  158. {
  159. if($this->searchArr['nativeplace'] % 500 ==0 )
  160. {
  161. $naddQuery .= " AND arc.nativeplace >= '{$this->searchArr['nativeplace']}' AND arc.nativeplace < '".($this->searchArr['nativeplace']+500)."'";
  162. }
  163. else
  164. {
  165. $naddQuery .= "AND arc.nativeplace = '{$this->searchArr['nativeplace']}'";
  166. }
  167. }
  168. if(!empty($this->searchArr['infotype']))
  169. {
  170. if($this->searchArr['infotype'] % 500 ==0 )
  171. {
  172. $naddQuery .= " AND arc.infotype >= '{$this->searchArr['infotype']}' AND arc.infotype < '".($this->searchArr['infotype']+500)."'";
  173. }
  174. else
  175. {
  176. $naddQuery .= "AND arc.infotype = '{$this->searchArr['infotype']}'";
  177. }
  178. }
  179. if(!empty($this->searchArr['keyword']))
  180. {
  181. $naddQuery .= "AND arc.title like '%{$this->searchArr['keyword']}%' ";
  182. }
  183. }
  184. if($naddQuery!='')
  185. {
  186. $this->sAddTable = true;
  187. $this->addSql .= $naddQuery;
  188. }
  189. if($this->TotalResult==-1)
  190. {
  191. if($this->sAddTable)
  192. {
  193. $cquery = "SELECT COUNT(*) AS dd FROM `{$this->AddTable}` arc WHERE ".$this->addSql;
  194. }
  195. else
  196. {
  197. $cquery = "SELECT COUNT(*) AS dd FROM `#@__arctiny` arc WHERE ".$this->addSql;
  198. }
  199. $row = $this->dsql->GetOne($cquery);
  200. if(is_array($row))
  201. {
  202. $this->TotalResult = $row['dd'];
  203. }
  204. else
  205. {
  206. $this->TotalResult = 0;
  207. }
  208. }
  209. //初始化列表模板,并统计页面总数
  210. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
  211. $tempfile = str_replace("{tid}",$this->TypeID,$tempfile);
  212. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  213. if ( defined('DEDEMOB') )
  214. {
  215. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  216. }
  217. if(!file_exists($tempfile))
  218. {
  219. $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default_sg.htm";
  220. if ( defined('DEDEMOB') )
  221. {
  222. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  223. }
  224. }
  225. if(!file_exists($tempfile)||!is_file($tempfile))
  226. {
  227. echo "模板文件不存在,无法解析文档!";
  228. exit();
  229. }
  230. $this->dtp->LoadTemplate($tempfile);
  231. $ctag = $this->dtp->GetTag("page");
  232. if(!is_object($ctag))
  233. {
  234. $ctag = $this->dtp->GetTag("list");
  235. }
  236. if(!is_object($ctag))
  237. {
  238. $this->PageSize = 20;
  239. }
  240. else
  241. {
  242. if($ctag->GetAtt('pagesize')!='')
  243. {
  244. $this->PageSize = $ctag->GetAtt('pagesize');
  245. }
  246. else
  247. {
  248. $this->PageSize = 20;
  249. }
  250. }
  251. $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  252. }
  253. /**
  254. * 列表创建HTML
  255. *
  256. * @access public
  257. * @param string $startpage 开始页面
  258. * @param string $makepagesize 生成尺寸
  259. * @return string
  260. */
  261. function MakeHtml($startpage=1,$makepagesize=0)
  262. {
  263. if(empty($startpage))
  264. {
  265. $startpage = 1;
  266. }
  267. //创建封面模板文件
  268. if($this->TypeLink->TypeInfos['isdefault']==-1)
  269. {
  270. echo '这个类目是动态类目!';
  271. return '';
  272. }
  273. //单独页面
  274. else if($this->TypeLink->TypeInfos['ispart']>0)
  275. {
  276. $reurl = $this->MakePartTemplets();
  277. return $reurl;
  278. }
  279. if(empty($this->TotalResult)) $this->CountRecord();
  280. //初步给固定值的标记赋值
  281. $this->ParseTempletsFirst();
  282. $totalpage = ceil($this->TotalResult/$this->PageSize);
  283. if($totalpage==0)
  284. {
  285. $totalpage = 1;
  286. }
  287. CreateDir(MfTypedir($this->Fields['typedir']));
  288. $murl = '';
  289. if($makepagesize > 0)
  290. {
  291. $endpage = $startpage+$makepagesize;
  292. }
  293. else
  294. {
  295. $endpage = ($totalpage+1);
  296. }
  297. if( $endpage >= $totalpage+1 )
  298. {
  299. $endpage = $totalpage+1;
  300. }
  301. if($endpage==1)
  302. {
  303. $endpage = 2;
  304. }
  305. for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)
  306. {
  307. $this->ParseDMFields($this->PageNo,1);
  308. $makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
  309. $makeFile = str_replace("{page}",$this->PageNo,$makeFile);
  310. $murl = $makeFile;
  311. if(!preg_match("/^\//",$makeFile))
  312. {
  313. $makeFile = "/".$makeFile;
  314. }
  315. $makeFile = $this->GetTruePath().$makeFile;
  316. $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
  317. $murl = $this->GetTrueUrl($murl);
  318. $this->dtp->SaveTo($makeFile);
  319. }
  320. if($startpage==1)
  321. {
  322. //如果列表启用封面文件,复制这个文件第一页
  323. if($this->TypeLink->TypeInfos['isdefault']==1
  324. && $this->TypeLink->TypeInfos['ispart']==0)
  325. {
  326. $onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
  327. $onlyrule = str_replace("{page}","1",$onlyrule);
  328. $list_1 = $this->GetTruePath().$onlyrule;
  329. $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
  330. $indexname = $this->GetTruePath().$murl;
  331. copy($list_1,$indexname);
  332. }
  333. }
  334. return $murl;
  335. }
  336. /**
  337. * 显示列表
  338. *
  339. * @access public
  340. * @return void
  341. */
  342. function Display()
  343. {
  344. if($this->TypeLink->TypeInfos['ispart']>0 && count($this->searchArr)==0 )
  345. {
  346. $this->DisplayPartTemplets();
  347. return ;
  348. }
  349. $this->CountRecord();
  350. /*
  351. if((empty($this->PageNo) || $this->PageNo==1) && $this->TypeLink->TypeInfos['ispart']==1)
  352. {
  353. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  354. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  355. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  356. $tempfile = $tmpdir."/".$tempfile;
  357. if(!file_exists($tempfile))
  358. {
  359. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  360. }
  361. $this->dtp->LoadTemplate($tempfile);
  362. }
  363. */
  364. $this->ParseTempletsFirst();
  365. $this->ParseDMFields($this->PageNo,0);
  366. $this->dtp->Display();
  367. }
  368. /**
  369. * 创建单独模板页面
  370. *
  371. * @access public
  372. * @return string
  373. */
  374. function MakePartTemplets()
  375. {
  376. $this->PartView = new PartView($this->TypeID,false);
  377. $this->PartView->SetTypeLink($this->TypeLink);
  378. $nmfa = 0;
  379. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  380. if($this->Fields['ispart']==1)
  381. {
  382. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  383. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  384. $tempfile = $tmpdir."/".$tempfile;
  385. if ( defined('DEDEMOB') )
  386. {
  387. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  388. }
  389. if(!file_exists($tempfile))
  390. {
  391. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  392. if ( defined('DEDEMOB') )
  393. {
  394. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  395. }
  396. }
  397. $this->PartView->SetTemplet($tempfile);
  398. }
  399. else if($this->Fields['ispart']==2)
  400. {
  401. //跳转网址
  402. return $this->Fields['typedir'];
  403. }
  404. CreateDir(MfTypedir($this->Fields['typedir']));
  405. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  406. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  407. $makeFile = $this->GetTruePath().$makeUrl;
  408. if($nmfa==0)
  409. {
  410. $this->PartView->SaveToHtml($makeFile);
  411. }
  412. else
  413. {
  414. if(!file_exists($makeFile))
  415. {
  416. $this->PartView->SaveToHtml($makeFile);
  417. }
  418. }
  419. return $this->GetTrueUrl($makeUrl);
  420. }
  421. /**
  422. * 显示单独模板页面
  423. *
  424. * @access public
  425. * @return void
  426. */
  427. function DisplayPartTemplets()
  428. {
  429. $this->PartView = new PartView($this->TypeID,false);
  430. $this->PartView->SetTypeLink($this->TypeLink);
  431. $nmfa = 0;
  432. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  433. if($this->Fields['ispart']==1)
  434. {
  435. //封面模板
  436. $tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
  437. $tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
  438. $tempfile = $tmpdir."/".$tempfile;
  439. if ( defined('DEDEMOB') )
  440. {
  441. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  442. }
  443. if(!file_exists($tempfile))
  444. {
  445. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  446. if ( defined('DEDEMOB') )
  447. {
  448. $tempfile =str_replace('.htm','_m.htm',$tempfile);
  449. }
  450. }
  451. $this->PartView->SetTemplet($tempfile);
  452. }
  453. else if($this->Fields['ispart']==2)
  454. {
  455. //跳转网址
  456. $gotourl = $this->Fields['typedir'];
  457. header("Location:$gotourl");
  458. exit();
  459. }
  460. CreateDir(MfTypedir($this->Fields['typedir']));
  461. $makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
  462. $makeFile = $this->GetTruePath().$makeUrl;
  463. if($nmfa==0)
  464. {
  465. $this->PartView->Display();
  466. }
  467. else
  468. {
  469. if(!file_exists($makeFile))
  470. {
  471. $this->PartView->Display();
  472. }
  473. else
  474. {
  475. include($makeFile);
  476. }
  477. }
  478. }
  479. /**
  480. * 获得站点的真实根路径
  481. *
  482. * @access public
  483. * @return string
  484. */
  485. function GetTruePath()
  486. {
  487. $truepath = $GLOBALS["cfg_basedir"];
  488. return $truepath;
  489. }
  490. /**
  491. * 获得真实连接路径
  492. *
  493. * @access public
  494. * @param string $nurl 连接地址
  495. * @return string
  496. */
  497. function GetTrueUrl($nurl)
  498. {
  499. if(preg_match("/^http:\/\//", $nurl)) return $nurl;
  500. if($this->Fields['moresite']==1)
  501. {
  502. if($this->Fields['sitepath']!='')
  503. {
  504. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  505. }
  506. $nurl = $this->Fields['siteurl'].$nurl;
  507. }
  508. return $nurl;
  509. }
  510. /**
  511. * 解析模板,对固定的标记进行初始给值
  512. *
  513. * @access private
  514. * @return void
  515. */
  516. function ParseTempletsFirst()
  517. {
  518. if(isset($this->TypeLink->TypeInfos['reid']))
  519. {
  520. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  521. }
  522. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  523. $GLOBALS['envs']['typeid'] = $this->TypeID;
  524. $GLOBALS['envs']['cross'] = 1;
  525. MakeOneTag($this->dtp,$this);
  526. }
  527. /**
  528. * 解析模板,对内容里的变动进行赋值
  529. *
  530. * @access public
  531. * @param int $PageNo 页码
  532. * @param int $ismake 是否编译
  533. * @return void
  534. */
  535. function ParseDMFields($PageNo, $ismake=1)
  536. {
  537. //替换第二页后的内容
  538. if(($PageNo>1 || strlen($this->Fields['content'])<10 ) && !$this->IsReplace)
  539. {
  540. $this->dtp->SourceString = str_replace('[cmsreplace]','display:none',$this->dtp->SourceString);
  541. $this->IsReplace = true;
  542. }
  543. foreach($this->dtp->CTags as $tagid=>$ctag)
  544. {
  545. if($ctag->GetName()=="list")
  546. {
  547. $limitstart = ($this->PageNo-1) * $this->PageSize;
  548. $row = $this->PageSize;
  549. if(trim($ctag->GetInnerText())=="")
  550. {
  551. $InnerText = GetSysTemplets("list_fulllist.htm");
  552. }
  553. else
  554. {
  555. $InnerText = trim($ctag->GetInnerText());
  556. }
  557. $this->dtp->Assign($tagid,
  558. $this->GetArcList(
  559. $limitstart,
  560. $row,
  561. $ctag->GetAtt("col"),
  562. $ctag->GetAtt("titlelen"),
  563. $ctag->GetAtt("listtype"),
  564. $ctag->GetAtt("orderby"),
  565. $InnerText,
  566. $ctag->GetAtt("tablewidth"),
  567. $ismake,
  568. $ctag->GetAtt("orderway")
  569. )
  570. );
  571. }
  572. else if($ctag->GetName()=="pagelist")
  573. {
  574. $list_len = trim($ctag->GetAtt("listsize"));
  575. $ctag->GetAtt("listitem")=="" ? $listitem="index,pre,pageno,next,end,option" : $listitem=$ctag->GetAtt("listitem");
  576. if($list_len=="")
  577. {
  578. $list_len = 3;
  579. }
  580. if($ismake==0)
  581. {
  582. $this->dtp->Assign($tagid,$this->GetPageListDM($list_len,$listitem));
  583. }
  584. else
  585. {
  586. $this->dtp->Assign($tagid,$this->GetPageListST($list_len,$listitem));
  587. }
  588. }
  589. else if($PageNo!=1 && $ctag->GetName()=='field' && $ctag->GetAtt('display')!='')
  590. {
  591. $this->dtp->Assign($tagid,'');
  592. }
  593. }
  594. }
  595. /**
  596. * 获得要创建的文件名称规则
  597. *
  598. * @access public
  599. * @param string $typeid 栏目ID
  600. * @param string $wname
  601. * @param string $typedir 栏目目录
  602. * @param string $defaultname 默认名称
  603. * @param string $namerule2 名称规则
  604. * @return string
  605. */
  606. function GetMakeFileRule($typeid,$wname,$typedir,$defaultname,$namerule2)
  607. {
  608. $typedir = MfTypedir($typedir);
  609. if($wname=='index')
  610. {
  611. return $typedir.'/'.$defaultname;
  612. }
  613. else
  614. {
  615. $namerule2 = str_replace('{tid}',$typeid,$namerule2);
  616. $namerule2 = str_replace('{typedir}',$typedir,$namerule2);
  617. return $namerule2;
  618. }
  619. }
  620. /**
  621. * 获得一个单列的文档列表
  622. *
  623. * @access public
  624. * @param int $limitstart 限制开始
  625. * @param int $row 行数
  626. * @param int $col 列数
  627. * @param int $titlelen 标题长度
  628. * @param int $infolen 描述长度
  629. * @param int $imgwidth 图片宽度
  630. * @param int $imgheight 图片高度
  631. * @param string $listtype 列表类型
  632. * @param string $orderby 排列顺序
  633. * @param string $innertext 底层模板
  634. * @param string $tablewidth 表格宽度
  635. * @param string $ismake 是否编译
  636. * @param string $orderWay 排序方式
  637. * @return string
  638. */
  639. function GetArcList($limitstart=0,$row=10,$col=1,$titlelen=30,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')
  640. {
  641. global $cfg_list_son;
  642. $typeid=$this->TypeID;
  643. if($row=='') $row = 10;
  644. if($limitstart=='') $limitstart = 0;
  645. if($titlelen=='') $titlelen = 100;
  646. if($listtype=='') $listtype = "all";
  647. if($orderby=='') $orderby='id';
  648. else $orderby=strtolower($orderby);
  649. if($orderWay=='') $orderWay = 'desc';
  650. $tablewidth = str_replace("%", "", $tablewidth);
  651. if($tablewidth=='') $tablewidth=100;
  652. if($col=='') $col=1;
  653. $colWidth = ceil(100 / $col);
  654. $tablewidth = $tablewidth."%";
  655. $colWidth = $colWidth."%";
  656. $innertext = trim($innertext);
  657. if($innertext=='') $innertext = GetSysTemplets('list_sglist.htm');
  658. //排序方式
  659. $ordersql = '';
  660. if($orderby=='senddate'||$orderby=='id')
  661. {
  662. $ordersql=" ORDER BY arc.aid $orderWay";
  663. }
  664. else if($orderby=='hot'||$orderby=='click')
  665. {
  666. $ordersql = " ORDER BY arc.click $orderWay";
  667. }
  668. else
  669. {
  670. $ordersql=" ORDER BY arc.aid $orderWay";
  671. }
  672. $addField = 'arc.'.join(',arc.',$this->ListFields);
  673. //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
  674. if(preg_match('/hot|click/', $orderby) || $this->sAddTable)
  675. {
  676. $query = "SELECT tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,
  677. tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,arc.aid,arc.aid AS id,arc.typeid,
  678. $addField
  679. FROM `{$this->AddTable}` arc
  680. LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  681. WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row";
  682. }
  683. //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)
  684. else
  685. {
  686. $t1 = ExecTime();
  687. $ids = array();
  688. $nordersql = str_replace('.aid','.id',$ordersql);
  689. $query = "SELECT id From `#@__arctiny` arc WHERE {$this->addSql} $nordersql LIMIT $limitstart,$row ";
  690. $this->dsql->SetQuery($query);
  691. $this->dsql->Execute();
  692. while($arr=$this->dsql->GetArray())
  693. {
  694. $ids[] = $arr['id'];
  695. }
  696. $idstr = join(',',$ids);
  697. if($idstr=='')
  698. {
  699. return '';
  700. }
  701. else
  702. {
  703. $query = "SELECT tp.typedir,tp.typename,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,
  704. tp.ispart,tp.moresite,tp.siteurl,tp.sitepath,arc.aid,arc.aid AS id,arc.typeid,
  705. $addField
  706. FROM `{$this->AddTable}` arc LEFT JOIN `#@__arctype` tp ON arc.typeid=tp.id
  707. WHERE arc.aid IN($idstr) AND arc.arcrank >-1 $ordersql ";
  708. }
  709. $t2 = ExecTime();
  710. //echo $t2-$t1;
  711. }
  712. $this->dsql->SetQuery($query);
  713. $this->dsql->Execute('al');
  714. $t2 = ExecTime();
  715. //echo $t2-$t1;
  716. $artlist = '';
  717. $this->dtp2->LoadSource($innertext);
  718. $GLOBALS['autoindex'] = 0;
  719. for($i=0;$i<$row;$i++)
  720. {
  721. if($col>1)
  722. {
  723. $artlist .= "<div>\r\n";
  724. }
  725. for($j=0;$j<$col;$j++)
  726. {
  727. if($row = $this->dsql->GetArray("al"))
  728. {
  729. $GLOBALS['autoindex']++;
  730. $ids[$row['aid']] = $row['id']= $row['aid'];
  731. //处理一些特殊字段
  732. $row['ismake'] = 1;
  733. $row['money'] = 0;
  734. $row['arcrank'] = 0;
  735. $row['filename'] = '';
  736. $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
  737. $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  738. $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],
  739. $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
  740. if($row['litpic'] == '-' || $row['litpic'] == '')
  741. {
  742. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
  743. }
  744. // 解决安装子目录之后,之前存储在数据表图片路径不对的问题 by wengxianhu
  745. if(!preg_match("#^http:\/\/#i", $row['litpic']))
  746. {
  747. $pattern_tmp = str_replace('/', '\/', $GLOBALS['cfg_cmspath']);
  748. if (!preg_match("#^{$pattern_tmp}#i", $row['litpic'])) {
  749. $row['litpic'] = $GLOBALS['cfg_cmspath'].$row['litpic'];
  750. $row['litpic'] = str_replace('//', '/', $row['litpic']);
  751. }
  752. }
  753. if(!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
  754. {
  755. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  756. }
  757. $row['picname'] = $row['litpic'];
  758. $row['pubdate'] = $row['senddate'];
  759. $row['stime'] = GetDateMK($row['pubdate']);
  760. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  761. $row['fulltitle'] = $row['title'];
  762. $row['title'] = cn_substr($row['title'],$titlelen);
  763. if(preg_match('/b/', $row['flag']))
  764. {
  765. $row['title'] = "<b>".$row['title']."</b>";
  766. }
  767. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  768. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  769. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  770. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  771. //编译附加表里的数据
  772. foreach($row as $k=>$v) $row[strtolower($k)] = $v;
  773. foreach($this->ChannelUnit->ChannelFields as $k=>$arr)
  774. {
  775. if(isset($row[$k]))
  776. {
  777. $row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);
  778. }
  779. }
  780. if(is_array($this->dtp2->CTags))
  781. {
  782. foreach($this->dtp2->CTags as $k=>$ctag)
  783. {
  784. if($ctag->GetName()=='array')
  785. {
  786. //传递整个数组,在runphp模式中有特殊作用
  787. $this->dtp2->Assign($k,$row);
  788. }
  789. else
  790. {
  791. if(isset($row[$ctag->GetName()]))
  792. {
  793. $this->dtp2->Assign($k,$row[$ctag->GetName()]);
  794. }
  795. else
  796. {
  797. $this->dtp2->Assign($k,'');
  798. }
  799. }
  800. }
  801. }
  802. $artlist .= $this->dtp2->GetResult();
  803. }//if hasRow
  804. }//Loop Col
  805. if($col>1)
  806. {
  807. $i += $col - 1;
  808. $artlist .= " </div>\r\n";
  809. }
  810. }//Loop Line
  811. $t3 = ExecTime();
  812. //echo ($t3-$t2);
  813. $this->dsql->FreeResult('al');
  814. return $artlist;
  815. }
  816. /**
  817. * 获取静态的分页列表
  818. *
  819. * @access public
  820. * @param int $list_len 列表宽度
  821. * @param string $listitem 列表样式
  822. * @return string
  823. */
  824. function GetPageListST($list_len,$listitem="index,end,pre,next,pageno")
  825. {
  826. $prepage="";
  827. $nextpage="";
  828. $prepagenum = $this->PageNo-1;
  829. $nextpagenum = $this->PageNo+1;
  830. if($list_len=="" || preg_match("/[^0-9]/", $list_len))
  831. {
  832. $list_len=3;
  833. }
  834. $totalpage = ceil($this->TotalResult / $this->PageSize);
  835. if($totalpage <= 1 && $this->TotalResult > 0)
  836. {
  837. return "<span class=\"pageinfo\">共 <strong>1</strong>页<strong>".$this->TotalResult."</strong>条记录</span>";
  838. }
  839. if($this->TotalResult == 0)
  840. {
  841. return "<span class=\"pageinfo\">共 <strong>0</strong>页<strong>".$this->TotalResult."</strong>条记录</span>";
  842. }
  843. $purl = $this->GetCurUrl();
  844. $maininfo = "<span class=\"pageinfo\">共 <strong>{$totalpage}</strong>页<strong>".$this->TotalResult."</strong>条</span>";
  845. $tnamerule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], $this->Fields['defaultname'], $this->Fields['namerule2']);
  846. $tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
  847. //获得上一页和主页的链接
  848. if($this->PageNo != 1)
  849. {
  850. $prepage.="<li><a href='".str_replace("{page}", $prepagenum, $tnamerule)."'>上一页</a></li>\r\n";
  851. $indexpage="<li><a href='".str_replace("{page}", 1, $tnamerule)."'>首页</a></li>\r\n";
  852. }
  853. else
  854. {
  855. $indexpage="<li>首页</li>\r\n";
  856. }
  857. //下一页,未页的链接
  858. if($this->PageNo != $totalpage && $totalpage>1)
  859. {
  860. $nextpage.="<li><a href='".str_replace("{page}", $nextpagenum, $tnamerule)."'>下一页</a></li>\r\n";
  861. $endpage="<li><a href='".str_replace("{page}", $totalpage, $tnamerule)."'>末页</a></li>\r\n";
  862. }
  863. else
  864. {
  865. $endpage="<li>末页</li>";
  866. }
  867. //option链接
  868. $optionlist = "";
  869. /*
  870. $optionlen = strlen($totalpage);
  871. $optionlen = $optionlen*10+18;
  872. $optionlist = "<li><select name='sldd' style='width:{$optionlen}px' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  873. for($mjj=1;$mjj<=$totalpage;$mjj++)
  874. {
  875. if($mjj==$this->PageNo)
  876. {
  877. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."' selected>$mjj</option>\r\n";
  878. }
  879. else
  880. {
  881. $optionlist .= "<option value='".str_replace("{page}",$mjj,$tnamerule)."'>$mjj</option>\r\n";
  882. }
  883. }
  884. $optionlist .= "</select><li>";
  885. */
  886. //获得数字链接
  887. $listdd = "";
  888. $total_list = $list_len * 2 + 1;
  889. if($this->PageNo >= $total_list)
  890. {
  891. $j = $this->PageNo - $list_len;
  892. $total_list = $this->PageNo + $list_len;
  893. if($total_list > $totalpage)
  894. {
  895. $total_list = $totalpage;
  896. }
  897. }
  898. else
  899. {
  900. $j=1;
  901. if($total_list > $totalpage)
  902. {
  903. $total_list = $totalpage;
  904. }
  905. }
  906. for($j; $j <= $total_list; $j++)
  907. {
  908. if($j == $this->PageNo)
  909. {
  910. $listdd.= "<li class=\"thisclass\">$j</li>\r\n";
  911. }
  912. else
  913. {
  914. $listdd.="<li><a href='".str_replace("{page}", $j, $tnamerule)."'>".$j."</a></li>\r\n";
  915. }
  916. }
  917. $plist = "";
  918. if(preg_match('/info/i', $listitem))
  919. {
  920. $plist .= $maininfo.' ';
  921. }
  922. if(preg_match('/index/i', $listitem))
  923. {
  924. $plist .= $indexpage.' ';
  925. }
  926. if(preg_match('/pre/i', $listitem))
  927. {
  928. $plist .= $prepage.' ';
  929. }
  930. if(preg_match('/pageno/i', $listitem))
  931. {
  932. $plist .= $listdd.' ';
  933. }
  934. if(preg_match('/next/i', $listitem))
  935. {
  936. $plist .= $nextpage.' ';
  937. }
  938. if(preg_match('/end/i', $listitem))
  939. {
  940. $plist .= $endpage.' ';
  941. }
  942. if(preg_match('/option/i', $listitem))
  943. {
  944. $plist .= $optionlist;
  945. }
  946. return $plist;
  947. }
  948. /**
  949. * 获取动态的分页列表
  950. *
  951. * @access public
  952. * @param int $list_len 列表宽度
  953. * @param string $listitem 列表样式
  954. * @return string
  955. */
  956. function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")
  957. {
  958. global $nativeplace,$infotype,$keyword;
  959. if(empty($nativeplace)) $nativeplace = 0;
  960. if(empty($infotype)) $infotype = 0;
  961. if(empty($keyword)) $keyword = '';
  962. $prepage = $nextpage = '';
  963. $prepagenum = $this->PageNo - 1;
  964. $nextpagenum = $this->PageNo + 1;
  965. if($list_len=="" || preg_match("/[^0-9]/", $list_len))
  966. {
  967. $list_len=3;
  968. }
  969. $totalpage = ceil($this->TotalResult / $this->PageSize);
  970. if($totalpage<=1 && $this->TotalResult>0)
  971. {
  972. return "<span class=\"pageinfo\">共1页/".$this->TotalResult."条记录</span>";
  973. }
  974. if($this->TotalResult == 0)
  975. {
  976. return "<span class=\"pageinfo\">共0页/".$this->TotalResult."条记录</span>";
  977. }
  978. $purl = $this->GetCurUrl();
  979. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&";
  980. $hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n";
  981. $hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n";
  982. $hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n";
  983. $hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n";
  984. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
  985. $purl .= "?".$geturl;
  986. //获得上一页和下一页的链接
  987. if($this->PageNo != 1)
  988. {
  989. $prepage.="<li><a href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  990. $indexpage="<li><a href='".$purl."PageNo=1'>首页</a></li>\r\n";
  991. }
  992. else
  993. {
  994. $indexpage="<li><a>首页</a></li>\r\n";
  995. }
  996. if($this->PageNo!=$totalpage && $totalpage>1)
  997. {
  998. $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  999. $endpage="<li><a href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  1000. }
  1001. else
  1002. {
  1003. $endpage="<li><a>末页</a></li>";
  1004. }
  1005. //获得数字链接
  1006. $listdd="";
  1007. $total_list = $list_len * 2 + 1;
  1008. if($this->PageNo >= $total_list)
  1009. {
  1010. $j = $this->PageNo - $list_len;
  1011. $total_list = $this->PageNo + $list_len;
  1012. if($total_list > $totalpage)
  1013. {
  1014. $total_list = $totalpage;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. $j=1;
  1020. if($total_list > $totalpage)
  1021. {
  1022. $total_list = $totalpage;
  1023. }
  1024. }
  1025. for($j; $j <= $total_list; $j++)
  1026. {
  1027. if($j == $this->PageNo)
  1028. {
  1029. $listdd.= "<li class=\"thisclass\"><a>$j</a></li>\r\n";
  1030. }
  1031. else
  1032. {
  1033. $listdd.="<li><a href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  1034. }
  1035. }
  1036. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  1037. return $plist;
  1038. }
  1039. /**
  1040. * 获得当前的页面文件的url
  1041. *
  1042. * @access private
  1043. * @return string
  1044. */
  1045. function GetCurUrl()
  1046. {
  1047. if(!empty($_SERVER["REQUEST_URI"]))
  1048. {
  1049. $nowurl = $_SERVER["REQUEST_URI"];
  1050. $nowurls = explode("?",$nowurl);
  1051. $nowurl = $nowurls[0];
  1052. }
  1053. else
  1054. {
  1055. $nowurl = $_SERVER["PHP_SELF"];
  1056. }
  1057. return $nowurl;
  1058. }
  1059. }//End Class