/** * Returns class instance * * @return FORUM_BOL_SubscriptionService */ public static function getInstance() { if (!isset(self::$classInstance)) { self::$classInstance = new self(); } return self::$classInstance; }
public function unsubscribeTopic($params) { if (!empty($params['id'])) { $subscribeService = FORUM_BOL_SubscriptionService::getInstance(); $userId = OW::getUser()->getId(); $topicId = (int) $params['id']; if ($subscribeService->isUserSubscribed($userId, $topicId)) { $subscribeService->deleteSubscription($userId, $topicId); echo json_encode(array('msg' => OW::getLanguage()->text('forum', 'subscription-canceled'))); } } exit; }
/** * Controller's default action * * @param array $params * @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) { //$isModerator = OW::getUser()->isAuthorized($forumSection->entity); //$canEdit = OW::getUser()->isAuthorized($forumSection->entity, 'add_topic'); $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()) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } $eventParams = array('pluginKey' => $forumSection->entity, 'action' => 'add_post'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $this->assign('authMsg', OW::getEventManager()->call('usercredits.error_message', $eventParams)); } $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId)); OW::getEventManager()->trigger($event); $eventData = $event->getData(); $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 || !$canEdit) { $this->assign('authMsg', OW::getLanguage()->text('base', 'authorization_failed_feedback')); } $eventParams = array('pluginKey' => 'forum', 'action' => 'add_post'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $this->assign('authMsg', OW::getEventManager()->call('usercredits.error_message', $eventParams)); } 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); $form = $this->generateForm($groupSelect, $groupId, $isHidden); OW::getDocument()->addStyleDeclaration(' .disabled_option { color: #9F9F9F; } '); $enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments'); $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->saveOrUpdateTopic($topicDto); $postDto = new FORUM_BOL_Post(); $postDto->topicId = $topicDto->id; $postDto->userId = $userId; $postDto->text = trim($data['text']); $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); } $accepted = floatval(OW::getConfig()->getValue('forum', 'attachment_filesize') * 1024 * 1024); if (isset($data['attachments']) && count($data['attachments'])) { $filesArray = $data['attachments']; $filesCount = count($filesArray['name']); $attachmentService = FORUM_BOL_PostAttachmentService::getInstance(); $skipped = 0; for ($i = 0; $i < $filesCount; $i++) { if (!strlen($filesArray['tmp_name'][$i])) { continue; } // skip unsupported extensions $ext = UTIL_File::getExtension($filesArray['name'][$i]); if (!$attachmentService->fileExtensionIsAllowed($ext)) { $skipped++; continue; } // skip too big files if ($filesArray['size'][$i] > $accepted) { $skipped++; continue; } $attachmentDto = new FORUM_BOL_PostAttachment(); $attachmentDto->postId = $postDto->id; $attachmentDto->fileName = htmlspecialchars($filesArray['name'][$i]); $attachmentDto->fileNameClean = UTIL_File::sanitizeName($attachmentDto->fileName); $attachmentDto->fileSize = $filesArray['size'][$i]; $attachmentDto->hash = uniqid(); $added = $attachmentService->addAttachment($attachmentDto, $filesArray['tmp_name'][$i]); if (!$added) { $skipped++; } } 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 ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } if ($isHidden) { $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); } $this->redirect($topicUrl); } else { $form->getElement('group')->addError(OW::getLanguage()->text('forum', 'select_group_error')); } } }
public function subscribeUser(OW_Event $e) { $params = $e->getParams(); $userId = (int) $params['userId']; $topicId = (int) $params['topicId']; if (!$userId || !$topicId) { return false; } $service = FORUM_BOL_SubscriptionService::getInstance(); if ($service->isUserSubscribed($userId, $topicId)) { return true; } $subs = new FORUM_BOL_Subscription(); $subs->userId = $userId; $subs->topicId = $topicId; $service->addSubscription($subs); return true; }
/** * 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')); } } }