public function addPhoto($params) { try { $info = BOL_AttachmentService::getInstance()->processPhotoAttachment($_FILES['attachment']); } catch (InvalidArgumentException $e) { exit("<script>parent.window.OW.error(" . json_encode($e->getMessage()) . "); parent.window.owattachments['" . $params['uid'] . "'].init();</script>"); } $oembedCmp = new BASE_CMP_OembedAttachment(array('type' => 'photo', 'url' => $info['url'], 'href' => $info['url']), true); $returnArray = array('cmp' => $oembedCmp->render(), 'url' => $info['url'], 'type' => 'photo', 'uid' => $params['uid'], 'genId' => $info['genId']); exit("<script>parent.window.owattachments['" . $params['uid'] . "'].hideLoader().addItem(" . json_encode($returnArray) . ");</script>"); }
public function onBeforeRender() { parent::onBeforeRender(); $items = BOL_AttachmentService::getInstance()->getFilesByBundleName($this->pluginKey, $this->uid); $itemsArr = array(); foreach ($items as $item) { $itemsArr[] = array('name' => $item['dto']->getOrigFileName(), 'size' => $item['dto']->getSize(), 'dbId' => $item['dto']->getId()); } $params = array('uid' => $this->uid, 'submitUrl' => OW::getRouter()->urlFor('BASE_CTRL_Attachment', 'addFile'), 'deleteUrl' => OW::getRouter()->urlFor('BASE_CTRL_Attachment', 'deleteFile'), 'showPreview' => $this->showPreview, 'selector' => $this->inputSelector, 'pluginKey' => $this->pluginKey, 'multiple' => $this->multiple, 'lItems' => $itemsArr); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'attachments.js'); OW::getDocument()->addOnloadScript("owFileAttachments['" . $this->uid . "'] = new OWFileAttachment(" . json_encode($params) . ");"); $this->assign('data', array('uid' => $this->uid, 'showPreview' => $this->showPreview, 'selector' => $this->inputSelector)); }
public function process() { $language = OW::getLanguage(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $values = $this->getValues(); $userId = OW::getUser()->getId(); $actionName = 'send_message'; $isAuthorized = OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorized) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { return array('result' => false, 'error' => $language->text('mailbox', 'send_message_permission_denied')); } } $checkResult = $conversationService->checkUser($userId, $values['opponentId']); if ($checkResult['isSuspended']) { return array('result' => false, 'error' => $checkResult['suspendReasonMessage']); } $values['message'] = UTIL_HtmlTag::stripTags(UTIL_HtmlTag::stripJs($values['message'])); $event = new OW_Event('mailbox.before_create_conversation', array('senderId' => $userId, 'recipientId' => $values['opponentId'], 'message' => $values['message'], 'subject' => $values['subject']), array('result' => true, 'error' => '', 'message' => $values['message'], 'subject' => $values['subject'])); OW::getEventManager()->trigger($event); $data = $event->getData(); if (empty($data['result'])) { return array('result' => false, 'error' => $data['error']); } if (!trim(strip_tags($values['subject']))) { return array('result' => false, 'error' => $language->text('mailbox', 'subject_is_required')); } $values['subject'] = $data['subject']; $values['message'] = $data['message']; $conversation = $conversationService->createConversation($userId, $values['opponentId'], $values['subject'], $values['message']); $message = $conversationService->getLastMessage($conversation->id); if (!empty($_FILES['attachment']["tmp_name"])) { $attachmentService = BOL_AttachmentService::getInstance(); $uid = $_POST['uid']; $maxUploadSize = OW::getConfig()->getValue('base', 'attch_file_max_size_mb'); $validFileExtensions = json_decode(OW::getConfig()->getValue('base', 'attch_ext_list'), true); $dtoArr = $attachmentService->processUploadedFile('mailbox', $_FILES['attachment'], $uid, $validFileExtensions, $maxUploadSize); $files = $attachmentService->getFilesByBundleName('mailbox', $uid); if (!empty($files)) { $conversationService->addMessageAttachments($message->id, $files); } } BOL_AuthorizationService::getInstance()->trackAction('mailbox', $actionName); return array('result' => true, 'conversationId' => $message->conversationId); }
public function removeAction($entityType, $entityId) { $dto = $this->actionDao->findAction($entityType, $entityId); if ($dto === null) { return; } $event = new OW_Event(self::EVENT_BEFORE_ACTION_DELETE, array("actionId" => $dto->id, "entityType" => $dto->entityType, "entityId" => $dto->entityId)); OW::getEventManager()->trigger($event); $this->likeDao->deleteByEntity($dto->entityType, $dto->entityId); $this->actionDao->delete($dto); $activityIds = $this->activityDao->findIdListByActionIds(array($dto->id)); $this->actionFeedDao->deleteByActivityIds($activityIds); $this->activityDao->deleteByIdList($activityIds); $commentEntity = BOL_CommentService::getInstance()->findCommentEntity($dto->entityType, $dto->entityId); if (!empty($commentEntity) && $commentEntity->pluginKey == 'newsfeed') { BOL_CommentService::getInstance()->deleteEntityComments($commentEntity->entityType, $commentEntity->entityId); BOL_CommentService::getInstance()->deleteCommentEntity($commentEntity->id); } $actionData = json_decode($dto->data, true); // delete attachments if (!empty($actionData['attachmentId'])) { BOL_AttachmentService::getInstance()->deleteAttachmentByBundle("newsfeed", $actionData['attachmentId']); } }
/** * Create new conversation * * @param MAILBOX_BOL_Conversation $conversation * @param int $userId * @return boolean */ public function process() { $values = $this->getValues(); $userId = OW::getUser()->getId(); $files = BOL_AttachmentService::getInstance()->getFilesByBundleName('mailbox', $values['uid']); $result = $this->sendMessage($userId, $values["opponentId"], $values["subject"], $values["message"], $files); OW::getSession()->delete('mailbox.new_message_form_attachments_uid'); return $result; }
public function postMessage($params) { $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $language = OW::getLanguage(); if ($errorMessage = $conversationService->checkPermissions()) { return array('error' => $errorMessage); } $userId = OW::getUser()->getId(); // $userSendMessageIntervalOk = $conversationService->checkUserSendMessageInterval($userId); // if (!$userSendMessageIntervalOk) // { // $send_message_interval = (int)OW::getConfig()->getValue('mailbox', 'send_message_interval'); // return array('error'=>$language->text('mailbox', 'feedback_send_message_interval_exceed', array('send_message_interval'=>$send_message_interval))); // } $conversationId = $params['convId']; if (!isset($conversationId)) { return array('error' => "Conversation is not defined"); } if (empty($params['text'])) { return array('error' => $language->text('mailbox', 'chat_message_empty')); } if (mb_strlen($params['text']) > self::MAX_MESSAGE_TEXT_LENGTH) { return array('error' => $language->text('mailbox', 'message_too_long_error', array('maxLength' => self::MAX_MESSAGE_TEXT_LENGTH))); } $conversation = $conversationService->getConversation($conversationId); if (empty($conversation)) { $uidParams = explode('_', $params['uid']); if (count($uidParams) == 5 && $uidParams[0] == 'mailbox' && $uidParams[1] == 'dialog') { $opponentId = (int) $uidParams[3]; $conversationId = $conversationService->getChatConversationIdWithUserById($userId, $opponentId); if ($conversationId != 0) { $conversation = $conversationService->getConversation($conversationId); } } } if (empty($conversation)) { $conversation = $conversationService->createChatConversation($userId, $opponentId); $conversationId = $conversation->getId(); } $opponentId = $conversation->initiatorId == $userId ? $conversation->interlocutorId : $conversation->initiatorId; $checkResult = $conversationService->checkUser($userId, $opponentId); MAILBOX_BOL_ConversationService::getInstance()->resetUserLastData($opponentId); if ($checkResult['isSuspended']) { return array('error' => $checkResult['suspendReasonMessage']); } $mode = $conversationService->getConversationMode($conversationId); $actionName = ''; switch ($mode) { case 'chat': $firstMessage = $conversationService->getFirstMessage($conversationId); if (empty($firstMessage)) { $actionName = 'send_chat_message'; } else { $actionName = 'reply_to_chat_message'; } $isAuthorized = OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorized) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { // return array('error'=>$language->text('mailbox', $actionName.'_permission_denied')); return array('error' => $status['msg']); } } $params['text'] = UTIL_HtmlTag::stripTags(UTIL_HtmlTag::stripJs($params['text'])); $params['text'] = nl2br($params['text']); break; case 'mail': $actionName = 'reply_to_message'; $isAuthorized = OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorized) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { // return array('error'=>$language->text('mailbox', $actionName.'_permission_denied')); return array('error' => $status['msg']); } } $params['text'] = UTIL_HtmlTag::stripJs($params['text']); break; } $event = new OW_Event('mailbox.before_send_message', array('senderId' => $userId, 'recipientId' => $opponentId, 'conversationId' => $conversation->id, 'message' => $params['text']), array('result' => true, 'error' => '', 'message' => $params['text'])); OW::getEventManager()->trigger($event); $data = $event->getData(); if (!$data['result']) { return $data; } $text = $data['message']; try { $message = $conversationService->createMessage($conversation, $userId, $text); $files = BOL_AttachmentService::getInstance()->getFilesByBundleName('mailbox', $params['uid']); if (!empty($files)) { $conversationService->addMessageAttachments($message->id, $files); } if (!empty($params['embedAttachments'])) { $oembedParams = json_decode($params['embedAttachments'], true); $oembedParams['message'] = $text; $messageParams = array('entityType' => 'mailbox', 'eventName' => 'renderOembed', 'params' => $oembedParams); $message->isSystem = true; $message->text = json_encode($messageParams); $conversationService->saveMessage($message); } } catch (InvalidArgumentException $e) { return array('error' => $e->getMessage()); } if (!empty($actionName)) { BOL_AuthorizationService::getInstance()->trackAction('mailbox', $actionName); } $item = $conversationService->getMessageData($message); return array('message' => $item); }
public function newmessage($params) { if (!OW::getUser()->isAuthenticated()) { $this->echoOut(array("error" => "You need to sign in to send message.")); } $conversationService = MAILBOX_BOL_ConversationService::getInstance(); // $userSendMessageIntervalOk = $conversationService->checkUserSendMessageInterval(OW::getUser()->getId()); // if (!$userSendMessageIntervalOk) // { // $send_message_interval = (int)OW::getConfig()->getValue('mailbox', 'send_message_interval'); // $this->echoOut( // array('error'=>OW::getLanguage()->text('mailbox', 'feedback_send_message_interval_exceed', array('send_message_interval'=>$send_message_interval))) // ); // } if (empty($_POST['conversationId']) || empty($_POST['opponentId']) || empty($_POST['uid']) || empty($_POST['newMessageText'])) { $this->echoOut(array("error" => OW::getLanguage()->text('base', 'form_validate_common_error_message'))); } $conversationId = $_POST['conversationId']; $userId = OW::getUser()->getId(); $actionName = 'reply_to_message'; $isAuthorized = OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorized) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { $this->echoOut(array("error" => OW::getLanguage()->text('mailbox', $actionName . '_permission_denied'))); } } $checkResult = $conversationService->checkUser($userId, $_POST['opponentId']); if ($checkResult['isSuspended']) { $this->echoOut(array("error" => $checkResult['suspendReasonMessage'])); } $conversation = $conversationService->getConversation($conversationId); try { $message = $conversationService->createMessage($conversation, $userId, $_POST['newMessageText']); if (!empty($_FILES['attachment']["tmp_name"])) { $attachmentService = BOL_AttachmentService::getInstance(); $uid = $_POST['uid']; $maxUploadSize = OW::getConfig()->getValue('base', 'attch_file_max_size_mb'); $validFileExtensions = json_decode(OW::getConfig()->getValue('base', 'attch_ext_list'), true); $dtoArr = $attachmentService->processUploadedFile('mailbox', $_FILES['attachment'], $uid, $validFileExtensions, $maxUploadSize); $files = $attachmentService->getFilesByBundleName('mailbox', $uid); if (!empty($files)) { $conversationService->addMessageAttachments($message->id, $files); } } $this->echoOut(array('message' => $conversationService->getMessageData($message))); } catch (InvalidArgumentException $e) { $this->echoOut(array("error" => $e->getMessage())); } }
private function deleteAttachmentFiles(BOL_Comment $comment) { // delete attachments $attch = $comment->getAttachment(); if ($attch !== null) { $tempArr = json_decode($attch, true); if (!empty($tempArr['uid']) && !empty($tempArr['pluginKey'])) { BOL_AttachmentService::getInstance()->deleteAttachmentByBundle($tempArr['pluginKey'], $tempArr['uid']); } } }
public function onSaveAttachmentImage(OW_Event $event) { $params = $event->getParams(); if (empty($params['uid']) || empty($params['pluginKey'])) { return null; } BOL_AttachmentService::getInstance()->updateStatusForBundle($params['pluginKey'], $params['uid'], 1); $result = BOL_AttachmentService::getInstance()->getFilesByBundleName($params['pluginKey'], $params['uid']); return $result ? $result[0] : null; }
public function onDeleteAttachmentImage(OW_Event $event) { $params = $event->getParams(); if (!empty($params["id"])) { BOL_AttachmentService::getInstance()->deleteAttachmentById($params["id"]); } else { if (!empty($params['url']) && strstr($params['url'], OW::getStorage()->getFileUrl(OW::getPluginManager()->getPlugin('base')->getUserFilesDir() . 'attachments'))) { BOL_AttachmentService::getInstance()->deleteAttachmentByUrl($params['url']); } } }
/** * Create new conversation * * @param MAILBOX_BOL_Conversation $conversation * @param int $userId * @return boolean */ public function process() { $values = $this->getValues(); $userId = OW::getUser()->getId(); $language = OW::getLanguage(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); // Check if user can send message $error = null; $actionName = 'send_message'; $userSendMessageIntervalOk = $conversationService->checkUserSendMessageInterval($userId); if (!$userSendMessageIntervalOk) { $send_message_interval = (int) OW::getConfig()->getValue('mailbox', 'send_message_interval'); $error = array('result' => false, 'error' => $language->text('mailbox', 'feedback_send_message_interval_exceed', array('send_message_interval' => $send_message_interval))); } else { if (!OW::getUser()->isAuthorized('mailbox', $actionName)) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { $error = array('result' => false, 'error' => $language->text('mailbox', $actionName . '_permission_denied')); } } } $result = $error; if ($error === null) { // Send message $files = BOL_AttachmentService::getInstance()->getFilesByBundleName('mailbox', $values['uid']); $result = $this->sendMessage($userId, $values["opponentId"], $values["subject"], $values["message"], $files); } OW::getSession()->delete('mailbox.new_message_form_attachments_uid'); return $result; }
/** * Controller's default action * * @param array $params * @throws AuthorizationException * @throws AuthenticateException */ public function index(array $params = null) { $groupId = isset($params['groupId']) && (int) $params['groupId'] ? (int) $params['groupId'] : 0; $forumService = FORUM_BOL_ForumService::getInstance(); $forumGroup = $forumService->getGroupInfo($groupId); if ($forumGroup) { $forumSection = $forumService->findSectionById($forumGroup->sectionId); $isHidden = $forumSection->isHidden; } else { $isHidden = false; } if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $userId = OW::getUser()->getId(); $this->assign('authMsg', null); if ($isHidden && isset($forumSection)) { $eventParams = array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'action' => 'add_topic'); $event = new OW_Event('forum.check_permissions', $eventParams); OW::getEventManager()->trigger($event); if (!$event->getData()) { throw new AuthorizationException(); } if (!OW::getUser()->isAuthorized($forumSection->entity, 'add_topic')) { $status = BOL_AuthorizationService::getInstance()->getActionStatus($forumSection->entity, 'add_topic'); throw new AuthorizationException($status['msg']); } $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId)); OW::getEventManager()->trigger($event); $eventData = $event->getData(); /** @var OW_Component $componentForumCaption */ $componentForumCaption = $eventData['component']; if (!empty($componentForumCaption)) { $this->assign('componentForumCaption', $componentForumCaption->render()); } else { $componentForumCaption = false; $this->assign('componentForumCaption', $componentForumCaption); } $bcItems = array(array('href' => OW::getRouter()->urlForRoute('group-default', array('groupId' => $forumGroup->getId())), 'label' => OW::getLanguage()->text($forumSection->entity, 'view_all_topics'))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->deactivateMenuItems(OW_Navigation::MAIN); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $forumSection->entity, $eventData['key']); $groupSelect = array(array('label' => $forumGroup->name, 'value' => $forumGroup->getId(), 'disabled' => false)); OW::getDocument()->setHeading(OW::getLanguage()->text($forumSection->entity, 'create_new_topic', array('group' => $forumGroup->name))); } else { $canEdit = OW::getUser()->isAuthorized('forum', 'edit'); if (!$userId) { throw new AuthorizationException(); } else { if (!$canEdit) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('forum', 'edit'); throw new AuthorizationException($status['msg']); } } if (!OW::getRequest()->isAjax()) { OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'forum', 'forum'); } $groupSelect = $forumService->getGroupSelectList(0, false, $userId); OW::getDocument()->setHeading(OW::getLanguage()->text('forum', 'create_new_topic')); } OW::getDocument()->setDescription(OW::getLanguage()->text('forum', 'meta_description_add_topic')); OW::getDocument()->setTitle(OW::getLanguage()->text('forum', 'meta_title_add_topic')); OW::getDocument()->setHeadingIconClass('ow_ic_write'); $this->assign('isHidden', $isHidden); $uid = uniqid(); $form = $this->generateForm($groupSelect, $groupId, $isHidden, $uid); OW::getDocument()->addStyleDeclaration(' .disabled_option { color: #9F9F9F; } '); $enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments'); if ($enableAttachments) { $attachmentCmp = new BASE_CLASS_FileAttachment('forum', $uid); $this->addComponent('attachments', $attachmentCmp); } $this->assign('enableAttachments', $enableAttachments); if (OW::getRequest()->isPost() && $form->isValid($_POST)) { $data = $form->getValues(); if ($data['group']) { $topicDto = new FORUM_BOL_Topic(); $topicDto->userId = $userId; $topicDto->groupId = $data['group']; $topicDto->title = strip_tags($data['title']); $forumService->addTopic($topicDto); $postDto = new FORUM_BOL_Post(); $postDto->topicId = $topicDto->id; $postDto->userId = $userId; $postDto->text = UTIL_HtmlTag::stripJs(UTIL_HtmlTag::stripTags($data['text'], array('form', 'input', 'button'), null, true)); $postDto->createStamp = time(); $forumService->saveOrUpdatePost($postDto); $topicDto->lastPostId = $postDto->getId(); $forumService->saveOrUpdateTopic($topicDto); // subscribe author to new posts if ($data['subscribe']) { $subService = FORUM_BOL_SubscriptionService::getInstance(); $subs = new FORUM_BOL_Subscription(); $subs->userId = $userId; $subs->topicId = $topicDto->id; $subService->addSubscription($subs); } if ($enableAttachments) { $filesArray = BOL_AttachmentService::getInstance()->getFilesByBundleName('forum', $data['attachmentUid']); if ($filesArray) { $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $skipped = 0; foreach ($filesArray as $file) { $attachmentDto = new FORUM_BOL_PostAttachment(); $attachmentDto->postId = $postDto->id; $attachmentDto->fileName = $file['dto']->origFileName; $attachmentDto->fileNameClean = $file['dto']->fileName; $attachmentDto->fileSize = $file['dto']->size * 1024; $attachmentDto->hash = uniqid(); $added = $attachmentService->addAttachment($attachmentDto, $file['path']); if (!$added) { $skipped++; } } BOL_AttachmentService::getInstance()->deleteAttachmentByBundle('forum', $data['attachmentUid']); if ($skipped) { OW::getFeedback()->warning(OW::getLanguage()->text('forum', 'not_all_attachments_added')); } } } $topicUrl = OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicDto->id)); //Newsfeed $params = array('pluginKey' => 'forum', 'entityType' => 'forum-topic', 'entityId' => $topicDto->id, 'userId' => $topicDto->userId); $event = new OW_Event('feed.action', $params); OW::getEventManager()->trigger($event); if ($isHidden && isset($forumSection)) { BOL_AuthorizationService::getInstance()->trackAction($forumSection->entity, 'add_topic'); $params = array('topicId' => $topicDto->id, 'entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'userId' => $topicDto->userId, 'topicUrl' => $topicUrl, 'topicTitle' => $topicDto->title, 'postText' => $postDto->text); $event = new OW_Event('forum.topic_add', $params); OW::getEventManager()->trigger($event); } else { BOL_AuthorizationService::getInstance()->trackAction('forum', 'edit'); } OW::getEventManager()->trigger(new OW_Event(FORUM_BOL_ForumService::EVENT_AFTER_TOPIC_ADD, array('topicId' => $topicDto->id))); $this->redirect($topicUrl); } else { $form->getElement('group')->addError(OW::getLanguage()->text('forum', 'select_group_error')); } } }
public function uploadAttachment($params) { $userId = OW::getUser()->getId(); if (!$userId) { throw new ApiResponseErrorException("Undefined userId"); } if (empty($_FILES['images'])) { throw new ApiResponseErrorException("Files were not uploaded"); } $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $checkResult = $conversationService->checkUser($params['userId'], $params['opponentId']); if ($checkResult['isSuspended']) { $this->assign('error', true); $this->assign('message', $checkResult['suspendReasonMessage']); $this->assign('suspendReason', $checkResult['suspendReason']); return; } $attachmentService = BOL_AttachmentService::getInstance(); $conversationId = $conversationService->getChatConversationIdWithUserById($userId, $params['opponentId']); if (empty($conversationId)) { $actionName = 'send_chat_message'; } else { $firstMessage = $conversationService->getFirstMessage($conversationId); if (empty($firstMessage)) { $actionName = 'send_chat_message'; } else { $actionName = 'reply_to_chat_message'; } } $isAuthorized = OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorized) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] == BOL_AuthorizationService::STATUS_PROMOTED) { $this->assign('error', true); $this->assign('message', $status['msg']); } else { if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { $language = OW::getLanguage(); $this->assign('error', true); $this->assign('message', $language->text('mailbox', $actionName . '_permission_denied')); } } return; } $finalFileArr = array(); foreach ($_FILES['images'] as $key => $items) { foreach ($items as $index => $item) { if (!isset($finalFileArr[$index])) { $finalFileArr[$index] = array(); } $finalFileArr[$index][$key] = $item; } } foreach ($finalFileArr as $item) { $opponentId = $params['opponentId']; $conversationId = $conversationService->getChatConversationIdWithUserById($userId, $opponentId); if (empty($conversationId)) { $conversation = $conversationService->createChatConversation($userId, $opponentId); $conversationId = $conversation->getId(); } else { $conversation = $conversationService->getConversation($conversationId); } $uid = UTIL_HtmlTag::generateAutoId('mailbox_conversation_' . $conversationId . '_' . $opponentId); try { $maxUploadSize = OW::getConfig()->getValue('base', 'attch_file_max_size_mb'); $validFileExtensions = json_decode(OW::getConfig()->getValue('base', 'attch_ext_list'), true); $dtoArr = $attachmentService->processUploadedFile('mailbox', $item, $uid, $validFileExtensions, $maxUploadSize); } catch (Exception $e) { throw new ApiResponseErrorException($e->getMessage()); } $files = $attachmentService->getFilesByBundleName('mailbox', $uid); if (!empty($files)) { try { $message = $conversationService->createMessage($conversation, $userId, OW::getLanguage()->text('mailbox', 'attachment')); $conversationService->addMessageAttachments($message->id, $files); $this->assign('message', $conversationService->getMessageData($message)); } catch (InvalidArgumentException $e) { throw new ApiResponseErrorException($e->getMessage()); } } } }
public function statusUpdate() { if (empty($_POST['status']) && empty($_FILES['attachment']["tmp_name"])) { $this->echoOut($_POST['feedAutoId'], array("error" => OW::getLanguage()->text('base', 'form_validate_common_error_message'))); } if (!OW::getUser()->isAuthenticated()) { $this->echoOut($_POST['feedAutoId'], array("error" => "You need to sign in to post.")); } $status = empty($_POST['status']) ? '' : strip_tags($_POST['status']); $content = array(); if (!empty($_FILES['attachment']["tmp_name"])) { try { $attachment = BOL_AttachmentService::getInstance()->processPhotoAttachment("newsfeed", $_FILES['attachment']); } catch (InvalidArgumentException $ex) { $this->echoOut($_POST['feedAutoId'], array("error" => $ex->getMessage())); } $content = array("type" => "photo", "url" => $attachment["url"]); } $userId = OW::getUser()->getId(); $event = new OW_Event("feed.before_content_add", array("feedType" => $_POST['feedType'], "feedId" => $_POST['feedId'], "visibility" => $_POST['visibility'], "userId" => $userId, "status" => $status, "type" => empty($content["type"]) ? "text" : $content["type"], "data" => $content)); OW::getEventManager()->trigger($event); $data = $event->getData(); if (!empty($data)) { $item = empty($data["entityType"]) || empty($data["entityId"]) ? null : array("entityType" => $data["entityType"], "entityId" => $data["entityId"]); $this->echoOut($_POST['feedAutoId'], array("item" => $item, "message" => empty($data["message"]) ? null : $data["message"], "error" => empty($data["error"]) ? null : $data["error"])); } $status = UTIL_HtmlTag::autoLink($status); $out = NEWSFEED_BOL_Service::getInstance()->addStatus(OW::getUser()->getId(), $_POST['feedType'], $_POST['feedId'], $_POST['visibility'], $status, array("content" => $content, "attachmentId" => $attachment["uid"])); $this->echoOut($_POST['feedAutoId'], array("item" => $out)); }
public function statusUpdate() { if (empty($_POST['status']) && empty($_FILES['attachment']["tmp_name"])) { $this->echoOut($_POST['feedAutoId'], array("error" => OW::getLanguage()->text('base', 'form_validate_common_error_message'))); } if (!OW::getUser()->isAuthenticated()) { $this->echoOut($_POST['feedAutoId'], array("error" => "You need to sign in to post.")); } $status = empty($_POST['status']) ? '' : strip_tags($_POST['status']); $content = array(); if (!empty($_FILES['attachment']["tmp_name"])) { try { $attachment = BOL_AttachmentService::getInstance()->processPhotoAttachment($_FILES['attachment']); } catch (InvalidArgumentException $ex) { $this->echoOut($_POST['feedAutoId'], array("error" => $ex->getMessage())); } $content = array("type" => "photo", "url" => $attachment["url"]); } $status = UTIL_HtmlTag::autoLink($status); $out = NEWSFEED_BOL_Service::getInstance()->addStatus(OW::getUser()->getId(), $_POST['feedType'], $_POST['feedId'], $_POST['visibility'], $status, array("content" => $content, "attachmentId" => $attachment["genId"])); $this->echoOut($_POST['feedAutoId'], $out); }
public function webcamHandler() { if (!OW::getRequest()->isPost()) { throw new Redirect404Exception(); } $service = BOL_AttachmentService::getInstance(); $attachDto = new BOL_Attachment(); $attachDto->setUserId(OW::getUser()->getId()); $attachDto->setAddStamp(time()); $attachDto->setStatus(0); $service->saveAttachment($attachDto); $fileName = 'attach_' . $attachDto->getId() . '.jpg'; $attachDto->setFileName($fileName); $service->saveAttachment($attachDto); $uploadPath = $service->getAttachmentsTempDir() . $fileName; $uploadUrl = $service->getAttachmentsTempUrl() . $fileName; // The JPEG snapshot is sent as raw input: $input = file_get_contents('php://input'); if (md5($input) == '7d4df9cc423720b7f1f3d672b89362be') { // Blank image. We don't need this one. echo json_encode(array('type' => 'takeError', 'error' => 'Empty photo', 'result' => array())); exit; } $result = file_put_contents($uploadPath, $input); if (!$result) { echo json_encode(array('type' => 'takeError', 'error' => 'Failed save the image. Make sure you chmod the uploads folder and its subfolders to 777', 'result' => array())); exit; } @chmod($uploadPath, 0666); $info = getimagesize($uploadPath); if ($info['mime'] != 'image/jpeg') { @unlink($uploadPath); echo json_encode(array('type' => 'takeError', 'error' => 'Wrong file', 'result' => array())); exit; } $content = new EQUESTIONS_CMP_AttPhotoPreview($uploadUrl); $xml = "<content><html><![CDATA[" . $content->render() . "]]></html><js></js></content><filePath>" . $uploadPath . "</filePath><fileId>" . $attachDto->getId() . "</fileId>"; $out = '<root>' . $xml . '</root>'; echo $out; exit; }
public function createConversation($params) { if (empty($params['uid']) || empty($params['opponentId']) || empty($params['subject']) || empty($params['text'])) { throw new ApiResponseErrorException("Illegal arguments"); } $userId = OW::getUser()->getId(); $params['userId'] = $userId; try { $params['text'] = nl2br($params['text']); $conversation = OW::getEventManager()->call('mailbox.create_conversation', $params); BOL_AuthorizationService::getInstance()->trackAction('mailbox', 'send_message'); } catch (Exception $e) { $this->assign('result', array('error' => true, 'message' => $e->getMessage())); return; } if (!empty($conversation)) { $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $messageDto = $conversationService->getLastMessage($conversation->id); $uid = 'mailbox_conversation_' . OW::getUser()->getId() . '_' . $params['uid']; $files = BOL_AttachmentService::getInstance()->getFilesByBundleName('mailbox', $uid); if (!empty($files)) { $conversationService->addMessageAttachments($messageDto->id, $files); } $list = OW::getEventManager()->call('mailbox.get_chat_user_list', array('userId' => $userId, 'count' => 10)); foreach ($list as $conv) { if ($conv['conversationId'] == $conversation->id) { $conversationItem = $conv; break; } } $list = SKANDROID_ABOL_MailboxService::getInstance()->prepareConversationList(array($conversationItem)); $this->assign('result', array('error' => false, 'conversation' => $list[0], 'billingInfo' => $this->service->getBillingInfo(array(SKANDROID_ABOL_MailboxService::ACTION_SEND_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_READ_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_REPLY_TO_MESSAGE)))); } }
/** * Controller's default action * * @param array $params * @throws AuthorizationException * @throws Redirect404Exception */ public function index(array $params = null) { $forumService = FORUM_BOL_ForumService::getInstance(); if (!isset($params['id']) || !($topicId = (int) $params['id'])) { throw new Redirect404Exception(); } $topicDto = $forumService->findTopicById($topicId); if (!$topicDto) { throw new Redirect404Exception(); } $forumGroup = $forumService->getGroupInfo($topicDto->groupId); $forumSection = $forumService->findSectionById($forumGroup->sectionId); $isHidden = $forumSection->isHidden; $userId = OW::getUser()->getId(); if ($isHidden) { $isModerator = OW::getUser()->isAuthorized($forumSection->entity); $eventParams = array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'action' => 'add_topic'); $event = new OW_Event('forum.check_permissions', $eventParams); OW::getEventManager()->trigger($event); $canPost = $event->getData(); //check permissions $canEdit = OW::getUser()->isAuthorized($forumSection->entity, 'add_topic') && $userId == $topicDto->userId; if (!$isModerator) { if (!$canPost) { throw new AuthorizationException(); } else { if (!$canEdit) { $status = BOL_AuthorizationService::getInstance()->getActionStatus($forumSection->entity, 'add_topic'); throw new AuthorizationException($status['msg']); } } } } else { $isModerator = OW::getUser()->isAuthorized('forum'); $canEdit = OW::getUser()->isAuthorized('forum', 'edit') && $userId == $topicDto->userId; if (!$canEdit && !$isModerator) { throw new AuthorizationException(); } } // first topic's post $postDto = $forumService->findTopicFirstPost($topicId); $this->assign('post', $postDto); $uid = uniqid(); $editTopicForm = $this->generateEditTopicForm($topicDto, $postDto, $uid); $this->addForm($editTopicForm); $lang = OW::getLanguage(); $router = OW::getRouter(); $topicInfo = $forumService->getTopicInfo($topicId); $groupUrl = $router->urlForRoute('group-default', array('groupId' => $topicDto->groupId)); $topicUrl = $router->urlForRoute('topic-default', array('topicId' => $topicDto->id)); $lang->addKeyForJs('forum', 'confirm_delete_attachment'); $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments'); $this->assign('enableAttachments', $enableAttachments); if ($enableAttachments) { $attachments = $attachmentService->findAttachmentsByPostIdList(array($postDto->id)); $this->assign('attachments', $attachments); $attachmentCmp = new BASE_CLASS_FileAttachment('forum', $uid); $this->addComponent('attachmentsCmp', $attachmentCmp); } if (OW::getRequest()->isPost() && $editTopicForm->isValid($_POST)) { $values = $editTopicForm->getValues(); $topicId = (int) $values['topic-id']; $postId = (int) $values['post-id']; $title = trim($values['title']); $text = trim($values['text']); $topicDto = $forumService->findTopicById($topicId); $postDto = $forumService->findPostById($postId); if ($topicDto === null || $postDto === null || $topicDto->userId != $userId && !$isModerator) { exit; } //save topic $topicDto->title = strip_tags($title); $forumService->saveOrUpdateTopic($topicDto); //save post $postDto->text = UTIL_HtmlTag::stripJs(UTIL_HtmlTag::stripTags($text, array('form', 'input', 'button'), null, true)); $forumService->saveOrUpdatePost($postDto); //save post edit info $editPostDto = $forumService->findEditPost($postId); if ($editPostDto === null) { $editPostDto = new FORUM_BOL_EditPost(); } $editPostDto->postId = $postId; $editPostDto->userId = $userId; $editPostDto->editStamp = time(); $forumService->saveOrUpdateEditPost($editPostDto); if ($enableAttachments) { $filesArray = BOL_AttachmentService::getInstance()->getFilesByBundleName('forum', $values['attachmentUid']); if ($filesArray) { $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $skipped = 0; foreach ($filesArray as $file) { $attachmentDto = new FORUM_BOL_PostAttachment(); $attachmentDto->postId = $postDto->id; $attachmentDto->fileName = $file['dto']->origFileName; $attachmentDto->fileNameClean = $file['dto']->fileName; $attachmentDto->fileSize = $file['dto']->size * 1024; $attachmentDto->hash = uniqid(); $added = $attachmentService->addAttachment($attachmentDto, $file['path']); if (!$added) { $skipped++; } } BOL_AttachmentService::getInstance()->deleteAttachmentByBundle('forum', $values['attachmentUid']); if ($skipped) { OW::getFeedback()->warning(OW::getLanguage()->text('forum', 'not_all_attachments_added')); } } } OW::getEventManager()->trigger(new OW_Event('feed.action', array('pluginKey' => 'forum', 'entityType' => 'forum-topic', 'entityId' => $topicDto->id, 'userId' => $topicDto->userId, 'time' => $postDto->createStamp))); OW::getEventManager()->trigger(new OW_Event(FORUM_BOL_ForumService::EVENT_AFTER_TOPIC_EDIT, array('topicId' => $topicDto->id))); $this->redirect($topicUrl); } OW::getDocument()->setHeading(OW::getLanguage()->text('forum', 'edit_topic_title')); OW::getDocument()->setHeadingIconClass('ow_ic_edit'); $this->assign('isHidden', $isHidden); if ($isHidden) { $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId)); OW::getEventManager()->trigger($event); $eventData = $event->getData(); /** @var OW_Component $componentForumCaption */ $componentForumCaption = $eventData['component']; if (!empty($componentForumCaption)) { $this->assign('componentForumCaption', $componentForumCaption->render()); } else { $componentForumCaption = false; $this->assign('componentForumCaption', $componentForumCaption); } $bcItems = array(array('href' => OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId)), 'label' => OW::getLanguage()->text('forum', 'back_to_topic'))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->deactivateMenuItems(OW_Navigation::MAIN); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $forumSection->entity, $eventData['key']); } else { $bcItems = array(array('href' => $router->urlForRoute('forum-default'), 'label' => $lang->text('forum', 'forum_index')), array('href' => $router->urlForRoute('forum-default') . '#section-' . $topicInfo['sectionId'], 'label' => $topicInfo['sectionName']), array('href' => $groupUrl, 'label' => $topicInfo['groupName']), array('href' => $topicUrl, 'label' => htmlspecialchars($topicDto->title))); $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems, $lang->text('forum', 'topic_location')); $this->addComponent('breadcrumb', $breadCrumbCmp); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'forum', 'forum'); } }
/** * This action adds a post and after execution redirects to default action * * @param array $params * @throws Redirect404Exception * @throws AuthenticateException */ public function addPost(array $params) { if (!isset($params['topicId']) || !($topicId = (int) $params['topicId'])) { throw new Redirect404Exception(); } $topicDto = $this->forumService->findTopicById($topicId); if (!$topicDto) { throw new Redirect404Exception(); } $uid = $params['uid']; $addPostForm = $this->generateAddPostForm($topicId, $uid); if (OW::getRequest()->isPost() && $addPostForm->isValid($_POST)) { $data = $addPostForm->getValues(); if ($data['topic'] && $data['topic'] == $topicDto->id && !$topicDto->locked) { if (!OW::getUser()->getId()) { throw new AuthenticateException(); } $postDto = new FORUM_BOL_Post(); $postDto->topicId = $data['topic']; $postDto->userId = OW::getUser()->getId(); $postDto->text = UTIL_HtmlTag::stripJs(UTIL_HtmlTag::stripTags($data['text'], array('form', 'input', 'button'), null, true)); $postDto->createStamp = time(); $this->forumService->saveOrUpdatePost($postDto); $topicDto->lastPostId = $postDto->getId(); $this->forumService->saveOrUpdateTopic($topicDto); $this->forumService->deleteByTopicId($topicId); $enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments'); if ($enableAttachments) { $filesArray = BOL_AttachmentService::getInstance()->getFilesByBundleName('forum', $data['attachmentUid']); if ($filesArray) { $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $skipped = 0; foreach ($filesArray as $file) { $attachmentDto = new FORUM_BOL_PostAttachment(); $attachmentDto->postId = $postDto->id; $attachmentDto->fileName = $file['dto']->origFileName; $attachmentDto->fileNameClean = $file['dto']->fileName; $attachmentDto->fileSize = $file['dto']->size * 1024; $attachmentDto->hash = uniqid(); $added = $attachmentService->addAttachment($attachmentDto, $file['path']); if (!$added) { $skipped++; } } BOL_AttachmentService::getInstance()->deleteAttachmentByBundle('forum', $data['attachmentUid']); if ($skipped) { OW::getFeedback()->warning(OW::getLanguage()->text('forum', 'not_all_attachments_added')); } } } $postUrl = $this->forumService->getPostUrl($topicId, $postDto->id); $event = new OW_Event('forum.add_post', array('postId' => $postDto->id, 'topicId' => $topicId, 'userId' => $postDto->userId)); OW::getEventManager()->trigger($event); $forumGroup = $this->forumService->findGroupById($topicDto->groupId); if ($forumGroup) { $forumSection = $this->forumService->findSectionById($forumGroup->sectionId); if ($forumSection) { $pluginKey = $forumSection->isHidden ? $forumSection->entity : 'forum'; $action = $forumSection->isHidden ? 'add_topic' : 'edit'; BOL_AuthorizationService::getInstance()->trackAction($pluginKey, $action); } } $this->redirect($postUrl); } } else { $this->redirect(OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId))); } }
public function __construct() { $this->service = BOL_AttachmentService::getInstance(); }
public function rmTempAttachments() { BOL_AttachmentService::getInstance()->deleteExpiredTempImages(); }
public function removeAttachment() { if (empty($_GET['actionId'])) { throw new Redirect404Exception(); } $actionId = (int) $_GET['actionId']; $dto = $this->service->findActionById($actionId); $data = json_decode($dto->data, true); if (!empty($data['attachmentId'])) { BOL_AttachmentService::getInstance()->deleteAttachmentByBundle("newsfeed", $data['attachmentId']); } unset($data['attachment']); $dto->data = json_encode($data); $this->service->saveAction($dto); exit; }