public function getPostCount($info = array()) { $info['post_status'] = "publish"; $PostsLogic = new PostsLogic(); $post_count = $PostsLogic->countAll("single", $info); return $post_count; }
/** * 列表显示,包括page和single * @param string $post_type 文章类型 * @param string $post_status 文章状态 * @param string $order 顺序 * @param string $keyword 搜索关键词 */ public function index($post_type = 'single', $post_status = 'publish', $order = 'post_id desc', $keyword = '') { //获取get参数 $cat = I('get.cat'); $tag = I('get.tag'); $page = I('get.page', C('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 = D('Cats', 'Logic')->getPostsId($cat); $post_ids = empty($post_ids) ? array('post_id' => 0) : $post_ids; $cat_detail = D('Cats', 'Logic')->detail($cat); $cat = '关于分类 ' . $cat_detail['cat_name'] . ' 的'; } else { if ($tag != '') { $post_ids = D('Tags', 'Logic')->getPostsId($tag); $post_ids = empty($post_ids) ? array('post_id' => 0) : $post_ids; $tag_detail = D('Tags', 'Logic')->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', $key . $cat . $tag . get_real_string($post_type) . '列表'); $this->assign('posts', $posts_list); $this->assign('pager', $pager_bar); $this->display('index_no_js'); }
/** * 文章归档 * @param string $key 搜索需要的关键字 */ public function archive($key = '') { $map['post_date'] = array('like', I('get.year', '%') . '-' . I('get.month', '%') . '-' . I('get.day', '%') . '%'); $info['post_content|post_title'] = array('like', "%{$key}%"); $PostsList = new PostsLogic(); $count = $PostsList->countAll('single', $map); // 查询满足要求的总记录数 if ($count != 0) { $Page = new GreenPage($count, get_opinion('PAGER')); // 实例化分页类 传入总记录数 $limit = $Page->firstRow . ',' . $Page->listRows; //获取分页信息 $res = $PostsList->getList($limit, 'single', 'post_date desc', true, $map); 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["posts"] = "没有文章"; $this->jsonReturn(0, $res_array); } }
public function count() { $year = I('request.year', date('Y')); $month_start = I('request.month_start', date('m')); $month_end = I('request.month_end', date('m')); if ($month_start == $month_end) { $condition['post_date'] = array('like', I('request.year', '%') . '-' . I('request.month', '%') . '-' . I('request.day', '%') . '%'); } else { if ($month_start == '%%') { $condition['post_date'] = array('between', "{$year}-0-0,{$year}-{$month_end}-31"); } else { if ($month_end == '%%') { $condition['post_date'] = array('between', "{$year}-{$month_start}-0,{$year}-12-31"); } else { $condition['post_date'] = array('between', "{$year}-{$month_start}-0,{$year}-{$month_end}-31"); } } } $UserLogic = new UserLogic(); $PostsLogic = new PostsLogic(); $user_list = $UserLogic->getList(false); foreach ($user_list as $key => $user) { $condition['user_id'] = $user['user_id']; $user_list[$key]['post_count'] = $PostsLogic->countAll('single', $condition); $user_list[$key]['date'] = substr($condition['post_date'][1], 0, 7); } $this->assign("user_list", $user_list); $this->assign("year", $year); $this->assign("month_start", $month_start); $this->assign("month_end", $month_end); $this->display('count'); }
/** * 未知类型归档 支持年月日参数传递 和用户id * @param $method 未知类型 * @param array $args 参数 */ public function _empty($method, $args) { $title_prefix = (I('get.year', '') ? I('get.year', '') . '年' : '') . (I('get.month', '') ? I('get.month', '') . '月' : '') . (I('get.day', '') ? I('get.day', '') . '日' : ''); //TODO 通用类型 $post_type = $method; $map['post_date'] = array('like', I('get.year', '%') . '-' . I('get.month', '%') . '-' . I('get.day', '%') . '%'); if (I('get.uid') != '') { $map['user_id'] = I('get.uid'); } $PostsLogic = new PostsLogic(); $count = $PostsLogic->countAll($post_type, $map); // 查询满足要求的总记录数 $count == 0 ? $res404 = 0 : ($res404 = 1); if ($count != 0) { $Page = new GreenPage($count, C('PAGER')); $pager_bar = $Page->show(); $limit = $Page->firstRow . ',' . $Page->listRows; $posts_list = $PostsLogic->getList($limit, $post_type, 'post_id desc', true, $map); } $this->assign('title', $title_prefix . '所有' . $post_type); $this->assign('res404', $res404); // 赋值数据集 $this->assign('postslist', $posts_list); // 赋值数据集 $this->assign('pager', $pager_bar); // 赋值分页输出 if (File::file_exists(T('Home@Archive/' . $post_type . '-list'))) { $this->display($post_type); } else { //TODO 这里怎么处理却决于你自己了。 $this->error404('缺少对应的模版而不能显示'); // $this->display('single-list'); } }
public function countAll() { $where = array(); //投稿员只能看到自己的 if (!$this->noVerify()) { $where['user_id'] = get_current_user_id(); } $PostsLogic = new PostsLogic(); $res = array(); $post_status = C('post_status'); foreach ($post_status as $key => $value) { $where['post_status'] = $key; $count = $PostsLogic->countAll('single', $where); // 查询满足要求的总记录数 $res['single'][$key] = $count; } $where['post_status'] = 'publish'; $count = $PostsLogic->countAll('single', $where); // 查询满足要求的总记录数 $res['page']['publish'] = $count; $this->jsonReturn(1, $res); }