/** * Save an entry * * @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')); } // Incoming $fields = Request::getVar('fields', array(), 'post', 'none', 2); $fields = array_map('trim', $fields); // Initiate extended database class $row = Comment::oneOrNew($fields['id'])->set($fields); // Store new content if (!$row->save()) { Notify::error($row->getError()); return $this->editTask($row); } Notify::success(Lang::txt('COM_WIKI_COMMENT_SAVED')); if ($this->getTask() == 'apply') { return $this->editTask($row); } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&page_id=' . $fields['page_id'], false)); }
/** * 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 = Comment::oneOrNew($fields['id'])->set($fields); // 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', Date::toSql())); // Save the data if (!$comment->save()) { $this->setError($comment->getError()); return $this->displayTask($comment); } // 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->save()) { $this->setError($this->page->getError()); } } // Log activity $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $comment->get('created_by')]); if ($comment->get('parent')) { $parent = Comment::oneOrFail($comment->get('parent')); $recipients[] = ['user', $parent->get('created_by')]; } if ($this->page->get('scope') != 'site') { $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')]; $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')]; } Event::trigger('system.logActivity', ['activity' => ['action' => $fields['id'] ? 'updated' : 'created', 'scope' => 'wiki.comment', 'scope_id' => $this->page->get('id'), 'anonymous' => $comment->get('anonymous', 0), 'description' => Lang::txt('COM_WIKI_ACTIVITY_COMMENT_' . ($fields['id'] ? 'UPDATED' : 'CREATED'), $comment->get('id'), '<a href="' . Route::url($this->page->link('comments')) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link('comments')), 'name' => $this->page->get('pagename'), 'comment' => $comment->get('id'))], 'recipients' => $recipients]); // Redirect to Comments page App::redirect(Route::url($this->page->link('comments'))); }