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

990 lines
42KB

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