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

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