/**
  * @param $id
  */
 public function posts($id = -1, $new_post = false)
 {
     $PostEvent = new PostsEvent();
     $this->post_id = $post_id = $id ? (int) $id : false;
     $Posts = new PostsLogic();
     if (IS_POST) {
         $post_data = $_POST;
         $post_data['post_modified'] = date("Y-m-d H:m:s", time());
         $post_data['post_type'] = $_POST['post_type'] ? $_POST['post_type'] : 'single';
         D("post_cat")->where(array("post_id" => $post_data['post_id']))->delete();
         D("post_tag")->where(array("post_id" => $post_data['post_id']))->delete();
         if (!empty($_POST['cats'])) {
             foreach ($_POST['cats'] as $cat_id) {
                 D("Post_cat")->add(array("cat_id" => $cat_id, "post_id" => $post_data['post_id']));
             }
         }
         if (!empty($_POST['tags'])) {
             foreach ($_POST['tags'] as $tag_id) {
                 D("Post_tag")->add(array("tag_id" => $tag_id, "post_id" => $post_data['post_id']));
             }
         }
         if ($post_data['post_type'] == 'single') {
             $url = U('Admin/Posts/index');
         } elseif ($post_data['post_type'] == 'page') {
             $url = U('Admin/Posts/page');
         } else {
             $url = U('Admin/Posts/index');
         }
         CacheManager::clearPostCacheById($id);
         if ($Posts->where(array("post_id" => $post_data["post_id"]))->save($post_data)) {
             $this->jsonReturn(1, "已经更新", $url);
         } else {
             //处理失败
             cookie('post_add' . $post_data["post_id"], gzcompress(json_encode($post_data)), 3600000);
             //支持大约2.8万个字符 Ueditor计算方法,所有中文和英文数字都算一个字符计算
             $this->jsonReturn(0, "更新失败", $url);
         }
     } else {
         $this->initEditor($id);
         //投稿员只能看到自己的
         if (!$this->noVerify()) {
             $where['user_id'] = get_current_user_id();
         }
         $where["post_id"] = $post_id;
         $post = D('Posts')->relation(true)->where($where)->find();
         if (empty($post)) {
             $this->error("不存在该记录");
         }
         if ($new_post) {
             $post['post_status'] = 'publish';
         }
         $tpl_type_list = $PostEvent->getTplList();
         //投稿员只能看到权限内部的分类
         if (!$this->noVerify()) {
             $user = D('User', 'Logic')->detail((int) $_SESSION[get_opinion('USER_AUTH_KEY')]);
             $role = D('Role')->where(array('id' => $user["user_role"]["role_id"]))->find();
             $cats = D('Cats', 'Logic')->where(array('in', json_decode($role["cataccess"])))->select();
             foreach ($cats as $key => $value) {
                 $cats[$key]['cat_slug'] = $cats[$key]['cat_name'];
             }
             $tags = array();
         } else {
             $cats = D('Cats', 'Logic')->category();
             $tags = D('Tags', 'Logic')->select();
         }
         $this->assign("cats", $cats);
         $this->assign("tags", $tags);
         $this->assign('tpl_type', gen_opinion_list($tpl_type_list, $post['post_template']));
         $this->assign('post_status', gen_opinion_list(get_opinion("post_status"), $post['post_status']));
         $this->assign('post_type', gen_opinion_list(get_opinion("post_type"), $post['post_type']));
         $this->assign("info", $post);
         $this->assign("handle", U('Admin/Posts/posts', array('id' => $id, 'new_post' => $new_post), true, false));
         $this->assign("action", '编辑文章');
         $this->assign("action_name", 'posts');
         $this->display('post_v3');
     }
 }
示例#2
0
 /**
  * 修改文章状态
  * @param $post_id
  * @param $post_status
  * @return mixed
  */
 public function changePostStatue($post_id, $post_status)
 {
     CacheManager::clearPostCacheById($post_id);
     return $this->where(array('post_id' => $post_id))->setField(array("post_status" => $post_status));
 }