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

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