国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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