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

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