【phpcms-v9】专题模块前端控制器index.php文件分析

<?php 
defined('IN_PHPCMS') or exit('No permission resources.');

pc_base::load_app_func('global', 'special');//加载global.func.php文件
class index {
	
	private $db;
	
	function __construct() {
		$this->db = pc_base::load_model('special_model');//table_name:special
	}
	
	/**
	 * 专题列表 
	 */
	public function special() {
		//站点id
		$siteid = $_GET['siteid'] ? intval($_GET['siteid']) : (get_siteid() ? get_siteid() : 1);
		//seo信息
		$SEO = seo($siteid);
		//加载专题列表页面
		include template('special', 'special_list');
	}
	
	/**
	 * 专题首页
	 */
	public function init() {
		//专题id
		$specialid = $_GET['id'] ? $_GET['id'] : ($_GET['specialid'] ? $_GET['specialid'] : 0);
		if (!$specialid) showmessage(L('illegal_action'));
		//相当于:select * from gt_special where id='$specialid' and disabled=0
		$info = $this->db->get_one(array('id'=>$specialid, 'disabled'=>0));
		if(!$info) showmessage(L('special_not_exist'), 'back');
		
		//将当前专题id所对应的字段作为变量导入到当前的符号表
		extract($info);
		
		$css = get_css(unserialize($css));
		if(!$ispage) {//字段变量:如果不分页的话
			$type_db = pc_base::load_model('type_model');//类别表
			//查询当前专题下所有的类别
			$types = $type_db->select(array('module'=>'special', 'parentid'=>$specialid), '*', '', '`listorder` ASC, `typeid` ASC', '', 'listorder');
		}
		if ($pics) {//字段变量:专题导入的图片报道信息,如:1|65|周克华被警方击毙
			$pic_data = get_pic_content($pics);
			unset($pics);
		}
		if ($voteid) {//字段变量:投票信息,如:vote|1|你最爱吃的饭?
			$vote_info = explode('|', $voteid);
			$voteid = $vote_info[1];//投票id
		}
		$siteid =  $_GET['siteid'] ? $_GET['siteid'] : get_siteid();//站点id
		$SEO = seo($siteid, '', $title, $description);//seo信息
		//评论表commentid字段的组成
		$commentid = id_encode('special', $id, $siteid);//组成生成id号:urlencode($modules.'-'.$contentid.'-'.$siteid);
		$template = $info['index_template'] ? $info['index_template'] : 'index';//模板
		define('STYLE',$info['style']);
		include template('special', $template);
	}
	
	/**
	 * 专题分类
	 */
	public function type() {
		$typeid = intval($_GET['typeid']);//分类id
		$specialid = intval($_GET['specialid']);//专题id
		if (!$specialid || !$typeid) showmessage(L('illegal_action'));
		//相当于:select * from gt_special where id='$special' and disabled=0  获取当前专题信息
		$info = $this->db->get_one(array('id'=>$specialid, 'disabled'=>0));
		if(!$info) showmessage(L('special_not_exist'), 'back');
		$page = max(intval($_GET['page']), 1);
		//当前专题信息
		extract($info);
		$css = get_css(unserialize($css));
		if(!$typeid) showmessage(L('illegal_action'));
		$type_db = pc_base::load_model('type_model');//类别表
		//相当于:select * from gt_type where typeid='$typeid'
		$info = $type_db->get_one(array('typeid'=>$_GET['typeid']));
		$SEO = seo($siteid, '', $info['typename'], '');//类别名称
		$template = $list_template ? $list_template : 'list';//类别对应的模板
		include template('special', $template);
	}
	
	/**
	 * 专题展示
	 */
	public function show() {
		$id = intval($_GET['id']);//专题文章id
		if(!$id) showmessage(L('content_not_exist'),'blank');
		
		$page = max(intval($_GET['page']), 1);
		$c_db = pc_base::load_model('special_content_model');//专题文章主表
		$c_data_db = pc_base::load_model('special_c_data_model');//专题文章附表
		$rs = $c_db->get_one(array('id'=>$_GET['id']));//获取当前专题文章的主表内容
		if(!$rs) showmessage(L('content_checking'),'blank');
		//将当前专题文章主表中的字段转化为变量
		extract($rs);
		
		//是否用附表数据
		if ($isdata) {
			$arr_content = $c_data_db->get_one(array('id'=>$_GET['id']));//附表数据
			if (is_array($arr_content)) extract($arr_content);//将当前专题文章附表中的字段转化为变量
		}
		$siteid = get_siteid();//站点id
		if ($paginationtype) { 			//文章使用分页时:0-不分页  1-自动分页    2-手动分页
			if($paginationtype==1) {
				if (strpos($content, '[/page]')!==false) {
					$content = preg_replace("|\[page\](.*)\[/page\]|U", '', $content);
				}
				if (strpos($content, '[page]')!==false) {
					$content = str_replace('[page]', '', $content);
				}
				$contentpage = pc_base::load_app_class('contentpage', 'content'); //调用自动分页类
				$content = $contentpage->get_data($content, $maxcharperpage); //自动分页,自动添加上[page]
			} 
		} else {//文章不使用分页的情况
			if (strpos($content, '[/page]')!==false) {
				$content = preg_replace("|\[page\](.*)\[/page\]|U", '', $content);
			}
			if (strpos($content, '[page]')!==false) {
				$content = str_replace('[page]', '', $content);
			}
		}
		$template = $show_template ? $show_template : 'show'; //调用模板
		$CONTENT_POS = strpos($content, '[page]');
		if ($CONTENT_POS !== false) {
			$contents = array_filter(explode('[page]', $content));
			$pagenumber = count($contents);
			$END_POS = strpos($content, '[/page]');
			if ($END_POS!==false && ($CONTENT_POS<7)) {
				$pagenumber--;
			}
			for ($i=1; $i<=$pagenumber; $i++) {
				$pageurls[$i] = content_url($_GET['id'], $i, $inputtime, 'php');
			}
			if ($END_POS !== false) {
				if($CONTENT_POS>7) {
					$content = '[page]'.$title.'[/page]'.$content;
				}
				if (preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
					foreach ($m[1] as $k=>$v) {
						$p = $k+1;
						$titles[$p]['title'] = strip_tags($v);
						$titles[$p]['url'] = $pageurls[$p][1];
					}
				}
			}
			//判断[page]出现的位置是否在第一位 
			if($CONTENT_POS<7) {
				$content = $contents[$page];
			} else {
				if ($page==1 && !empty($titles)) {
					$content = $title.'[/page]'.$contents[$page-1];
				} else {
					$content = $contents[$page-1];
				}
			}
			if($titles) {
				list($title, $content) = explode('[/page]', $content);
				$content = trim($content);
				if(strpos($content,'</p>')===0) {
					$content = '<p>'.$content;
				}
				if(stripos($content,'<p>')===0) {
					$content = $content.'</p>';
				}
			}
			pc_base::load_app_func('util', 'content');
			$title_pages = content_pages($pagenumber,$page, $pageurls);//分页代码
		}
		//当前专题的标题和url
		$_special = $this->db->get_one(array('id'=>$specialid), '`title`, `url`');
		pc_base::load_sys_class('format', '', 0);
		$inputtime = format::date($inputtime);//发布时间
		$SEO = seo($siteid, '', $title);
		$template = $show_template ? $show_template : 'show';
		$style = $style ? $style : 'default';
		include template('special', $template, $style);
	}
	
	public function comment_show() {
		$commentid = isset($_GET['commentid']) ? $_GET['commentid'] : 0;
		$url = isset($_GET['url']) ? $_GET['url'] : HTTP_REFERER;
		$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
		$userid = param::get_cookie('_userid');
		include template('special', 'comment_show');
	}
	
	public function comment() {
		if (!$_GET['id']) return '0';
		$siteid =  $_GET['siteid'] ? $_GET['siteid'] : get_siteid();
		$id = intval($_GET['id']);
		$commentid = id_encode('special', $id, $siteid);
		$username = param::get_cookie('_username');
		$userid = param::get_cookie('_userid');
		if (!$userid) {
			showmessage(L('login_website'), APP_PATH.'index.php?m=member&c=index');
		}
		$date = date('m-d H:i', SYS_TIME);
		if ($_POST['dosubmit']) {
			$r = $this->db->get_one(array('id'=>$_POST['id']), '`title`, `url`');
			$comment = pc_base::load_app_class('comment', 'comment');
			if ($comment->add($commentid, $siteid, array('userid'=>$userid, 'username'=>$username, 'content'=>$_POST['content']), '', $r['title'], $r['url'])) {
				exit($username.'|'.SYS_TIME.'|'.$_POST['content']);
			} else {
				exit(0);
			}
		} else {
			pc_base::load_sys_class('form');
			include template('special', 'comment');
		}
	}
}
?>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值