国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

702 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|https|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. if (is_array($attlists)) {
  415. for ($i = 0; isset($attlists[$i]); $i++) {
  416. if (empty($attlists[$i])) {
  417. continue;
  418. }
  419. list($k, $v) = explode('|', $attlists[$i]);
  420. if (!isset($atts[$k])) {
  421. $atts[$k] = $v;
  422. }
  423. }
  424. }
  425. }
  426. /**
  427. * 给块标记赋值
  428. *
  429. * @param object $dtp 模板解析引擎
  430. * @param object $refObj 实例化对象
  431. * @param object $parfield
  432. * @return string
  433. */
  434. function MakeOneTag(&$dtp, &$refObj, $parfield = 'Y')
  435. {
  436. global $cfg_disable_tags;
  437. $cfg_disable_tags = isset($cfg_disable_tags) ? $cfg_disable_tags : 'php';
  438. $disable_tags = explode(',', $cfg_disable_tags);
  439. $alltags = array();
  440. $dtp->setRefObj($refObj);
  441. //读取自由调用tag列表
  442. $dh = dir(DEDEINC.'/taglib');
  443. while ($filename = $dh->read()) {
  444. if (preg_match("/\.lib\./", $filename)) {
  445. $alltags[] = str_replace('.lib.php', '', $filename);
  446. }
  447. }
  448. $dh->Close();
  449. //遍历tag元素
  450. if (!is_array($dtp->CTags)) {
  451. return '';
  452. }
  453. foreach ($dtp->CTags as $tagid => $ctag) {
  454. $tagname = $ctag->GetName();
  455. if ($tagname == 'field' && $parfield == 'Y') {
  456. $vname = $ctag->GetAtt('name');
  457. if ($vname == 'array' && isset($refObj->Fields)) {
  458. $dtp->Assign($tagid, $refObj->Fields);
  459. } else if (isset($refObj->Fields[$vname])) {
  460. $dtp->Assign($tagid, $refObj->Fields[$vname]);
  461. } else if ($ctag->GetAtt('noteid') != '') {
  462. if (isset($refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')])) {
  463. $dtp->Assign($tagid, $refObj->Fields[$vname.'_'.$ctag->GetAtt('noteid')]);
  464. }
  465. }
  466. continue;
  467. }
  468. //由于考虑兼容性,原来文章调用使用的标记别名统一保留,这些标记实际调用的解析文件为inc_arclist.php
  469. if (preg_match("/^(artlist|likeart|hotart|imglist|imginfolist|coolart|specart|autolist)$/", $tagname)) {
  470. $tagname = 'arclist';
  471. }
  472. if ($tagname == 'friendlink') {
  473. $tagname = 'flink';
  474. }
  475. if (in_array($tagname, $alltags)) {
  476. if (in_array($tagname, $disable_tags)) {
  477. if (DEBUG_LEVEL) echo 'DedeBIZ Error:Tag disabled:"'.$tagname.'" <a href="https://www.dedebiz.com/help/" target="_blank">more</a>!';
  478. continue;
  479. }
  480. if (DEBUG_LEVEL == TRUE) {
  481. $ttt1 = ExecTime();
  482. }
  483. $filename = DEDEINC.'/taglib/'.$tagname.'.lib.php';
  484. include_once($filename);
  485. $funcname = 'lib_'.$tagname;
  486. $dtp->Assign($tagid, $funcname($ctag, $refObj));
  487. if (DEBUG_LEVEL == TRUE) {
  488. $queryTime = ExecTime() - $ttt1;
  489. if (PHP_SAPI === 'cli') {
  490. echo '标签:'.$tagname.'载入花费时间:'.$queryTime."\r\n";
  491. } else {
  492. echo DedeAlert('标签:'.$tagname.'载入花费时间:'.$queryTime, ALERT_WARNING);
  493. }
  494. }
  495. }
  496. }
  497. }
  498. /**
  499. * 获取某栏目的url
  500. *
  501. * @param array $typeinfos 栏目信息
  502. * @return string
  503. */
  504. function GetOneTypeUrlA($typeinfos)
  505. {
  506. return GetTypeUrl(
  507. $typeinfos['id'],
  508. MfTypedir($typeinfos['typedir']),
  509. $typeinfos['isdefault'],
  510. $typeinfos['defaultname'],
  511. $typeinfos['ispart'],
  512. $typeinfos['namerule2'],
  513. $typeinfos['moresite'],
  514. $typeinfos['siteurl'],
  515. $typeinfos['sitepath']
  516. );
  517. }
  518. /**
  519. * 设置全局环境变量
  520. *
  521. * @param int $typeid 栏目ID
  522. * @param string $typename 栏目名称
  523. * @param string $aid 文档ID
  524. * @param string $title 标题
  525. * @param string $curfile 当前文件
  526. * @return string
  527. */
  528. function SetSysEnv($typeid = 0, $typename = '', $aid = 0, $title = '', $curfile = '')
  529. {
  530. global $_sys_globals;
  531. if (empty($_sys_globals['curfile'])) {
  532. $_sys_globals['curfile'] = $curfile;
  533. }
  534. if (empty($_sys_globals['typeid'])) {
  535. $_sys_globals['typeid'] = $typeid;
  536. }
  537. if (empty($_sys_globals['typename'])) {
  538. $_sys_globals['typename'] = $typename;
  539. }
  540. if (empty($_sys_globals['aid'])) {
  541. $_sys_globals['aid'] = $aid;
  542. }
  543. }
  544. /**
  545. * 获得图书的URL
  546. *
  547. * @param string $bid 书籍ID
  548. * @param string $title 标题
  549. * @param string $gdir
  550. * @return string
  551. */
  552. function GetBookUrl($bid, $title, $gdir = 0)
  553. {
  554. global $cfg_cmspath;
  555. $bookurl = $gdir == 1 ? "{$cfg_cmspath}/book/".DedeID2Dir($bid) : "{$cfg_cmspath}/book/".DedeID2Dir($bid).'/'.GetPinyin($title).'-'.$bid.'.html';
  556. return $bookurl;
  557. }
  558. /**
  559. * 根据ID生成目录
  560. *
  561. * @param string $aid 内容ID
  562. * @return int
  563. */
  564. function DedeID2Dir($aid)
  565. {
  566. $n = ceil($aid / 1000);
  567. return $n;
  568. }
  569. /**
  570. * 获得自由列表的网址
  571. *
  572. * @param string $lid 列表id
  573. * @param string $namerule 命名规则
  574. * @param string $listdir 列表目录
  575. * @param string $defaultpage 默认页面
  576. * @param string $nodefault 没有默认页面
  577. * @return string
  578. */
  579. function GetFreeListUrl($lid, $namerule, $listdir, $defaultpage, $nodefault)
  580. {
  581. $listdir = str_replace('{cmspath}', $GLOBALS['cfg_cmspath'], $listdir);
  582. if ($nodefault == 1) {
  583. $okfile = str_replace('{page}', '1', $namerule);
  584. $okfile = str_replace('{listid}', $lid, $okfile);
  585. $okfile = str_replace('{listdir}', $listdir, $okfile);
  586. } else {
  587. $okfile = $GLOBALS['cfg_phpurl']."/freelist.php?lid=$lid";
  588. return $okfile;
  589. }
  590. $okfile = str_replace("\\", "/", $okfile);
  591. $okfile = str_replace("//", "/", $okfile);
  592. $trueFile = $GLOBALS['cfg_basedir'].$okfile;
  593. if (!@file_exists($trueFile)) {
  594. $okfile = $GLOBALS['cfg_phpurl']."/freelist.php?lid=$lid";
  595. }
  596. return $okfile;
  597. }
  598. /**
  599. * 获取网站搜索的热门关键词
  600. *
  601. * @param object $dsql
  602. * @param string $num 获取数目
  603. * @param string $nday 天数
  604. * @param string $klen 关键词字数
  605. * @param string $orderby 排列顺序
  606. * @return string
  607. */
  608. function GetHotKeywords(&$dsql, $num = 8, $nday = 365, $klen = 16, $orderby = 'count')
  609. {
  610. global $cfg_phpurl;
  611. $nowtime = time();
  612. $num = @intval($num);
  613. $nday = @intval($nday);
  614. $klen = @intval($klen);
  615. if (empty($nday)) {
  616. $nday = 365;
  617. }
  618. if (empty($num)) {
  619. $num = 6;
  620. }
  621. if (empty($klen)) {
  622. $klen = 16;
  623. }
  624. $klen = $klen + 1;
  625. $mintime = $nowtime - ($nday * 24 * 3600);
  626. if (empty($orderby)) {
  627. $orderby = 'count';
  628. }
  629. $dsql->SetQuery("SELECT keyword FROM `#@__search_keywords` WHERE lasttime>$mintime AND length(keyword)<$klen ORDER BY $orderby DESC LIMIT 0,$num");
  630. $dsql->Execute('hw');
  631. $hotword = "";
  632. while ($row = $dsql->GetArray('hw')) {
  633. $hotword .= " <a href='".$cfg_phpurl."/search.php?keyword=".urlencode($row['keyword'])."&searchtype=titlekeyword'>".$row['keyword']."</a> ";
  634. }
  635. return $hotword;
  636. }
  637. /**
  638. * 使用绝对网址
  639. *
  640. * @param string $gurl 地址
  641. * @return string
  642. */
  643. function Gmapurl($gurl)
  644. {
  645. return preg_match("/http[s]?:\/\//i", $gurl) ? $gurl : $GLOBALS['cfg_basehost'].$gurl;
  646. }
  647. /**
  648. * 引用回复标记处理
  649. *
  650. * @param string $quote
  651. * @return string
  652. */
  653. function Quote_replace($quote)
  654. {
  655. $quote = str_replace('{quote}', '<div class="decmt-box">', $quote);
  656. $quote = str_replace('{title}', '<div class="decmt-title"><span class="username">', $quote);
  657. $quote = str_replace('{/title}', '</span></div>', $quote);
  658. $quote = str_replace('&lt;br/&gt;', '<br>', $quote);
  659. $quote = str_replace('&lt;', '<', $quote);
  660. $quote = str_replace('&gt;', '>', $quote);
  661. $quote = str_replace('{content}', '<div class="decmt-content">', $quote);
  662. $quote = str_replace('{/content}', '</div>', $quote);
  663. $quote = str_replace('{/quote}', '</div>', $quote);
  664. return $quote;
  665. }
  666. /**
  667. * 获取、写入指定cacheid的块
  668. *
  669. * @param string $cacheid 缓存ID
  670. * @return string
  671. */
  672. function GetCacheBlock($cacheid)
  673. {
  674. global $cfg_puccache_time;
  675. $cachefile = DEDEDATA.'/cache/'.$cacheid.'.inc';
  676. if (
  677. !file_exists($cachefile) || filesize($cachefile) == 0 ||
  678. $cfg_puccache_time == 0 || time() - filemtime($cachefile) > $cfg_puccache_time
  679. ) {
  680. return '';
  681. }
  682. $fp = fopen($cachefile, 'r');
  683. $str = @fread($fp, filesize($cachefile));
  684. fclose($fp);
  685. return $str;
  686. }
  687. /**
  688. * 写入缓存块
  689. *
  690. * @param string $cacheid 缓存ID
  691. * @param string $str 字符串信息
  692. * @return string
  693. */
  694. function WriteCacheBlock($cacheid, $str)
  695. {
  696. $cachefile = DEDEDATA.'/cache/'.$cacheid.'.inc';
  697. $fp = fopen($cachefile, 'w');
  698. $str = fwrite($fp, $str);
  699. fclose($fp);
  700. }