index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. pc_base::load_app_func('global');
  4. pc_base::load_sys_class('format', '', 0);
  5. class index {
  6. function __construct() {
  7. $this->db = pc_base::load_model('content_model');
  8. $this->siteid = isset($_GET['siteid']) && (intval($_GET['siteid']) > 0) ? intval(trim($_GET['siteid'])) : (param::get_cookie('siteid') ? param::get_cookie('siteid') : 1);
  9. param::set_cookie('siteid',$this->siteid);
  10. $this->wap_site = getcache('wap_site','wap');
  11. $this->types = getcache('wap_type','wap');
  12. $this->wap = $this->wap_site[$this->siteid];
  13. define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);
  14. if($this->wap['status']!=1) exit(L('wap_close_status'));
  15. }
  16. //展示首页
  17. public function init() {
  18. $WAP = $this->wap;
  19. $TYPE = $this->types;
  20. $WAP_SETTING = string2array($WAP['setting']);
  21. $GLOBALS['siteid'] = $siteid = max($this->siteid,1);
  22. $template = $WAP_SETTING['index_template'] ? $WAP_SETTING['index_template'] : 'index';
  23. include template('wap', $template);
  24. }
  25. //展示列表页
  26. public function lists() {
  27. $parentids = array();
  28. $WAP = $this->wap;
  29. $TYPE = $this->types;
  30. $WAP_SETTING = string2array($WAP['setting']);
  31. $GLOBALS['siteid'] = $siteid = max($this->siteid,1);
  32. $typeid = intval($_GET['typeid']);
  33. if(!$typeid) exit(L('parameter_error'));
  34. $catid = $this->types[$typeid]['cat'];
  35. $siteids = getcache('category_content','commons');
  36. $siteid = $siteids[$catid];
  37. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  38. if(!isset($CATEGORYS[$catid])) exit(L('parameter_error'));
  39. $CAT = $CATEGORYS[$catid];
  40. $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
  41. extract($CAT);
  42. foreach($TYPE as $_t) $parentids[] = $_t['parentid'];
  43. $template = ($TYPE[$typeid]['parentid']==0 && in_array($typeid,array_unique($parentids))) ? $WAP_SETTING['category_template'] : $WAP_SETTING['list_template'];
  44. $MODEL = getcache('model','commons');
  45. $modelid = $CAT['modelid'];
  46. $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  47. $total = $this->db->count(array('status'=>'99','catid'=>$catid));
  48. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  49. $pagesize = $WAP_SETTING['listnum'] ? intval($WAP_SETTING['listnum']) : 20 ;
  50. $offset = ($page - 1) * $pagesize;
  51. $list = $this->db->select(array('status'=>'99','catid'=>$catid), '*', $offset.','.$pagesize,'inputtime DESC');
  52. //构造wap url规则
  53. define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');
  54. $GLOBALS['URL_ARRAY'] = array('typeid'=>$typeid);
  55. $pages = wpa_pages($total, $page, $pagesize);
  56. include template('wap', $template);
  57. }
  58. //展示内容页
  59. public function show() {
  60. $WAP = $this->wap;
  61. $WAP_SETTING = string2array($WAP['setting']);
  62. $TYPE = $this->types;
  63. $GLOBALS['siteid'] = $siteid = max($this->siteid,1);
  64. $typeid = $type_tmp = intval($_GET['typeid']);
  65. $catid = $_GET['catid'];
  66. $id = intval($_GET['id']);
  67. if(!$catid || !$id) exit(L('parameter_error'));
  68. $siteids = getcache('category_content','commons');
  69. $siteid = $siteids[$catid];
  70. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  71. $page = intval($_GET['page']);
  72. $page = max($page,1);
  73. if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) exit(L('information_does_not_exist','','content'));
  74. $this->category = $CAT = $CATEGORYS[$catid];
  75. $this->category_setting = $CAT['setting'] = string2array($this->category['setting']);
  76. $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
  77. $MODEL = getcache('model','commons');
  78. $modelid = $CAT['modelid'];
  79. $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  80. $r = $this->db->get_one(array('id'=>$id));
  81. if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');
  82. $this->db->table_name = $tablename.'_data';
  83. $r2 = $this->db->get_one(array('id'=>$id));
  84. $rs = $r2 ? array_merge($r,$r2) : $r;
  85. //再次重新赋值,以数据库为准
  86. $catid = $CATEGORYS[$r['catid']]['catid'];
  87. $modelid = $CATEGORYS[$catid]['modelid'];
  88. require_once CACHE_MODEL_PATH.'content_output.class.php';
  89. $content_output = new content_output($modelid,$catid,$CATEGORYS);
  90. $data = $content_output->get($rs);
  91. extract($data);
  92. $typeid = $type_tmp;
  93. if(strpos($content, '[/page]')!==false) {
  94. $content = preg_replace("|\[page\](.*)\[/page\]|U", '', $content);
  95. } elseif (strpos($content, '[page]')!==false) {
  96. $content = str_replace('[page]', '', $content);
  97. }
  98. //根据设置字节数对文章加入分页标记
  99. if($maxcharperpage < 10) $maxcharperpage = $WAP_SETTING['c_num'];
  100. $contentpage = pc_base::load_app_class('contentpage','content');
  101. $content = $contentpage->get_data($content,$maxcharperpage);
  102. $isshow = 1;
  103. if($pictureurls) {
  104. $pictureurl = pic_pages($pictureurls);
  105. $isshow = 0;
  106. //进行图片分页处理
  107. $PIC_POS = strpos($pictureurl, '[page]');
  108. if($PIC_POS !== false) {
  109. $this->url = pc_base::load_app_class('wap_url', 'wap');
  110. $pictureurls = array_filter(explode('[page]', $pictureurl));
  111. $pagenumber = count($pictureurls);
  112. if (strpos($pictureurl, '[/page]')!==false && ($CONTENT_POS<7)) {
  113. $pagenumber--;
  114. }
  115. for($i=1; $i<=$pagenumber; $i++) {
  116. $pageurls[$i] = $this->url->show($id, $i, $catid, $typeid);
  117. }
  118. $END_POS = strpos($pictureurl, '[/page]');
  119. if($END_POS !== false) {
  120. if(preg_match_all("|\[page\](.*)\[/page\]|U", $pictureurl, $m, PREG_PATTERN_ORDER)) {
  121. foreach($m[1] as $k=>$v) {
  122. $p = $k+1;
  123. $titles[$p]['title'] = strip_tags($v);
  124. $titles[$p]['url'] = $pageurls[$p][0];
  125. }
  126. }
  127. }
  128. //当不存在 [/page]时,则使用下面分页
  129. $pages = content_pages($pagenumber,$page, $pageurls, 0);
  130. //判断[page]出现的位置是否在第一位
  131. if($CONTENT_POS<7) {
  132. $pictureurl = $pictureurls[$page];
  133. } else {
  134. if ($page==1 && !empty($titles)) {
  135. $pictureurl = $title.'[/page]'.$pictureurls[$page-1];
  136. } else {
  137. $pictureurl = $pictureurls[$page-1];
  138. }
  139. }
  140. }
  141. }
  142. //进行自动分页处理
  143. $CONTENT_POS = strpos($content, '[page]');
  144. if($CONTENT_POS !== false) {
  145. $this->url = pc_base::load_app_class('wap_url', 'wap');
  146. $contents = array_filter(explode('[page]', $content));
  147. $pagenumber = count($contents);
  148. if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) {
  149. $pagenumber--;
  150. }
  151. for($i=1; $i<=$pagenumber; $i++) {
  152. $pageurls[$i] = $this->url->show($id, $i, $catid, $typeid);
  153. }
  154. $END_POS = strpos($content, '[/page]');
  155. if($END_POS !== false) {
  156. if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
  157. foreach($m[1] as $k=>$v) {
  158. $p = $k+1;
  159. $titles[$p]['title'] = strip_tags($v);
  160. $titles[$p]['url'] = $pageurls[$p][0];
  161. }
  162. }
  163. }
  164. //当不存在 [/page]时,则使用下面分页
  165. $pages = content_pages($pagenumber,$page, $pageurls);
  166. //判断[page]出现的位置是否在第一位
  167. if($CONTENT_POS<7) {
  168. $content = $contents[$page];
  169. } else {
  170. if ($page==1 && !empty($titles)) {
  171. $content = $title.'[/page]'.$contents[$page-1];
  172. } else {
  173. $content = $contents[$page-1];
  174. }
  175. }
  176. if($_GET['remains']=='true') {
  177. $content = $pages ='';
  178. for($i=$page;$i<=$pagenumber;$i++) {
  179. $content .=$contents[$i-1];
  180. }
  181. }
  182. }
  183. $content = content_strip(wml_strip($content));
  184. $template = $WAP_SETTING['show_template'] ? $WAP_SETTING['show_template'] : 'show';
  185. include template('wap', $template);
  186. }
  187. //提交评论
  188. function comment() {
  189. $WAP = $this->wap;
  190. $TYPE = $this->types;
  191. if($_POST['dosumbit']) {
  192. $comment = pc_base::load_app_class('comment','comment');
  193. pc_base::load_app_func('global','comment');
  194. $username = $this->wap['sitename'].L('phpcms_friends');
  195. $userid = param::get_cookie('_userid');
  196. $catid = intval($_POST['catid']);
  197. $typeid = intval($_POST['typeid']);
  198. $contentid = intval($_POST['id']);
  199. $msg = trim($_POST['msg']);
  200. $commentid = remove_xss(safe_replace(trim($_POST['commentid'])));
  201. $title = $_POST['title'];
  202. $url = $_POST['url'];
  203. //通过API接口调用数据的标题、URL地址
  204. if (!$data = get_comment_api($commentid)) {
  205. exit(L('parameter_error'));
  206. } else {
  207. $title = $data['title'];
  208. $url = $data['url'];
  209. unset($data);
  210. }
  211. $data = array('userid'=>$userid, 'username'=>$username, 'content'=>$msg);
  212. $comment->add($commentid, $this->siteid, $data, $id, $title, $url);
  213. echo '<script type="text/javaScript" src="'.JS_PATH.'jquery.min.js"></script><script language="JavaScript" src="'.JS_PATH.'admin_common.js"></script>';
  214. echo L('wap_guestbook').'<br/><a href="'.show_url($catid,$contentid,$typeid).'">'.L('wap_goback').'</a><script language=javascript>setTimeout("redirect(\''.HTTP_REFERER.'\');",3000);</script>';
  215. }
  216. }
  217. //评论列表页
  218. function comment_list() {
  219. $WAP = $this->wap;
  220. $TYPE = $this->types;
  221. $comment = pc_base::load_app_class('comment','comment');
  222. pc_base::load_app_func('global','comment');
  223. $typeid = intval($_GET['typeid']);
  224. $GLOBALS['siteid'] = max($this->siteid,1);
  225. $commentid = isset($_GET['commentid']) && trim(addslashes(urldecode($_GET['commentid']))) ? trim(addslashes(urldecode($_GET['commentid']))) : exit(L('illegal_parameters'));
  226. if(!preg_match("/^[a-z0-9_\-]+$/i",$commentid)) exit(L('illegal_parameters'));
  227. list($modules, $contentid, $siteid) = decode_commentid($commentid);
  228. list($module, $catid) = explode('_', $modules);
  229. $comment_setting_db = pc_base::load_model('comment_setting_model');
  230. $setting = $comment_setting_db->get_one(array('siteid'=>$this->siteid));
  231. //通过API接口调用数据的标题、URL地址
  232. if (!$data = get_comment_api($commentid)) {
  233. exit(L('illegal_parameters'));
  234. } else {
  235. $title = $data['title'];
  236. $url = $data['url'];
  237. unset($data);
  238. }
  239. include template('wap', 'comment_list');
  240. }
  241. //导航页
  242. function maps() {
  243. $WAP = $this->wap;
  244. $TYPE = $this->types;
  245. $WAP_SETTING = string2array($WAP['setting']);
  246. $GLOBALS['siteid'] = max($this->siteid,1);
  247. include template('wap', 'maps');
  248. }
  249. //展示大图
  250. function big_image() {
  251. $WAP = $this->wap;
  252. $TYPE = $this->types;
  253. $WAP_SETTING = string2array($WAP['setting']);
  254. $GLOBALS['siteid'] = max($this->siteid,1);
  255. $url=base64_decode(trim($_GET['url']));
  256. $url = str_replace(array('"',"'",'(',')',' '),'',$url);
  257. if(!preg_match('/(jpg|png|gif|bmp)$/i',fileext($url))) exit('img src error');
  258. $width = $_GET['w'] ? trim(intval($_GET['w'])) : 320 ;
  259. $new_url = thumb($url,$width,0);
  260. include template('wap', 'big_image');
  261. }
  262. }
  263. ?>