Beispiel #1
0
 public function action_write()
 {
     $this->template->page_title = 'Write Article';
     $user = new Model_User();
     $session = Session::instance()->get('user');
     $view = View::factory('cp/entries/write');
     $view->author = $users->get_user_by_session_id($session);
     if ($this->request->method() === Request::POST) {
         if (!Security::check($this->request->post('csrf_token'))) {
             throw new HTTP_Exception_401("Bad token!");
         }
         $post_title = $this->request->post('title');
         $post_slug = $this->request->post('slug');
         $post_content = $this->request->post('content');
         $post_author = $this->request->post('author');
         $post_date = time();
         if (empty($post_title) and empty($post_content) and empty($post_author) and empty($post_date)) {
             throw new Exception('Please don`t make empty fields!');
         }
         if (empty($post_slug)) {
             $post_slug = URL::title($post_title, '_');
         }
         $entry = new Model_Entry();
         $data = array('title' => $post_title, 'slug' => $post_slug, 'content' => $post_content, 'author' => $post_author, 'date' => $post_date);
         $insert_entry = $entry->insert_entry($data);
         if (!$insert_entry) {
             throw new Exception('Check if you are connected to database!');
         }
         $this->request->redirect('cp/entries/write/');
     }
     $this->template->content = $view->render();
 }