/**
  * @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');
     }
 }
 public function cache()
 {
     $this->assign('HTML_CACHE_ON', (int) get_opinion('HTML_CACHE_ON', true));
     $this->assign('DB_FIELDS_CACHE', (int) get_opinion('DB_FIELDS_CACHE'));
     $this->assign('DB_SQL_BUILD_CACHE', (int) get_opinion('DB_SQL_BUILD_CACHE'));
     $this->assign('DATA_CACHE_TYPE', gen_opinion_list(get_opinion("cache_type"), get_opinion('DATA_CACHE_TYPE', true, "File")));
     $this->display();
 }
 /**
  * @param $id
  */
 public function posts($id = -1)
 {
     $this->action = '编辑文章';
     $this->action_name = 'posts';
     $this->post_id = $post_id = $_GET['id'] ? (int) $_GET['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';
         M("post_cat")->where(array("post_id" => $post_data['post_id']))->delete();
         M("post_tag")->where(array("post_id" => $post_data['post_id']))->delete();
         if (!empty($_POST['cats'])) {
             foreach ($_POST['cats'] as $cat_id) {
                 M("Post_cat")->add(array("cat_id" => $cat_id, "post_id" => $post_data['post_id']));
             }
         }
         if (!empty($_POST['tags'])) {
             foreach ($_POST['tags'] as $tag_id) {
                 M("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');
         }
         if ($Posts->save($post_data)) {
             $this->jsonReturn(1, "已经更新", $url);
         } else {
             $this->jsonReturn(0, "更新失败", $url);
         }
     } else {
         //投稿员只能看到自己的
         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("不存在该记录");
         }
         $PostEvent = new PostsEvent();
         $tpl_type_list = $PostEvent->get_tpl_type_list();
         $this->assign('tpl_type', gen_opinion_list($tpl_type_list, $post['post_template']));
         //投稿员只能看到自己的
         if (!$this->noVerify()) {
             $user_id = (int) $_SESSION[C('USER_AUTH_KEY')];
             $user = D('User', 'Logic')->detail($user_id);
             $role_id = $user["user_role"]["role_id"];
             $role = D('Role')->where(array('id' => $role_id))->find();
             $where['cat_id'] = array('in', json_decode($role["cataccess"]));
             $cats = D('Cats', 'Logic')->where($where)->select();
             foreach ($cats as $key => $value) {
                 $cats[$key]['cat_slug'] = $cats[$key]['cat_name'];
             }
         } else {
             $cats = D('Cats', 'Logic')->category();
             $tags = D('Tags', 'Logic')->select();
         }
         $this->assign("cats", $cats);
         $this->assign("tags", $tags);
         $this->assign("info", $post);
         $this->assign("handle", U('Admin/Posts/posts', array('id' => $id), true, false));
         $this->assign("publish", "更新");
         $this->display('add');
     }
 }
 /**
  *
  */
 public function green()
 {
     $DEFAULT_ADMIN_THEME = array('AdminLTE' => 'AdminLTE', 'Metronic' => 'Metronic');
     $this->assign('DEFAULT_ADMIN_THEME', gen_opinion_list($DEFAULT_ADMIN_THEME, get_opinion('DEFAULT_ADMIN_THEME', true, "Metronic")));
     $this->display();
 }
 /**
  * 编辑链接
  * @param $id
  */
 public function editlink($id)
 {
     if (IS_POST) {
         $data = I('post.');
         if ($_FILES['img']['size'] != 0) {
             $config = array("savePath" => 'Links/', "maxSize" => 1000000, "exts" => array('jpg', 'bmp', 'png', 'jpeg'), "subName" => array('date', 'Y/m-d'));
             $upload = new Upload($config);
             $info = $upload->upload();
             if (!$info) {
                 // 上传错误提示错误信息
                 $this->error($upload->getError());
             } else {
                 // 上传成功 获取上传文件信息
                 $file_path_full = $info['img']['fullpath'];
                 $image = new \Think\Image();
                 $image->open($file_path_full);
                 $image->thumb(200, 150)->save($file_path_full);
                 $img_url = $info['img']['urlpath'];
                 // $img_url = "http://" . $_SERVER['SERVER_NAME'] . str_replace('index.php', '', __APP__) . $file_path_full;
                 unset($data['img']);
                 $data['link_img'] = $img_url;
             }
         }
         if (D('Links', 'Logic')->where(array('link_id' => $id))->save($data)) {
             $this->success('链接编辑成功', U('Admin/Custom/links', array('id' => $data['link_group_id'])));
         } else {
             $this->error('链接编辑失败', U('Admin/Custom/links', array('id' => $data['link_group_id'])));
         }
     } else {
         $this->form_url = U('Admin/Custom/editlink', array('id' => $id));
         $link = D('Links', 'Logic')->detail($id);
         $link_groups = D('Link_group', 'Logic')->select();
         $link_group_select = array_column_5($link_groups, 'link_group_name', 'link_group_id');
         $this->assign('link_group', gen_opinion_list($link_group_select, $link['link_group_id']));
         $this->assign('imgurl', $link['link_img']);
         $this->assign('link', $link);
         // print_array($this->link);
         $this->action = '编辑链接';
         $this->buttom = '编辑';
         $this->display('addlink');
     }
 }