public function __construct($conversationData) { parent::__construct(); $this->consoleItem = new BASE_CMP_ConsoleListItem(); $this->convId = $conversationData['conversationId']; $userId = OW::getUser()->getId(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $this->opponentId = $conversationData['opponentId']; $avatarUrl = BOL_AvatarService::getInstance()->getAvatarUrl($this->opponentId); $this->avatarUrl = $avatarUrl ? $avatarUrl : BOL_AvatarService::getInstance()->getDefaultAvatarUrl(); $this->profileUrl = BOL_UserService::getInstance()->getUserUrl($this->opponentId); $this->displayName = BOL_UserService::getInstance()->getDisplayName($this->opponentId); $this->mode = $conversationData['mode']; $this->text = $conversationData['previewText']; $this->dateLabel = $conversationData['dateLabel']; $this->unreadMessageCount = $conversationService->countUnreadMessagesForConversation($this->convId, $userId); if ($this->mode == 'mail') { $this->url = $conversationService->getConversationUrl($this->convId); $this->addClass('ow_mailbox_request_item ow_cursor_default'); } if ($this->mode == 'chat') { $this->url = 'javascript://'; $this->addClass('ow_chat_request_item ow_cursor_default'); $js = "\$('.consoleChatItem#mailboxConsoleMessageItem{$this->convId}').bind('click', function(){\n var convId = \$(this).data('convid');\n var opponentId = \$(this).data('opponentid');\n OW.trigger('mailbox.open_dialog', {convId: convId, opponentId: opponentId, mode: 'chat', isSelected: true});\n OW.Console.getItem('mailbox').hideContent();\n });"; OW::getDocument()->addOnloadScript($js); } if ($conversationData['conversationRead'] == 0) { $this->addClass('ow_console_new_message'); } }
public function onConsolePagesCollect(BASE_CLASS_EventCollector $event) { OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'underscore-min.js', 'text/javascript', 3000); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('base')->getStaticJsUrl() . 'backbone-min.js', 'text/javascript', 3000); // OW::getDocument()->addScript( OW::getPluginManager()->getPlugin('base')->getStaticJsUrl().'backbone.js', 'text/javascript', 3000 ); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('mailbox')->getStaticJsUrl() . 'mobile_mailbox.js', 'text/javascript', 3000); $userListUrl = OW::getRouter()->urlForRoute('mailbox_user_list'); $convListUrl = OW::getRouter()->urlForRoute('mailbox_conv_list'); $authorizationResponderUrl = OW::getRouter()->urlFor('MAILBOX_CTRL_Ajax', 'authorization'); $pingResponderUrl = OW::getRouter()->urlFor('MAILBOX_CTRL_Ajax', 'ping'); $getHistoryResponderUrl = OW::getRouter()->urlFor('MAILBOX_CTRL_Ajax', 'getHistory'); $userId = OW::getUser()->getId(); $displayName = BOL_UserService::getInstance()->getDisplayName($userId); $avatarUrl = BOL_AvatarService::getInstance()->getAvatarUrl($userId); if (empty($avatarUrl)) { $avatarUrl = BOL_AvatarService::getInstance()->getDefaultAvatarUrl(); } $profileUrl = BOL_UserService::getInstance()->getUserUrl($userId); $lastSentMessage = MAILBOX_BOL_ConversationService::getInstance()->getLastSentMessage($userId); $lastMessageTimestamp = (int) ($lastSentMessage ? $lastSentMessage->timeStamp : 0); $params = array('getHistoryResponderUrl' => $getHistoryResponderUrl, 'pingResponderUrl' => $pingResponderUrl, 'authorizationResponderUrl' => $authorizationResponderUrl, 'userListUrl' => $userListUrl, 'convListUrl' => $convListUrl, 'pingInterval' => 5000, 'lastMessageTimestamp' => $lastMessageTimestamp, 'user' => array('userId' => $userId, 'displayName' => $displayName, 'profileUrl' => $profileUrl, 'avatarUrl' => $avatarUrl)); $js = UTIL_JsGenerator::composeJsString('OWM.Mailbox = new MAILBOX_Mobile({$params});', array('params' => $params)); OW::getDocument()->addOnloadScript($js, 'text/javascript', 3000); $event->add(array('key' => 'convers', 'cmpClass' => 'MAILBOX_MCMP_ConsoleConversationsPage', 'order' => 2)); }
public function __construct($data) { $script = UTIL_JsGenerator::composeJsString(' OWM.bind("mailbox.ready", function(readyStatus){ if (readyStatus == 2){ OWM.conversation = new MAILBOX_Conversation({$params}); OWM.conversationView = new MAILBOX_MailConversationView({model: OWM.conversation}); } }); ', array('params' => $data)); OW::getDocument()->addOnloadScript($script); OW::getLanguage()->addKeyForJs('mailbox', 'text_message_invitation'); $form = new MAILBOX_MCLASS_NewMailMessageForm($data['conversationId'], $data['opponentId']); $this->addForm($form); $this->assign('data', $data); $this->assign('defaultAvatarUrl', BOL_AvatarService::getInstance()->getDefaultAvatarUrl()); $firstMessage = MAILBOX_BOL_ConversationService::getInstance()->getFirstMessage($data['conversationId']); if (empty($firstMessage)) { $actionName = 'send_message'; } else { $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_PROMOTED) { $this->assign('sendAuthMessage', $status['msg']); } elseif ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { $this->assign('sendAuthMessage', OW::getLanguage()->text('mailbox', $actionName . '_permission_denied')); } } }
public function onBeforeRender() { parent::onBeforeRender(); $viewAllUrl = OW::getRouter()->urlForRoute('mailbox_messages_default'); $this->assign('viewAllUrl', $viewAllUrl); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $activeModeList = $conversationService->getActiveModeList(); $mailModeEnabled = in_array('mail', $activeModeList) ? true : false; $this->assign('mailModeEnabled', $mailModeEnabled); $actionName = 'send_message'; $event = new OW_Event('mailbox.show_send_message_button', array(), false); OW::getEventManager()->trigger($event); $showSendMessage = $event->getData(); $isAuthorizedSendMessage = $showSendMessage && OW::getUser()->isAuthorized('mailbox', $actionName); if (!$isAuthorizedSendMessage) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', $actionName); if ($status['status'] == BOL_AuthorizationService::STATUS_PROMOTED) { $script = '$("#mailboxConsoleListSendMessageBtn").click(function(){ OW.authorizationLimitedFloatbox(' . json_encode($status['msg']) . '); });'; OW::getDocument()->addOnloadScript($script); $isAuthorizedSendMessage = true; //this service is promoted } } $this->assign('isAuthorizedSendMessage', $isAuthorizedSendMessage); }
public function resetAllUsersLastData() { $sql = "SELECT COUNT(*) FROM `" . MAILBOX_BOL_UserLastDataDao::getInstance()->getTableName() . "` AS `uld`\nLEFT JOIN `" . BOL_UserOnlineDao::getInstance()->getTableName() . "` AS uo ON uo.userId = uld.userId\nWHERE uo.id IS NULL"; $usersOfflineButOnline = OW::getDbo()->queryForColumn($sql); if ($usersOfflineButOnline > 0) { MAILBOX_BOL_ConversationService::getInstance()->resetAllUsersLastData(); } }
public function initJs() { parent::initJs(); $jsUrl = OW::getPluginManager()->getPlugin('mailbox')->getStaticJsUrl() . 'mailbox_console.js'; OW::getDocument()->addScript($jsUrl); $js = UTIL_JsGenerator::newInstance(); $js->addScript('OW.MailboxConsole = new OW_MailboxConsole({$key}, {$params});', array('key' => $this->getKey(), 'params' => array('issetMails' => (bool) MAILBOX_BOL_ConversationService::getInstance()->getInboxConversationList(OW::getUser()->getId(), 0, 1)))); OW::getDocument()->addOnloadScript($js); }
protected function initJs() { $js = UTIL_JsGenerator::newInstance(); $js->addScript('OW.Console.addItem(new OW_ConsoleDropdownList({$uniqId}, {$contentIniqId}), {$key});', array('uniqId' => $this->consoleItem->getUniqId(), 'key' => $this->getKey(), 'contentIniqId' => $this->consoleItem->getContentUniqId())); OW::getDocument()->addOnloadScript($js); $this->list->initJs(); $js = UTIL_JsGenerator::newInstance(); $js->addScript('OW.MailboxConsole = new OW_MailboxConsole({$key}, {$params});', array('key' => $this->getKey(), 'params' => array('issetMails' => (bool) MAILBOX_BOL_ConversationService::getInstance()->getInboxConversationList(OW::getUser()->getId(), 0, 1)))); OW::getDocument()->addOnloadScript($js); return $this->consoleItem->getUniqId(); }
public function render() { $userId = OW::getUser()->getId(); $userSettingsForm = MAILBOX_BOL_ConversationService::getInstance()->getUserSettingsForm(); $this->addForm($userSettingsForm); $userSettingsForm->getElement('user_id')->setValue($userId); $friendsEnabled = (bool) OW::getEventManager()->call('plugin.friends'); $this->assign('friendsEnabled', $friendsEnabled); $showAllMembersModeEnabled = (bool) OW::getConfig()->getValue('mailbox', 'show_all_members'); $this->assign('showAllMembersModeEnabled', $showAllMembersModeEnabled); return parent::render(); }
public function getMenu($userId, $type = 'main') { $items = array(); $pm = OW::getPluginManager(); switch ($type) { case 'main': if ($pm->isPluginActive("usearch")) { $items[] = array('key' => 'Search', 'label' => 'Search', 'counter' => 0); } if ($pm->isPluginActive('mailbox')) { $activeModes = MAILBOX_BOL_ConversationService::getInstance()->getActiveModeList(); $messageList = MAILBOX_BOL_MessageDao::getInstance()->findUnreadMessages($userId, array(), time(), $activeModes); $count = count($messageList); // Hot fix. TODO refactor //$count = MAILBOX_BOL_ConversationService::getInstance()->getUnreadMessageCount($userId); $items[] = array('key' => 'Mailbox', 'label' => 'Messages', 'counter' => $count); } if ($pm->isPluginActive('matchmaking')) { $items[] = array('key' => 'Matches', 'label' => 'My Matches', 'counter' => 0); if ($pm->isPluginActive("googlelocation")) { $items[] = array('key' => 'SpeedMatch', 'label' => 'SpeedMatch', 'counter' => 0); } } if ($pm->isPluginActive('ocsguests')) { $count = OW::getEventManager()->call('guests.get_new_guests_count', array('userId' => $userId)); $items[] = array('key' => 'Guests', 'label' => 'Guests', 'counter' => $count); } if ($pm->isPluginActive('bookmarks')) { $items[] = array('key' => 'Bookmarks', 'label' => 'Bookmarks', 'counter' => 0); } if (SKADATEIOS_ABOL_Service::getInstance()->isBillingEnabled()) { $label = 'Membership & Credits'; if (!$pm->isPluginActive("usercredits")) { $label = "membership"; } if (!$pm->isPluginActive("membership")) { $label = "credits"; } $items[] = array('key' => 'Billing', 'label' => $label, 'counter' => 0); } else { $items[] = array('key' => 'About', 'label' => 'About', 'counter' => 0); } break; case 'bottom': //$items[] = array('key' => 'Desktop', 'label' => 'Desktop Version', 'url' => OW_URL_HOME . 'desktop-version'); $items[] = array('key' => 'Terms', 'label' => 'Terms & Policies', 'custom' => true); break; } return $items; }
public function __construct(BASE_CLASS_WidgetParameter $paramObject) { parent::__construct(); $userId = OW::getUser()->getId(); if ($userId !== null) { $count = MAILBOX_BOL_ConversationService::getInstance()->getNewInboxConversationCount($userId); if ($count > 0) { OW::getDocument()->addOnloadScript(" \$('.new_message_note_widget').click(\n function()\n {\n window.location = '" . OW::getRouter()->urlForRoute('mailbox_inbox') . "';\n } ); "); $this->assign('count', $count); } else { $this->setVisible(false); } } else { $this->setVisible(false); } }
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 deleteConversation($params) { if (!OW::getUser()->isAuthenticated()) { echo json_encode(array()); exit; } $userId = OW::getUser()->getId(); $conversationId = (int) $params['conversationId']; if (!empty($conversationId)) { MAILBOX_BOL_ConversationService::getInstance()->deleteConversation(array($conversationId), $userId); $this->notice = OW::getLanguage()->text('mailbox', 'delete_conversation_message'); return true; } else { $this->error = OW::getLanguage()->text('mailbox', 'conversation_id_undefined'); return false; } }
public function transferCredits($userId, $receiveUser, $creditValue) { $debitValue = $creditValue * -1; $userCreditsService = USERCREDITS_BOL_CreditsService::getInstance(); $creditsService = CREDITS_BOL_Service::getInstance(); $sendItem = $this->logAction($creditsService->getSentActionId(), $userId, $debitValue); $receiveItem = $this->logAction($creditsService->getReceiveActionId(), $receiveUser, $creditValue); $userCreditsService->increaseBalance($receiveUser, $creditValue); $userCreditsService->decreaseBalance($userId, $creditValue); $sqlInsert = "INSERT INTO " . OW_DB_PREFIX . "credits_sent_log(senderItem, receiverItem, sender, receiver) \n VALUES(:sendItem, :receiveItem, :userId, :receiveUser)"; $qParams = array('sendItem' => $sendItem, 'receiveItem' => $receiveItem, 'userId' => $userId, 'receiveUser' => $receiveUser); OW::getDbo()->query($sqlInsert, $qParams); $service = BOL_UserService::getInstance(); $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId, $receiveUser)); $names = $service->getDisplayNamesForList(array($userId, $receiveUser)); $uUrls = $service->getUserUrlsForList(array($userId, $receiveUser)); if (OW::getConfig()->getValue('credits', 'enableNotification') == '1') { //Send notification to receiver $avatar = $avatars[$userId]; $notificationParams = array('pluginKey' => 'credits', 'action' => 'credits-received', 'entityType' => 'received', 'entityId' => $receiveItem, 'userId' => $receiveUser, 'time' => time()); $sender = '<a href="' . $uUrls[$userId] . '" target="_blank" >' . $names[$userId] . '</a>'; $notificationData = array('string' => array('key' => 'credits+notify_credits_received', 'vars' => array('sender' => $sender, 'credits' => $creditValue)), 'avatar' => $avatar, 'url' => $uUrls[$userId]); $event = new OW_Event('notifications.add', $notificationParams, $notificationData); OW::getEventManager()->trigger($event); } $subject = OW::getLanguage()->text('credits', 'credits_email_subject', array('requester_name' => $names[$userId], 'credits' => $creditValue)); $content = OW::getLanguage()->text('credits', 'credits_email_content', array('requester_name' => $names[$userId], 'requester_url' => $uUrls[$userId], 'credits' => $creditValue, 'user_url' => $uUrls[$receiveUser], 'name' => $names[$receiveUser])); if (OW::getConfig()->getValue('credits', 'enableEmail') == '1') { $tmpUser = $service->findUserById($receiveUser); $sitemail = OW::getConfig()->getValue('base', 'site_email'); $sitename = OW::getConfig()->getValue('base', 'site_name'); $mail = OW::getMailer()->createMail(); $mail->addRecipientEmail($tmpUser->getEmail()); $mail->setSender($sitemail, $sitename); $mail->setSenderSuffix(true); $mail->setSubject($subject); $mail->setHtmlContent($content); $mail->setTextContent(UTIL_HtmlTag::stripTags($content)); OW::getMailer()->addToQueue($mail); } if (OW::getConfig()->getValue('credits', 'enablePM') == '1') { $conversation = MAILBOX_BOL_ConversationService::getInstance()->createConversation($userId, $receiveUser, $subject, $content); } return true; }
public function __construct($params = array()) { parent::__construct(); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('mailbox')->getStaticJsUrl() . 'conversation_list.js', 'text/javascript', 3008); $defaultAvatarUrl = BOL_AvatarService::getInstance()->getDefaultAvatarUrl(); $this->assign('defaultAvatarUrl', $defaultAvatarUrl); $js = "var conversationListModel = new MAILBOX_ConversationListModel;\n"; if (!empty($params['conversationId'])) { $js .= "conversationListModel.set('activeConvId', {$params['conversationId']});"; $js .= "conversationListModel.set('pageConvId', {$params['conversationId']});"; } $js .= "OW.Mailbox.conversationListController = new MAILBOX_ConversationListView({model: conversationListModel});"; OW::getDocument()->addOnloadScript($js, 3009); $conversationSearchForm = new Form('conversationSearchForm'); $search = new MAILBOX_CLASS_SearchField('conversation_search'); $search->setHasInvitation(true); $search->setInvitation(OW::getLanguage()->text('mailbox', 'label_invitation_conversation_search')); OW::getLanguage()->addKeyForJs('mailbox', 'label_invitation_conversation_search'); $conversationSearchForm->addElement($search); $this->addForm($conversationSearchForm); $modeList = MAILBOX_BOL_ConversationService::getInstance()->getActiveModeList(); $singleMode = count($modeList) == 1; $this->assign('singleMode', $singleMode); }
public function startSpeedmatchConversation($userId, $opponentId) { if (!$userId || !$opponentId) { return false; } $content = array('entityType' => 'speedmatch', 'eventName' => 'display_mutual_message', 'params' => array('userId' => $userId, 'opponentId' => $opponentId)); $activeModes = OW::getEventManager()->call('mailbox.get_active_mode_list'); if (count($activeModes) === 2 || in_array('chat', $activeModes)) { $eventParams = array('mode' => count($activeModes) === 2 ? 'chat' : $activeModes[0], 'userId' => $userId, 'opponentId' => $opponentId, 'isSystem' => 1, 'text' => json_encode($content)); $event = new OW_Event('mailbox.post_message', $eventParams); OW::getEventManager()->trigger($event); $data = $event->getData(); if (isset($data['error']) && $data['error'] === false && isset($data['message'])) { return $data['message']['convId']; } } else { $params = array('userId' => $userId, 'opponentId' => $opponentId, 'text' => json_encode($content), 'subject' => OW::getLanguage()->text('skadate', 'speedmatch_subject')); try { $conversation = OW::getEventManager()->call('mailbox.create_conversation', $params); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $messageDto = $conversationService->getLastMessage($conversation->id); $messageDto->isSystem = 1; $conversationService->saveMessage($messageDto); } catch (Exception $e) { } if (!empty($conversation)) { return $conversation->id; } } return false; }
/** * Deprecated see AjaxService / bulkActions */ public function bulkOptions() { $userId = OW::getUser()->getId(); switch ($_POST['actionName']) { case 'markUnread': $count = MAILBOX_BOL_ConversationService::getInstance()->markConversation($_POST['convIdList'], $userId, MAILBOX_BOL_ConversationService::MARK_TYPE_UNREAD); $message = OW::getLanguage()->text('mailbox', 'mark_unread_message', array('count' => $count)); break; case 'markRead': $count = MAILBOX_BOL_ConversationService::getInstance()->markConversation($_POST['convIdList'], $userId, MAILBOX_BOL_ConversationService::MARK_TYPE_READ); $message = OW::getLanguage()->text('mailbox', 'mark_read_message', array('count' => $count)); break; case 'delete': $count = MAILBOX_BOL_ConversationService::getInstance()->deleteConversation($_POST['convIdList'], $userId); $message = OW::getLanguage()->text('mailbox', 'delete_message', array('count' => $count)); break; } exit(json_encode(array('count' => $count, 'message' => $message))); }
public function onGetActiveModeList(OW_Event $event) { $activeModeList = MAILBOX_BOL_ConversationService::getInstance()->getActiveModeList(); $event->setData($activeModeList); return $activeModeList; }
/** * Deletes sent conversation * * @param int $conversationId * @param int $page */ public function deleteSent($params) { $userId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated() || $userId === null) { throw new AuthenticateException(); // TODO: Redirect to login page } $conversationId = (int) $params['conversationId']; $page = (int) $params['page'] > 0 ? (int) $params['page'] : 1; $conversationService = MAILBOX_BOL_ConversationService::getInstance(); if (!empty($conversationId)) { $conversationService->deleteConversation(array($conversationId), $userId); $language = OW::getLanguage(); OW::getFeedback()->info($language->text('mailbox', 'delete_conversation_message')); $this->redirect(OW::getRouter()->urlForRoute("mailbox_sent") . "?page=" . $page); } }
protected function sendMessage($userId, $opponentId, $subject, $message, $files = array()) { $language = OW::getLanguage(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $userSendMessageIntervalOk = $conversationService->checkUserSendMessageInterval($userId); if (!$userSendMessageIntervalOk) { $send_message_interval = (int) OW::getConfig()->getValue('mailbox', 'send_message_interval'); return array('result' => false, 'error' => $language->text('mailbox', 'feedback_send_message_interval_exceed', array('send_message_interval' => $send_message_interval))); } $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', $actionName . '_permission_denied')); } } $checkResult = $conversationService->checkUser($userId, $opponentId); if ($checkResult['isSuspended']) { return array('result' => false, 'error' => $checkResult['suspendReasonMessage']); } // $message = UTIL_HtmlTag::stripTags(UTIL_HtmlTag::stripJs($message)); $message = UTIL_HtmlTag::stripJs($message); // $message = nl2br($message); $event = new OW_Event('mailbox.before_create_conversation', array('senderId' => $userId, 'recipientId' => $opponentId, 'message' => $message, 'subject' => $subject), array('result' => true, 'error' => '', 'message' => $message, 'subject' => $subject)); OW::getEventManager()->trigger($event); $data = $event->getData(); if (empty($data['result'])) { return array('result' => 'permission_denied', 'message' => $data['error']); } $subject = $data['subject']; $message = $data['message']; $conversation = $conversationService->createConversation($userId, $opponentId, htmlspecialchars($subject), $message); $messageDto = $conversationService->getLastMessage($conversation->id); if (!empty($files)) { $conversationService->addMessageAttachments($messageDto->id, $files); } BOL_AuthorizationService::getInstance()->trackAction('mailbox', 'send_message'); $conversationService->resetUserLastData($userId); $conversationService->resetUserLastData($opponentId); return array('result' => true, 'lastMessageTimestamp' => $messageDto->timeStamp); }
public function sendReport($params) { $userId = OW::getUser()->getId(); if (!$userId) { throw new ApiResponseErrorException(); } if (empty($params['entityId']) || empty($params['entityType']) || !isset($params['reason'])) { throw new ApiResponseErrorException(); } $entityId = $params['entityId']; $entityType = $params['entityType']; $userService = BOL_UserService::getInstance(); $lang = OW::getLanguage(); $reasons = array(0 => 'spam', 1 => 'offensive', 2 => 'illegal'); $reason = $lang->text('skadateios', $reasons[$params['reason']]); $user = $userService->findUserById($userId); $assigns = array('reason' => $reason, 'reportedUserUrl' => OW_URL_HOME . 'user/' . $user->getUsername()); switch ($entityType) { case 'photo': if (!is_numeric($entityId)) { $name = substr($entityId, strrpos($entityId, '/') + 1); $parts = explode("_", $name); $entityId = $parts[1]; } $ownerId = PHOTO_BOL_PhotoService::getInstance()->findPhotoOwner($entityId); $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'photo/view/' . $entityId . '/latest'; break; case 'avatar': $ownerId = $entityId; $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'user/' . $reportedUser->getUsername(); break; case 'attachment': $attachment = MAILBOX_BOL_AttachmentDao::getInstance()->findById($entityId); $ext = UTIL_File::getExtension($attachment->fileName); $attachmentPath = MAILBOX_BOL_ConversationService::getInstance()->getAttachmentFilePath($attachment->id, $attachment->hash, $ext, $attachment->fileName); $assigns['userUrl'] = OW::getStorage()->getFileUrl($attachmentPath); break; default: case 'profile': $ownerId = $entityId; $reportedUser = $userService->findUserById($ownerId); if (!$reportedUser) { throw new ApiResponseErrorException(); } $assigns['userUrl'] = OW_URL_HOME . 'user/' . $reportedUser->getUsername(); break; } $subject = $lang->text('skadateios', 'user_reported_subject'); $text = $lang->text('skadateios', 'user_reported_notification_text', $assigns); $html = $lang->text('skadateios', 'user_reported_notification_html', $assigns); try { $email = OW::getConfig()->getValue('base', 'site_email'); $mail = OW::getMailer()->createMail()->addRecipientEmail($email)->setTextContent($text)->setHtmlContent($html)->setSubject($subject); OW::getMailer()->send($mail); } catch (Exception $e) { throw new ApiResponseErrorException(); } }
public function conversations($params) { if (!OW::getUser()->isAuthenticated()) { exit(array()); } $userId = OW::getUser()->getId(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $list = $conversationService->getConversationListByUserId($userId); exit(json_encode($list)); } else { exit(json_encode('todo')); } }
public function getUserOnlineInfoForUserIdList($userIdList, $userWithCorrespondenceIdList = null, $friendIdList = null) { if (empty($userIdList)) { return array(); } $activeModes = $this->getActiveModeList(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $userInfoList = array(); $userId = OW::getUser()->getId(); $blockedByUserIdList = $this->isBlockedByUserIdList($userId, $userIdList); $onlineStatusByUserIdList = $this->getUserStatusForUserIdList($userIdList); if (in_array('chat', $activeModes)) { $canInviteByUserIdList = $this->getInviteToChatPrivacySettingsForUserIdList($userId, $userIdList); } else { $canInviteByUserIdList = array(); } foreach ($userIdList as $opponentId) { $info = array('status' => $onlineStatusByUserIdList[$opponentId]); if (in_array('chat', $activeModes)) { $info['canInvite'] = $canInviteByUserIdList[$opponentId]; if (!$info['canInvite']) { $info['wasBlocked'] = true; } } $userInfoList[$opponentId] = $info; $userInfoList[$opponentId]['wasBlocked'] = in_array($opponentId, $blockedByUserIdList) ? true : false; } return $userInfoList; }
public function winkBack($params) { if (empty($params['messageId'])) { throw new ApiResponseErrorException('Message id required'); } $message = MAILBOX_BOL_ConversationService::getInstance()->getMessage($params['messageId']); try { $winkResult = OW::getEventManager()->call('winks.winkBack', array('userId' => $message->senderId, 'partnerId' => $message->recipientId, 'messageId' => $message->id, 'sendNotification' => true)); if (!empty($winkResult['result'])) { SKANDROID_ABOL_MailboxService::getInstance()->sendWinkNotification($winkResult['partnerId'], $winkResult['userId']); } } catch (Exception $e) { $this->assign('result', array('error' => true, 'message' => $e->getMessage())); return; } if (isset($winkResult['result']) && $winkResult['result'] === false) { $this->assign('result', array('error' => true, 'message' => strip_tags($winkResult['msg']))); } else { $message = MAILBOX_BOL_ConversationService::getInstance()->getMessageDataForApi($message); $message = $this->service->prepareMessageList(array($message)); $this->assign('result', array('error' => false, 'message' => $message[0], 'count' => $this->service->countUnreadMessage($message[0]['convId'], OW::getUser()->getId()), 'billingInfo' => $this->service->getBillingInfo(array(SKANDROID_ABOL_MailboxService::ACTION_READ_CHAT_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_REPLY_CHAT_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_READ_MESSAGE, SKANDROID_ABOL_MailboxService::ACTION_REPLY_CHAT_MESSAGE)))); } }
public function sendMessage($userId, $subject, $message, $attachments = array()) { $conversationService = MAILBOX_BOL_ConversationService::getInstance(); // credits check $creditsEventParams = array('pluginKey' => 'mailbox', 'action' => 'send_message'); if (OW::getEventManager()->call('usercredits.check_balance', $creditsEventParams) === false) { $error = OW::getEventManager()->call('usercredits.error_message', $creditsEventParams); throw new LogicException($error); } $conversation = $conversationService->createConversation($this->userId, $userId, htmlspecialchars($subject), $message); $message = $conversationService->getLastMessages($conversation->id); foreach ($attachments as $fileDto) { $attachmentDto = new MAILBOX_BOL_Attachment(); $attachmentDto->messageId = $message->initiatorMessageId; $attachmentDto->fileName = htmlspecialchars($fileDto->fileName); $attachmentDto->fileSize = $fileDto->fileSize; $attachmentDto->hash = $fileDto->hash; $tmpFilePath = OW::getPluginManager()->getPlugin('mcompose')->getPluginFilesDir() . uniqid('mcomose_') . '.' . UTIL_File::getExtension($fileDto->fileName); if ($conversationService->fileExtensionIsAllowed(UTIL_File::getExtension($fileDto->fileName)) && copy($fileDto->filePath, $tmpFilePath)) { $conversationService->addAttachment($attachmentDto, $tmpFilePath); } } // credits track OW::getEventManager()->call('usercredits.track_action', $creditsEventParams); return true; }
public function mailboxUpdate() { if (OW::getConfig()->configExists('mailbox', 'update_to_revision_3081')) { MAILBOX_BOL_ConversationService::getInstance()->removeNl2br(); } }
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())); } }
public function convs($params) { header('Content-Type: text/plain'); if (!OW::getUser()->isAuthenticated()) { exit(json_encode(array())); } $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $data = $conversationService->getConversationListByUserId(OW::getUser()->getId()); exit(base64_encode(json_encode($data))); }
/** * Adds new message to the conversation * * @param MAILBOX_BOL_Conversation $conversation * @param int $userId * @return boolean */ public function process(MAILBOX_BOL_Conversation $conversation, $userId) { if (!isset($conversation) || empty($userId)) { return false; } $isAuthorized = OW::getUser()->isAuthorized('mailbox', 'send_message'); if (!$isAuthorized) { return array('result' => false, 'error' => OW::getLanguage()->text('mailbox', 'write_permission_denied')); } $opponentId = $conversation->initiatorId == $userId ? $conversation->interlocutorId : $conversation->initiatorId; // credits check $eventParams = array('pluginKey' => 'mailbox', 'action' => 'send_message', 'extra' => array('senderId' => $userId, 'recipientId' => $opponentId)); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $error = OW::getEventManager()->call('usercredits.error_message', $eventParams); return array('result' => false, 'error' => $error); } $values = $this->getValues(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $message = $conversationService->createMessage($conversation, $userId, $values['message']); $language = OW::getLanguage(); OW::getFeedback()->info($language->text('mailbox', 'add_message')); if (isset($_FILES['attachments']) && count($_FILES['attachments'])) { $conversationService->addMessageAttachments($message->id, $_FILES['attachments']); } // credits track if ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } return array('result' => true); }
/** * Creates new conversation * * @param int $initiatorId * @param int $interlocutorId */ public function process($initiatorId, $interlocutorId) { if (OW::getRequest()->isAjax()) { if (empty($initiatorId) || empty($interlocutorId)) { echo json_encode(array('result' => false)); exit; } $isAuthorized = OW::getUser()->isAuthorized('mailbox', 'send_message'); if (!$isAuthorized) { echo json_encode(array('result' => 'permission_denied')); exit; } // credits check $eventParams = array('pluginKey' => 'mailbox', 'action' => 'send_message', 'extra' => array('senderId' => $initiatorId, 'recipientId' => $interlocutorId)); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $error = OW::getEventManager()->call('usercredits.error_message', $eventParams); echo json_encode(array('result' => 'permission_denied', 'message' => $error)); exit; } $captcha = $this->getElement('captcha'); $captcha->setRequired(); if ($this->displayCapcha && (!$captcha->isValid() || !UTIL_Validator::isCaptchaValid($captcha->getValue()))) { echo json_encode(array('result' => 'display_captcha')); exit; } $values = $this->getValues(); $conversationService = MAILBOX_BOL_ConversationService::getInstance(); $uploadFiles = MAILBOX_BOL_FileUploadService::getInstance(); $conversation = $conversationService->createConversation($initiatorId, $interlocutorId, htmlspecialchars($values['subject']), $values['message']); $message = $conversationService->getLastMessages($conversation->id); $fileDtoList = $uploadFiles->findUploadFileList($values['attachments']); foreach ($fileDtoList as $fileDto) { $attachmentDto = new MAILBOX_BOL_Attachment(); $attachmentDto->messageId = $message->initiatorMessageId; $attachmentDto->fileName = htmlspecialchars($fileDto->fileName); $attachmentDto->fileSize = $fileDto->fileSize; $attachmentDto->hash = $fileDto->hash; if ($conversationService->fileExtensionIsAllowed(UTIL_File::getExtension($fileDto->fileName))) { $conversationService->addAttachment($attachmentDto, $fileDto->filePath); } $uploadFiles->deleteUploadFile($fileDto->hash, $fileDto->userId); } // credits track if ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } BOL_PreferenceService::getInstance()->savePreferenceValue('mailbox_create_conversation_display_capcha', false, OW::getUser()->getId()); $timestamp = 0; if ($this->displayCapcha == false) { $timestamp = time(); } BOL_PreferenceService::getInstance()->savePreferenceValue('mailbox_create_conversation_stamp', $timestamp, OW::getUser()->getId()); echo json_encode(array('result' => true)); exit; } }
public function consoleSendList(BASE_CLASS_EventCollector $event) { $params = $event->getParams(); $userIdList = $params['userIdList']; $conversationListByUserId = MAILBOX_BOL_ConversationService::getInstance()->getConversationListForConsoleNotificationMailer($userIdList); $conversationIdList = array(); foreach ($conversationListByUserId as $recipientId => $conversationList) { foreach ($conversationList as $conversation) { $conversationIdList[$conversation['id']] = $conversation['id']; } } $result = MAILBOX_BOL_ConversationService::getInstance()->getConversationListByIdList($conversationIdList); $conversationList = array(); foreach ($result as $conversation) { $conversationList[$conversation->id] = $conversation; } foreach ($conversationListByUserId as $recipientId => $list) { foreach ($list as $conversation) { $senderId = $conversation['initiatorId'] == $recipientId ? $conversation['interlocutorId'] : $conversation['initiatorId']; $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($senderId)); $avatar = $avatars[$senderId]; $event->add(array('pluginKey' => 'mailbox', 'entityType' => 'mailbox-conversation', 'entityId' => $conversation['id'], 'userId' => $recipientId, 'action' => 'mailbox-new_message', 'time' => $conversation['timeStamp'], 'data' => array('avatar' => $avatar, 'string' => OW::getLanguage()->text('mailbox', 'email_notifications_comment', array('userName' => BOL_UserService::getInstance()->getDisplayName($senderId), 'userUrl' => BOL_UserService::getInstance()->getUserUrl($senderId), 'conversationUrl' => MAILBOX_BOL_ConversationService::getInstance()->getConversationUrl($conversation['id']))), 'content' => $conversation['text']))); if (!empty($conversationList[$conversation['id']])) { $conversationList[$conversation['id']]->notificationSent = 1; MAILBOX_BOL_ConversationService::getInstance()->saveConversation($conversationList[$conversation['id']]); } } } }