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

782 lines
22KB

  1. <?php if(!defined('DEDEINC')) exit('dedecms');
  2. /**
  3. * 文档小助手
  4. *
  5. * @version $Id: channelunit.helper.php 1 16:49 2010年7月6日Z tianya $
  6. * @package DedeCMS.Helpers
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. /**
  12. * 用星表示软件或Flash的等级
  13. *
  14. * @param string $rank 星星数
  15. * @return string
  16. */
  17. if ( ! function_exists('GetRankStar'))
  18. {
  19. function GetRankStar($rank)
  20. {
  21. $nstar = "";
  22. for($i=1;$i<=$rank;$i++)
  23. {
  24. $nstar .= "★";
  25. }
  26. for($i;$i<=5;$i++)
  27. {
  28. $nstar .= "☆";
  29. }
  30. return $nstar;
  31. }
  32. }
  33. /**
  34. * 获得文章网址
  35. * 如果要获得文件的路径,直接用
  36. * GetFileUrl($aid,$typeid,$timetag,$title,$ismake,$rank,$namerule,$typedir,$money)
  37. * 即是不指定站点参数则返回相当对根目录的真实路径
  38. *
  39. * @param int $aid 文档ID
  40. * @param int $typeid 栏目ID
  41. * @param int $timetag 时间戳
  42. * @param string $title 标题
  43. * @param int $ismake 是否生成
  44. * @param int $rank 阅读权限
  45. * @param string $namerule 名称规则
  46. * @param string $typedir 栏目dir
  47. * @param string $money 需要金币
  48. * @param string $filename 文件名称
  49. * @param string $moresite 多站点
  50. * @param string $siteurl 站点地址
  51. * @param string $sitepath 站点路径
  52. * @return string
  53. */
  54. if ( ! function_exists('GetFileUrl'))
  55. {
  56. function GetFileUrl($aid,$typeid,$timetag,$title,$ismake=0,$rank=0,$namerule='',$typedir='',
  57. $money=0, $filename='',$moresite=0,$siteurl='',$sitepath='')
  58. {
  59. $articleUrl = GetFileName($aid,$typeid,$timetag,$title,$ismake,$rank,$namerule,$typedir,$money,$filename);
  60. $sitepath = MfTypedir($sitepath);
  61. //是否强制使用绝对网址
  62. if($GLOBALS['cfg_multi_site']=='Y')
  63. {
  64. if($siteurl=='')
  65. {
  66. $siteurl = $GLOBALS['cfg_basehost'];
  67. }
  68. if($moresite==1)
  69. {
  70. $articleUrl = preg_replace("#^".$sitepath.'#', '', $articleUrl);
  71. }
  72. if(!preg_match("/http:/", $articleUrl))
  73. {
  74. $articleUrl = $siteurl.$articleUrl;
  75. }
  76. }
  77. return $articleUrl;
  78. }
  79. }
  80. /**
  81. * 获得新文件名(本函数会自动创建目录)
  82. *
  83. * @param int $aid 文档ID
  84. * @param int $typeid 栏目ID
  85. * @param int $timetag 时间戳
  86. * @param string $title 标题
  87. * @param int $ismake 是否生成
  88. * @param int $rank 阅读权限
  89. * @param string $namerule 名称规则
  90. * @param string $typedir 栏目dir
  91. * @param string $money 需要金币
  92. * @param string $filename 文件名称
  93. * @return string
  94. */
  95. if ( ! function_exists('GetFileNewName'))
  96. {
  97. function GetFileNewName($aid,$typeid,$timetag,$title,$ismake=0,$rank=0,$namerule='',$typedir='',$money=0,$filename='')
  98. {
  99. global $cfg_arc_dirname;
  100. $articlename = GetFileName($aid,$typeid,$timetag,$title,$ismake,$rank,$namerule,$typedir,$money,$filename);
  101. if(preg_match("/\?/", $articlename))
  102. {
  103. return $articlename;
  104. }
  105. if($cfg_arc_dirname=='Y' && preg_match("/\/$/", $articlename))
  106. {
  107. $articlename = $articlename."index.html";
  108. }
  109. $slen = strlen($articlename)-1;
  110. for($i=$slen;$i>=0;$i--)
  111. {
  112. if($articlename[$i]=='/')
  113. {
  114. $subpos = $i;
  115. break;
  116. }
  117. }
  118. $okdir = substr($articlename,0,$subpos);
  119. CreateDir($okdir);
  120. return $articlename;
  121. }
  122. }
  123. /**
  124. * 获得文件相对于主站点根目录的物理文件名(动态网址返回url)
  125. *
  126. * @param int $aid 文档ID
  127. * @param int $typeid 栏目ID
  128. * @param int $timetag 时间戳
  129. * @param string $title 标题
  130. * @param int $ismake 是否生成
  131. * @param int $rank 阅读权限
  132. * @param string $namerule 名称规则
  133. * @param string $typedir 栏目dir
  134. * @param string $money 需要金币
  135. * @param string $filename 文件名称
  136. * @return string
  137. */
  138. if ( ! function_exists('GetFileName'))
  139. {
  140. function GetFileName($aid,$typeid,$timetag,$title,$ismake=0,$rank=0,$namerule='',$typedir='',$money=0,$filename='')
  141. {
  142. global $cfg_rewrite, $cfg_cmspath, $cfg_arcdir, $cfg_special, $cfg_arc_dirname;
  143. //没指定栏目时用固定规则(专题)
  144. if(empty($namerule)) {
  145. $namerule = $cfg_special.'/arc-{aid}.html';
  146. $typeid = -1;
  147. }
  148. if($rank!=0 || $ismake==-1 || $typeid==0 || $money>0)
  149. {
  150. //动态文章
  151. if($cfg_rewrite == 'Y')
  152. {
  153. return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';
  154. }
  155. else
  156. {
  157. return $GLOBALS['cfg_phpurl']."/view.php?aid=$aid";
  158. }
  159. }
  160. else
  161. {
  162. $articleDir = MfTypedir($typedir);
  163. $articleRule = strtolower($namerule);
  164. if($articleRule=='')
  165. {
  166. $articleRule = strtolower($GLOBALS['cfg_df_namerule']);
  167. }
  168. if($typedir=='')
  169. {
  170. $articleDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
  171. }
  172. $dtime = GetDateMk($timetag);
  173. list($y, $m, $d) = explode('-', $dtime);
  174. $arr_rpsource = array('{typedir}','{y}','{m}','{d}','{timestamp}','{aid}','{cc}');
  175. $arr_rpvalues = array($articleDir,$y, $m, $d, $timetag, $aid, dd2char($m.$d.$aid.$y));
  176. if($filename != '')
  177. {
  178. $articleRule = dirname($articleRule).'/'.$filename.$GLOBALS['cfg_df_ext'];
  179. }
  180. $articleRule = str_replace($arr_rpsource,$arr_rpvalues,$articleRule);
  181. if(preg_match("/\{p/", $articleRule))
  182. {
  183. $articleRule = str_replace('{pinyin}',GetPinyin($title).'_'.$aid,$articleRule);
  184. $articleRule = str_replace('{py}',GetPinyin($title,1).'_'.$aid,$articleRule);
  185. }
  186. $articleUrl = '/'.preg_replace("/^\//", '', $articleRule);
  187. if(preg_match("/index\.html/", $articleUrl) && $cfg_arc_dirname=='Y')
  188. {
  189. $articleUrl = str_replace('index.html', '', $articleUrl);
  190. }
  191. return $articleUrl;
  192. }
  193. }
  194. }
  195. /**
  196. * 获得指定类目的URL链接
  197. * 对于使用封面文件和单独页面的情况,强制使用默认页名称
  198. *
  199. * @param int $typeid 栏目ID
  200. * @param string $typedir 栏目目录
  201. * @param int $isdefault 是否默认
  202. * @param string $defaultname 默认名称
  203. * @param int $ispart 栏目属性
  204. * @param string $namerule2 名称规则
  205. * @param string $moresite 多站点
  206. * @param string $siteurl 站点地址
  207. * @param string $sitepath 站点目录
  208. * @return string
  209. */
  210. if ( ! function_exists('GetTypeUrl'))
  211. {
  212. function GetTypeUrl($typeid,$typedir,$isdefault,$defaultname,$ispart,$namerule2,$moresite=0,$siteurl='',$sitepath='')
  213. {
  214. global $cfg_typedir_df;
  215. $typedir = MfTypedir($typedir);
  216. $sitepath = MfTypedir($sitepath);
  217. if($isdefault==-1)
  218. {
  219. //动态
  220. $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
  221. }
  222. else if($ispart==2)
  223. {
  224. //跳转网址
  225. $reurl = $typedir;
  226. return $reurl;
  227. }
  228. else
  229. {
  230. if($isdefault==0 && $ispart==0)
  231. {
  232. $reurl = str_replace("{page}","1",$namerule2);
  233. $reurl = str_replace("{tid}",$typeid,$reurl);
  234. $reurl = str_replace("{typedir}",$typedir,$reurl);
  235. }
  236. else
  237. {
  238. if($cfg_typedir_df=='N' || $isdefault==0) $reurl = $typedir.'/'.$defaultname;
  239. else $reurl = $typedir.'/';
  240. }
  241. }
  242. if( !preg_match("/^http:\/\//",$reurl) ) {
  243. $reurl = preg_replace("/\/{1,}/i", '/', $reurl);
  244. }
  245. if($GLOBALS['cfg_multi_site']=='Y')
  246. {
  247. if($siteurl=='') {
  248. $siteurl = $GLOBALS['cfg_basehost'];
  249. }
  250. if($moresite==1 ) {
  251. $reurl = preg_replace("#^".$sitepath."#", '', $reurl);
  252. }
  253. if( !preg_match("/^http:\/\//", $reurl) ) {
  254. $reurl = $siteurl.$reurl;
  255. }
  256. }
  257. return $reurl;
  258. }
  259. }
  260. /**
  261. * 魔法变量,用于获取两个可变的值
  262. *
  263. * @param string $v1 第一个变量
  264. * @param string $v2 第二个变量
  265. * @return string
  266. */
  267. if ( ! function_exists('MagicVar'))
  268. {
  269. function MagicVar($v1,$v2)
  270. {
  271. return $GLOBALS['autoindex']%2==0 ? $v1 : $v2;
  272. }
  273. }
  274. /**
  275. * 获取某个类目的所有上级栏目id
  276. *
  277. * @param int $tid 栏目ID
  278. * @return string
  279. */
  280. if ( ! function_exists('GetTopids'))
  281. {
  282. function GetTopids($tid)
  283. {
  284. $arr = GetParentIds($tid);
  285. return join(',',$arr);
  286. }
  287. }
  288. /**
  289. * 获取上级ID列表
  290. *
  291. * @access public
  292. * @param string $tid 栏目ID
  293. * @return string
  294. */
  295. if ( ! function_exists('GetParentIds'))
  296. {
  297. function GetParentIds($tid)
  298. {
  299. global $cfg_Cs;
  300. $GLOBALS['pTypeArrays'][] = $tid;
  301. if(!is_array($cfg_Cs))
  302. {
  303. require_once(DEDEDATA."/cache/inc_catalog_base.inc");
  304. }
  305. if(!isset($cfg_Cs[$tid]) || $cfg_Cs[$tid][0]==0)
  306. {
  307. return $GLOBALS['pTypeArrays'];
  308. }
  309. else
  310. {
  311. return GetParentIds($cfg_Cs[$tid][0]);
  312. }
  313. }
  314. }
  315. /**
  316. * 检测栏目是否是另一个栏目的父目录
  317. *
  318. * @access public
  319. * @param string $sid 顶级目录id
  320. * @param string $pid 下级目录id
  321. * @return bool
  322. */
  323. if ( ! function_exists('IsParent'))
  324. {
  325. function IsParent($sid, $pid)
  326. {
  327. $pTypeArrays = GetParentIds($sid);
  328. return in_array($pid, $pTypeArrays);
  329. }
  330. }
  331. /**
  332. * 获取一个类目的顶级类目id
  333. *
  334. * @param string $tid 栏目ID
  335. * @return string
  336. */
  337. if ( ! function_exists('GetTopid'))
  338. {
  339. function GetTopid($tid)
  340. {
  341. global $cfg_Cs;
  342. if(!is_array($cfg_Cs))
  343. {
  344. require_once(DEDEDATA."/cache/inc_catalog_base.inc");
  345. }
  346. if(!isset($cfg_Cs[$tid][0]) || $cfg_Cs[$tid][0]==0)
  347. {
  348. return $tid;
  349. }
  350. else
  351. {
  352. return GetTopid($cfg_Cs[$tid][0]);
  353. }
  354. }
  355. }
  356. /**
  357. * 获得某id的所有下级id
  358. *
  359. * @param string $id 栏目id
  360. * @param string $channel 模型ID
  361. * @param string $addthis 是否包含本身
  362. * @return string
  363. */
  364. function GetSonIds($id,$channel=0,$addthis=true)
  365. {
  366. global $cfg_Cs;
  367. $GLOBALS['idArray'] = array();
  368. if( !is_array($cfg_Cs) && file_exists(DEDEDATA."/cache/inc_catalog_base.inc") )
  369. {
  370. require_once(DEDEDATA."/cache/inc_catalog_base.inc");
  371. }
  372. GetSonIdsLogic($id,$cfg_Cs,$channel,$addthis);
  373. $rquery = join(',',$GLOBALS['idArray']);
  374. $rquery = preg_replace("/,$/", '', $rquery);
  375. return $rquery;
  376. }
  377. //递归逻辑
  378. function GetSonIdsLogic($id,$sArr,$channel=0,$addthis=false)
  379. {
  380. if($id!=0 && $addthis)
  381. {
  382. $GLOBALS['idArray'][$id] = $id;
  383. }
  384. if(is_array($sArr))
  385. {
  386. foreach($sArr as $k=>$v)
  387. {
  388. if( $v[0]==$id && ($channel==0 || $v[1]==$channel ))
  389. {
  390. GetSonIdsLogic($k,$sArr,$channel,true);
  391. }
  392. }
  393. }
  394. }
  395. /**
  396. * 栏目目录规则
  397. *
  398. * @param string $typedir 栏目目录
  399. * @return string
  400. */
  401. function MfTypedir($typedir)
  402. {
  403. if(preg_match("/^http:|^ftp:/i", $typedir)) return $typedir;
  404. $typedir = str_replace("{cmspath}",$GLOBALS['cfg_cmspath'],$typedir);
  405. $typedir = preg_replace("/\/{1,}/", "/", $typedir);
  406. return $typedir;
  407. }
  408. /**
  409. * 模板目录规则
  410. *
  411. * @param string $tmpdir 模板目录
  412. * @return string
  413. */
  414. function MfTemplet($tmpdir)
  415. {
  416. $tmpdir = str_replace("{style}", $GLOBALS['cfg_df_style'], $tmpdir);
  417. $tmpdir = preg_replace("/\/{1,}/", "/", $tmpdir);
  418. return $tmpdir;
  419. }
  420. /**
  421. * 清除用于js的空白块
  422. *
  423. * @param string $atme 字符
  424. * @return string
  425. */
  426. function FormatScript($atme)
  427. {
  428. return $atme=='&nbsp;' ? '' : $atme;
  429. }
  430. /**
  431. * 给属性默认值
  432. *
  433. * @param array $atts 属性
  434. * @param array $attlist 属性列表
  435. * @return string
  436. */
  437. function FillAttsDefault(&$atts, $attlist)
  438. {
  439. $attlists = explode(',', $attlist);
  440. for($i=0; isset($attlists[$i]); $i++)
  441. {
  442. list($k, $v) = explode('|', $attlists[$i]);
  443. if(!isset($atts[$k]))
  444. {
  445. $atts[$k] = $v;
  446. }
  447. }
  448. }
  449. /**
  450. * 给块标记赋值
  451. *
  452. * @param object $dtp 模板解析引擎
  453. * @param object $refObj 实例化对象
  454. * @param object $parfield
  455. * @return string
  456. */
  457. function MakeOneTag(&$dtp, &$refObj, $parfield='Y')
  458. {
  459. global $cfg_disable_tags;
  460. $cfg_disable_tags = isset($cfg_disable_tags)? $cfg_disable_tags : 'php';
  461. $disable_tags = explode(',', $cfg_disable_tags);
  462. $alltags = array();
  463. $dtp->setRefObj($refObj);
  464. //读取自由调用tag列表
  465. $dh = dir(DEDEINC.'/taglib');
  466. while($filename = $dh->read())
  467. {
  468. if(preg_match("/\.lib\./", $filename))
  469. {
  470. $alltags[] = str_replace('.lib.php','',$filename);
  471. }
  472. }
  473. $dh->Close();
  474. //遍历tag元素
  475. if(!is_array($dtp->CTags))
  476. {
  477. return '';
  478. }
  479. foreach($dtp->CTags as $tagid=>$ctag)
  480. {
  481. $tagname = $ctag->GetName();
  482. if($tagname=='field' && $parfield=='Y')
  483. {
  484. $vname = $ctag->GetAtt('name');
  485. if( $vname=='array' && isset($refObj->Fields) )
  486. {
  487. $dtp->Assign($tagid,$refObj->Fields);
  488. }
  489. else if(isset($refObj->Fields[$vname]))
  490. {
  491. $dtp->Assign($tagid,$refObj->Fields[$vname]);
  492. }
  493. else if($ctag->GetAtt('noteid') != '')
  494. {
  495. if( isset($refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')]) )
  496. {
  497. $dtp->Assign($tagid, $refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')]);
  498. }
  499. }
  500. continue;
  501. }
  502. //由于考虑兼容性,原来文章调用使用的标记别名统一保留,这些标记实际调用的解析文件为inc_arclist.php
  503. if(preg_match("/^(artlist|likeart|hotart|imglist|imginfolist|coolart|specart|autolist)$/", $tagname))
  504. {
  505. $tagname='arclist';
  506. }
  507. if($tagname=='friendlink')
  508. {
  509. $tagname='flink';
  510. }
  511. if(in_array($tagname,$alltags))
  512. {
  513. if(in_array($tagname, $disable_tags))
  514. {
  515. if(DEBUG_LEVEL) echo 'DedeCMS Error:Tag disabled:"'.$tagname.'" <a href="https://www.dedebiz.com/help/" target="_blank">more...</a>!';
  516. continue;
  517. }
  518. if (DEBUG_LEVEL==TRUE) {
  519. $ttt1 = ExecTime();
  520. }
  521. $filename = DEDEINC.'/taglib/'.$tagname.'.lib.php';
  522. include_once($filename);
  523. $funcname = 'lib_'.$tagname;
  524. $dtp->Assign($tagid,$funcname($ctag,$refObj));
  525. if (DEBUG_LEVEL==TRUE) {
  526. $queryTime = ExecTime() - $ttt1;
  527. echo '<div style="color: #856404;background-color: #fff3cd;border-color: #ffeeba;position: relative;padding: .75rem 1.25rem;margin-bottom: 1rem;border: 1px solid transparent;border-radius: .25rem;" class="alert alert-warning" role="alert">标签:'.$tagname.'载入花费时间:'.$queryTime."</div>\r\n";
  528. }
  529. }
  530. }
  531. }
  532. /**
  533. * 获取某栏目的url
  534. *
  535. * @param array $typeinfos 栏目信息
  536. * @return string
  537. */
  538. function GetOneTypeUrlA($typeinfos)
  539. {
  540. return GetTypeUrl($typeinfos['id'],MfTypedir($typeinfos['typedir']),$typeinfos['isdefault'],$typeinfos['defaultname'],
  541. $typeinfos['ispart'],$typeinfos['namerule2'],$typeinfos['moresite'],$typeinfos['siteurl'],$typeinfos['sitepath']);
  542. }
  543. /**
  544. * 设置全局环境变量
  545. *
  546. * @param int $typeid 栏目ID
  547. * @param string $typename 栏目名称
  548. * @param string $aid 文档ID
  549. * @param string $title 标题
  550. * @param string $curfile 当前文件
  551. * @return string
  552. */
  553. function SetSysEnv($typeid=0,$typename='',$aid=0,$title='',$curfile='')
  554. {
  555. global $_sys_globals;
  556. if(empty($_sys_globals['curfile']))
  557. {
  558. $_sys_globals['curfile'] = $curfile;
  559. }
  560. if(empty($_sys_globals['typeid']))
  561. {
  562. $_sys_globals['typeid'] = $typeid;
  563. }
  564. if(empty($_sys_globals['typename']))
  565. {
  566. $_sys_globals['typename'] = $typename;
  567. }
  568. if(empty($_sys_globals['aid']))
  569. {
  570. $_sys_globals['aid'] = $aid;
  571. }
  572. }
  573. /**
  574. * 获得图书的URL
  575. *
  576. * @param string $bid 书籍ID
  577. * @param string $title 标题
  578. * @param string $gdir
  579. * @return string
  580. */
  581. function GetBookUrl($bid,$title,$gdir=0)
  582. {
  583. global $cfg_cmspath;
  584. $bookurl = $gdir==1 ?
  585. "{$cfg_cmspath}/book/".DedeID2Dir($bid) : "{$cfg_cmspath}/book/".DedeID2Dir($bid).'/'.GetPinyin($title).'-'.$bid.'.html';
  586. return $bookurl;
  587. }
  588. /**
  589. * 根据ID生成目录
  590. *
  591. * @param string $aid 内容ID
  592. * @return int
  593. */
  594. function DedeID2Dir($aid)
  595. {
  596. $n = ceil($aid / 1000);
  597. return $n;
  598. }
  599. /**
  600. * 获得自由列表的网址
  601. *
  602. * @param string $lid 列表id
  603. * @param string $namerule 命名规则
  604. * @param string $listdir 列表目录
  605. * @param string $defaultpage 默认页面
  606. * @param string $nodefault 没有默认页面
  607. * @return string
  608. */
  609. function GetFreeListUrl($lid,$namerule,$listdir,$defaultpage,$nodefault){
  610. $listdir = str_replace('{cmspath}',$GLOBALS['cfg_cmspath'],$listdir);
  611. if($nodefault==1)
  612. {
  613. $okfile = str_replace('{page}','1',$namerule);
  614. $okfile = str_replace('{listid}',$lid,$okfile);
  615. $okfile = str_replace('{listdir}',$listdir,$okfile);
  616. }
  617. else
  618. {
  619. $okfile = $GLOBALS['cfg_phpurl']."/freelist.php?lid=$lid";
  620. return $okfile;
  621. }
  622. $okfile = str_replace("\\","/",$okfile);
  623. $okfile = str_replace("//","/",$okfile);
  624. $trueFile = $GLOBALS['cfg_basedir'].$okfile;
  625. if(!@file_exists($trueFile))
  626. {
  627. $okfile = $GLOBALS['cfg_phpurl']."/freelist.php?lid=$lid";
  628. }
  629. return $okfile;
  630. }
  631. /**
  632. * 获取网站搜索的热门关键字
  633. *
  634. * @param object $dsql
  635. * @param string $num 获取数目
  636. * @param string $nday 天数
  637. * @param string $klen 关键词字数
  638. * @param string $orderby 排列顺序
  639. * @return string
  640. */
  641. function GetHotKeywords(&$dsql,$num=8,$nday=365,$klen=16,$orderby='count')
  642. {
  643. global $cfg_phpurl;
  644. $nowtime = time();
  645. $num = @intval($num);
  646. $nday = @intval($nday);
  647. $klen = @intval($klen);
  648. if(empty($nday))
  649. {
  650. $nday = 365;
  651. }
  652. if(empty($num))
  653. {
  654. $num = 6;
  655. }
  656. if(empty($klen))
  657. {
  658. $klen = 16;
  659. }
  660. $klen = $klen+1;
  661. $mintime = $nowtime - ($nday * 24 * 3600);
  662. if(empty($orderby))
  663. {
  664. $orderby = 'count';
  665. }
  666. $dsql->SetQuery("SELECT keyword FROM `#@__search_keywords` WHERE lasttime>$mintime AND length(keyword)<$klen ORDER BY $orderby DESC LIMIT 0,$num");
  667. $dsql->Execute('hw');
  668. $hotword = "";
  669. while($row=$dsql->GetArray('hw'))
  670. {
  671. $hotword .= " <a href='".$cfg_phpurl."/search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'>".$row['keyword']."</a> ";
  672. }
  673. return $hotword;
  674. }
  675. /**
  676. * 使用绝对网址
  677. *
  678. * @param string $gurl 地址
  679. * @return string
  680. */
  681. function Gmapurl($gurl)
  682. {
  683. return preg_match("/http[s]?:\/\//i", $gurl) ? $gurl : $GLOBALS['cfg_basehost'].$gurl;
  684. }
  685. /**
  686. * 引用回复标记处理
  687. *
  688. * @param string $quote
  689. * @return string
  690. */
  691. function Quote_replace($quote)
  692. {
  693. $quote = str_replace('{quote}','<div class="decmt-box">',$quote);
  694. $quote = str_replace('{title}','<div class="decmt-title"><span class="username">',$quote);
  695. $quote = str_replace('{/title}','</span></div>',$quote);
  696. $quote = str_replace('&lt;br/&gt;','<br>',$quote);
  697. $quote = str_replace('&lt;', '<', $quote);
  698. $quote = str_replace('&gt;', '>', $quote);
  699. $quote = str_replace('{content}','<div class="decmt-content">',$quote);
  700. $quote = str_replace('{/content}','</div>',$quote);
  701. $quote = str_replace('{/quote}','</div>',$quote);
  702. return $quote;
  703. }
  704. /**
  705. * 获取、写入指定cacheid的块
  706. *
  707. * @param string $cacheid 缓存ID
  708. * @return string
  709. */
  710. function GetCacheBlock($cacheid)
  711. {
  712. global $cfg_puccache_time;
  713. $cachefile = DEDEDATA.'/cache/'.$cacheid.'.inc';
  714. if(!file_exists($cachefile) || filesize($cachefile)==0 ||
  715. $cfg_puccache_time==0 || time() - filemtime($cachefile) > $cfg_puccache_time)
  716. {
  717. return '';
  718. }
  719. $fp = fopen($cachefile, 'r');
  720. $str = @fread($fp, filesize($cachefile));
  721. fclose($fp);
  722. return $str;
  723. }
  724. /**
  725. * 写入缓存块
  726. *
  727. * @param string $cacheid 缓存ID
  728. * @param string $str 字符串信息
  729. * @return string
  730. */
  731. function WriteCacheBlock($cacheid, $str)
  732. {
  733. $cachefile = DEDEDATA.'/cache/'.$cacheid.'.inc';
  734. $fp = fopen($cachefile, 'w');
  735. $str = fwrite($fp, $str);
  736. fclose($fp);
  737. }