/** * Apply a filter action on a comment. * @param {string} $action The action to perform. * @param {ae_CommentModel} $co The comment to apply the action on. * @return {boolean} TRUE, if the comment shall be saved, FALSE otherwise. */ protected static function applyAction($action, ae_CommentModel $co) { switch ($action) { case ae_CommentfilterModel::ACTION_APPROVE: $co->setStatus(ae_CommentModel::STATUS_APPROVED); $keep = TRUE; break; case ae_CommentfilterModel::ACTION_UNAPPROVE: $co->setStatus(ae_CommentModel::STATUS_UNAPPROVED); $keep = TRUE; break; case ae_CommentfilterModel::ACTION_SPAM: $co->setStatus(ae_CommentModel::STATUS_SPAM); $keep = TRUE; break; case ae_CommentfilterModel::ACTION_TRASH: $co->setStatus(ae_CommentModel::STATUS_TRASH); $keep = TRUE; break; case ae_CommentfilterModel::ACTION_DROP: $co->setStatus(ae_CommentModel::STATUS_TRASH); $keep = FALSE; break; default: $keep = TRUE; } return $keep; }
public function testSetStatus() { $c = new ae_CommentModel(); $this->assertTrue(ae_CommentModel::isValidStatus($c->getStatus())); $c->setStatus(ae_CommentModel::STATUS_APPROVED); $this->assertEquals($c->getStatus(), ae_CommentModel::STATUS_APPROVED); $this->setExpectedException('Exception'); $c->setStatus('bogus'); }
$co = new ae_CommentModel(); // Bad errors try { $co->setPostId($_POST['comment-post']); } catch (Exception $exc) { header('Location: ../?p=' . $_POST['comment-post'] . '&error=invalid_data#comment-form'); exit; } // Forgivable errors with default values for fallback try { $co->setAuthorName($_POST['comment-author-name']); $co->setAuthorEmail($_POST['comment-author-email']); $co->setAuthorUrl($url); $co->setAuthorIp($_SERVER['REMOTE_ADDR']); $co->setContent($content); $co->setStatus(COMMENT_DEFAULT_STATUS); if (ae_Security::isLoggedIn()) { $co->setUserId(ae_Security::getCurrentUserId()); } $filter = array('LIMIT' => FALSE, 'WHERE' => 'cf_status = :status'); $params = array(':status' => ae_CommentfilterModel::STATUS_ACTIVE); $cfList = new ae_CommentfilterList($filter, $params, FALSE); $keep = $cfList->applyFilters($co); if (!$keep) { header('Location: ../?p=' . $_POST['comment-post'] . '&error=comment_deleted_by_filter'); exit; } $co->save(); } catch (Exception $exc) { header('Location: ../?p=' . $_POST['comment-post'] . '&error=failed_to_save#comment-form'); exit;