国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

1096 wiersze
45KB

  1. <?php
  2. if (!defined('DEDEINC')) exit("Request Error!");
  3. /**
  4. * 文档类
  5. *
  6. * @version $Id: arc.archives.class.php 4 15:13 2010年7月7日Z tianya $
  7. * @package DedeBIZ.Libraries
  8. * @copyright Copyright (c) 2021, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC . "/typelink.class.php");
  13. require_once(DEDEINC . "/channelunit.class.php");
  14. require_once(DEDEINC . "/downmix.inc.php");
  15. @set_time_limit(0);
  16. /**
  17. * 主文档类(Archives类)
  18. *
  19. * @package TypeLink
  20. * @subpackage DedeBIZ.Libraries
  21. * @link https://www.dedebiz.com
  22. */
  23. class Archives
  24. {
  25. var $TypeLink;
  26. var $ChannelUnit;
  27. var $dsql;
  28. var $Fields;
  29. var $dtp;
  30. var $ArcID;
  31. var $SplitPageField;
  32. var $SplitFields;
  33. var $NowPage;
  34. var $TotalPage;
  35. var $NameFirst;
  36. var $ShortName;
  37. var $FixedValues;
  38. var $TempSource;
  39. var $IsError;
  40. var $SplitTitles;
  41. var $PreNext;
  42. var $addTableRow;
  43. var $remoteDir;
  44. /**
  45. * php5构造函数
  46. *
  47. * @access public
  48. * @param int $aid 文档ID
  49. * @return string
  50. */
  51. function __construct($aid)
  52. {
  53. global $dsql;
  54. $this->IsError = FALSE;
  55. $this->ArcID = $aid;
  56. $this->PreNext = array();
  57. $this->dsql = $dsql;
  58. $query = "SELECT channel,typeid FROM `#@__arctiny` WHERE id='$aid' ";
  59. $arr = $this->dsql->GetOne($query);
  60. if (!is_array($arr)) {
  61. $this->IsError = TRUE;
  62. } else {
  63. if ($arr['channel'] == 0) $arr['channel'] = 1;
  64. $this->ChannelUnit = new ChannelUnit($arr['channel'], $aid);
  65. $this->TypeLink = new TypeLink($arr['typeid']);
  66. if ($this->ChannelUnit->ChannelInfos['issystem'] != -1) {
  67. // 如果当前文档不是系统模型,为单表模型
  68. $query = "SELECT arc.*,tp.reid,tp.typedir,ch.addtable
  69. FROM `#@__archives` arc
  70. LEFT JOIN #@__arctype tp on tp.id=arc.typeid
  71. LEFT JOIN #@__channeltype as ch on arc.channel = ch.id
  72. WHERE arc.id='$aid' ";
  73. $this->Fields = $this->dsql->GetOne($query);
  74. } else {
  75. $this->Fields['title'] = '';
  76. $this->Fields['money'] = $this->Fields['arcrank'] = 0;
  77. $this->Fields['senddate'] = $this->Fields['pubdate'] = $this->Fields['mid'] = $this->Fields['adminid'] = 0;
  78. $this->Fields['ismake'] = 1;
  79. $this->Fields['filename'] = '';
  80. }
  81. if ($this->TypeLink->TypeInfos['corank'] > 0 && $this->Fields['arcrank'] == 0) {
  82. $this->Fields['arcrank'] = $this->TypeLink->TypeInfos['corank'];
  83. }
  84. $this->Fields['tags'] = GetTags($aid);
  85. $this->dtp = new DedeTagParse();
  86. $this->dtp->SetRefObj($this);
  87. $this->SplitPageField = $this->ChannelUnit->SplitPageField;
  88. $this->SplitFields = '';
  89. $this->TotalPage = 1;
  90. $this->NameFirst = '';
  91. $this->ShortName = 'html';
  92. $this->FixedValues = '';
  93. $this->TempSource = '';
  94. $this->remoteDir = '';
  95. if (empty($GLOBALS['pageno'])) {
  96. $this->NowPage = 1;
  97. } else {
  98. $this->NowPage = $GLOBALS['pageno'];
  99. }
  100. //特殊的字段数据处理
  101. $this->Fields['aid'] = $aid;
  102. $this->Fields['id'] = $aid;
  103. $this->Fields['position'] = $this->TypeLink->GetPositionLink(TRUE);
  104. $this->Fields['typeid'] = $arr['typeid'];
  105. //设置一些全局参数的值
  106. foreach ($GLOBALS['PubFields'] as $k => $v) {
  107. $this->Fields[$k] = $v;
  108. }
  109. //为了减少重复查询,这里直接把附加表查询记录放在 $this->addTableRow 中,在 ParAddTable() 不再查询
  110. if ($this->ChannelUnit->ChannelInfos['addtable'] != '') {
  111. $query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}` WHERE `aid` = '$aid'";
  112. $this->addTableRow = $this->dsql->GetOne($query);
  113. }
  114. //issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
  115. if ($this->ChannelUnit->ChannelInfos['addtable'] != '' && $this->ChannelUnit->ChannelInfos['issystem'] != -1) {
  116. if (is_array($this->addTableRow)) {
  117. $this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
  118. $this->Fields['templet'] = $this->addTableRow['templet'];
  119. $this->Fields['userip'] = $this->addTableRow['userip'];
  120. }
  121. $this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
  122. $this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
  123. $this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
  124. } else {
  125. $this->Fields['templet'] = $this->Fields['redirecturl'] = '';
  126. }
  127. } //!error
  128. }
  129. //php4构造函数
  130. function Archives($aid)
  131. {
  132. $this->__construct($aid);
  133. }
  134. /**
  135. * 解析附加表的内容
  136. *
  137. * @access public
  138. * @return void
  139. */
  140. function ParAddTable()
  141. {
  142. //读取附加表信息,并把附加表的资料经过编译处理后导入到$this->Fields中,以方便在模板中用 {dede:field name='fieldname' /} 标记统一调用
  143. if ($this->ChannelUnit->ChannelInfos['addtable'] != '') {
  144. $row = $this->addTableRow;
  145. if ($this->ChannelUnit->ChannelInfos['issystem'] == -1) {
  146. $this->Fields['title'] = $row['title'];
  147. $this->Fields['senddate'] = $this->Fields['pubdate'] = $row['senddate'];
  148. $this->Fields['mid'] = $this->Fields['adminid'] = $row['mid'];
  149. $this->Fields['ismake'] = 1;
  150. $this->Fields['arcrank'] = 0;
  151. $this->Fields['money'] = 0;
  152. $this->Fields['filename'] = '';
  153. }
  154. if (is_array($row)) {
  155. foreach ($row as $k => $v) $row[strtolower($k)] = $v;
  156. }
  157. if (is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields)) {
  158. foreach ($this->ChannelUnit->ChannelFields as $k => $arr) {
  159. if (isset($row[$k])) {
  160. if (!empty($arr['rename'])) {
  161. $nk = $arr['rename'];
  162. } else {
  163. $nk = $k;
  164. }
  165. $cobj = $this->GetCurTag($k);
  166. if (is_object($cobj)) {
  167. foreach ($this->dtp->CTags as $ctag) {
  168. if ($ctag->GetTagName() == 'field' && $ctag->GetAtt('name') == $k) {
  169. //带标识的专题节点
  170. if ($ctag->GetAtt('noteid') != '') {
  171. $this->Fields[$k . '_' . $ctag->GetAtt('noteid')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  172. }
  173. //带类型的字段节点
  174. else if ($ctag->GetAtt('type') != '') {
  175. $this->Fields[$k . '_' . $ctag->GetAtt('type')] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  176. }
  177. //其它字段
  178. else {
  179. $this->Fields[$nk] = $this->ChannelUnit->MakeField($k, $row[$k], $ctag);
  180. }
  181. }
  182. }
  183. } else {
  184. $this->Fields[$nk] = $row[$k];
  185. }
  186. if ($arr['type'] == 'htmltext' && $GLOBALS['cfg_keyword_replace'] == 'Y' && !empty($this->Fields['keywords'])) {
  187. $this->Fields[$nk] = $this->ReplaceKeyword($this->Fields['keywords'], $this->Fields[$nk]);
  188. }
  189. }
  190. } //End foreach
  191. }
  192. //设置全局环境变量
  193. $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
  194. @SetSysEnv($this->Fields['typeid'], $this->Fields['typename'], $this->Fields['id'], $this->Fields['title'], 'archives');
  195. }
  196. //完成附加表信息读取
  197. unset($row);
  198. //处理要分页显示的字段
  199. $this->SplitTitles = array();
  200. if ($this->SplitPageField != '' && $GLOBALS['cfg_arcsptitle'] = 'Y'
  201. && isset($this->Fields[$this->SplitPageField])
  202. ) {
  203. $this->SplitFields = explode("#p#", $this->Fields[$this->SplitPageField]);
  204. $i = 1;
  205. foreach ($this->SplitFields as $k => $v) {
  206. $tmpv = cn_substr($v, 50);
  207. $pos = strpos($tmpv, '#e#');
  208. if ($pos > 0) {
  209. $st = trim(cn_substr($tmpv, $pos));
  210. if ($st == "" || $st == "副标题" || $st == "分页标题") {
  211. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v);
  212. continue;
  213. } else {
  214. $this->SplitFields[$k] = preg_replace("/^(.*)#e#/is", "", $v);
  215. $this->SplitTitles[$k] = $st;
  216. }
  217. } else {
  218. continue;
  219. }
  220. $i++;
  221. }
  222. $this->TotalPage = count($this->SplitFields);
  223. $this->Fields['totalpage'] = $this->TotalPage;
  224. }
  225. //处理默认缩略图等
  226. if (isset($this->Fields['litpic'])) {
  227. if ($this->Fields['litpic'] == '-' || $this->Fields['litpic'] == '') {
  228. $this->Fields['litpic'] = $GLOBALS['cfg_cmspath'] . '/static/defaultpic.jpg';
  229. }
  230. if (!preg_match("#^http:\/\/#i", $this->Fields['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
  231. $this->Fields['litpic'] = $GLOBALS['cfg_mainsite'] . $this->Fields['litpic'];
  232. }
  233. $this->Fields['picname'] = $this->Fields['litpic'];
  234. //模板里直接使用{dede:field name='image'/}获取缩略图
  235. $this->Fields['image'] = (!preg_match('/jpg|gif|png/i', $this->Fields['picname']) ? '' : "<img src='{$this->Fields['picname']}' />");
  236. }
  237. // 处理投票选项
  238. if (isset($this->Fields['voteid']) && !empty($this->Fields['voteid'])) {
  239. $this->Fields['vote'] = '';
  240. $voteid = $this->Fields['voteid'];
  241. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_cmspath']}/data/vote/vote_{$voteid}.js'></script>";
  242. if ($GLOBALS['cfg_multi_site'] == 'Y') {
  243. $this->Fields['vote'] = "<script language='javascript' src='{$GLOBALS['cfg_mainsite']}/data/vote/vote_{$voteid}.js'></script>";
  244. }
  245. }
  246. if (isset($this->Fields['goodpost']) && isset($this->Fields['badpost'])) {
  247. //digg
  248. if ($this->Fields['goodpost'] + $this->Fields['badpost'] == 0) {
  249. $this->Fields['goodper'] = $this->Fields['badper'] = 0;
  250. } else {
  251. $this->Fields['goodper'] = number_format($this->Fields['goodpost'] / ($this->Fields['goodpost'] + $this->Fields['badpost']), 3) * 100;
  252. $this->Fields['badper'] = 100 - $this->Fields['goodper'];
  253. }
  254. }
  255. }
  256. //获得当前字段参数
  257. function GetCurTag($fieldname)
  258. {
  259. if (!isset($this->dtp->CTags)) {
  260. return '';
  261. }
  262. foreach ($this->dtp->CTags as $ctag) {
  263. if ($ctag->GetTagName() == 'field' && $ctag->GetAtt('name') == $fieldname) {
  264. return $ctag;
  265. } else {
  266. continue;
  267. }
  268. }
  269. return '';
  270. }
  271. /**
  272. * 生成静态HTML
  273. *
  274. * @access public
  275. * @param int $isremote 是否远程
  276. * @return string
  277. */
  278. function MakeHtml($isremote = 0)
  279. {
  280. global $fileFirst, $cfg_basehost;
  281. if ($this->IsError) {
  282. return '';
  283. }
  284. $this->Fields["displaytype"] = "st";
  285. //预编译$th
  286. $this->LoadTemplet();
  287. $this->ParAddTable();
  288. $this->ParseTempletsFirst();
  289. $this->Fields['senddate'] = empty($this->Fields['senddate']) ? '' : $this->Fields['senddate'];
  290. $this->Fields['title'] = empty($this->Fields['title']) ? '' : $this->Fields['title'];
  291. $this->Fields['arcrank'] = empty($this->Fields['arcrank']) ? 0 : $this->Fields['arcrank'];
  292. $this->Fields['ismake'] = empty($this->Fields['ismake']) ? 0 : $this->Fields['ismake'];
  293. $this->Fields['money'] = empty($this->Fields['money']) ? 0 : $this->Fields['money'];
  294. $this->Fields['filename'] = empty($this->Fields['filename']) ? '' : $this->Fields['filename'];
  295. //分析要创建的文件名称
  296. $filename = GetFileNewName(
  297. $this->ArcID,
  298. $this->Fields['typeid'],
  299. $this->Fields['senddate'],
  300. $this->Fields['title'],
  301. $this->Fields['ismake'],
  302. $this->Fields['arcrank'],
  303. $this->TypeLink->TypeInfos['namerule'],
  304. $this->TypeLink->TypeInfos['typedir'],
  305. $this->Fields['money'],
  306. $this->Fields['filename']
  307. );
  308. $filenames = explode(".", $filename);
  309. $this->ShortName = $filenames[count($filenames) - 1];
  310. if ($this->ShortName == '') $this->ShortName = 'html';
  311. $fileFirst = preg_replace("/\." . $this->ShortName . "$/i", "", $filename);
  312. $this->Fields['namehand'] = basename($fileFirst);
  313. $filenames = explode("/", $filename);
  314. $this->NameFirst = preg_replace("/\." . $this->ShortName . "$/i", "", $filenames[count($filenames) - 1]);
  315. if ($this->NameFirst == '') {
  316. $this->NameFirst = $this->arcID;
  317. }
  318. //获得当前文档的全名
  319. $filenameFull = GetFileUrl(
  320. $this->ArcID,
  321. $this->Fields['typeid'],
  322. $this->Fields["senddate"],
  323. $this->Fields["title"],
  324. $this->Fields["ismake"],
  325. $this->Fields["arcrank"],
  326. $this->TypeLink->TypeInfos['namerule'],
  327. $this->TypeLink->TypeInfos['typedir'],
  328. $this->Fields["money"],
  329. $this->Fields['filename'],
  330. $this->TypeLink->TypeInfos['moresite'],
  331. $this->TypeLink->TypeInfos['siteurl'],
  332. $this->TypeLink->TypeInfos['sitepath']
  333. );
  334. $this->Fields['arcurl'] = $this->Fields['fullname'] = $filenameFull;
  335. //对于已设置不生成HTML的文章直接返回网址
  336. if (
  337. $this->Fields['ismake'] == -1 || $this->Fields['arcrank'] != 0 || $this->Fields['money'] > 0
  338. || ($this->Fields['typeid'] == 0 && $this->Fields['channel'] != -1)
  339. ) {
  340. return $this->GetTrueUrl($filename);
  341. }
  342. //循环生成HTML文件
  343. else {
  344. $seoUrls = array();
  345. for ($i = 1; $i <= $this->TotalPage; $i++) {
  346. if ($this->TotalPage > 1) {
  347. $this->Fields['tmptitle'] = (empty($this->Fields['tmptitle']) ? $this->Fields['title'] : $this->Fields['tmptitle']);
  348. if ($i > 1) $this->Fields['title'] = $this->Fields['tmptitle'] . "($i)";
  349. }
  350. if ($i > 1) {
  351. $TRUEfilename = $this->GetTruePath() . $fileFirst . "_" . $i . "." . $this->ShortName;
  352. $URLFilename = $fileFirst . "_" . $i . "." . $this->ShortName;
  353. } else {
  354. $TRUEfilename = $this->GetTruePath() . $filename;
  355. $URLFilename = $filename;
  356. }
  357. $seoUrls = array_merge($seoUrls, array($cfg_basehost . $URLFilename));
  358. $this->ParseDMFields($i, 1);
  359. $this->dtp->SaveTo($TRUEfilename);
  360. }
  361. }
  362. $this->dsql->ExecuteNoneQuery("Update `#@__archives` SET ismake=1 WHERE id='" . $this->ArcID . "'");
  363. return $this->GetTrueUrl($filename);
  364. }
  365. /**
  366. * 获得真实连接路径
  367. *
  368. * @access public
  369. * @param string $nurl 连接
  370. * @return string
  371. */
  372. function GetTrueUrl($nurl)
  373. {
  374. return GetFileUrl(
  375. $this->Fields['id'],
  376. $this->Fields['typeid'],
  377. $this->Fields['senddate'],
  378. $this->Fields['title'],
  379. $this->Fields['ismake'],
  380. $this->Fields['arcrank'],
  381. $this->TypeLink->TypeInfos['namerule'],
  382. $this->TypeLink->TypeInfos['typedir'],
  383. $this->Fields['money'],
  384. $this->Fields['filename'],
  385. $this->TypeLink->TypeInfos['moresite'],
  386. $this->TypeLink->TypeInfos['siteurl'],
  387. $this->TypeLink->TypeInfos['sitepath']
  388. );
  389. }
  390. /**
  391. * 获得站点的真实根路径
  392. *
  393. * @access public
  394. * @return string
  395. */
  396. function GetTruePath()
  397. {
  398. $TRUEpath = $GLOBALS["cfg_basedir"];
  399. return $TRUEpath;
  400. }
  401. /**
  402. * 获得指定键值的字段
  403. *
  404. * @access public
  405. * @param string $fname 键名称
  406. * @param object $ctag 标记
  407. * @return string
  408. */
  409. function GetField($fname, $ctag)
  410. {
  411. //所有Field数组 OR 普通Field
  412. if ($fname == 'array') {
  413. return $this->Fields;
  414. }
  415. //指定了ID的节点
  416. else if ($ctag->GetAtt('noteid') != '') {
  417. if (isset($this->Fields[$fname . '_' . $ctag->GetAtt('noteid')])) {
  418. return $this->Fields[$fname . '_' . $ctag->GetAtt('noteid')];
  419. }
  420. }
  421. //指定了type的节点
  422. else if ($ctag->GetAtt('type') != '') {
  423. if (isset($this->Fields[$fname . '_' . $ctag->GetAtt('type')])) {
  424. return $this->Fields[$fname . '_' . $ctag->GetAtt('type')];
  425. }
  426. } else if (isset($this->Fields[$fname])) {
  427. return $this->Fields[$fname];
  428. }
  429. return '';
  430. }
  431. /**
  432. * 获得模板文件位置
  433. *
  434. * @access public
  435. * @return string
  436. */
  437. function GetTempletFile()
  438. {
  439. global $cfg_basedir, $cfg_templets_dir, $cfg_df_style;
  440. $cid = $this->ChannelUnit->ChannelInfos['nid'];
  441. if (!empty($this->Fields['templet'])) {
  442. $filetag = MfTemplet($this->Fields['templet']);
  443. if (!preg_match("#\/#", $filetag)) $filetag = $GLOBALS['cfg_df_style'] . '/' . $filetag;
  444. } else {
  445. $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  446. }
  447. $tid = $this->Fields['typeid'];
  448. $filetag = str_replace('{cid}', $cid, $filetag);
  449. $filetag = str_replace('{tid}', $tid, $filetag);
  450. $tmpfile = $cfg_basedir . $cfg_templets_dir . '/' . $filetag;
  451. if ($cid == 'spec') {
  452. if (!empty($this->Fields['templet'])) {
  453. $tmpfile = $cfg_basedir . $cfg_templets_dir . '/' . $filetag;
  454. } else {
  455. $tmpfile = $cfg_basedir . $cfg_templets_dir . "/{$cfg_df_style}/article_spec.htm";
  456. }
  457. }
  458. if (defined('DEDEMOB')) {
  459. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  460. }
  461. if (!file_exists($tmpfile)) {
  462. $tmpfile = $cfg_basedir . $cfg_templets_dir . "/{$cfg_df_style}/" . ($cid == 'spec' ? 'article_spec.htm' : 'article_default.htm');
  463. if (defined('DEDEMOB')) {
  464. $tmpfile = str_replace('.htm', '_m.htm', $tmpfile);
  465. }
  466. }
  467. if (!preg_match("#.htm$#", $tmpfile)) return FALSE;
  468. return $tmpfile;
  469. }
  470. /**
  471. * 动态输出结果
  472. *
  473. * @access public
  474. * @return void
  475. */
  476. function display()
  477. {
  478. global $htmltype;
  479. if ($this->IsError) {
  480. return '';
  481. }
  482. $this->Fields["displaytype"] = "dm";
  483. if ($this->NowPage > 1) $this->Fields["title"] = $this->Fields["title"] . "({$this->NowPage})";
  484. //预编译
  485. $this->LoadTemplet();
  486. $this->ParAddTable();
  487. $this->ParseTempletsFirst();
  488. //跳转网址
  489. $this->Fields['flag'] = empty($this->Fields['flag']) ? "" : $this->Fields['flag'];
  490. if (preg_match("#j#", $this->Fields['flag']) && $this->Fields['redirecturl'] != '') {
  491. if ($GLOBALS['cfg_jump_once'] == 'N') {
  492. $pageHtml = "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $GLOBALS['cfg_soft_lang'] . "\">\r\n<title>" . $this->Fields['title'] . "</title>\r\n";
  493. $pageHtml .= "<meta http-equiv=\"refresh\" content=\"3;URL=" . $this->Fields['redirecturl'] . "\">\r\n</head>\r\n<body>\r\n";
  494. $pageHtml .= "现在正在转向:" . $this->Fields['title'] . ",请稍候...<br/><br/>\r\n转向内容简介:" . $this->Fields['description'] . "\r\n</body>\r\n</html>\r\n";
  495. echo $pageHtml;
  496. } else {
  497. header("location:{$this->Fields['redirecturl']}");
  498. }
  499. exit();
  500. }
  501. $pageCount = $this->NowPage;
  502. $this->ParseDMFields($pageCount, 0);
  503. $this->dtp->display();
  504. }
  505. /**
  506. * 载入模板
  507. *
  508. * @access public
  509. * @return void
  510. */
  511. function LoadTemplet()
  512. {
  513. if ($this->TempSource == '') {
  514. $tempfile = $this->GetTempletFile();
  515. if (!file_exists($tempfile) || !is_file($tempfile)) {
  516. echo "文档ID:{$this->Fields['id']} - {$this->TypeLink->TypeInfos['typename']} - {$this->Fields['title']}<br />";
  517. echo "模板文件不存在,无法解析文档!";
  518. exit();
  519. }
  520. $this->dtp->LoadTemplate($tempfile);
  521. $this->TempSource = $this->dtp->SourceString;
  522. } else {
  523. $this->dtp->LoadSource($this->TempSource);
  524. }
  525. }
  526. /**
  527. * 解析模板,对固定的标记进行初始给值
  528. *
  529. * @access public
  530. * @return void
  531. */
  532. function ParseTempletsFirst()
  533. {
  534. if (empty($this->Fields['keywords'])) {
  535. $this->Fields['keywords'] = '';
  536. }
  537. if (empty($this->Fields['reid'])) {
  538. $this->Fields['reid'] = 0;
  539. }
  540. $GLOBALS['envs']['tags'] = $this->Fields['tags'];
  541. if (isset($this->TypeLink->TypeInfos['reid'])) {
  542. $GLOBALS['envs']['reid'] = $this->TypeLink->TypeInfos['reid'];
  543. }
  544. $GLOBALS['envs']['keyword'] = $this->Fields['keywords'];
  545. $GLOBALS['envs']['typeid'] = $this->Fields['typeid'];
  546. $GLOBALS['envs']['topid'] = GetTopid($this->Fields['typeid']);
  547. $GLOBALS['envs']['aid'] = $GLOBALS['envs']['id'] = $this->Fields['id'];
  548. $GLOBALS['envs']['adminid'] = $GLOBALS['envs']['mid'] = isset($this->Fields['mid']) ? $this->Fields['mid'] : 1;
  549. $GLOBALS['envs']['channelid'] = $this->TypeLink->TypeInfos['channeltype'];
  550. if ($this->Fields['reid'] > 0) {
  551. $GLOBALS['envs']['typeid'] = $this->Fields['reid'];
  552. }
  553. MakeOneTag($this->dtp, $this, 'N');
  554. }
  555. /**
  556. * 解析模板,对内容里的变动进行赋值
  557. *
  558. * @access public
  559. * @param string $pageNo 页码数
  560. * @param string $ismake 是否生成
  561. * @return string
  562. */
  563. function ParseDMFields($pageNo, $ismake = 1)
  564. {
  565. $this->NowPage = $pageNo;
  566. $this->Fields['nowpage'] = $this->NowPage;
  567. if ($this->SplitPageField != '' && isset($this->Fields[$this->SplitPageField])) {
  568. $this->Fields[$this->SplitPageField] = $this->SplitFields[$pageNo - 1];
  569. if ($pageNo > 1) $this->Fields['description'] = trim(preg_replace("/[\r\n\t]/", ' ', cn_substr(html2text($this->Fields[$this->SplitPageField]), 200)));
  570. }
  571. //解析模板
  572. if (is_array($this->dtp->CTags)) {
  573. foreach ($this->dtp->CTags as $i => $ctag) {
  574. if ($ctag->GetName() == 'field') {
  575. $this->dtp->Assign($i, $this->GetField($ctag->GetAtt('name'), $ctag));
  576. } else if ($ctag->GetName() == 'pagebreak') {
  577. if ($ismake == 0) {
  578. $this->dtp->Assign($i, $this->GetPagebreakDM($this->TotalPage, $this->NowPage, $this->ArcID));
  579. } else {
  580. $this->dtp->Assign($i, $this->GetPagebreak($this->TotalPage, $this->NowPage, $this->ArcID));
  581. }
  582. } else if ($ctag->GetName() == 'pagetitle') {
  583. if ($ismake == 0) {
  584. $this->dtp->Assign($i, $this->GetPageTitlesDM($ctag->GetAtt("style"), $pageNo));
  585. } else {
  586. $this->dtp->Assign($i, $this->GetPageTitlesST($ctag->GetAtt("style"), $pageNo));
  587. }
  588. } else if ($ctag->GetName() == 'prenext') {
  589. $this->dtp->Assign($i, $this->GetPreNext($ctag->GetAtt('get')));
  590. } else if ($ctag->GetName() == 'fieldlist') {
  591. $innertext = trim($ctag->GetInnerText());
  592. if ($innertext == '') $innertext = GetSysTemplets('tag_fieldlist.htm');
  593. $dtp2 = new DedeTagParse();
  594. $dtp2->SetNameSpace('field', '[', ']');
  595. $dtp2->LoadSource($innertext);
  596. $oldSource = $dtp2->SourceString;
  597. $oldCtags = $dtp2->CTags;
  598. $res = '';
  599. if (is_array($this->ChannelUnit->ChannelFields) && is_array($dtp2->CTags)) {
  600. foreach ($this->ChannelUnit->ChannelFields as $k => $v) {
  601. if (isset($v['autofield']) && empty($v['autofield'])) {
  602. continue;
  603. }
  604. $dtp2->SourceString = $oldSource;
  605. $dtp2->CTags = $oldCtags;
  606. $fname = $v['itemname'];
  607. foreach ($dtp2->CTags as $tid => $ctag2) {
  608. if ($ctag2->GetName() == 'name') {
  609. $dtp2->Assign($tid, $fname);
  610. } else if ($ctag2->GetName() == 'tagname') {
  611. $dtp2->Assign($tid, $k);
  612. } else if ($ctag2->GetName() == 'value') {
  613. if (isset($this->Fields[$k])) {
  614. $this->Fields[$k] = $this->ChannelUnit->MakeField($k, $this->Fields[$k], $ctag2);
  615. @$dtp2->Assign($tid, $this->Fields[$k]);
  616. }
  617. }
  618. }
  619. $res .= $dtp2->GetResult();
  620. }
  621. }
  622. $this->dtp->Assign($i, $res);
  623. } //end case
  624. } //结束模板循环
  625. }
  626. }
  627. /**
  628. * 关闭所占用的资源
  629. *
  630. * @access public
  631. * @return void
  632. */
  633. function Close()
  634. {
  635. $this->FixedValues = '';
  636. $this->Fields = '';
  637. }
  638. /**
  639. * 获取上一篇,下一篇链接
  640. *
  641. * @access public
  642. * @param string $gtype 获取类型
  643. * pre:上一篇 preimg:上一篇图片 next:下一篇 nextimg:下一篇图片
  644. * @return string
  645. */
  646. function GetPreNext($gtype = '')
  647. {
  648. $rs = '';
  649. if (count($this->PreNext) < 2) {
  650. $aid = $this->ArcID;
  651. $preR = $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
  652. $nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
  653. $next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
  654. $pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
  655. $query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic,
  656. t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
  657. from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id ";
  658. $nextRow = $this->dsql->GetOne($query . $next);
  659. $preRow = $this->dsql->GetOne($query . $pre);
  660. if (is_array($preRow)) {
  661. if (defined('DEDEMOB')) {
  662. $mlink = 'view.php?aid=' . $preRow['id'];
  663. } else {
  664. $mlink = GetFileUrl(
  665. $preRow['id'],
  666. $preRow['typeid'],
  667. $preRow['senddate'],
  668. $preRow['title'],
  669. $preRow['ismake'],
  670. $preRow['arcrank'],
  671. $preRow['namerule'],
  672. $preRow['typedir'],
  673. $preRow['money'],
  674. $preRow['filename'],
  675. $preRow['moresite'],
  676. $preRow['siteurl'],
  677. $preRow['sitepath']
  678. );
  679. }
  680. $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
  681. $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> ";
  682. } else {
  683. $this->PreNext['pre'] = "上一篇:没有了 ";
  684. $this->PreNext['preimg'] = "<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
  685. }
  686. if (is_array($nextRow)) {
  687. if (defined('DEDEMOB')) {
  688. $mlink = 'view.php?aid=' . $preRow['id'];
  689. } else {
  690. $mlink = GetFileUrl(
  691. $nextRow['id'],
  692. $nextRow['typeid'],
  693. $nextRow['senddate'],
  694. $nextRow['title'],
  695. $nextRow['ismake'],
  696. $nextRow['arcrank'],
  697. $nextRow['namerule'],
  698. $nextRow['typedir'],
  699. $nextRow['money'],
  700. $nextRow['filename'],
  701. $nextRow['moresite'],
  702. $nextRow['siteurl'],
  703. $nextRow['sitepath']
  704. );
  705. }
  706. $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
  707. $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
  708. } else {
  709. $this->PreNext['next'] = "下一篇:没有了 ";
  710. $this->PreNext['nextimg'] = "<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
  711. }
  712. }
  713. if ($gtype == 'pre') {
  714. $rs = $this->PreNext['pre'];
  715. } else if ($gtype == 'preimg') {
  716. $rs = $this->PreNext['preimg'];
  717. } else if ($gtype == 'next') {
  718. $rs = $this->PreNext['next'];
  719. } else if ($gtype == 'nextimg') {
  720. $rs = $this->PreNext['nextimg'];
  721. } else {
  722. $rs = $this->PreNext['pre'] . " &nbsp; " . $this->PreNext['next'];
  723. }
  724. return $rs;
  725. }
  726. /**
  727. * 获得动态页面分页列表
  728. *
  729. * @access public
  730. * @param int $totalPage 总页数
  731. * @param int $nowPage 当前页数
  732. * @param int $aid 文档id
  733. * @return string
  734. */
  735. function GetPagebreakDM($totalPage, $nowPage, $aid)
  736. {
  737. global $cfg_rewrite;
  738. if ($totalPage == 1) {
  739. return "";
  740. }
  741. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共" . $totalPage . "页: </span></li>";
  742. $nPage = $nowPage - 1;
  743. $lPage = $nowPage + 1;
  744. if ($nowPage == 1) {
  745. $PageList .= "<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  746. } else {
  747. if ($nPage == 1) {
  748. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>上一页</a></li>";
  749. if ($cfg_rewrite == 'Y') {
  750. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  751. }
  752. } else {
  753. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$nPage'>上一页</a></li>";
  754. if ($cfg_rewrite == 'Y') {
  755. $PageList = str_replace(".php?aid=", "-", $PageList);
  756. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  757. }
  758. }
  759. }
  760. for ($i = 1; $i <= $totalPage; $i++) {
  761. if ($i == 1) {
  762. if ($nowPage != 1) {
  763. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid'>1</a></li>";
  764. if ($cfg_rewrite == 'Y') {
  765. $PageList = preg_replace("#.php\?aid=(\d+)#i", '-\\1-1.html', $PageList);
  766. }
  767. } else {
  768. $PageList .= "<li class=\"page-item active\"><a class='page-link'>1</a></li>";
  769. }
  770. } else {
  771. $n = $i;
  772. if ($nowPage != $i) {
  773. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$i'>" . $n . "</a></li>";
  774. if ($cfg_rewrite == 'Y') {
  775. $PageList = str_replace(".php?aid=", "-", $PageList);
  776. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  777. }
  778. } else {
  779. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  780. }
  781. }
  782. }
  783. if ($lPage <= $totalPage) {
  784. $PageList .= "<li class='page-item'><a class='page-link' href='view.php?aid=$aid&pageno=$lPage'>下一页</a></li>";
  785. if ($cfg_rewrite == 'Y') {
  786. $PageList = str_replace(".php?aid=", "-", $PageList);
  787. $PageList = preg_replace("#&pageno=(\d+)#i", '-\\1.html', $PageList);
  788. }
  789. } else {
  790. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  791. }
  792. return $PageList;
  793. }
  794. /**
  795. * 获得静态页面分页列表
  796. *
  797. * @access public
  798. * @param int $totalPage 总页数
  799. * @param int $nowPage 当前页数
  800. * @param int $aid 文档id
  801. * @return string
  802. */
  803. function GetPagebreak($totalPage, $nowPage, $aid)
  804. {
  805. if ($totalPage == 1) {
  806. return "";
  807. }
  808. $PageList = "<li class='page-item d-none d-sm-block disabled'><span class=\"page-link\">共" . $totalPage . "页: </span></li>";
  809. $nPage = $nowPage - 1;
  810. $lPage = $nowPage + 1;
  811. if ($nowPage == 1) {
  812. $PageList .= "<li class='page-item d-none d-sm-block disabled'><a class='page-link' href='#'>上一页</a></li>";
  813. } else {
  814. if ($nPage == 1) {
  815. $PageList .= "<li class='page-item'><a class='page-link' href='" . $this->NameFirst . "." . $this->ShortName . "'>上一页</a></li>";
  816. } else {
  817. $PageList .= "<li class='page-item'><a class='page-link' href='" . $this->NameFirst . "_" . $nPage . "." . $this->ShortName . "'>上一页</a></li>";
  818. }
  819. }
  820. for ($i = 1; $i <= $totalPage; $i++) {
  821. if ($i == 1) {
  822. if ($nowPage != 1) {
  823. $PageList .= "<li class='page-item'><a class='page-link' href='" . $this->NameFirst . "." . $this->ShortName . "'>1</a></li>";
  824. } else {
  825. $PageList .= "<li class=\"page-item active\"><span class='page-link'>1</span></li>";
  826. }
  827. } else {
  828. $n = $i;
  829. if ($nowPage != $i) {
  830. $PageList .= "<li class='page-item'><a class='page-link' href='" . $this->NameFirst . "_" . $i . "." . $this->ShortName . "'>" . $n . "</a></li>";
  831. } else {
  832. $PageList .= "<li class=\"page-item active\"><span class='page-link'>{$n}</span></li>";
  833. }
  834. }
  835. }
  836. if ($lPage <= $totalPage) {
  837. $PageList .= "<li class='page-item'><a class='page-link' href='" . $this->NameFirst . "_" . $lPage . "." . $this->ShortName . "'>下一页</a></li>";
  838. } else {
  839. $PageList .= "<li class='page-item'><span class='page-link'>下一页</span></li>";
  840. }
  841. return $PageList;
  842. }
  843. /**
  844. * 获得动态页面小标题
  845. *
  846. * @access public
  847. * @param string $styleName 类型名称
  848. * @param string $pageNo 页码数
  849. * @return string
  850. */
  851. function GetPageTitlesDM($styleName, $pageNo)
  852. {
  853. if ($this->TotalPage == 1) {
  854. return "";
  855. }
  856. if (count($this->SplitTitles) == 0) {
  857. return "";
  858. }
  859. $i = 1;
  860. $aid = $this->ArcID;
  861. if ($styleName == 'link') {
  862. $revalue = "";
  863. foreach ($this->SplitTitles as $k => $v) {
  864. if ($i == 1) {
  865. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  866. } else {
  867. if ($pageNo == $i) {
  868. $revalue .= " $v \r\n";
  869. } else {
  870. $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> \r\n";
  871. }
  872. }
  873. $i++;
  874. }
  875. } else {
  876. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  877. foreach ($this->SplitTitles as $k => $v) {
  878. if ($i == 1) {
  879. $revalue .= "<option value='" . $this->Fields['phpurl'] . "/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  880. } else {
  881. if ($pageNo == $i) {
  882. $revalue .= "<option value='" . $this->Fields['phpurl'] . "/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>\r\n";
  883. } else {
  884. $revalue .= "<option value='" . $this->Fields['phpurl'] . "/view.php?aid=$aid&pageno=$i'>{$i}、{$v}</option>\r\n";
  885. }
  886. }
  887. $i++;
  888. }
  889. $revalue .= "</select>\r\n";
  890. }
  891. return $revalue;
  892. }
  893. /**
  894. * 获得静态页面小标题
  895. *
  896. * @access public
  897. * @param string $styleName 类型名称
  898. * @param string $pageNo 页码数
  899. * @return string
  900. */
  901. function GetPageTitlesST($styleName, $pageNo)
  902. {
  903. if ($this->TotalPage == 1) {
  904. return "";
  905. }
  906. if (count($this->SplitTitles) == 0) {
  907. return "";
  908. }
  909. $i = 1;
  910. if ($styleName == 'link') {
  911. $revalue = "";
  912. foreach ($this->SplitTitles as $k => $v) {
  913. if ($i == 1) {
  914. $revalue .= "<a href='" . $this->NameFirst . "." . $this->ShortName . "'>$v</a> \r\n";
  915. } else {
  916. if ($pageNo == $i) {
  917. $revalue .= " $v \r\n";
  918. } else {
  919. $revalue .= "<a href='" . $this->NameFirst . "_" . $i . "." . $this->ShortName . "'>$v</a> \r\n";
  920. }
  921. }
  922. $i++;
  923. }
  924. } else {
  925. $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>\r\n";
  926. foreach ($this->SplitTitles as $k => $v) {
  927. if ($i == 1) {
  928. $revalue .= "<option value='" . $this->NameFirst . "." . $this->ShortName . "'>{$i}、{$v}</option>\r\n";
  929. } else {
  930. if ($pageNo == $i) {
  931. $revalue .= "<option value='" . $this->NameFirst . "_" . $i . "." . $this->ShortName . "' selected>{$i}、{$v}</option>\r\n";
  932. } else {
  933. $revalue .= "<option value='" . $this->NameFirst . "_" . $i . "." . $this->ShortName . "'>{$i}、{$v}</option>\r\n";
  934. }
  935. }
  936. $i++;
  937. }
  938. $revalue .= "</select>\r\n";
  939. }
  940. return $revalue;
  941. }
  942. /**
  943. * 高亮问题修正, 排除alt title <a></a>直接的字符替换
  944. *
  945. * @param string $kw
  946. * @param string $body
  947. * @return string
  948. */
  949. function ReplaceKeyword($kw, &$body)
  950. {
  951. global $cfg_cmspath;
  952. $maxkey = 5;
  953. $kws = explode(",", trim($kw)); //以分好为间隔符
  954. $i = 0;
  955. $karr = $kaarr = $GLOBALS['replaced'] = array();
  956. //暂时屏蔽超链接
  957. $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body);
  958. /*
  959. foreach($kws as $k)
  960. {
  961. $k = trim($k);
  962. if($k!="")
  963. {
  964. if($i > $maxkey)
  965. {
  966. break;
  967. }
  968. $myrow = $this->dsql->GetOne("SELECT * FROM #@__keywords WHERE keyword='$k' AND rpurl<>'' ");
  969. if(is_array($myrow))
  970. {
  971. $karr[] = $k;
  972. $GLOBALS['replaced'][$k] = 0;
  973. $kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>";
  974. }
  975. $i++;
  976. }
  977. }
  978. */
  979. $query = "SELECT * FROM #@__keywords WHERE rpurl<>'' ORDER BY rank DESC";
  980. $this->dsql->SetQuery($query);
  981. $this->dsql->Execute();
  982. while ($row = $this->dsql->GetArray()) {
  983. $key = trim($row['keyword']);
  984. $key_url = trim($row['rpurl']);
  985. $karr[] = $key;
  986. $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>";
  987. }
  988. $GLOBALS['_dd_karr'] = $karr;
  989. $GLOBALS['_dd_kaarr'] = $kaarr;
  990. // 这里可能会有错误
  991. if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
  992. $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight8", $body);
  993. } else if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
  994. $body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  995. } else {
  996. $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
  997. }
  998. //恢复超链接
  999. $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body);
  1000. return $body;
  1001. }
  1002. } //End Archives
  1003. function _highlight8($matches){
  1004. return _highlight($matches[2], $GLOBALS['_dd_karr'], $GLOBALS['_dd_kaarr'], $matches[1]);
  1005. }
  1006. //高亮专用, 替换多次是可能不能达到最多次
  1007. function _highlight($string, $words, $result, $pre)
  1008. {
  1009. global $cfg_replace_num;
  1010. if (version_compare(PHP_VERSION, '5.5.0', '>=') && version_compare(PHP_VERSION, '8.0.0', '<')) {
  1011. $string = $string[0];
  1012. $pre = $pre[0];
  1013. }
  1014. $string = str_replace('\"', '"', $string);
  1015. if ($cfg_replace_num > 0) {
  1016. foreach ($words as $key => $word) {
  1017. if ($GLOBALS['replaced'][$word] == 1) {
  1018. continue;
  1019. }
  1020. $string = preg_replace("#" . preg_quote($word) . "#", $result[$key], $string, $cfg_replace_num);
  1021. if (strpos($string, $word) !== FALSE) {
  1022. $GLOBALS['replaced'][$word] = 1;
  1023. }
  1024. }
  1025. } else {
  1026. $string = str_replace($words, $result, $string);
  1027. }
  1028. return $pre . $string;
  1029. }