index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. //模型缓存路径
  4. define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
  5. pc_base::load_app_func('util','content');
  6. class index {
  7. private $db;
  8. function __construct() {
  9. $this->db = pc_base::load_model('content_model');
  10. $this->_userid = param::get_cookie('_userid');
  11. $this->_username = param::get_cookie('_username');
  12. $this->_groupid = param::get_cookie('_groupid');
  13. }
  14. //首页
  15. public function init() {
  16. if(isset($_GET['siteid'])) {
  17. $siteid = intval($_GET['siteid']);
  18. } else {
  19. $siteid = 1;
  20. }
  21. $siteid = $GLOBALS['siteid'] = max($siteid,1);
  22. define('SITEID', $siteid);
  23. $_userid = $this->_userid;
  24. $_username = $this->_username;
  25. $_groupid = $this->_groupid;
  26. //SEO
  27. $SEO = seo($siteid);
  28. $sitelist = getcache('sitelist','commons');
  29. $default_style = $sitelist[$siteid]['default_style'];
  30. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  31. include template('content','index',$default_style);
  32. }
  33. //内容页
  34. public function show() {
  35. $catid = intval($_GET['catid']);
  36. $id = intval($_GET['id']);
  37. if(!$catid || !$id) showmessage(L('information_does_not_exist'),'blank');
  38. $_userid = $this->_userid;
  39. $_username = $this->_username;
  40. $_groupid = $this->_groupid;
  41. $page = intval($_GET['page']);
  42. $page = max($page,1);
  43. $siteids = getcache('category_content','commons');
  44. $siteid = $siteids[$catid];
  45. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  46. if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('information_does_not_exist'),'blank');
  47. $this->category = $CAT = $CATEGORYS[$catid];
  48. $this->category_setting = $CAT['setting'] = string2array($this->category['setting']);
  49. $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
  50. $MODEL = getcache('model','commons');
  51. $modelid = $CAT['modelid'];
  52. $tablename = $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  53. $r = $this->db->get_one(array('id'=>$id));
  54. if(!$r || $r['status'] != 99) showmessage(L('info_does_not_exists'),'blank');
  55. $this->db->table_name = $tablename.'_data';
  56. $r2 = $this->db->get_one(array('id'=>$id));
  57. $rs = $r2 ? array_merge($r,$r2) : $r;
  58. //再次重新赋值,以数据库为准
  59. $catid = $CATEGORYS[$r['catid']]['catid'];
  60. $modelid = $CATEGORYS[$catid]['modelid'];
  61. require_once CACHE_MODEL_PATH.'content_output.class.php';
  62. $content_output = new content_output($modelid,$catid,$CATEGORYS);
  63. $data = $content_output->get($rs);
  64. extract($data);
  65. //检查文章会员组权限
  66. if($groupids_view && is_array($groupids_view)) {
  67. $_groupid = param::get_cookie('_groupid');
  68. $_groupid = intval($_groupid);
  69. if(!$_groupid) {
  70. $forward = urlencode(get_url());
  71. showmessage(L('login_website'),APP_PATH.'index.php?m=member&c=index&a=login&forward='.$forward);
  72. }
  73. if(!in_array($_groupid,$groupids_view)) showmessage(L('no_priv'));
  74. } else {
  75. //根据栏目访问权限判断权限
  76. $_priv_data = $this->_category_priv($catid);
  77. if($_priv_data=='-1') {
  78. $forward = urlencode(get_url());
  79. showmessage(L('login_website'),APP_PATH.'index.php?m=member&c=index&a=login&forward='.$forward);
  80. } elseif($_priv_data=='-2') {
  81. showmessage(L('no_priv'));
  82. }
  83. }
  84. if(module_exists('comment')) {
  85. $allow_comment = isset($allow_comment) ? $allow_comment : 1;
  86. } else {
  87. $allow_comment = 0;
  88. }
  89. //阅读收费 类型
  90. $paytype = $rs['paytype'];
  91. $readpoint = $rs['readpoint'];
  92. $allow_visitor = 1;
  93. if($readpoint || $this->category_setting['defaultchargepoint']) {
  94. if(!$readpoint) {
  95. $readpoint = $this->category_setting['defaultchargepoint'];
  96. $paytype = $this->category_setting['paytype'];
  97. }
  98. //检查是否支付过
  99. $allow_visitor = self::_check_payment($catid.'_'.$id,$paytype);
  100. if(!$allow_visitor) {
  101. $http_referer = urlencode(get_url());
  102. $allow_visitor = sys_auth($catid.'_'.$id.'|'.$readpoint.'|'.$paytype).'&http_referer='.$http_referer;
  103. } else {
  104. $allow_visitor = 1;
  105. }
  106. }
  107. //最顶级栏目ID
  108. $arrparentid = explode(',', $CAT['arrparentid']);
  109. $top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid;
  110. $template = $template ? $template : $CAT['setting']['show_template'];
  111. if(!$template) $template = 'show';
  112. //SEO
  113. $seo_keywords = '';
  114. if(!empty($keywords)) $seo_keywords = implode(',',$keywords);
  115. $SEO = seo($siteid, $catid, $title, $description, $seo_keywords);
  116. define('STYLE',$CAT['setting']['template_list']);
  117. if(isset($rs['paginationtype'])) {
  118. $paginationtype = $rs['paginationtype'];
  119. $maxcharperpage = $rs['maxcharperpage'];
  120. }
  121. $pages = $titles = '';
  122. if($rs['paginationtype']==1) {
  123. //自动分页
  124. if($maxcharperpage < 10) $maxcharperpage = 500;
  125. $contentpage = pc_base::load_app_class('contentpage');
  126. $content = $contentpage->get_data($content,$maxcharperpage);
  127. }
  128. if($rs['paginationtype']!=0) {
  129. //手动分页
  130. $CONTENT_POS = strpos($content, '[page]');
  131. if($CONTENT_POS !== false) {
  132. $this->url = pc_base::load_app_class('url', 'content');
  133. $contents = array_filter(explode('[page]', $content));
  134. $pagenumber = count($contents);
  135. if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) {
  136. $pagenumber--;
  137. }
  138. for($i=1; $i<=$pagenumber; $i++) {
  139. $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);
  140. }
  141. $END_POS = strpos($content, '[/page]');
  142. if($END_POS !== false) {
  143. if($CONTENT_POS>7) {
  144. $content = '[page]'.$title.'[/page]'.$content;
  145. }
  146. if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
  147. foreach($m[1] as $k=>$v) {
  148. $p = $k+1;
  149. $titles[$p]['title'] = strip_tags($v);
  150. $titles[$p]['url'] = $pageurls[$p][0];
  151. }
  152. }
  153. }
  154. //当不存在 [/page]时,则使用下面分页
  155. $pages = content_pages($pagenumber,$page, $pageurls);
  156. //判断[page]出现的位置是否在第一位
  157. if($CONTENT_POS<7) {
  158. $content = $contents[$page];
  159. } else {
  160. if ($page==1 && !empty($titles)) {
  161. $content = $title.'[/page]'.$contents[$page-1];
  162. } else {
  163. $content = $contents[$page-1];
  164. }
  165. }
  166. if($titles) {
  167. list($title, $content) = explode('[/page]', $content);
  168. $content = trim($content);
  169. if(strpos($content,'</p>')===0) {
  170. $content = '<p>'.$content;
  171. }
  172. if(stripos($content,'<p>')===0) {
  173. $content = $content.'</p>';
  174. }
  175. }
  176. }
  177. }
  178. $this->db->table_name = $tablename;
  179. //上一页
  180. $previous_page = $this->db->get_one("`catid` = '$catid' AND `id`<'$id' AND `status`=99",'*','id DESC');
  181. //下一页
  182. $next_page = $this->db->get_one("`catid`= '$catid' AND `id`>'$id' AND `status`=99",'*','id ASC');
  183. // 2020年7月15日16:41:28 yf 取消显示没有上一条或者下一条的
  184. // if(empty($previous_page)) {
  185. // $previous_page = array('title'=>L('first_page'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('first_page').'\');');
  186. // }
  187. // if(empty($next_page)) {
  188. // $next_page = array('title'=>L('last_page'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('last_page').'\');');
  189. // }
  190. include template('content',$template);
  191. }
  192. //列表页
  193. public function lists() {
  194. $catid = $_GET['catid'] = intval($_GET['catid']);
  195. // $catid=$catid == 1?2:$catid;
  196. $_priv_data = $this->_category_priv($catid);
  197. if($_priv_data=='-1') {
  198. $forward = urlencode(get_url());
  199. showmessage(L('login_website'),APP_PATH.'index.php?m=member&c=index&a=login&forward='.$forward);
  200. } elseif($_priv_data=='-2') {
  201. showmessage(L('no_priv'));
  202. }
  203. $_userid = $this->_userid;
  204. $_username = $this->_username;
  205. $_groupid = $this->_groupid;
  206. if(!$catid) showmessage(L('category_not_exists'),'blank');
  207. $siteids = getcache('category_content','commons');
  208. $siteid = $siteids[$catid];
  209. $CATEGORYS = getcache('category_content_'.$siteid,'commons');
  210. if(!isset($CATEGORYS[$catid])) showmessage(L('category_not_exists'),'blank');
  211. $CAT = $CATEGORYS[$catid];
  212. $siteid = $GLOBALS['siteid'] = $CAT['siteid'];
  213. extract($CAT);
  214. $setting = string2array($setting);
  215. //SEO
  216. if(!$setting['meta_title']) $setting['meta_title'] = $catname;
  217. $SEO = seo($siteid, '',$setting['meta_title'],$setting['meta_description'],$setting['meta_keywords']);
  218. define('STYLE',$setting['template_list']);
  219. $page = intval($_GET['page']);
  220. $template = $setting['category_template'] ? $setting['category_template'] : 'category';
  221. $template_list = $setting['list_template'] ? $setting['list_template'] : 'list';
  222. if($type==0) {
  223. $template = $child ? $template : $template_list;
  224. $arrparentid = explode(',', $arrparentid);
  225. $top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid;
  226. $array_child = array();
  227. $self_array = explode(',', $arrchildid);
  228. //获取一级栏目ids
  229. foreach ($self_array as $arr) {
  230. if($arr!=$catid && $CATEGORYS[$arr][parentid]==$catid) {
  231. $array_child[] = $arr;
  232. }
  233. }
  234. $arrchildid = implode(',', $array_child);
  235. //URL规则
  236. $urlrules = getcache('urlrules','commons');
  237. $urlrules = str_replace('|', '~',$urlrules[$category_ruleid]);
  238. $tmp_urls = explode('~',$urlrules);
  239. $tmp_urls = isset($tmp_urls[1]) ? $tmp_urls[1] : $tmp_urls[0];
  240. preg_match_all('/{\$([a-z0-9_]+)}/i',$tmp_urls,$_urls);
  241. if(!empty($_urls[1])) {
  242. foreach($_urls[1] as $_v) {
  243. $GLOBALS['URL_ARRAY'][$_v] = $_GET[$_v];
  244. }
  245. }
  246. define('URLRULE', $urlrules);
  247. $GLOBALS['URL_ARRAY']['categorydir'] = $categorydir;
  248. $GLOBALS['URL_ARRAY']['catdir'] = $catdir;
  249. $GLOBALS['URL_ARRAY']['catid'] = $catid;
  250. $content=$this->db->contents($catid);//内容页获取内容;
  251. include template('content',$template);
  252. } else {
  253. //单网页
  254. $this->page_db = pc_base::load_model('page_model');
  255. $r = $this->page_db->get_one(array('catid'=>$catid));
  256. if($r) extract($r);
  257. $template = $setting['page_template'] ? $setting['page_template'] : 'page';
  258. $arrchild_arr = $CATEGORYS[$parentid]['arrchildid'];
  259. if($arrchild_arr=='') $arrchild_arr = $CATEGORYS[$catid]['arrchildid'];
  260. $arrchild_arr = explode(',',$arrchild_arr);
  261. array_shift($arrchild_arr);
  262. $keywords = $keywords ? $keywords : $setting['meta_keywords'];
  263. $SEO = seo($siteid, 0, $title,$setting['meta_description'],$keywords);
  264. include template('content',$template);
  265. }
  266. }
  267. //JSON 输出
  268. public function json_list() {
  269. if($_GET['type']=='keyword' && $_GET['modelid'] && $_GET['keywords']) {
  270. //根据关键字搜索
  271. $modelid = intval($_GET['modelid']);
  272. $id = intval($_GET['id']);
  273. $MODEL = getcache('model','commons');
  274. if(isset($MODEL[$modelid])) {
  275. $keywords = safe_replace(new_html_special_chars($_GET['keywords']));
  276. $keywords = addslashes(iconv('utf-8','gbk',$keywords));
  277. $this->db->set_model($modelid);
  278. $result = $this->db->select("keywords LIKE '%$keywords%'",'id,title,url',10);
  279. if(!empty($result)) {
  280. $data = array();
  281. foreach($result as $rs) {
  282. if($rs['id']==$id) continue;
  283. if(CHARSET=='gbk') {
  284. foreach($rs as $key=>$r) {
  285. $rs[$key] = iconv('gbk','utf-8',$r);
  286. }
  287. }
  288. $data[] = $rs;
  289. }
  290. if(count($data)==0) exit('0');
  291. echo json_encode($data);
  292. } else {
  293. //没有数据
  294. exit('0');
  295. }
  296. }
  297. }
  298. }
  299. /**
  300. * 检查支付状态
  301. */
  302. protected function _check_payment($flag,$paytype) {
  303. $_userid = $this->_userid;
  304. $_username = $this->_username;
  305. if(!$_userid) return false;
  306. pc_base::load_app_class('spend','pay',0);
  307. $setting = $this->category_setting;
  308. $repeatchargedays = intval($setting['repeatchargedays']);
  309. if($repeatchargedays) {
  310. $fromtime = SYS_TIME - 86400 * $repeatchargedays;
  311. $r = spend::spend_time($_userid,$fromtime,$flag);
  312. if($r['id']) return true;
  313. }
  314. return false;
  315. }
  316. /**
  317. * 检查阅读权限
  318. *
  319. */
  320. protected function _category_priv($catid) {
  321. $catid = intval($catid);
  322. if(!$catid) return '-2';
  323. $_groupid = $this->_groupid;
  324. $_groupid = intval($_groupid);
  325. if($_groupid==0) $_groupid = 8;
  326. $this->category_priv_db = pc_base::load_model('category_priv_model');
  327. $result = $this->category_priv_db->select(array('catid'=>$catid,'is_admin'=>0,'action'=>'visit'));
  328. if($result) {
  329. if(!$_groupid) return '-1';
  330. foreach($result as $r) {
  331. if($r['roleid'] == $_groupid) return '1';
  332. }
  333. return '-2';
  334. } else {
  335. return '1';
  336. }
  337. }
  338. }
  339. ?>