Ejemplo n.º 1
0
 public function addComment()
 {
     $errorMessage = false;
     $isMobile = !empty($_POST['isMobile']) && (bool) $_POST['isMobile'];
     $params = $this->getParamsObject();
     if (empty($_POST['commentText']) && empty($_POST['attachmentInfo']) && empty($_POST['oembedInfo'])) {
         $errorMessage = OW::getLanguage()->text('base', 'comment_required_validator_message');
     } else {
         if (!OW::getUser()->isAuthorized($params->getPluginKey(), 'add_comment')) {
             $status = BOL_AuthorizationService::getInstance()->getActionStatus($params->getPluginKey(), 'add_comment');
             $errorMessage = $status['msg'];
         } else {
             if (BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $params->getOwnerId())) {
                 $errorMessage = OW::getLanguage()->text('base', 'user_block_message');
             }
         }
     }
     if ($errorMessage) {
         exit(json_encode(array('error' => $errorMessage)));
     }
     $commentText = empty($_POST['commentText']) ? '' : trim($_POST['commentText']);
     $attachment = null;
     if (BOL_TextFormatService::getInstance()->isCommentsRichMediaAllowed() && !$isMobile) {
         if (!empty($_POST['attachmentInfo'])) {
             $tempArr = json_decode($_POST['attachmentInfo'], true);
             OW::getEventManager()->call('base.attachment_save_image', array('uid' => $tempArr['uid'], 'pluginKey' => $tempArr['pluginKey']));
             $tempArr['href'] = $tempArr['url'];
             $tempArr['type'] = 'photo';
             $attachment = json_encode($tempArr);
         } else {
             if (!empty($_POST['oembedInfo'])) {
                 $tempArr = json_decode($_POST['oembedInfo'], true);
                 // add some actions
                 $attachment = json_encode($tempArr);
             }
         }
     }
     $comment = $this->commentService->addComment($params->getEntityType(), $params->getEntityId(), $params->getPluginKey(), OW::getUser()->getId(), $commentText, $attachment);
     // trigger event comment add
     $event = new OW_Event('base_add_comment', array('entityType' => $params->getEntityType(), 'entityId' => $params->getEntityId(), 'userId' => OW::getUser()->getId(), 'commentId' => $comment->getId(), 'pluginKey' => $params->getPluginKey(), 'attachment' => json_decode($attachment, true)));
     OW::getEventManager()->trigger($event);
     BOL_AuthorizationService::getInstance()->trackAction($params->getPluginKey(), 'add_comment');
     if ($isMobile) {
         $commentListCmp = new BASE_MCMP_CommentsList($params, $_POST['cid']);
     } else {
         $commentListCmp = new BASE_CMP_CommentsList($params, $_POST['cid']);
     }
     exit(json_encode(array('newAttachUid' => $this->commentService->generateAttachmentUid($params->getEntityType(), $params->getEntityId()), 'entityType' => $params->getEntityType(), 'entityId' => $params->getEntityId(), 'commentList' => $commentListCmp->render(), 'onloadScript' => OW::getDocument()->getOnloadScript(), 'commentCount' => $this->commentService->findCommentCount($params->getEntityType(), $params->getEntityId()))));
 }