国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1016 lines
43KB

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