Exemplo n.º 1
0
 function add($args)
 {
     $articleId = isset($args[0]) ? (int) $args[0] : 0;
     $galleyId = isset($args[1]) ? (int) $args[1] : 0;
     $parentId = isset($args[2]) ? (int) $args[2] : 0;
     list($journal, $issue, $article) = CommentHandler::validate($articleId);
     // Bring in comment constants
     $commentDao =& DAORegistry::getDAO('CommentDAO');
     $enableComments = $journal->getSetting('enableComments');
     switch ($enableComments) {
         case COMMENTS_UNAUTHENTICATED:
             break;
         case COMMENTS_AUTHENTICATED:
         case COMMENTS_ANONYMOUS:
             // The user must be logged in to post comments.
             if (!Request::getUser()) {
                 Validation::redirectLogin();
             }
             break;
         default:
             // Comments are disabled.
             Validation::redirectLogin();
     }
     $parent =& $commentDao->getComment($parentId, $articleId);
     if (isset($parent) && $parent->getArticleId() != $articleId) {
         Request::redirect(null, null, 'view', array($articleId, $galleyId));
     }
     import('comment.form.CommentForm');
     $commentForm =& new CommentForm(null, $articleId, $galleyId, isset($parent) ? $parentId : null);
     $commentForm->initData();
     if (isset($args[3]) && $args[3] == 'save') {
         $commentForm->readInputData();
         if ($commentForm->validate()) {
             $commentForm->execute();
             Request::redirect(null, null, 'view', array($articleId, $galleyId, $parentId), array('refresh' => 1));
         }
     }
     CommentHandler::setupTemplate($article, $galleyId, $parent);
     $commentForm->display();
 }