page.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. class page_lib
  3. {
  4. var $psize = 20;
  5. var $pageid = 0;
  6. var $half = 5;
  7. var $lang = "";
  8. function __construct()
  9. {
  10. $this->psize = defined("SYS_PSIZE") ? SYS_PSIZE : 20;
  11. $this->pageid = intval($_GET[SYS_PAGEID]);
  12. if(!$this->pageid)
  13. {
  14. $this->pageid = 1;
  15. }
  16. $this->half = 5;
  17. }
  18. #[兼容PHP4]
  19. function page_lib()
  20. {
  21. $this->__construct();
  22. }
  23. function __destruct()
  24. {
  25. return true;
  26. }
  27. function set_psize($count=20)
  28. {
  29. $this->psize = intval($count);
  30. }
  31. function set_half($count=5)
  32. {
  33. $this->half = intval($count);
  34. }
  35. function langs($lang="")
  36. {
  37. if(!$lang || !is_array($lang))
  38. {
  39. $app = sys_init();
  40. $lang["home"] = $app->lang["page_home"];
  41. $lang["prev"] = $app->lang["page_prev"];
  42. $lang["next"] = $app->lang["page_next"];
  43. $lang["last"] = $app->lang["page_last"];
  44. }
  45. if(!$lang || !is_array($lang))
  46. {
  47. $this->lang["home"] = "首页";
  48. $this->lang["prev"] = "上一页";
  49. $this->lang["next"] = "下一页";
  50. $this->lang["last"] = "尾页";
  51. }
  52. else
  53. {
  54. $this->lang = $lang;
  55. }
  56. }
  57. function page_www($url,$total,$ifarray=false,$ifselect=true)
  58. {
  59. if(!$this->lang)
  60. {
  61. $this->langs();
  62. }
  63. if(!$total || !$url)
  64. {
  65. return false;
  66. }
  67. $app = sys_init();
  68. if($app->sys_config["site_type"] != "html" && $app->sys_config["site_type"] != "rewrite")
  69. {
  70. return $this->page($url,$total,$ifarray,$ifselect);
  71. }
  72. if($app->sys_config["site_type"] == "html" && !$app->sys_config["sitehtml"])
  73. {
  74. $app->sys_config["site_type"] = "rewrite";
  75. }
  76. if($app->sys_config["site_type"] == "rewrite")
  77. {
  78. return $this->page_rewrite($url,$total,$ifarray,$ifselect);
  79. }
  80. if(substr($url,-1) != "/")
  81. {
  82. $url .= "/";
  83. }
  84. $pageid = $this->pageid;
  85. if($pageid<1)
  86. {
  87. $pageid = 1;
  88. }
  89. $half_page = $this->half;
  90. #[共有页数]
  91. $total_page = intval($total/$this->psize);
  92. if($total%$this->psize)
  93. {
  94. $total_page++;#[判断是否存余,如存,则加一
  95. }
  96. #[判断如果分页ID超过总页数时]
  97. if($pageid > $total_page)
  98. {
  99. $pageid = $total_page;
  100. }
  101. #[Html]
  102. $array_m = 0;
  103. if($pageid > 0)
  104. {
  105. $returnlist[$array_m]["url"] = $url."index.html";
  106. $returnlist[$array_m]["name"] = $this->lang["home"];
  107. $returnlist[$array_m]["status"] = 0;
  108. if($pageid>1)
  109. {
  110. $array_m++;
  111. $returnlist[$array_m]["url"] = $pageid > 2 ? $url.($pageid-1).".html" : $url."index.html";
  112. $returnlist[$array_m]["name"] = $this->lang["prev"];
  113. $returnlist[$array_m]["status"] = 0;
  114. }
  115. }
  116. if($half_page>0)
  117. {
  118. #[添加中间项]
  119. for($i=$pageid-$half_page,$i>0 || $i=0,$j=$pageid+$half_page,$j<$total_page || $j=$total_page;$i<$j;$i++)
  120. {
  121. $l = $i + 1;
  122. $array_m++;
  123. $returnlist[$array_m]["url"] = $l == 1 ? $url."index.html" : $url.$l.".html";
  124. $returnlist[$array_m]["name"] = $l;
  125. $returnlist[$array_m]["status"] = ($l == $pageid) ? 1 : 0;
  126. }
  127. }
  128. if($half_page <1)
  129. {
  130. $half_page = 5;
  131. }
  132. #[添加尾项]
  133. if($pageid < $total_page)
  134. {
  135. $array_m++;
  136. $t_pageid = ($pageid+1)>1 ? ($pageid+1) : "index";
  137. $returnlist[$array_m]["url"] = $url.$t_pageid.".html";
  138. $returnlist[$array_m]["name"] = $this->lang["next"];
  139. $returnlist[$array_m]["status"] = 0;
  140. }
  141. $array_m++;
  142. if($pageid != $total_page)
  143. {
  144. $returnlist[$array_m]["url"] = $url.$total_page.".html";
  145. $returnlist[$array_m]["name"] = $this->lang["last"];
  146. $returnlist[$array_m]["status"] = 0;
  147. }
  148. if($ifarray)
  149. {
  150. return $returnlist;
  151. }
  152. #[组织样式]
  153. $msg = "<table class='pagelist' cellpadding='0' cellspacing='1'><tr><td class='n'>".$this->psize."/".$total."</td>";
  154. foreach($returnlist AS $key=>$value)
  155. {
  156. if($value["status"])
  157. {
  158. $msg .= "<td class='m'>".$value["name"]."</td>";
  159. }
  160. else
  161. {
  162. $msg .= "<td class='n'><a href='".$value["url"]."'>".$value["name"]."</a></td>";
  163. }
  164. }
  165. $msg .= "</tr></table>";
  166. unset($returnlist);
  167. return $msg;
  168. }
  169. function page_rewrite($url,$total,$ifarray=false,$ifselect=true)
  170. {
  171. if(!$this->lang)
  172. {
  173. $this->langs();
  174. }
  175. if(!$total || !$url)
  176. {
  177. return false;
  178. }
  179. $app = sys_init();
  180. //$urlend = ".html";
  181. $url = substr($url,0,-5);
  182. $pageid = $this->pageid;
  183. if($pageid<1)
  184. {
  185. $pageid = 1;
  186. }
  187. $half_page = $this->half;
  188. #[共有页数]
  189. $total_page = intval($total/$this->psize);
  190. if($total%$this->psize)
  191. {
  192. $total_page++;#[判断是否存余,如存,则加一
  193. }
  194. #[判断如果分页ID超过总页数时]
  195. if($pageid > $total_page)
  196. {
  197. $pageid = $total_page;
  198. }
  199. #[Html]
  200. $array_m = 0;
  201. if($pageid > 0)
  202. {
  203. $returnlist[$array_m]["url"] = $url.".html";
  204. $returnlist[$array_m]["name"] = $this->lang["home"];
  205. $returnlist[$array_m]["status"] = 0;
  206. if($pageid>1)
  207. {
  208. $array_m++;
  209. $returnlist[$array_m]["url"] = $pageid > 2 ? $url."-".($pageid-1).".html" : $url.".html";
  210. $returnlist[$array_m]["name"] = $this->lang["prev"];
  211. $returnlist[$array_m]["status"] = 0;
  212. }
  213. }
  214. if($half_page>0)
  215. {
  216. #[添加中间项]
  217. for($i=$pageid-$half_page,$i>0 || $i=0,$j=$pageid+$half_page,$j<$total_page || $j=$total_page;$i<$j;$i++)
  218. {
  219. $l = $i + 1;
  220. $array_m++;
  221. $returnlist[$array_m]["url"] = $l == 1 ? $url.".html" : $url."-".$l.".html";
  222. $returnlist[$array_m]["name"] = $l;
  223. $returnlist[$array_m]["status"] = ($l == $pageid) ? 1 : 0;
  224. }
  225. }
  226. if($half_page <1)
  227. {
  228. $half_page = 5;
  229. }
  230. #[添加尾项]
  231. if($pageid < $total_page)
  232. {
  233. $array_m++;
  234. $t_pageid = ($pageid+1)>1 ? ($pageid+1) : "index";
  235. $returnlist[$array_m]["url"] = ($pageid+1)>1 ? $url."-".($pageid+1).".html" : $url.".html";
  236. $returnlist[$array_m]["name"] = $this->lang["next"];
  237. $returnlist[$array_m]["status"] = 0;
  238. }
  239. $array_m++;
  240. if($pageid != $total_page)
  241. {
  242. $returnlist[$array_m]["url"] = $url."-".$total_page.".html";
  243. $returnlist[$array_m]["name"] = $this->lang["last"];
  244. $returnlist[$array_m]["status"] = 0;
  245. }
  246. if($ifarray)
  247. {
  248. return $returnlist;
  249. }
  250. #[组织样式]
  251. $msg = "<table class='pagelist' cellpadding='0' cellspacing='1'><tr><td class='n'>".$this->psize."/".$total."</td>";
  252. foreach($returnlist AS $key=>$value)
  253. {
  254. if($value["status"])
  255. {
  256. $msg .= "<td class='m'>".$value["name"]."</td>";
  257. }
  258. else
  259. {
  260. $msg .= "<td class='n'><a href='".$value["url"]."'>".$value["name"]."</a></td>";
  261. }
  262. }
  263. $msg .= "</tr></table>";
  264. unset($returnlist);
  265. return $msg;
  266. }
  267. function page($url,$total,$ifarray=false,$ifselect=true)
  268. {
  269. if(!$this->lang)
  270. {
  271. $this->langs();
  272. }
  273. if(!$total || !$url)
  274. {
  275. return false;
  276. }
  277. if(substr($url,-1) != "&")
  278. {
  279. $url .= "&";
  280. }
  281. $pageid = $this->pageid;
  282. $half_page = $this->half;
  283. #[共有页数]
  284. $total_page = intval($total/$this->psize);
  285. if($total%$this->psize)
  286. {
  287. $total_page++;#[判断是否存余,如存,则加一
  288. }
  289. #[判断如果分页ID超过总页数时]
  290. if($pageid > $total_page)
  291. {
  292. $pageid = $total_page;
  293. }
  294. #[Html]
  295. $array_m = 0;
  296. if($pageid > 0)
  297. {
  298. $returnlist[$array_m]["url"] = $url;
  299. $returnlist[$array_m]["name"] = $this->lang["home"];
  300. $returnlist[$array_m]["status"] = 0;
  301. if($pageid > 1)
  302. {
  303. $array_m++;
  304. $returnlist[$array_m]["url"] = $url."pageid=".($pageid-1);
  305. $returnlist[$array_m]["name"] = $this->lang["prev"];
  306. $returnlist[$array_m]["status"] = 0;
  307. }
  308. }
  309. if($half_page>0)
  310. {
  311. #[添加中间项]
  312. for($i=$pageid-$half_page,$i>0 || $i=0,$j=$pageid+$half_page,$j<$total_page || $j=$total_page;$i<$j;$i++)
  313. {
  314. $l = $i + 1;
  315. $array_m++;
  316. $returnlist[$array_m]["url"] = $url."pageid=".$l;
  317. $returnlist[$array_m]["name"] = $l;
  318. $returnlist[$array_m]["status"] = ($l == $pageid) ? 1 : 0;
  319. }
  320. }
  321. if($half_page <1)
  322. {
  323. $half_page = 5;
  324. }
  325. #[添加select里的中间项]
  326. for($i=$pageid-$half_page*3,$i>0 || $i=0,$j=$pageid+$half_page*3,$j<$total_page || $j=$total_page;$i<$j;$i++)
  327. {
  328. $l = $i + 1;
  329. $select_option_msg = "<option value='".$l."'";
  330. if($l == $pageid)
  331. {
  332. $select_option_msg .= " selected";
  333. }
  334. $select_option_msg .= ">".$l."</option>";
  335. $select_option[] = $select_option_msg;
  336. }
  337. #[添加尾项]
  338. if($pageid < $total_page)
  339. {
  340. $array_m++;
  341. $returnlist[$array_m]["url"] = $url."pageid=".($pageid+1);
  342. $returnlist[$array_m]["name"] = $this->lang["next"];
  343. $returnlist[$array_m]["status"] = 0;
  344. }
  345. $array_m++;
  346. if($pageid != $total_page)
  347. {
  348. $returnlist[$array_m]["url"] = $url."pageid=".$total_page;
  349. $returnlist[$array_m]["name"] = $this->lang["last"];
  350. $returnlist[$array_m]["status"] = 0;
  351. }
  352. if($ifarray)
  353. {
  354. return $returnlist;
  355. }
  356. #[组织样式]
  357. $msg = "<table class='pagelist' cellpadding='0' cellspacing='1'><tr><td class='n'>".$this->psize."/".$total."</td>";
  358. foreach($returnlist AS $key=>$value)
  359. {
  360. if($value["status"])
  361. {
  362. $msg .= "<td class='m'>".$value["name"]."</td>";
  363. }
  364. else
  365. {
  366. $msg .= "<td class='n'><a href='".$value["url"]."'>".$value["name"]."</a></td>";
  367. }
  368. }
  369. if($ifselect)
  370. {
  371. $msg .= "<td><select onchange=\"window.location.href='".$url."pageid='+this.value\">".implode("",$select_option)."</option></select></td>";
  372. }
  373. $msg .= "</tr></table>";
  374. unset($returnlist);
  375. return $msg;
  376. }
  377. }
  378. ?>