home.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. // JavaScript Document
  2. <?php
  3. if(!function_exists("error"))
  4. {
  5. function error($msg="",$url="",$time=2)
  6. {
  7. $app = sys_init();
  8. //哪果没有内容
  9. if(!$msg && !$url)
  10. {
  11. exit("error: false");
  12. }
  13. //如果没有内容提示,则直接跳转
  14. if(!$msg)
  15. {
  16. sys_header($url);
  17. }
  18. //如果有内容提示跳转
  19. $app->tpl->assign("msg",$msg);
  20. $app->tpl->assign("error_url",$url);
  21. if($url)
  22. {
  23. $error_note = sys_eval($app->lang["error_note"],$time);
  24. $app->tpl->assign("error_note",$error_note);
  25. }
  26. $app->tpl->assign("time",$time);
  27. //毫秒级,在JS中应用
  28. $app->tpl->assign("micro_time",$time*1000);
  29. $app->tpl->display("error.".$app->tpl->ext);
  30. exit();
  31. }
  32. }
  33. //rs是数组,根据数组原则生成静态页及伪静态页链接
  34. function msg_url($rs,$format=true)
  35. {
  36. $app = sys_init();
  37. if(!$rs)
  38. {
  39. return $app->url();
  40. }
  41. if(!$format || ($app->sys_config["site_type"] != "html" && $app->sys_config["site_type"] != "rewrite"))
  42. {
  43. $ext = $rs["identifier"] ? "ts=".$rs["identifier"] : "id=".$rs["id"];
  44. return $app->url("msg",$ext);
  45. }
  46. if($app->sys_config["site_type"] == "html" && !$app->sys_config["sitehtml"])
  47. {
  48. $app->sys_config["sitehtml"] = $app->sys_config["siteurl"]."html/".$app->langid."/";
  49. }
  50. if($app->sys_config["site_type"] == "rewrite")
  51. {
  52. $url = "c".$rs["id"].".html";
  53. if($rs["identifier"])
  54. {
  55. $url = $rs["identifier"].".html";
  56. }
  57. return $url;
  58. }
  59. //格式化网址
  60. $url = $app->sys_config["sitehtml"];
  61. if(substr($url,-1) != "/")
  62. {
  63. $url .= "/";
  64. }
  65. $this_url_end = ($rs["identifier"] && $rs["identifier"] != "index") ? $rs["identifier"].".html" : "c".$rs["id"].".html";
  66. if($rs["htmltype"] == "root")
  67. {
  68. $url .= $this_url_end;
  69. }
  70. elseif($rs["htmltype"] == "mid" || $rs["htmltype"] == "cateid")
  71. {
  72. $url .= $app->module_idlist[$rs["module_id"]]."/";
  73. if($rs["htmltype"] == "cateid" && $rs["cate_id"])
  74. {
  75. $url .= $app->cate_idlist[$rs["cate_id"]]."/";
  76. }
  77. $url .= $this_url_end;
  78. }
  79. else
  80. {
  81. $url .= date("Ym/d/",$rs["post_date"]);
  82. $url .= $this_url_end;
  83. }
  84. return $url;
  85. }
  86. //模块列表
  87. function module_url($rs,$pageid=0,$format=true,$ifindex=true)
  88. {
  89. $app = sys_init();
  90. if(!$rs)
  91. {
  92. return $app->url();
  93. }
  94. if(!$format || ($app->sys_config["site_type"] != "html" && $app->sys_config["site_type"] != "rewrite"))
  95. {
  96. $ext = $rs["identifier"] ? "ms=".$rs["identifier"] : "mid=".$rs["id"];
  97. if($pageid>1)
  98. {
  99. $ext .= "&".SYS_PAGEID."=".$pageid;
  100. }
  101. return $app->url("list",$ext);
  102. }
  103. if($app->sys_config["site_type"] == "html" && !$app->sys_config["sitehtml"])
  104. {
  105. $app->sys_config["sitehtml"] = $app->sys_config["siteurl"]."html/".$app->langid."/";
  106. }
  107. if($app->sys_config["site_type"] == "rewrite")
  108. {
  109. $url = $rs["identifier"] ? "ms-".$rs["identifier"] : "mid-".$rs["id"];
  110. $url.= $pageid<2 ? ".html" : "-".$pageid.".html";
  111. return $url;
  112. }
  113. //针对HTML的格式化
  114. $url = $app->sys_config["sitehtml"];
  115. if(substr($url,-1) != "/")
  116. {
  117. $url .= "/";
  118. }
  119. $url.= $rs["identifier"]."/";
  120. if($pageid<2)
  121. {
  122. if($ifindex)
  123. {
  124. $url .= "index.html";
  125. }
  126. }
  127. else
  128. {
  129. $url .= $pageid.".html";
  130. }
  131. return $url;
  132. }
  133. function list_url($rs,$pageid=0,$format=true,$ifindex=true)
  134. {
  135. $app = sys_init();
  136. if(!$rs)
  137. {
  138. return $app->url();
  139. }
  140. if(!$format || ($app->sys_config["site_type"] != "html" && $app->sys_config["site_type"] != "rewrite"))
  141. {
  142. $ext = $rs["identifier"] ? "cs=".$rs["identifier"] : "id=".$rs["id"];
  143. if($pageid>1)
  144. {
  145. $ext .= "&".SYS_PAGEID."=".$pageid;
  146. }
  147. return $app->url("list",$ext);
  148. }
  149. if($app->sys_config["site_type"] == "html" && !$app->sys_config["sitehtml"])
  150. {
  151. $app->sys_config["sitehtml"] = $app->sys_config["siteurl"]."html/".$app->langid."/";
  152. }
  153. if($app->sys_config["site_type"] == "rewrite")
  154. {
  155. $url = $rs["identifier"] ? "cs-".$rs["identifier"] : "cid-".$rs["id"];
  156. $url.= $pageid<2 ? ".html" : "-".$pageid.".html";
  157. return $url;
  158. }
  159. //针对HTML的格式化
  160. $url = $app->sys_config["sitehtml"];
  161. if(substr($url,-1) != "/")
  162. {
  163. $url .= "/";
  164. }
  165. $url .= $app->module_idlist[$rs["module_id"]] . "/";
  166. $url .= $app->cate_idlist[$rs["id"]]."/";
  167. if($pageid<2)
  168. {
  169. if($ifindex)
  170. {
  171. $url .= "index.html";
  172. }
  173. }
  174. else
  175. {
  176. $url .= $pageid.".html";
  177. }
  178. return $url;
  179. }
  180. if(!function_exists("site_url"))
  181. {
  182. function site_url($value,$extend="",$format=true,$format_type_ext="&amp;")
  183. {
  184. $app = sys_init();
  185. if(!$value)
  186. {
  187. return $app->url();
  188. }
  189. if(!$format || ($app->sys_config["site_type"] != "html" && $app->sys_config["site_type"] != "rewrite"))
  190. {
  191. return $app->url($value,$extend,$format_type_ext);
  192. }
  193. if($app->sys_config["site_type"] == "html" && !$app->sys_config["sitehtml"])
  194. {
  195. $app->sys_config["sitehtml"] = $app->sys_config["siteurl"]."html/".$app->langid."/";
  196. }
  197. $format_type = $app->sys_config["site_type"];
  198. //切分地址
  199. $ext = explode(",",$value);
  200. $c = $ext[0];
  201. if(!$c)
  202. {
  203. return false;
  204. }
  205. if(!$c != "list" || $c != "msg")
  206. {
  207. return $app->url($value,$extend,$format_type_ext);
  208. }
  209. $f = $ext[1] ? $ext[1] : "";
  210. $d = $ext[2] ? $ext[2] : "";
  211. if($extend)
  212. {
  213. $array = explode("&",$extend);
  214. foreach($array AS $k=>$v)
  215. {
  216. $tmp_array = explode("=",$v);
  217. $$tmp_array[0] = $tmp_array[1];
  218. }
  219. }
  220. if($c == "list" && $extend)
  221. {
  222. if($cid || $cs)
  223. {
  224. if($format_type == "rewrite")
  225. {
  226. $url = $cid ? "cid-".$cid : "cs-".$cs;
  227. if($pageid && $pageid>1)
  228. {
  229. $url .= "-".$pageid;
  230. }
  231. $url .= ".html";
  232. return $url;
  233. }
  234. else
  235. {
  236. $app->load_model("cate");
  237. if(!$cid && $cs)
  238. {
  239. $cid = $app->cate_m->get_cid_from_code($cs);
  240. }
  241. if($cid)
  242. {
  243. $rs = $app->cate_m->get_one($cid);
  244. return list_url($rs);
  245. }
  246. }
  247. }
  248. else
  249. {
  250. if($format_type == "rewrite")
  251. {
  252. $url = $mid ? "mid-".$mid : "ms-".$ms;
  253. if($pageid && $pageid>1)
  254. {
  255. $url .= "-".$pageid;
  256. }
  257. $url .= ".html";
  258. return $url;
  259. }
  260. else
  261. {
  262. $app->load_model("module");
  263. if($ms && !$mid)
  264. {
  265. $mid = $app->module_m->get_mid_from_code($ms);
  266. }
  267. if($mid)
  268. {
  269. $rs = $app->module_m->get_one($mid);
  270. return module_url($rs);
  271. }
  272. }
  273. }
  274. }
  275. elseif($c == "msg" && $extend)
  276. {
  277. if($format_type == "rewrite")
  278. {
  279. $url = $id ? "c".$id.".html" : $ts.".html";
  280. return $url;
  281. }
  282. else
  283. {
  284. $app->load_model("msg");
  285. if($id)
  286. {
  287. $rs = $app->msg_m->get_one($id);
  288. }
  289. else
  290. {
  291. $rs = $app->msg_m->get_one_fromtype($ts,$_SESSION["sys_lang_id"]);
  292. }
  293. return msg_url($rs);
  294. }
  295. }
  296. return $app->url($value,$extend,$format_type_ext);
  297. }
  298. }
  299. if(!function_exists("sys_format_content"))
  300. {
  301. function sys_format_content($msg)
  302. {
  303. if(!$msg)
  304. {
  305. return false;
  306. }
  307. $msg = str_replace("[:page:]","",$msg);
  308. $list = array();
  309. preg_match_all("/\[((download|video):([0-9]+))\]/isU",$msg,$list);
  310. $list = array_unique($list[1]);
  311. if(!$list || !is_array($list) || count($list)<1)
  312. {
  313. return $msg;
  314. }
  315. $app = sys_init();
  316. $app->load_model("upfile");
  317. if(!$app->lang["download"])
  318. {
  319. $app->lang["download"] = "download";
  320. }
  321. foreach($list AS $key=>$value)
  322. {
  323. $array = explode(":",$value);
  324. if(!$array[1])
  325. {
  326. continue;
  327. }
  328. if(!$array[0])
  329. {
  330. $array[0] = "download";
  331. }
  332. $type = in_array($array[0],array("download","video")) ? $array[0] : "download";
  333. $id = $array[1];
  334. $rs = $app->upfile_m->get_one($id);
  335. if(!$rs)
  336. {
  337. continue;
  338. }
  339. if($type == "video")
  340. {
  341. $width = $app->sys_config["video_width"] ? $app->sys_config["video_width"] : "500";
  342. $height = $app->sys_config["video_height"] ? $app->sys_config["video_height"] : "400";
  343. $pre_image = $rs["flv_pic"] ? $rs["flv_pic"] : $app->sys_config["video_image"];
  344. $n_msg = "<div class='video'>";
  345. $n_msg.= "<script type='text/javascript'>";
  346. $n_msg.= 'var htmlmsg = Media.init("'.$rs["filename"].'","'.$width.'","'.$height.'","'.$pre_image.'");';
  347. $n_msg.= "document.write(htmlmsg);</script>";
  348. $n_msg.= "</div>";
  349. }
  350. else
  351. {
  352. $n_msg = "<div class='download'><a href='".site_url("download","id=".$id)."'>";
  353. $n_msg.= "<img src='images/download.gif' align='absmiddle'> ";
  354. $n_msg.= $app->lang["download"].": ".$rs["title"];
  355. $n_msg.= "</a></div>";
  356. }
  357. $msg = str_replace("[".$value."]",$n_msg,$msg);
  358. }
  359. return $msg;
  360. }
  361. }
  362. function sys_format_module_id_code()
  363. {
  364. $app = sys_init();
  365. $rs = $app->module_m->get_id_code_list();
  366. if($rs)
  367. {
  368. $app->module_codelist = $rs["code"];
  369. $app->module_idlist = $rs["id"];
  370. unset($rs);
  371. }
  372. return true;
  373. }
  374. function sys_format_cate_id_code()
  375. {
  376. $app = sys_init();
  377. $rs = $app->cate_m->get_id_code_list();
  378. if($rs)
  379. {
  380. $app->cate_codelist = $rs["code"];
  381. $app->cate_idlist = $rs["id"];
  382. unset($rs);
  383. }
  384. return true;
  385. }
  386. function sys_format_menu($rs)
  387. {
  388. $app = sys_init();
  389. $site_html = $app->sys_config["sitehtml"] ? $app->sys_config["sitehtml"] : $app->sys_config["siteurl"]."html/".$app->langid."/";
  390. $index_php = $app->sys_config["indexphp"] ? $app->sys_config["indexphp"] : "index.php";
  391. $site_url = $app->sys_config["siteurl"] ? $app->sys_config["siteurl"] : base_url();
  392. if(!$rs["link_html"]) $rs["link_html"] = $rs["link"];
  393. if(!$rs["link_rewrite"]) $rs["link_rewrite"] = $rs["link"];
  394. if($app->sys_config["site_type"] == "html")
  395. {
  396. $rs["link"] = $rs["link_html"];
  397. }
  398. elseif($app->sys_config["site_type"] == "rewrite")
  399. {
  400. $rs["link"] = $rs["link_rewrite"];
  401. }
  402. $rs["link"] = str_replace("{control_trigger}",$app->config->c,$rs["link"]);
  403. $rs["link"] = str_replace("{site_html}",$site_html,$rs["link"]);
  404. $rs["link"] = str_replace("{index_php}",$index_php,$rs["link"]);
  405. $rs["link"] = str_replace("{site_url}",$site_url,$rs["link"]);
  406. unset($rs["link_html"],$rs["link_rewrite"]);
  407. return $rs;
  408. }
  409. function sys_user_popedom($chktype="read")
  410. {
  411. $app = sys_init();
  412. $app->load_model("usergroup");
  413. if($_SESSION["user_id"])
  414. {
  415. $rs = $_SESSION["group_id"] ? $app->usergroup_m->get_one($_SESSION["group_id"]) : $app->usergroup_m->get_default();
  416. if(!$rs)
  417. {
  418. return false;
  419. }
  420. }
  421. else
  422. {
  423. $rs = $app->usergroup_m->get_guest();
  424. if(!$rs)
  425. {
  426. return false;
  427. }
  428. }
  429. //格式化权限
  430. $popedom = "";
  431. if($chktype == "read") $popedom = $rs["popedom_read"];
  432. if($chktype == "post") $popedom = $rs["popedom_post"];
  433. if($chktype == "reply") $popedom = $rs["popedom_reply"];
  434. if(!$popedom)
  435. {
  436. return false;
  437. }
  438. if($popedom == "all") return $popedom;
  439. //格式化权限
  440. $array = $m = $c = array();
  441. $popedom = sys_id_list($popedom);
  442. foreach($popedom AS $key=>$value)
  443. {
  444. $tmp = explode(":",$value);
  445. if($tmp[0] == "m")
  446. {
  447. $m[] = $tmp[1];
  448. }
  449. else
  450. {
  451. $c[] = $tmp[1];
  452. }
  453. }
  454. unset($popedom);
  455. if((!$m || count($m)<1) && (!$c || count($c)<1))
  456. {
  457. return false;
  458. }
  459. $popedom = array();
  460. $popedom["module"] = $m ? $m : false;
  461. $popedom["category"] = $c ? $c : false;
  462. return $popedom;
  463. }
  464. if(!function_exists("d"))
  465. {
  466. function d($var,$func = "print_r")
  467. {
  468. echo "<pre>";
  469. $func($var);
  470. echo "</pre>";
  471. }
  472. }
  473. function JS2UTF8($str)
  474. {
  475. for($i=0;$i<strlen($str);$i+=6){
  476. list($a,$b)=sscanf(substr($str,$i),"%%u%02x%02x");
  477. $unicode.=chr($b).chr($a);
  478. }
  479. return iconv("UNICODELITTLE","UTF-8",$unicode);
  480. }
  481. ?>