当前位置: 首页>>代码示例>>PHP>>正文


PHP Publication::getPublicComments方法代码示例

本文整理汇总了PHP中Publication::getPublicComments方法的典型用法代码示例。如果您正苦于以下问题:PHP Publication::getPublicComments方法的具体用法?PHP Publication::getPublicComments怎么用?PHP Publication::getPublicComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Publication的用法示例。


在下文中一共展示了Publication::getPublicComments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: takeAction

 /**
  * Performs the action; returns true on success, false on error.
  *
  * @param $p_context - the current context object
  * @return bool
  */
 public function takeAction(CampContext &$p_context)
 {
     $p_context->default_url->reset_parameter('f_' . $this->m_name);
     $p_context->url->reset_parameter('f_' . $this->m_name);
     if (!is_null($this->m_error)) {
         return false;
     }
     // Check that the article exists.
     $articleMetaObj = $p_context->default_article;
     if (!$articleMetaObj->defined) {
         $this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.', ACTION_PREVIEW_COMMENT_ERR_NO_ARTICLE);
         return false;
     }
     if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked) {
         $this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.', ACTION_PREVIEW_COMMENT_ERR_NOT_ENABLED);
         return false;
     }
     // Get the publication.
     $publicationObj = new Publication($articleMetaObj->publication->identifier);
     $user = $p_context->user;
     if ($user->defined) {
         $this->m_properties['reader_email'] = $user->email;
     } else {
         if (!isset($this->m_properties['reader_email'])) {
             $this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.', ACTION_SUBMIT_COMMENT_ERR_NO_PUBLIC);
             return false;
         }
         if (!$publicationObj->getPublicComments()) {
             $this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.', ACTION_SUBMIT_COMMENT_ERR_NO_EMAIL);
             return false;
         }
     }
     // Check if the reader was banned from posting comments.
     global $controller;
     $repositoryAcceptance = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment\\Acceptance');
     $repository = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment');
     if ($repositoryAcceptance->checkParamsBanned($userRealName, $userEmail, $userIp, $publication_id)) {
         $this->m_error = new PEAR_Error('You are banned from submitting comments.', ACTION_SUBMIT_COMMENT_ERR_BANNED);
         return false;
     }
     $this->m_error = ACTION_OK;
     return true;
 }
开发者ID:nidzix,项目名称:Newscoop,代码行数:49,代码来源:MetaActionPreview_Comment.php

示例2: takeAction

 /**
  * Performs the action; returns true on success, false on error.
  *
  * @param $p_context - the current context object
  * @return bool
  */
 public function takeAction(CampContext &$p_context)
 {
     $p_context->default_url->reset_parameter('f_' . $this->m_name);
     $p_context->url->reset_parameter('f_' . $this->m_name);
     \CampRequest::SetVar('f_' . $this->m_name);
     $translator = \Zend_Registry::get('container')->getService('translator');
     $userService = \Zend_Registry::get('container')->getService('user');
     if (!is_null($this->m_error)) {
         return false;
     }
     // Check that the article exists.
     $articleMetaObj = $p_context->default_article;
     if (!$articleMetaObj->defined) {
         $this->m_error = new PEAR_Error('The article was not selected. You must view an article in order to post comments.', ACTION_SUBMIT_COMMENT_ERR_NO_ARTICLE);
         return false;
     }
     if (!$articleMetaObj->comments_enabled || $articleMetaObj->comments_locked) {
         $this->m_error = new PEAR_Error('Comments are not enabled for this publication/article.', ACTION_SUBMIT_COMMENT_ERR_NOT_ENABLED);
         return false;
     }
     // Detect if it's a bot bot_detect
     if (!empty($this->m_properties['bot_detect'])) {
         $this->m_error = new PEAR_Error('The comment cannot be submitted.', ACTION_SUBMIT_COMMENT_BOT_DETECTED);
         return false;
     }
     $publication_id = $articleMetaObj->publication->identifier;
     // Get the publication.
     $publicationObj = new Publication($publication_id);
     $user = $p_context->user;
     $userIp = $userService->getUserIp();
     if ($user->defined) {
         $userId = $user->identifier;
         $userEmail = $user->email;
         if ($this->m_properties['nickname'] == '') {
             $userRealName = $user->name;
         } else {
             $userRealName = $this->m_properties['nickname'];
         }
         if ($this->m_properties['is_anonymous']) {
             $userRealName = $translator->trans('Anonymous', array(), 'comments');
         }
     } else {
         if (!$publicationObj->getPublicComments()) {
             $this->m_error = new PEAR_Error('You must be a registered user in order to submit a comment. Please subscribe or log in if you already have a subscription.', ACTION_SUBMIT_COMMENT_ERR_NO_PUBLIC);
             return false;
         } else {
             if (!isset($this->m_properties['reader_email'])) {
                 $this->m_error = new PEAR_Error('EMail field is empty. You must fill in your EMail address.', ACTION_SUBMIT_COMMENT_ERR_NO_EMAIL);
                 return false;
             }
         }
         $userId = null;
         $userEmail = $this->m_properties['reader_email'];
         $userRealName = $this->m_properties['nickname'];
     }
     // Validate the CAPTCHA code if it was enabled for the current publication.
     if ($publicationObj->isCaptchaEnabled()) {
         if ($this->_processCaptcha() === FALSE) {
             return FALSE;
         }
     }
     // Check if the reader was banned from posting comments.
     global $controller;
     $repositoryAcceptance = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment\\Acceptance');
     $repository = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment');
     if ($repositoryAcceptance->checkParamsBanned($userRealName, $userEmail, $userIp, $publication_id)) {
         $this->m_error = new PEAR_Error('You are banned from submitting comments.', ACTION_SUBMIT_COMMENT_ERR_BANNED);
         return false;
     }
     // get the article object
     $articleObj = new Article($articleMetaObj->language->number, $articleMetaObj->number);
     // Set the parent to the currently viewed comment if a certain existing
     // comment was selected. Otherwise, set the parent identifier to the root message.
     // Create the comment. If there was an error creating the comment set the
     // error code to 'internal error' and exit.
     $values = array('thread' => $articleMetaObj->number, 'language' => $articleMetaObj->language->code, 'name' => $userRealName, 'email' => $userEmail, 'message' => $this->m_properties['content'], 'subject' => $this->m_properties['subject'], 'parent' => $this->m_properties['parent'], 'ip' => $userIp, 'time_created' => new DateTime());
     // If the user was unknown (public comment) and public comments were moderated
     // or the user was known (subscriber comment) and subscriber comments were moderated
     // set the comment status to 'hold'. Otherwise, set the status to 'approved'.
     if (!is_null($userId) && $publicationObj->commentsSubscribersModerated() || is_null($userId) && $publicationObj->commentsPublicModerated()) {
         $values['status'] = "pending";
     } else {
         $values['status'] = "approved";
     }
     // If the user was known set it
     if (!is_null($userId)) {
         $values['user'] = $userId;
     }
     //If there is a comment idetifier set it the parent of the comment
     if ($p_context->comment->identifier) {
         $values['parent'] = $p_context->comment->identifier;
     }
     $commentObj = $repository->getPrototype();
     $comment = $repository->save($commentObj, $values);
//.........这里部分代码省略.........
开发者ID:sourcefabric,项目名称:newscoop,代码行数:101,代码来源:MetaActionSubmit_Comment.php


注:本文中的Publication::getPublicComments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。