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

1014 lines
45KB

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