Esempio n. 1
0
File: page.php Progetto: ruoL/fun-x
 public function update_action()
 {
     if (!$this->input->is_ajax_request()) {
         show_404();
     }
     $pid = (int) $this->input->post('pid');
     if ($pid === 0) {
         JSON('error', '数据错误,无法更新页面!');
     }
     $name = $this->input->post('name', true);
     $link = $this->input->post('link', true);
     $keyword = $this->input->post('keyword', true);
     $description = $this->input->post('description', true);
     $content = $this->input->post('content');
     $content = strip_tags($content, '<p><a><strong><img><em><span><ul><ol><li><br>');
     $sort = (int) $this->input->post('sort');
     if (trim($description) == '') {
         $data['description'] = substring(strip_tags($content), 120);
     } else {
         $data['description'] = $description;
     }
     $data['name'] = $name;
     $data['link'] = url_title($link, 'underscore', true);
     $data['keyword'] = format_keyword($keyword);
     $data['content'] = htmlspecialchars($content);
     $data['created'] = $data['updated'] = time();
     $data['sort'] = $sort > 255 ? 255 : $sort;
     if (empty($data['name'])) {
         JSON('error', '请填写页面名称!');
     }
     if (empty($data['link'])) {
         JSON('error', '请填写页面链接');
     }
     if ($this->page_model->get_info(array('pid !=' => $pid, 'name' => $data['name']))) {
         JSON('error', '对不起,页面名称已经存在!');
     }
     if ($this->page_model->get_info(array('pid !=' => $pid, 'link' => $data['link']))) {
         JSON('error', '对不起,页面链接已经存在!');
     }
     if (strip_tags($content) == '') {
         JSON('error', '请填写页面内容');
     }
     $this->db->update('page', $data, array('pid' => $pid));
     unset($data);
     if ($this->db->affected_rows()) {
         JSON('success', '恭喜,页面已更新成功!');
     } else {
         JSON('error', '页面更新失败,请重试!');
     }
 }
Esempio n. 2
0
 public function update_action()
 {
     if (!$this->input->is_ajax_request()) {
         show_404();
     }
     $cid = (int) $this->input->post('cid');
     if ($cid === 0) {
         JSON('error', '对不起,更新分类提交失败!');
     }
     $name = $this->input->post('name', true);
     $link = $this->input->post('link', true);
     $keyword = $this->input->post('keyword', true);
     $description = $this->input->post('description', true);
     $sort = (int) $this->input->post('sort');
     $data['name'] = trim($name);
     $data['link'] = url_title($link, 'underscore', true);
     $data['sort'] = $sort > 255 ? 255 : $sort;
     $data['keyword'] = format_keyword($keyword);
     $data['description'] = substring(format_content($description), 240);
     if (!$data['name'] or !$data['link']) {
         JSON('error', '对不起,请填写必填字段!');
     }
     if ($this->category_model->get_info(array('cid !=' => $cid, 'name' => $name))) {
         JSON('error', '对不起,分类名称已经存在!');
     }
     if ($this->category_model->get_info(array('cid !=' => $cid, 'link' => $link))) {
         JSON('error', '对不起,分类链接名称已经存在!');
     }
     $this->db->update('category', $data, array('cid' => $cid));
     if ($this->db->affected_rows()) {
         JSON('success', '恭喜,分类 ' . $data['name'] . ' 更新成功!');
     } else {
         JSON('error', '对不起,分类没有更新或更新失败!');
     }
 }
Esempio n. 3
0
 public function create_action()
 {
     if (!$this->input->is_ajax_request()) {
         show_404();
     }
     $cid = (int) $this->input->post('cid');
     $index = (int) $this->input->post('index');
     $from = $this->input->post('fromurl', true);
     $title = $this->input->post('title', true);
     $keyword = $this->input->post('keyword', true);
     $description = $this->input->post('description', true);
     $content = $this->input->post('content');
     $content = strip_tags($content, '<p><a><strong><img><em><span><ul><ol><li><br>');
     if (trim($description) == '') {
         $data['description'] = substring(strip_tags($content), 200);
     } else {
         $data['description'] = $description;
     }
     $data['cid'] = $cid;
     $data['from'] = is_url($from) ? $from : '';
     $data['image'] = str_exists($content, '<img src=') ? 1 : 0;
     $data['title'] = trim($title);
     $data['index'] = $index;
     $data['keyword'] = format_keyword($keyword);
     $data['content'] = htmlspecialchars($content);
     $data['created'] = $data['updated'] = time();
     $data['state'] = 1;
     if ($data['cid'] === 0) {
         JSON('error', '请选择文章分类!');
     }
     if (empty($data['title'])) {
         JSON('error', '请填写文章标题!');
     }
     if (strip_tags($content) == '') {
         JSON('error', '请填写文章内容!');
     }
     $action = $this->input->post('action', true);
     switch ($action) {
         case 'update':
             $success = '恭喜,文章已更新成功!';
             $error = '对不起,文章更新失败,请重试!';
             break;
         case 'draft':
             $data['state'] = 0;
             $success = '草稿已存于 ' . date('Y年m月d H:i');
             $error = '草稿保存失败,请重试!';
             break;
         default:
             $success = '恭喜,文章已发布成功!';
             $error = '对不起,文章发布失败,请重试!';
     }
     $draft_id = (int) $this->input->post('draftid');
     $state_id = $this->_create_article($draft_id, $data);
     if ($state_id) {
         JSON('success', $success, $state_id);
     } else {
         JSON('error', $error, $state_id);
     }
 }