/** * Save a comment * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); $fields = Request::getVar('comment', array(), 'post'); // Bind the form data to our object $comment = new Comment($fields['id']); if (!$comment->bind($fields)) { $this->setError($comment->getError()); $this->displayTask(); return; } // Parse the wikitext and set some values $comment->set('chtml', NULL); $comment->set('chtml', $comment->content('parsed')); $comment->set('anonymous', $comment->get('anonymous') ? 1 : 0); $comment->set('created', $comment->get('created') ? $comment->get('created') : Date::toSql()); // Save the data if (!$comment->store(true)) { $this->setError($comment->getError()); $this->displayTask(); return; } // Did they rate the page? // If so, update the page with the new average rating if ($comment->get('rating')) { $this->page->calculateRating(); if (!$this->page->store()) { $this->setError($this->page->getError()); } } // Redirect to Comments page App::redirect(Route::url($this->page->link('comments'))); }
/** * Set the status on one or more entries * * @return void */ public function stateTask() { // Check for request forgeries Request::checkToken(['get', 'post']); $state = $this->getTask() == 'unpublish' ? 2 : 0; // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $pageid = Request::getInt('pageid', 0); // Check for an ID if (count($ids) < 1) { $action = $state == 1 ? Lang::txt('COM_WIKI_UNPUBLISH') : Lang::txt('COM_WIKI_PUBLISH'); App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $pageid, false), Lang::txt('COM_WIKI_ERROR_SELECT_TO', $action), 'error'); return; } // Loop through all the IDs foreach ($ids as $id) { $entry = new Comment(intval($id)); $entry->set('status', $state); if (!$entry->store()) { \Notify::error($entry->getError()); } } // Set message if ($state == 1) { $message = Lang::txt('COM_WIKI_ITEMS_PUBLISHED', count($ids)); } else { $message = Lang::txt('COM_WIKI_ITEMS_UNPUBLISHED', count($ids)); } // Set redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $pageid, false), $message); }