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

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