/** * */ public function menuAdd() { $CatsLogic = new CatsLogic(); $TagsLogic = new TagsLogic(); $PostsLogic = new PostsLogic(); $cat_list = $CatsLogic->category(); $tag_list = $TagsLogic->field('tag_id,tag_name')->select(); $post_list = $PostsLogic->field('post_id,post_title')->select(); $cat_list = array_column_5($cat_list, 'cat_slug', 'cat_id'); $tag_list = array_column_5($tag_list, 'tag_name', 'tag_id'); $post_list = array_column_5($post_list, 'post_title', 'post_id'); $action = '添加菜单'; $action_url = U('Admin/Custom/menuAdd'); $form_url = U('Admin/Custom/menuAddHandle'); $Menu = new Category('Menu', array('menu_id', 'menu_pid', 'menu_name', 'menu_construct')); $menu_list = $Menu->getList(); // 获取分类结构 $url_function = C('url_function'); $this->assign('url_function', gen_opinion_list($url_function)); $url_open = C('url_open'); $this->assign('url_open', gen_opinion_list($url_open)); $this->assign('cat_list', gen_opinion_list($cat_list)); $this->assign('tag_list', gen_opinion_list($tag_list)); $this->assign('post_list', gen_opinion_list($post_list)); $this->assign('menu', $menu_list); $this->assign('action', $action); $this->assign('action_url', $action_url); $this->assign('form_url', $form_url); $this->display(); }
/** * 兼容旧式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'); }
/** * 兼容旧式CMS深目录结构的二级cat结构 * @param $info */ public function channel($info) { //TODO 兼容旧式CMS深目录结构的二级cat结构 $CatsLogic = new CatsLogic(); $cat = $CatsLogic->detail($info); $children = $CatsLogic->getChildren($cat['cat_id']); if (empty($children['cat_children'])) { $children = $CatsLogic->getChildren($children['cat_father']); } $CatsLogic = new CatsLogic(); $Posts = new PostsLogic(); $cat = $CatsLogic->detail($info); $this->if404($cat, "非常抱歉,没有这个分类,可能它已经躲起来了"); //优雅的404 $posts_id = $CatsLogic->getPostsIdWithChildren($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_date 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'])); if (File::file_exists(T('Home@Archive/channel-list'))) { $this->display('Archive/channel-list'); } else { //TODO 这里怎么处理却决于你自己了。 // $this->error404('缺少对应的模版而不能显示'); $this->display('Archive/single-list'); } }
/** * 删除分类 * @param $id */ public function delCategory($id = -1) { $CatsLogic = new CatsLogic(); if ($id == 1) { $this->error("默认分类不可删除"); } else { if ($CatsLogic->relation(true)->delete($id)) { $data['cat_id'] = '1'; if (D('Post_cat')->where(array("cat_id" => $id))->find()) { $post = D('Post_cat')->where(array("cat_id" => $id))->select(); foreach ($post as $v) { D('Post_cat')->where(array("pc_id" => $v['pc_id']))->data($data)->save(); } } $this->success('分类删除成功', U('Admin/Posts/category')); } else { $this->success('分类删除失败:没有找到指定分类,可能它已经被删除', U('Admin/Posts/category')); } } }
/** * 父类与子类分类列表 * @usage {:W('Widget/catSidebar',array("cat_id"=>$cat_id))} */ public function catSidebar($cat_id = 0, $default_title) { if ($cat_id == null) { $this->assign('cat_sidebar_title', $default_title); // 赋值数据集 $CatList = new CatsLogic(); $Cat = new \Common\Util\Category('Cats', array('cat_id', 'cat_father', 'cat_name', 'cat_name')); $children['cat_children'] = $Cat->getList(); foreach ($children['cat_children'] as $key => $value) { $children['cat_children'][$key]['cat_children'] = $children['cat_children'][$key]; } $this->assign('children2', $children); } else { $Cat = new CatsLogic(); $children = $Cat->getChildren($cat_id); if (empty($children['cat_children'])) { //无子类处理 if ($children['cat_father'] == 0) { //无父类 $this->assign('cat_sidebar_title', $children["cat_name"]); // 赋值数据集 } else { //有父类 $children2 = $Cat->getChildren($children['cat_father']); $this->assign('cat_sidebar_title', $children2["cat_name"]); // 赋值数据集 $this->assign('children2', $children2); } } else { //有子类处理 $this->assign('cat_sidebar_title', $children["cat_name"]); // 赋值数据集 $this->assign('children2', $children); } } $this->assign('cat_id', $cat_id); // 赋值数据集 $this->display('Widget:cat_sidebar'); }
/** * 分类文章 * @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); } }
/** * 编辑菜单 * @param $id */ public function menuEdit($id) { $menu_item = D('Menu')->where(array('menu_id' => $id))->find(); if (!$menu_item) { $this->error('不存在这个菜单项'); } $this->assign('info', $menu_item); $CatsLogic = new CatsLogic(); $TagsLogic = new TagsLogic(); $PostsLogic = new PostsLogic(); /** * 文章分类标签 start */ $cat_list = $CatsLogic->category(); $tag_list = $TagsLogic->field('tag_id,tag_name')->select(); $post_list = $PostsLogic->field('post_id,post_title')->select(); $cat_list = array_column_5($cat_list, 'cat_slug', 'cat_id'); $tag_list = array_column_5($tag_list, 'tag_name', 'tag_id'); $post_list = array_column_5($post_list, 'post_title', 'post_id'); $this->assign('cat_list', gen_opinion_list($cat_list)); $this->assign('tag_list', gen_opinion_list($tag_list)); $this->assign('post_list', gen_opinion_list($post_list)); /** * 文章分类标签 end */ $action = '编辑菜单'; $action_url = U('Admin/Custom/menuEdit', array('id' => $id)); $form_url = U('Admin/Custom/menuEditHandle', array('id' => $id)); $Menu = new Category('Menu', array('menu_id', 'menu_pid', 'menu_name', 'menu_construct')); $menu_list = $Menu->getList(); // 获取分类结构 $url_function = get_opinion('url_function'); $this->assign('url_function', gen_opinion_list($url_function, $menu_item["menu_function"])); $url_open = get_opinion('url_open'); $this->assign('url_open', gen_opinion_list($url_open, $menu_item["menu_action"])); //父级节点 $menu_list2 = array_column_5($menu_list, 'menu_construct', 'menu_id'); $this->assign('menu_list2', gen_opinion_list($menu_list2, $menu_item['menu_pid'])); //显示排序 $menu_list3 = array_column_5($menu_list, 'menu_construct', 'menu_sort'); $this->assign('menu_list3', gen_opinion_list($menu_list3, $menu_item['menu_sort'])); $this->assign('menu', $menu_list); $this->assign('action', $action); $this->assign('action_url', $action_url); $this->assign('form_url', $form_url); $this->display(); }
/** * 删除分类 * @param $id */ public function delCategory($id = -1) { $CatsLogic = new CatsLogic(); $PostsLogic = new PostsLogic(); $process_method = I('post.process_method'); if ($process_method == 'tocat' && I('post.newcat') == $id) { $this->error("移动后的分类不能和当前分类相同"); } if ($id == 1) { $this->error("默认分类不可删除"); } else { if ($CatsLogic->delete($id)) { if (D('Post_cat')->where(array("cat_id" => $id))->find()) { $pc_list = D('Post_cat')->where(array("cat_id" => $id))->select(); foreach ($pc_list as $pc) { if ($process_method == 'del') { $PostsLogic->preDel($pc['post_id']); } if ($process_method == 'tocat') { $data['cat_id'] = I('post.newcat'); D('Post_cat')->where(array("pc_id" => $pc['pc_id']))->data($data)->save(); } } } } else { $this->error('分类删除失败:没有找到指定分类,可能它已经被删除', U('Admin/Posts/category')); } } $this->success('分类删除成功', U('Admin/Posts/category')); }