国内流行的内容管理系统(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.

1015 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 "栏目:{$this->TypeLink->TypeInfos['typename']},主题模板文件不存在,无法更新栏目";
  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. return '../apps/list.php?tid='.$this->TypeLink->TypeInfos['id'];
  251. }
  252. //单独页面
  253. else if ($this->TypeLink->TypeInfos['ispart'] > 0) {
  254. $reurl = $this->MakePartTemplets();
  255. return $reurl;
  256. }
  257. if (empty($this->TotalResult)) $this->CountRecord();
  258. //初步给固定值的标记赋值
  259. $this->ParseTempletsFirst();
  260. $totalpage = ceil($this->TotalResult / $this->pagesize);
  261. if ($totalpage == 0) {
  262. $totalpage = 1;
  263. }
  264. CreateDir(MfTypedir($this->Fields['typedir']));
  265. $murl = '';
  266. if ($makepagesize > 0) {
  267. $endpage = $startpage + $makepagesize;
  268. } else {
  269. $endpage = ($totalpage + 1);
  270. }
  271. if ($endpage >= $totalpage + 1) {
  272. $endpage = $totalpage + 1;
  273. }
  274. if ($endpage == 1) {
  275. $endpage = 2;
  276. }
  277. for ($this->PageNo = $startpage; $this->PageNo < $endpage; $this->PageNo++) {
  278. $this->ParseDMFields($this->PageNo, 1);
  279. $makeFile = $this->GetMakeFileRule($this->Fields['id'], 'list', $this->Fields['typedir'], '', $this->Fields['namerule2']);
  280. $makeFile = str_replace("{page}", $this->PageNo, $makeFile);
  281. $murl = $makeFile;
  282. if (!preg_match("/^\//", $makeFile)) {
  283. $makeFile = "/".$makeFile;
  284. }
  285. $makeFile = $this->GetTruePath().$makeFile;
  286. $makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
  287. $murl = $this->GetTrueUrl($murl);
  288. $this->dtp->SaveTo($makeFile);
  289. if (PHP_SAPI === 'cli') {
  290. DedeCli::showProgress(ceil(($this->PageNo / $endpage) * 100), 100);
  291. }
  292. }
  293. if ($startpage == 1) {
  294. //如果列表启用封面文件,复制这个文件第一页
  295. if (
  296. $this->TypeLink->TypeInfos['isdefault'] == 1
  297. && $this->TypeLink->TypeInfos['ispart'] == 0
  298. ) {
  299. $onlyrule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], '', $this->Fields['namerule2']);
  300. $onlyrule = str_replace("{page}", "1", $onlyrule);
  301. $list_1 = $this->GetTruePath().$onlyrule;
  302. $murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
  303. $indexname = $this->GetTruePath().$murl;
  304. copy($list_1, $indexname);
  305. }
  306. }
  307. return $murl;
  308. }
  309. /**
  310. * 显示列表
  311. *
  312. * @access public
  313. * @return void
  314. */
  315. function Display()
  316. {
  317. if ($this->mod === 0) {
  318. if ($this->TypeLink->TypeInfos['ispart'] > 0 && count($this->searchArr) == 0) {
  319. $this->DisplayPartTemplets();
  320. return;
  321. }
  322. $this->CountRecord();
  323. $this->ParseTempletsFirst();
  324. $this->ParseDMFields($this->PageNo, 0);
  325. $this->dtp->Display();
  326. } else {
  327. $this->CountRecord();
  328. $result = $this->GetAPIList($this->PageNo,$this->pagesize);
  329. if (!is_array($result)) {
  330. echo json_encode(array(
  331. "code" => -1,
  332. "msg" => "none result",
  333. ));
  334. } else {
  335. echo json_encode(array(
  336. "code" => 0,
  337. "msg" => "",
  338. "lists" => $result,
  339. "total" => intval($this->TotalResult),
  340. ));
  341. }
  342. }
  343. }
  344. /**
  345. * GetAPIList
  346. *
  347. * @param mixed $PageNo 页码
  348. * @param mixed $row 行数
  349. * @param mixed $titlelen 标题宽度
  350. * @param mixed $orderby 排序
  351. * @param mixed $orderWay 排序方式
  352. * @return void
  353. */
  354. function GetAPIList($PageNo, $row = 10, $titlelen = 30, $orderby = "default", $orderWay = 'desc')
  355. {
  356. $limitstart = ($PageNo - 1) * $row;
  357. if ($titlelen == '') $titlelen = 100;
  358. if ($orderby == '') $orderby = 'id';
  359. else $orderby = strtolower($orderby);
  360. if ($orderWay == '') $orderWay = 'desc';
  361. //排序方式
  362. $ordersql = '';
  363. if ($orderby == 'senddate' || $orderby == 'id') {
  364. $ordersql = " ORDER BY arc.aid $orderWay";
  365. } else if ($orderby == 'hot' || $orderby == 'click') {
  366. $ordersql = " ORDER BY arc.click $orderWay";
  367. } else {
  368. $ordersql = " ORDER BY arc.aid $orderWay";
  369. }
  370. $addField = 'arc.'.join(',arc.', $this->ListFields);
  371. //如果不用默认的sortrank或id排序,使用联合查询数据量大时非常缓慢
  372. if (preg_match('/hot|click/', $orderby) || $this->sAddTable) {
  373. $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";
  374. }
  375. //普通情况先从arctiny表查出id,然后按id查询速度非常快
  376. else {
  377. $t1 = ExecTime();
  378. $ids = array();
  379. $nordersql = str_replace('.aid', '.id', $ordersql);
  380. $query = "SELECT id FROM `#@__arctiny` arc WHERE {$this->addSql} $nordersql LIMIT $limitstart,$row";
  381. $this->dsql->SetQuery($query);
  382. $this->dsql->Execute();
  383. while ($arr = $this->dsql->GetArray()) {
  384. $ids[] = $arr['id'];
  385. }
  386. $idstr = join(',', $ids);
  387. if ($idstr == '') {
  388. return '';
  389. } else {
  390. $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";
  391. }
  392. $t2 = ExecTime();
  393. }
  394. $this->dsql->SetQuery($query);
  395. $this->dsql->Execute('al');
  396. $t2 = ExecTime();
  397. $GLOBALS['autoindex'] = 0;
  398. $result = array();
  399. while ($row = $this->dsql->GetArray("al")) {
  400. $GLOBALS['autoindex']++;
  401. $ids[$row['aid']] = $row['id'] = $row['aid'];
  402. //处理一些特殊字段
  403. $row['ismake'] = 1;
  404. $row['money'] = 0;
  405. $row['arcrank'] = 0;
  406. $row['filename'] = '';
  407. $row['filename'] = $row['arcurl'] = GetFileUrl(
  408. $row['id'],
  409. $row['typeid'],
  410. $row['senddate'],
  411. $row['title'],
  412. $row['ismake'],
  413. $row['arcrank'],
  414. $row['namerule'],
  415. $row['typedir'],
  416. $row['money'],
  417. $row['filename'],
  418. $row['moresite'],
  419. $row['siteurl'],
  420. $row['sitepath']
  421. );
  422. $row['typeurl'] = GetTypeUrl(
  423. $row['typeid'],
  424. MfTypedir($row['typedir']),
  425. $row['isdefault'],
  426. $row['defaultname'],
  427. $row['ispart'],
  428. $row['namerule2'],
  429. $row['moresite'],
  430. $row['siteurl'],
  431. $row['sitepath']
  432. );
  433. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  434. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  435. }
  436. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  437. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  438. }
  439. $row['picname'] = $row['litpic'];
  440. $row['pubdate'] = $row['senddate'];
  441. $row['stime'] = GetDateMK($row['pubdate']);
  442. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  443. $row['fulltitle'] = $row['title'];
  444. $row['title'] = cn_substr($row['title'], $titlelen);
  445. if (preg_match('/b/', $row['flag'])) {
  446. $row['title'] = "".$row['title']."";
  447. }
  448. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  449. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  450. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  451. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  452. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  453. //编译附加表里的数据
  454. foreach ($row as $k => $v) $row[strtolower($k)] = $v;
  455. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  456. if (isset($row[$k])) {
  457. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  458. }
  459. }
  460. $result[] = $row;
  461. } //if hasRow
  462. $t3 = ExecTime();
  463. $this->dsql->FreeResult('al');
  464. return $result;
  465. }
  466. /**
  467. * 创建单独模板页面
  468. *
  469. * @access public
  470. * @return string
  471. */
  472. function MakePartTemplets()
  473. {
  474. $this->PartView = new PartView($this->TypeID, false);
  475. $this->PartView->SetTypeLink($this->TypeLink);
  476. $nmfa = 0;
  477. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  478. if ($this->Fields['ispart'] == 1) {
  479. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  480. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  481. $tempfile = $tmpdir."/".$tempfile;
  482. if (!file_exists($tempfile)) {
  483. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  484. }
  485. $this->PartView->SetTemplet($tempfile);
  486. } else if ($this->Fields['ispart'] == 2) {
  487. //跳转网址
  488. return $this->Fields['typedir'];
  489. }
  490. CreateDir(MfTypedir($this->Fields['typedir']));
  491. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  492. $makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
  493. $makeFile = $this->GetTruePath().$makeUrl;
  494. if ($nmfa == 0) {
  495. $this->PartView->SaveToHtml($makeFile);
  496. } else {
  497. if (!file_exists($makeFile)) {
  498. $this->PartView->SaveToHtml($makeFile);
  499. }
  500. }
  501. return $this->GetTrueUrl($makeUrl);
  502. }
  503. /**
  504. * 显示单独模板页面
  505. *
  506. * @access public
  507. * @return void
  508. */
  509. function DisplayPartTemplets()
  510. {
  511. $this->PartView = new PartView($this->TypeID, false);
  512. $this->PartView->SetTypeLink($this->TypeLink);
  513. $nmfa = 0;
  514. $tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
  515. if ($this->Fields['ispart'] == 1) {
  516. //封面模板
  517. $tempfile = str_replace("{tid}", $this->TypeID, $this->Fields['tempindex']);
  518. $tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
  519. $tempfile = $tmpdir."/".$tempfile;
  520. if (!file_exists($tempfile)) {
  521. $tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
  522. }
  523. $this->PartView->SetTemplet($tempfile);
  524. } else if ($this->Fields['ispart'] == 2) {
  525. //跳转网址
  526. $gotourl = $this->Fields['typedir'];
  527. header("Location:$gotourl");
  528. exit();
  529. }
  530. CreateDir(MfTypedir($this->Fields['typedir']));
  531. $makeUrl = $this->GetMakeFileRule($this->Fields['id'], "index", MfTypedir($this->Fields['typedir']), $this->Fields['defaultname'], $this->Fields['namerule2']);
  532. $makeFile = $this->GetTruePath().$makeUrl;
  533. if ($nmfa == 0) {
  534. $this->PartView->Display();
  535. } else {
  536. if (!file_exists($makeFile)) {
  537. $this->PartView->Display();
  538. } else {
  539. include($makeFile);
  540. }
  541. }
  542. }
  543. /**
  544. * 获得站点的真实根路径
  545. *
  546. * @access public
  547. * @return string
  548. */
  549. function GetTruePath()
  550. {
  551. $truepath = $GLOBALS["cfg_basedir"];
  552. return $truepath;
  553. }
  554. /**
  555. * 获得真实连接路径
  556. *
  557. * @access public
  558. * @param string $nurl 连接地址
  559. * @return string
  560. */
  561. function GetTrueUrl($nurl)
  562. {
  563. if (preg_match("/^http[s]?:\/\//", $nurl)) return $nurl;
  564. if ($this->Fields['moresite'] == 1) {
  565. if ($this->Fields['sitepath'] != '') {
  566. $nurl = preg_replace("/^".$this->Fields['sitepath']."/", '', $nurl);
  567. }
  568. $nurl = $this->Fields['siteurl'].$nurl;
  569. }
  570. return $nurl;
  571. }
  572. /**
  573. * 解析模板,对固定的标记进行初始给值
  574. *
  575. * @access private
  576. * @return void
  577. */
  578. function ParseTempletsFirst()
  579. {
  580. if (isset($this->TypeLink->TypeInfos['reid'])) {
  581. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  582. }
  583. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  584. $GLOBALS['envs']['typeid'] = $this->TypeID;
  585. $GLOBALS['envs']['cross'] = 1;
  586. MakeOneTag($this->dtp, $this);
  587. }
  588. /**
  589. * 解析模板,对文档里的变动进行赋值
  590. *
  591. * @access public
  592. * @param int $PageNo 页码
  593. * @param int $ismake 是否编译
  594. * @return void
  595. */
  596. function ParseDMFields($PageNo, $ismake = 1)
  597. {
  598. //替换第二页后的文档
  599. if (($PageNo > 1 || strlen($this->Fields['content']) < 10) && !$this->IsReplace) {
  600. $this->dtp->SourceString = str_replace('[cmsreplace]', 'display:none', $this->dtp->SourceString);
  601. $this->IsReplace = true;
  602. }
  603. foreach ($this->dtp->CTags as $tagid => $ctag) {
  604. if ($ctag->GetName() == "list") {
  605. $limitstart = ($this->PageNo - 1) * $this->pagesize;
  606. $row = $this->pagesize;
  607. if (trim($ctag->GetInnerText()) == "") {
  608. $InnerText = GetSysTemplets("list_fulllist.htm");
  609. } else {
  610. $InnerText = trim($ctag->GetInnerText());
  611. }
  612. $this->dtp->Assign(
  613. $tagid,
  614. $this->GetArcList(
  615. $limitstart,
  616. $row,
  617. $ctag->GetAtt("col"),
  618. $ctag->GetAtt("titlelen"),
  619. $ctag->GetAtt("listtype"),
  620. $ctag->GetAtt("orderby"),
  621. $InnerText,
  622. $ctag->GetAtt("tablewidth"),
  623. $ismake,
  624. $ctag->GetAtt("orderway")
  625. )
  626. );
  627. } else if ($ctag->GetName() == "pagelist") {
  628. $list_len = trim($ctag->GetAtt("listsize"));
  629. $ctag->GetAtt("listitem") == "" ? $listitem = "index,pre,pageno,next,end,option" : $listitem = $ctag->GetAtt("listitem");
  630. if ($list_len == "") {
  631. $list_len = 3;
  632. }
  633. if ($ismake == 0) {
  634. $this->dtp->Assign($tagid, $this->GetPageListDM($list_len, $listitem));
  635. } else {
  636. $this->dtp->Assign($tagid, $this->GetPageListST($list_len, $listitem));
  637. }
  638. } else if ($PageNo != 1 && $ctag->GetName() == 'field' && $ctag->GetAtt('display') != '') {
  639. $this->dtp->Assign($tagid, '');
  640. }
  641. }
  642. }
  643. /**
  644. * 获得要创建的文件名称规则
  645. *
  646. * @access public
  647. * @param string $typeid 栏目id
  648. * @param string $wname
  649. * @param string $typedir 栏目目录
  650. * @param string $defaultname 默认名称
  651. * @param string $namerule2 名称规则
  652. * @return string
  653. */
  654. function GetMakeFileRule($typeid, $wname, $typedir, $defaultname, $namerule2)
  655. {
  656. $typedir = MfTypedir($typedir);
  657. if ($wname == 'index') {
  658. return $typedir.'/'.$defaultname;
  659. } else {
  660. $namerule2 = str_replace('{tid}', $typeid, $namerule2);
  661. $namerule2 = str_replace('{typedir}', $typedir, $namerule2);
  662. return $namerule2;
  663. }
  664. }
  665. /**
  666. * 获得一个单列的文档列表
  667. *
  668. * @access public
  669. * @param int $limitstart 限制开始
  670. * @param int $row 行数
  671. * @param int $col 列数
  672. * @param int $titlelen 标题长度
  673. * @param int $infolen 描述长度
  674. * @param int $imgwidth 图片宽度
  675. * @param int $imgheight 图片高度
  676. * @param string $listtype 列表类型
  677. * @param string $orderby 排列顺序
  678. * @param string $innertext 底层模板
  679. * @param string $tablewidth 表格宽度
  680. * @param string $ismake 是否编译
  681. * @param string $orderWay 排序方式
  682. * @return string
  683. */
  684. function GetArcList($limitstart = 0, $row = 10, $col = 1, $titlelen = 30, $listtype = "all", $orderby = "default", $innertext = "", $tablewidth = "100", $ismake = 1, $orderWay = 'desc')
  685. {
  686. global $cfg_list_son;
  687. $typeid = $this->TypeID;
  688. if ($row == '') $row = 10;
  689. if ($limitstart == '') $limitstart = 0;
  690. if ($titlelen == '') $titlelen = 100;
  691. if ($listtype == '') $listtype = "all";
  692. if ($orderby == '') $orderby = 'id';
  693. else $orderby = strtolower($orderby);
  694. if ($orderWay == '') $orderWay = 'desc';
  695. $tablewidth = str_replace("%", "", $tablewidth);
  696. if ($tablewidth == '') $tablewidth = 100;
  697. if ($col == '') $col = 1;
  698. $colWidth = ceil(100 / $col);
  699. $tablewidth = $tablewidth."%";
  700. $colWidth = $colWidth."%";
  701. $innertext = trim($innertext);
  702. if ($innertext == '') $innertext = GetSysTemplets('list_sglist.htm');
  703. //排序方式
  704. $ordersql = '';
  705. if ($orderby == 'senddate' || $orderby == 'id') {
  706. $ordersql = " ORDER BY arc.aid $orderWay";
  707. } else if ($orderby == 'hot' || $orderby == 'click') {
  708. $ordersql = " ORDER BY arc.click $orderWay";
  709. } else {
  710. $ordersql = " ORDER BY arc.aid $orderWay";
  711. }
  712. $addField = 'arc.'.join(',arc.', $this->ListFields);
  713. //如果不用默认的sortrank或id排序,使用联合查询数据量大时非常缓慢
  714. if (preg_match('/hot|click/', $orderby) || $this->sAddTable) {
  715. $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";
  716. }
  717. //普通情况先从arctiny表查出id,然后按id查询速度非常快
  718. else {
  719. $t1 = ExecTime();
  720. $ids = array();
  721. $nordersql = str_replace('.aid', '.id', $ordersql);
  722. $query = "SELECT id FROM `#@__arctiny` arc WHERE {$this->addSql} $nordersql LIMIT $limitstart,$row";
  723. $this->dsql->SetQuery($query);
  724. $this->dsql->Execute();
  725. while ($arr = $this->dsql->GetArray()) {
  726. $ids[] = $arr['id'];
  727. }
  728. $idstr = join(',', $ids);
  729. if ($idstr == '') {
  730. return '';
  731. } else {
  732. $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";
  733. }
  734. $t2 = ExecTime();
  735. }
  736. $this->dsql->SetQuery($query);
  737. $this->dsql->Execute('al');
  738. $t2 = ExecTime();
  739. $artlist = '';
  740. $this->dtp2->LoadSource($innertext);
  741. $GLOBALS['autoindex'] = 0;
  742. for ($i = 0; $i < $row; $i++) {
  743. if ($col > 1) {
  744. $artlist .= "<div>\r\n";
  745. }
  746. for ($j = 0; $j < $col; $j++) {
  747. if ($row = $this->dsql->GetArray("al")) {
  748. $GLOBALS['autoindex']++;
  749. $ids[$row['aid']] = $row['id'] = $row['aid'];
  750. //处理一些特殊字段
  751. $row['ismake'] = 1;
  752. $row['money'] = 0;
  753. $row['arcrank'] = 0;
  754. $row['filename'] = '';
  755. $row['filename'] = $row['arcurl'] = GetFileUrl(
  756. $row['id'],
  757. $row['typeid'],
  758. $row['senddate'],
  759. $row['title'],
  760. $row['ismake'],
  761. $row['arcrank'],
  762. $row['namerule'],
  763. $row['typedir'],
  764. $row['money'],
  765. $row['filename'],
  766. $row['moresite'],
  767. $row['siteurl'],
  768. $row['sitepath']
  769. );
  770. $row['typeurl'] = GetTypeUrl(
  771. $row['typeid'],
  772. MfTypedir($row['typedir']),
  773. $row['isdefault'],
  774. $row['defaultname'],
  775. $row['ispart'],
  776. $row['namerule2'],
  777. $row['moresite'],
  778. $row['siteurl'],
  779. $row['sitepath']
  780. );
  781. if ($row['litpic'] == '-' || $row['litpic'] == '') {
  782. $row['litpic'] = $GLOBALS['cfg_cmspath'].'/static/web/img/thumbnail.jpg';
  783. }
  784. if (!preg_match("/^http:\/\//", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  785. $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
  786. }
  787. $row['picname'] = $row['litpic'];
  788. $row['pubdate'] = $row['senddate'];
  789. $row['stime'] = GetDateMK($row['pubdate']);
  790. $row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
  791. $row['fulltitle'] = $row['title'];
  792. $row['title'] = cn_substr($row['title'], $titlelen);
  793. if (preg_match('/b/', $row['flag'])) {
  794. $row['title'] = "".$row['title']."";
  795. }
  796. $row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
  797. $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
  798. $row['memberurl'] = $GLOBALS['cfg_memberurl'];
  799. $row['templeturl'] = $GLOBALS['cfg_templeturl'];
  800. $row['face'] = empty($row['face'])? $GLOBALS['cfg_mainsite'].'/static/web/img/admin.png' : $row['face'];
  801. //编译附加表里的数据
  802. foreach ($row as $k => $v) $row[strtolower($k)] = $v;
  803. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  804. if (isset($row[$k])) {
  805. $row[$k] = $this->ChannelUnit->MakeField($k, $row[$k]);
  806. }
  807. }
  808. if (is_array($this->dtp2->CTags)) {
  809. foreach ($this->dtp2->CTags as $k => $ctag) {
  810. if ($ctag->GetName() == 'array') {
  811. //传递整个数组,在runphp模式中有特殊作用
  812. $this->dtp2->Assign($k, $row);
  813. } else {
  814. if (isset($row[$ctag->GetName()])) {
  815. $this->dtp2->Assign($k, $row[$ctag->GetName()]);
  816. } else {
  817. $this->dtp2->Assign($k, '');
  818. }
  819. }
  820. }
  821. }
  822. $artlist .= $this->dtp2->GetResult();
  823. } //if hasRow
  824. }//Loop Col
  825. if ($col > 1) {
  826. $i += $col - 1;
  827. $artlist .= "</div>\r\n";
  828. }
  829. }//Loop Line
  830. $t3 = ExecTime();
  831. $this->dsql->FreeResult('al');
  832. return $artlist;
  833. }
  834. /**
  835. * 获取静态的分页列表
  836. *
  837. * @access public
  838. * @param int $list_len 列表宽度
  839. * @param string $listitem 列表样式
  840. * @return string
  841. */
  842. function GetPageListST($list_len, $listitem = "index,end,pre,next,pageno")
  843. {
  844. $prepage = "";
  845. $nextpage = "";
  846. $prepagenum = $this->PageNo - 1;
  847. $nextpagenum = $this->PageNo + 1;
  848. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  849. $list_len = 3;
  850. }
  851. $totalpage = ceil($this->TotalResult / $this->pagesize);
  852. if ($totalpage <= 1 && $this->TotalResult > 0) {
  853. return "<li class='page-item disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>";
  854. }
  855. if ($this->TotalResult == 0) {
  856. return "<li class='page-item disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>";
  857. }
  858. $purl = $this->GetCurUrl();
  859. $maininfo = "<li class='page-item disabled'><span class='page-link'>{$totalpage}页".$this->TotalResult."条</span></li>";
  860. $tnamerule = $this->GetMakeFileRule($this->Fields['id'], "list", $this->Fields['typedir'], $this->Fields['defaultname'], $this->Fields['namerule2']);
  861. $tnamerule = preg_replace("/^(.*)\//", '', $tnamerule);
  862. //获得上一页和首页的链接
  863. if ($this->PageNo != 1) {
  864. $prepage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $prepagenum, $tnamerule)."'>上一页</a></li>\r\n";
  865. $indexpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", 1, $tnamerule)."'>首页</a></li>\r\n";
  866. } else {
  867. $indexpage = "<li class='page-item'>首页</li>\r\n";
  868. }
  869. //下一页和未页的链接
  870. if ($this->PageNo != $totalpage && $totalpage > 1) {
  871. $nextpage .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $nextpagenum, $tnamerule)."'>下一页</a></li>\r\n";
  872. $endpage = "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $totalpage, $tnamerule)."'>末页</a></li>\r\n";
  873. } else {
  874. $endpage = "<li class='page-item'><a class='page-link'>末页</a></li>";
  875. }
  876. //option链接
  877. $optionlist = "";
  878. //获得数字链接
  879. $listdd = "";
  880. $total_list = $list_len * 2 + 1;
  881. if ($this->PageNo >= $total_list) {
  882. $j = $this->PageNo - $list_len;
  883. $total_list = $this->PageNo + $list_len;
  884. if ($total_list > $totalpage) {
  885. $total_list = $totalpage;
  886. }
  887. } else {
  888. $j = 1;
  889. if ($total_list > $totalpage) {
  890. $total_list = $totalpage;
  891. }
  892. }
  893. for ($j; $j <= $total_list; $j++) {
  894. if ($j == $this->PageNo) {
  895. $listdd .= "<li class='page-item active'><a class='page-link'>$j</a></li>\r\n";
  896. } else {
  897. $listdd .= "<li class='page-item'><a class='page-link' href='".str_replace("{page}", $j, $tnamerule)."'>".$j."</a></li>\r\n";
  898. }
  899. }
  900. $plist = "";
  901. if (preg_match('/info/i', $listitem)) {
  902. $plist .= $maininfo.' ';
  903. }
  904. if (preg_match('/index/i', $listitem)) {
  905. $plist .= $indexpage.' ';
  906. }
  907. if (preg_match('/pre/i', $listitem)) {
  908. $plist .= $prepage.' ';
  909. }
  910. if (preg_match('/pageno/i', $listitem)) {
  911. $plist .= $listdd.' ';
  912. }
  913. if (preg_match('/next/i', $listitem)) {
  914. $plist .= $nextpage.' ';
  915. }
  916. if (preg_match('/end/i', $listitem)) {
  917. $plist .= $endpage.' ';
  918. }
  919. if (preg_match('/option/i', $listitem)) {
  920. $plist .= $optionlist;
  921. }
  922. return $plist;
  923. }
  924. /**
  925. * 获取动态的分页列表
  926. *
  927. * @access public
  928. * @param int $list_len 列表宽度
  929. * @param string $listitem 列表样式
  930. * @return string
  931. */
  932. function GetPageListDM($list_len, $listitem = "index,end,pre,next,pageno")
  933. {
  934. global $nativeplace, $infotype, $keyword;
  935. if (empty($nativeplace)) $nativeplace = 0;
  936. if (empty($infotype)) $infotype = 0;
  937. if (empty($keyword)) $keyword = '';
  938. $prepage = $nextpage = '';
  939. $prepagenum = $this->PageNo - 1;
  940. $nextpagenum = $this->PageNo + 1;
  941. if ($list_len == "" || preg_match("/[^0-9]/", $list_len)) {
  942. $list_len = 3;
  943. }
  944. $totalpage = ceil($this->TotalResult / $this->pagesize);
  945. if ($totalpage <= 1 && $this->TotalResult > 0) {
  946. return "<li class='page-item disabled'><span class='page-link'>1页".$this->TotalResult."条</span></li>";
  947. }
  948. if ($this->TotalResult == 0) {
  949. return "<li class='page-item disabled'><span class='page-link'>0页".$this->TotalResult."条</span></li>";
  950. }
  951. $purl = $this->GetCurUrl();
  952. $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&nativeplace=$nativeplace&infotype=$infotype&keyword=".urlencode($keyword)."&";
  953. $hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."' />\r\n";
  954. $hidenform = "<input type='hidden' name='nativeplace' value='$nativeplace' />\r\n";
  955. $hidenform = "<input type='hidden' name='infotype' value='$infotype' />\r\n";
  956. $hidenform = "<input type='hidden' name='keyword' value='$keyword' />\r\n";
  957. $hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."' />\r\n";
  958. $purl .= "?".$geturl;
  959. //获得上一页和下一页的链接
  960. if ($this->PageNo != 1) {
  961. $prepage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$prepagenum'>上一页</a></li>\r\n";
  962. $indexpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=1'>首页</a></li>\r\n";
  963. } else {
  964. $indexpage = "<li class='page-item disabled'><a class='page-link'>首页</a></li>\r\n";
  965. }
  966. if ($this->PageNo != $totalpage && $totalpage > 1) {
  967. $nextpage .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$nextpagenum'>下一页</a></li>\r\n";
  968. $endpage = "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$totalpage'>末页</a></li>\r\n";
  969. } else {
  970. $endpage = "<li class='page-item disabled'><a class='page-link'>末页</a></li>";
  971. }
  972. //获得数字链接
  973. $listdd = "";
  974. $total_list = $list_len * 2 + 1;
  975. if ($this->PageNo >= $total_list) {
  976. $j = $this->PageNo - $list_len;
  977. $total_list = $this->PageNo + $list_len;
  978. if ($total_list > $totalpage) {
  979. $total_list = $totalpage;
  980. }
  981. } else {
  982. $j = 1;
  983. if ($total_list > $totalpage) {
  984. $total_list = $totalpage;
  985. }
  986. }
  987. for ($j; $j <= $total_list; $j++) {
  988. if ($j == $this->PageNo) {
  989. $listdd .= "<li class='page-item active'><a class='page-link'>$j</a></li>\r\n";
  990. } else {
  991. $listdd .= "<li class='page-item'><a class='page-link' href='".$purl."PageNo=$j'>".$j."</a></li>\r\n";
  992. }
  993. }
  994. $plist = $indexpage.$prepage.$listdd.$nextpage.$endpage;
  995. return $plist;
  996. }
  997. /**
  998. * 获得当前的页面文件链接
  999. *
  1000. * @access private
  1001. * @return string
  1002. */
  1003. function GetCurUrl()
  1004. {
  1005. if (!empty($_SERVER["REQUEST_URI"])) {
  1006. $nowurl = $_SERVER["REQUEST_URI"];
  1007. $nowurls = explode("?", $nowurl);
  1008. $nowurl = $nowurls[0];
  1009. } else {
  1010. $nowurl = $_SERVER["PHP_SELF"];
  1011. }
  1012. return $nowurl;
  1013. }
  1014. }//End Class
  1015. ?>