/** * 查询指定分类的详细信息 * @param int $info detail 查询的 id 或者slug */ public function detail($info = 1) { if (get_opinion("auto_channel", false, false)) { $this->channel($info); Hook::listen('app_end'); die; } $CatsLogic = new CatsLogic(); $PostsLogic = new PostsLogic(); $cat = $CatsLogic->detail($info); // $this->assign('cat_id', $cat['cat_id']); // 赋值数据集 $this->if404($cat, "非常抱歉,没有这个分类,可能它已经躲起来了"); //优雅的404 $posts_id = $CatsLogic->getPostsId($cat['cat_id']); $count = sizeof($posts_id); $count == 0 ? $res404 = 0 : ($res404 = 1); if (!empty($posts_id)) { $Page = new GreenPage($count, get_opinion('PAGER')); $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $PostsLogic->getList($limit, 'single', 'post_date desc', true, array(), $posts_id); } $this->assign('title', '分类 ' . $cat['cat_name'] . ' 所有文章'); // 赋值数据集 $this->assign('res404', $res404); $this->assign('postslist', $posts_list); // 赋值数据集 $this->assign('pager', $pager_bar); // 赋值分页输出 $this->assign('breadcrumbs', get_breadcrumbs('cats', $cat['cat_id'])); $this->display('Archive/single-list'); }
/** * 兼容旧式CMS深目录结构的二级cat结构 * @param $info */ public function channel($info) { //TODO 兼容旧式CMS深目录结构的二级cat结构 $Cat = new CatsLogic(); $cat = $Cat->detail($info); $children = $Cat->getChildren($cat['cat_id']); $Cat = new CatsLogic(); $Posts = new PostsLogic(); $cat = $Cat->detail($info); $this->if404($cat, "非常抱歉,没有这个分类,可能它已经躲起来了"); //优雅的404 $posts_id = $Cat->getPostsId($cat['cat_id']); $count = sizeof($posts_id); $count == 0 ? $res404 = 0 : ($res404 = 1); if (!empty($posts_id)) { $Page = new GreenPage($count, get_opinion('PAGER')); $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $Posts->getList($limit, 'single', 'post_id desc', true, array(), $posts_id); } $this->assign('children', $children); $this->assign('title', $cat['cat_name']); // 赋值数据集 $this->assign('res404', $res404); $this->assign('postslist', $posts_list); // 赋值数据集 $this->assign('pager', $pager_bar); // 赋值分页输出 $this->assign('breadcrumbs', get_breadcrumbs('cats', $cat['cat_id'])); $this->display('Archive/channel-list'); }
/** * 列表显示,包括page和single * @param string $post_type 文章类型 * @param string $post_status 文章状态 * @param string $order 顺序 * @param string $keyword 搜索关键词 * @param string $tpl 模板名称 * @param string $name */ public function index($post_type = 'single', $post_status = 'publish', $order = 'post_date desc', $keyword = '', $tpl = 'index_no_js', $name = '') { $CatsLogic = new CatsLogic(); $TagsLogic = new TagsLogic(); //获取get参数 $cat = I('get.cat'); $tag = I('get.tag'); $page = I('get.page', get_opinion('PAGER')); $where = array('post_status' => $post_status); $where['post_content|post_title'] = array('like', "%{$keyword}%"); $post_ids = array(); //投稿员只能看到自己的 if (!$this->noVerify()) { $where['user_id'] = get_current_user_id(); } //处理详细信息 搜索,指定TAG CAT文章 if ($cat != '') { $post_ids = $CatsLogic->getPostsId($cat); $post_ids = empty($post_ids) ? array('post_id' => 0) : $post_ids; $cat_detail = $CatsLogic->detail($cat); $cat = '关于分类 ' . $cat_detail['cat_name'] . ' 的'; } else { if ($tag != '') { $post_ids = $TagsLogic->getPostsId($tag); $post_ids = empty($post_ids) ? array('post_id' => 0) : $post_ids; $tag_detail = $TagsLogic->detail($tag); $tag = '关于标签' . $tag_detail['tag_name'] . ' 的'; } else { if ($keyword != '') { $key = '关于' . $keyword . ' 的'; } } } $PostsLogic = new PostsLogic(); $count = $PostsLogic->countAll($post_type, $where, $post_ids); // 查询满足要求的总记录数 if ($count != 0) { $Page = new GreenPage($count, $page); // 实例化分页类 传入总记录数 $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $PostsLogic->getList($limit, $post_type, $order, true, $where, $post_ids); } $this->assign('post_type', $post_type); $this->assign('action', $name . $key . $cat . $tag . get_real_string($post_type) . '列表'); $this->assign('posts', $posts_list); $this->assign('pager', $pager_bar); $this->display($tpl); }
/** * 分类文章 * @param int $id 分类id */ public function cat($id) { $Cat = new CatsLogic(); $Posts = new PostsLogic(); $cat = $Cat->detail($id); $posts_id = $Cat->getPostsId($cat['cat_id']); $count = sizeof($posts_id); if (!empty($posts_id)) { $Page = new GreenPage($count, get_opinion('PAGER')); $limit = $Page->firstRow . ',' . $Page->listRows; $res = $Posts->getList($limit, 'single', 'post_date desc', true, array(), $posts_id); foreach ($res as $key => $value) { $res[$key]['post_content'] = strip_tags($res[$key]['post_content']); $res[$key]['post_url'] = U('Api/Index/post', array('id' => $res[$key]['post_id']), false, true); $res[$key]["post_img"] = get_post_img($value); } $res_array["posts"] = $res; $this->jsonReturn(1, $res_array); } else { $res_array["detail"] = "没有文章"; $this->jsonReturn(0, $res_array); } }