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

686 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. //伪静态文档,Nginx伪静态规则参考:rewrite ^/([0-9]+).html$ /apps/view.php?arcID=$1;rewrite ^/([0-9]+)-([0-9]+).html$ /apps/view.php?aid=$1&pageno=$2;
  149. if ($cfg_rewrite == 'Y') {
  150. //目录版return "/article/".$aid."";
  151. //网页版
  152. return "/".$aid.".html";
  153. } else {
  154. return $GLOBALS['cfg_phpurl']."/view.php?aid=$aid";
  155. }
  156. } else {
  157. $articleDir = MfTypedir($typedir);
  158. $articleRule = strtolower($namerule);
  159. if ($articleRule == '') {
  160. $articleRule = strtolower($GLOBALS['cfg_df_namerule']);
  161. }
  162. if ($typedir == '') {
  163. $articleDir = $GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir'];
  164. }
  165. $dtime = GetDateMk($timetag);
  166. list($y, $m, $d) = explode('-', $dtime);
  167. $arr_rpsource = array('{typedir}', '{y}', '{m}', '{d}', '{timestamp}', '{aid}', '{cc}');
  168. $arr_rpvalues = array($articleDir, $y, $m, $d, $timetag, $aid, dd2char($m.$d.$aid.$y));
  169. if ($filename != '') {
  170. $articleRule = dirname($articleRule).'/'.$filename.$GLOBALS['cfg_df_ext'];
  171. }
  172. $articleRule = str_replace($arr_rpsource, $arr_rpvalues, $articleRule);
  173. if (preg_match("/\{p/", $articleRule)) {
  174. $articleRule = str_replace('{pinyin}', GetPinyin($title).'_'.$aid, $articleRule);
  175. $articleRule = str_replace('{py}', GetPinyin($title, 1).'_'.$aid, $articleRule);
  176. }
  177. $articleUrl = '/'.preg_replace("/^\//", '', $articleRule);
  178. if (preg_match("/index\.html/", $articleUrl) && $cfg_arc_dirname == 'Y') {
  179. $articleUrl = str_replace('index.html', '', $articleUrl);
  180. }
  181. return $articleUrl;
  182. }
  183. }
  184. }
  185. /**
  186. * 获得指定类目的URL链接
  187. * 对于使用封面文件和单独页面的情况,强制使用默认页名称
  188. *
  189. * @param int $typeid 栏目ID
  190. * @param string $typedir 栏目目录
  191. * @param int $isdefault 是否默认
  192. * @param string $defaultname 默认名称
  193. * @param int $ispart 栏目属性
  194. * @param string $namerule2 名称规则
  195. * @param string $moresite 多站点
  196. * @param string $siteurl 站点地址
  197. * @param string $sitepath 站点目录
  198. * @return string
  199. */
  200. if (!function_exists('GetTypeUrl')) {
  201. function GetTypeUrl($typeid, $typedir, $isdefault, $defaultname, $ispart, $namerule2, $moresite = 0, $siteurl = '', $sitepath = '')
  202. {
  203. global $cfg_typedir_df;
  204. $typedir = MfTypedir($typedir);
  205. $sitepath = MfTypedir($sitepath);
  206. //伪静态栏目,Nginx伪静态规则参考:rewrite ^/list([0-9]+)$ /apps/list.php?tid=$1;rewrite ^/list([0-9]+)-([0-9]+)$ /apps/list.php?tid=$1&PageNo=$2;
  207. if($isdefault==-1) {
  208. //目录版
  209. $reurl = "/list".$typeid."";
  210. //网页版$reurl = "/list".$typeid.".html";
  211. } else if ($ispart == 2) {
  212. //跳转网址
  213. $reurl = $typedir;
  214. return $reurl;
  215. } else {
  216. if ($isdefault == 0 && $ispart == 0) {
  217. $reurl = str_replace("{page}", "1", $namerule2);
  218. $reurl = str_replace("{tid}", $typeid, $reurl);
  219. $reurl = str_replace("{typedir}", $typedir, $reurl);
  220. } else {
  221. if ($cfg_typedir_df == 'N' || $isdefault == 0) $reurl = $typedir.'/'.$defaultname;
  222. else $reurl = $typedir.'/';
  223. }
  224. }
  225. if (!preg_match("/^http:\/\//", $reurl)) {
  226. $reurl = preg_replace("/\/{1,}/i", '/', $reurl);
  227. }
  228. if ($GLOBALS['cfg_multi_site'] == 'Y') {
  229. if ($siteurl == '') {
  230. $siteurl = $GLOBALS['cfg_basehost'];
  231. }
  232. if ($moresite == 1) {
  233. $reurl = preg_replace("#^".$sitepath."#", '', $reurl);
  234. }
  235. if (!preg_match("/^http:\/\//", $reurl)) {
  236. $reurl = $siteurl.$reurl;
  237. }
  238. }
  239. return $reurl;
  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:|^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(',', $attlist);
  404. for ($i = 0; isset($attlists[$i]); $i++) {
  405. list($k, $v) = explode('|', $attlists[$i]);
  406. if (!isset($atts[$k])) {
  407. $atts[$k] = $v;
  408. }
  409. }
  410. }
  411. /**
  412. * 给块标记赋值
  413. *
  414. * @param object $dtp 模板解析引擎
  415. * @param object $refObj 实例化对象
  416. * @param object $parfield
  417. * @return string
  418. */
  419. function MakeOneTag(&$dtp, &$refObj, $parfield = 'Y')
  420. {
  421. global $cfg_disable_tags;
  422. $cfg_disable_tags = isset($cfg_disable_tags) ? $cfg_disable_tags : 'php';
  423. $disable_tags = explode(',', $cfg_disable_tags);
  424. $alltags = array();
  425. $dtp->setRefObj($refObj);
  426. //读取自由调用tag列表
  427. $dh = dir(DEDEINC.'/taglib');
  428. while ($filename = $dh->read()) {
  429. if (preg_match("/\.lib\./", $filename)) {
  430. $alltags[] = str_replace('.lib.php', '', $filename);
  431. }
  432. }
  433. $dh->Close();
  434. //遍历tag元素
  435. if (!is_array($dtp->CTags)) {
  436. return '';
  437. }
  438. foreach ($dtp->CTags as $tagid => $ctag) {
  439. $tagname = $ctag->GetName();
  440. if ($tagname == 'field' && $parfield == 'Y') {
  441. $vname = $ctag->GetAtt('name');
  442. if ($vname == 'array' && isset($refObj->Fields)) {
  443. $dtp->Assign($tagid, $refObj->Fields);
  444. } else if (isset($refObj->Fields[$vname])) {
  445. $dtp->Assign($tagid, $refObj->Fields[$vname]);
  446. } else if ($ctag->GetAtt('noteid') != '') {
  447. if (isset($refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')])) {
  448. $dtp->Assign($tagid, $refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')]);
  449. }
  450. }
  451. continue;
  452. }
  453. //由于考虑兼容性,原来文章调用使用的标记别名统一保留,这些标记实际调用的解析文件为inc_arclist.php
  454. if (preg_match("/^(artlist|likeart|hotart|imglist|imginfolist|coolart|specart|autolist)$/", $tagname)) {
  455. $tagname = 'arclist';
  456. }
  457. if ($tagname == 'friendlink') {
  458. $tagname = 'flink';
  459. }
  460. if (in_array($tagname, $alltags)) {
  461. if (in_array($tagname, $disable_tags)) {
  462. if (DEBUG_LEVEL) echo 'DedeBIZ Error:Tag disabled:"'.$tagname.'" <a href="https://www.dedebiz.com/help/" target="_blank">more</a>!';
  463. continue;
  464. }
  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 '<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";
  478. }
  479. }
  480. }
  481. }
  482. }
  483. /**
  484. * 获取某栏目的url
  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. * 获得图书的URL
  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. }