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())))); }
public function addComment() { $errorMessage = false; $isMobile = !empty($_POST['isMobile']) && (bool) $_POST['isMobile']; $params = $this->getParamsObject(); if (empty($_POST['commentText']) && empty($_POST['attch'])) { $errorMessage = OW::getLanguage()->text('base', 'comment_required_validator_message'); } else { if (!empty($_POST['commentText'])) { $commentText = $_POST['commentText']; } else { $commentText = ''; } } if (!OW::getUser()->isAuthorized($params->getPluginKey(), 'add_comment')) { $errorMessage = OW::getLanguage()->text('base', 'comment_add_auth_error'); } else { if (BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $params->getOwnerId())) { $errorMessage = OW::getLanguage()->text('base', 'user_block_message'); } else { $eventParams = array('pluginKey' => $params->getPluginKey(), 'action' => 'add_comment'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $errorMessage = OW::getEventManager()->call('usercredits.error_message', $eventParams); } } } if ($errorMessage) { exit(json_encode(array('error' => $errorMessage))); } if (BOL_TextFormatService::getInstance()->isCommentsRichMediaAllowed() && !$isMobile) { $attachment = empty($_POST['attch']) ? null : $_POST['attch']; if ($attachment !== null) { $tempArr = json_decode($attachment, true); if (!empty($tempArr['type'])) { if ($tempArr['type'] == 'photo' && isset($tempArr['genId'])) { $tempArr['url'] = $tempArr['href'] = OW::getEventManager()->call('base.attachment_save_image', array('genId' => $tempArr['genId'])); unset($tempArr['uid']); } else { if ($tempArr['type'] == 'video') { $tempArr['html'] = BOL_TextFormatService::getInstance()->validateVideoCode($tempArr['html']); } } $attachment = json_encode($tempArr); } else { $attachment = null; } } } else { $attachment = null; } $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); if ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } if ($isMobile) { $commentListCmp = new BASE_MCMP_CommentsList($params, $_POST['cid']); } else { $commentListCmp = new BASE_CMP_CommentsList($params, $_POST['cid']); } exit(json_encode(array('entityType' => $params->getEntityType(), 'entityId' => $params->getEntityId(), 'commentList' => $commentListCmp->render(), 'onloadScript' => OW::getDocument()->getOnloadScript()))); }