/** * 退出操作 * */ public function logout() { //接受ajax请求 if (jet_Get('r') == 'ajax') { $_SERVER['REQUEST_METHOD'] == 'POST' or die('welcome to jet'); if (!$this->get_cookie('user')) { $array = array('msg' => '您尚未登录', 'has' => false); } elseif ($this->let_cookie('user')) { $array = array('msg' => '退出成功', 'has' => true); } else { $array = array('msg' => '退出失败', 'has' => 'false'); } echo jet_JSON($array); exit; } //尚未登录 if (!$this->get_cookie('user')) { $this->redirect('你尚未登录哦', 'R:home_page'); exit; } if ($this->let_cookie('user')) { $this->redirect('退出成功!', 'R:home_page', '2'); } else { $this->redirect('退出失败!', 'R:home_page', 2); } }
/** * 文章管理 */ public function post() { //显示文章列表 if ($this->a == '' or $this->a == 'index' or $this->a == 'list') { $list = $this->model('post')->select(); foreach ($list as $key => $value) { foreach ($value as $k => $v) { if ($k == 'summary') { $list[$key][$k] = strip_tags($v); } } } $this->assign('list', $list); $this->render('admin/post/index'); } //发布文章 if ($this->a == 'publish') { if (jet_Post('action') == 'do_publish') { $data['title'] = jet_Post('title'); $data['summary'] = jet_Post('summary'); $data['content'] = jet_Post('content'); if ($data['summary'] == false) { $data['summary'] = substr(strip_tags($data['content']), 0, jet_config('summary_length')); } //$data['publish_time'] = time(); $data['views'] = mt_rand(19, 45); $data['author'] = $this->current_user(); //dump($data); $flag = $this->model('post')->insert($data); if ($flag) { //创建通知 $message = array('sender' => 'system', 'receiver' => 'ALL_USER', 'content' => '博主有新的文章' . $data['title'], 'type' => 'system'); $this->model('notification')->insert($message); echo jet_JSON(array('msg' => '发布成功!', 'has' => true, 'id' => $flag)); return; } else { echo jet_JSON(array('msg' => '发布失败!', 'has' => false)); return; } } else { $category = $this->model('category')->where("type != 'first'")->select(); $this->assign('category', $category); $this->assign('action', 'do_publish'); $c = array('category' => ''); $this->assign('post', $c); $this->render('admin/post/editor'); } } //删除文章 if ($this->a == 'delete' or $this->a == 'd') { $data = array('msg' => false); $id = jet_Post('id'); if (is_numeric($id)) { $f = $this->model('post')->where($id)->delete(); if ($f) { $data['msg'] = true; foreach ($data as $key => $value) { $data[$key] = urlencode($value); } $data = json_encode($data); echo urldecode($data); } else { $data['msg'] = false; foreach ($data as $key => $value) { $data[$key] = urlencode($value); } $data = json_encode($data); echo urldecode($data); } } } //修改文章 if ($this->a == 'modify' or $this->a == 'm') { if (jet_Post('action') != 'do_modify') { $id = jet_Get('id'); $post = $this->model('post')->where($id)->select(); $post[0]['summary'] = strip_tags($post[0]['summary']); $this->assign('post', $post[0]); $this->assign('action', 'do_modify'); $category = $this->model('category')->where("type != 'first'")->select(); $this->assign('category', $category); $this->render('admin/post/editor'); } elseif (jet_Post('action') == 'do_modify') { $id = jet_Post('id'); $data['title'] = jet_Post('title'); $data['summary'] = jet_Post('summary'); $data['content'] = jet_Post('content'); if ($data['summary'] == false) { $data['summary'] = substr(strip_tags($data['content']), 0, jet_config('summary_length')); } $flag = $this->model('post')->where($id)->update($data); if ($flag) { $message = array('sender' => 'system', 'receiver' => 'ALL_USER', 'content' => '博主有新的文章' . $data['title'], 'type' => 'system'); $this->model('notification')->insert($message); echo jet_JSON(array('msg' => '修改成功!', 'has' => true, 'id' => $id)); return; } else { echo jet_JSON(array('msg' => '修改失败!', 'has' => false)); return; } } } }