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

channelunit.helper.php 22KB

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