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

727 lines
22KB

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