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

687 lines
22KB

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