arc.archives.class.php 46 KB

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