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

728 lines
22KB

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