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

697 lines
23KB

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