示例#1
0
/**
 * @param $name
 * @param null $value
 * @param null $expire
 * @param null $path
 * @param null $domain
 * @return mixed
 */
function jet_cookie($name, $value = null, $expire = null, $path = null, $domain = null)
{
    //判断前缀
    if (strpos($name, jet_config('cookie_prefix')) == false) {
        $name = jet_config('cookie_prefix') . $name;
    }
    //设置cookie
    if ($expire > 0) {
        setcookie($name, $value, $expire, $path, $domain);
    } else {
        return $_COOKIE[$name];
    }
}
示例#2
0
 /**
  * 文章管理
  */
 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;
             }
         }
     }
 }