Example #1
0
 /**
  * Save a post and redirects to listing
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     User::setState('com_forum.edit.thread.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     $fields['sticky'] = isset($fields['sticky']) ? $fields['sticky'] : 0;
     $fields['closed'] = isset($fields['closed']) ? $fields['closed'] : 0;
     $fields['anonymous'] = isset($fields['anonymous']) ? $fields['anonymous'] : 0;
     if ($fields['id']) {
         $fields['modified'] = \Date::toSql();
         $fields['modified_by'] = User::get('id');
     }
     // Initiate extended database class
     $post = Post::oneOrNew(intval($fields['id']))->set($fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminThread();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $post->assetRules = $validData['rules'];
     }
     // Store new content
     if (!$post->save()) {
         Notify::error($post->getError());
         return $this->editTask($post);
     }
     // Handle attachments
     if (!$this->uploadTask($post->get('thread', $post->get('id')), $post->get('id'))) {
         Notify::error($this->getError());
         return $this->editTask($post);
     }
     // Process tags
     $post->tag(trim(Request::getVar('tags', '')));
     Notify::success(Lang::txt('COM_FORUM_POST_SAVED'));
     if ($this->getTask() == 'apply') {
         return $this->editTask($post);
     }
     // Redirect
     $p = '';
     if ($thread = Request::getInt('thread', 0)) {
         $p = '&task=thread&thread=' . $thread;
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . $p, false));
 }
Example #2
0
 /**
  * Save a post and redirects to listing
  *
  * @return     void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     \User::setState('com_forum.edit.thread.data', null);
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     // Bind the rules.
     $data = Request::getVar('jform', array(), 'post');
     if (isset($data['rules']) && is_array($data['rules'])) {
         $model = new AdminThread();
         $form = $model->getForm($data, false);
         $validData = $model->validate($form, $data);
         $fields['rules'] = $validData['rules'];
     }
     if ($fields['id']) {
         $old = new Post($this->database);
         $old->load(intval($fields['id']));
     }
     $fields['sticky'] = isset($fields['sticky']) ? $fields['sticky'] : 0;
     $fields['closed'] = isset($fields['closed']) ? $fields['closed'] : 0;
     $fields['anonymous'] = isset($fields['anonymous']) ? $fields['anonymous'] : 0;
     // Initiate extended database class
     $model = new Post($this->database);
     if (!$model->bind($fields)) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     // Check content
     if (!$model->check()) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     // Store new content
     if (!$model->store()) {
         Notify::error($model->getError());
         return $this->editTask($model);
     }
     if ($fields['id']) {
         if ($old->category_id != $fields['category_id']) {
             $model->updateReplies(array('category_id' => $fields['category_id']), $model->id);
         }
     }
     $this->uploadTask($model->thread ? $model->thread : $model->id, $model->id);
     $msg = Lang::txt('COM_FORUM_THREAD_SAVED');
     $p = '';
     if ($parent = Request::getInt('parent', 0)) {
         $msg = Lang::txt('COM_FORUM_POST_SAVED');
         $p = '&task=thread&parent=' . $parent;
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . $p, false), $msg, 'message');
 }