DedeV6移动版
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.

archives.m.class.php 46KB

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