/** * Returns an instance of class (singleton pattern implementation). * * @return BOL_VoteService */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function delete(Link $dto) { BOL_CommentService::getInstance()->deleteEntityComments('link', $dto->getId()); BOL_TagService::getInstance()->deleteEntityTags($dto->getId(), 'link'); BOL_VoteService::getInstance()->deleteEntityItemVotes($dto->getId(), 'link'); BOL_FlagService::getInstance()->deleteByTypeAndEntityId('link', $dto->getId()); OW::getCacheManager()->clean(array(LinkDao::CACHE_TAG_LINK_COUNT)); OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'link', 'entityId' => $dto->getId()))); $this->dao->delete($dto); }
public function onDeleteUserContent(OW_Event $event) { $params = $event->getParams(); $userId = (int) $params['userId']; if ($userId > 0) { $moderatorId = BOL_AuthorizationService::getInstance()->getModeratorIdByUserId($userId); if ($moderatorId !== null) { BOL_AuthorizationService::getInstance()->deleteModerator($moderatorId); } BOL_AuthorizationService::getInstance()->deleteUserRolesByUserId($userId); if (isset($params['deleteContent']) && (bool) $params['deleteContent']) { BOL_CommentService::getInstance()->deleteUserComments($userId); BOL_RateService::getInstance()->deleteUserRates($userId); BOL_VoteService::getInstance()->deleteUserVotes($userId); } //delete widgets BOL_ComponentEntityService::getInstance()->onEntityDelete(BOL_ComponentEntityService::PLACE_DASHBOARD, $userId); BOL_ComponentEntityService::getInstance()->onEntityDelete(BOL_ComponentEntityService::PLACE_PROFILE, $userId); // delete email verify BOL_EmailVerifyService::getInstance()->deleteByUserId($userId); // delete remote auth info BOL_RemoteAuthService::getInstance()->deleteByUserId($userId); // delete user auth token BOL_AuthTokenDao::getInstance()->deleteByUserId($userId); } }
private function getData($first, $count) { $service = LinkService::getInstance(); $list = array(); $itemCount = 0; $case = $this->getCase(); switch ($case) { case 'most-discussed': $commentService = BOL_CommentService::getInstance(); $info = array(); $info = $commentService->findMostCommentedEntityList('link', $first, $count); $idList = array(); foreach ($info as $item) { $idList[] = $item['id']; } if (empty($idList)) { break; } $dtoList = $service->findListByIdList($idList); foreach ($dtoList as $dto) { $list[] = array('dto' => $dto, 'commentCount' => $info[$dto->id]['commentCount']); } function sortMostCommented($e, $e2) { return $e['commentCount'] < $e2['commentCount']; } usort($list, 'sortMostCommented'); $itemsCount = $commentService->findCommentedEntityCount('link'); OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'most_discussed_title')); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'most_discussed_description')); break; case 'top-rated': $info = array(); $info = BOL_VoteService::getInstance()->findMostVotedEntityList('link', $first, $count); $idList = array(); foreach ($info as $item) { $idList[] = $item['id']; } if (empty($idList)) { break; } $dtoList = $service->findListByIdList($idList); foreach ($dtoList as $dto) { $list[] = array('dto' => $dto, 'sum' => $info[$dto->id]['sum']); } function sortTopRated($e, $e2) { return $e['sum'] < $e2['sum']; } usort($list, 'sortTopRated'); $itemCount = BOL_VoteService::getInstance()->findMostVotedEntityCount('link'); OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'top_rated_title')); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'top_rated_description')); break; case 'browse-by-tag': if (empty($_GET['tag'])) { $mostPopularTagsArray = BOL_TagService::getInstance()->findMostPopularTags('link', 20); $mostPopularTags = ""; foreach ($mostPopularTagsArray as $tag) { $mostPopularTags .= $tag['label'] . ", "; } OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'browse_by_tag_title')); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'browse_by_tag_description', array('tags' => $mostPopularTags))); break; } $info = BOL_TagService::getInstance()->findEntityListByTag('link', UTIL_HtmlTag::stripTags($_GET['tag']), $first, $count); $itemCount = BOL_TagService::getInstance()->findEntityCountByTag('link', UTIL_HtmlTag::stripTags($_GET['tag'])); foreach ($info as $item) { $idList[] = $item; } if (empty($idList)) { break; } $dtoList = $service->findListByIdList($idList); foreach ($dtoList as $dto) { $dto->setUrl(strip_tags($dto->getUrl())); $dto->setTitle(strip_tags($dto->getTitle())); $dto->setDescription(BASE_CMP_TextFormatter::fromBBtoHtml($dto->getDescription())); $list[] = array('dto' => $dto); } OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'browse_by_tag_item_title', array('tag' => htmlspecialchars(UTIL_HtmlTag::stripTags($_GET['tag']))))); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'browse_by_tag_item_description', array('tag' => htmlspecialchars(UTIL_HtmlTag::stripTags($_GET['tag']))))); break; case false !== strstr($_SERVER['REQUEST_URI'], 'latest'): default: $dtoList = $service->findList($first, $count); $itemCount = $service->countLinks(); foreach ($dtoList as $dto) { $list[] = array('dto' => $dto); } OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'latest_title')); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'latest_description')); break; } return array($list, $itemCount); }
public function index($params) { $plugin = OW::getPluginManager()->getPlugin('links'); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'links', 'main_menu_item'); if (!OW::getUser()->isAdmin() && !OW::getUser()->isAuthorized('links', 'view')) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } /* @var $service LinkService */ $service = LinkService::getInstance(); /* @var $userService BOL_UserService */ $userService = BOL_UserService::getInstance(); /* @var $author BOL_User */ if (!empty($params['user'])) { $author = $userService->findByUsername($params['user']); } else { $author = $userService->findUserById(OW::getUser()->getId()); } if (empty($author)) { throw new Redirect404Exception(); return; } /* Check privacy permissions */ $eventParams = array('action' => LinkService::PRIVACY_ACTION_VIEW_LINKS, 'ownerId' => $author->getId(), 'viewerId' => OW::getUser()->getId()); OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams); /* */ $displayName = $userService->getDisplayName($author->getId()); $this->assign('author', $author); $this->assign('username', $author->getUsername()); $this->assign('displayname', $displayName); if ($author->getId() == OW::getUser()->getId()) { $this->setPageHeading(OW::getLanguage()->text('links', 'my_links')); $this->setPageHeadingIconClass('ow_ic_write'); OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'my_links')); } else { $this->setPageHeading(OW::getLanguage()->text('links', 'user_link_page_heading', array('display_name' => $displayName))); $this->setPageHeadingIconClass('ow_ic_write'); OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'user_links_title', array('display_name' => $displayName))); } OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'user_links_description', array('display_name' => $displayName))); $page = !empty($_GET['page']) && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1; $rpp = (int) OW::getConfig()->getValue('links', 'results_per_page'); $first = ($page - 1) * $rpp; $count = $rpp; $list = $service->findUserLinkList($author->getId(), $first, $count); $itemsCount = $service->countUserLinks($author->getId()); $posts = array(); $commentInfo = array(); $idList = array(); foreach ($list as $dto) { $idList[] = $dto->getId(); $text = BASE_CMP_TextFormatter::fromBBtoHtml($dto->getDescription()); $descLength = 120; $text = strip_tags($text); if (strlen($text) > $descLength) { $text = UTIL_String::truncate($text, $descLength, '...'); $text .= ' <a href="' . OW::getRouter()->urlForRoute('link', array('id' => $dto->getId())) . '" class="ow_lbutton">' . OW::getLanguage()->text('base', 'more') . '</a>'; } $posts[$dto->getId()] = array('id' => $dto->getId(), 'href' => $dto->getUrl(), 'title' => UTIL_String::truncate($dto->getTitle(), 65, '...'), 'text' => $text); } if (!empty($idList)) { $voteService = BOL_VoteService::getInstance(); switch (OW::getConfig()->getValue('links', 'result_mode')) { case LinkService::RESULT_MODE_SUM: $this->assign('mode', 'sum'); break; case LinkService::RESULT_MODE_DETAILED: $this->assign('mode', 'detailed'); break; } $voteTotal = $voteService->findTotalVotesResultForList($idList, 'link'); foreach ($voteTotal as $val) { $posts[$val['id']]['isVoted'] = true; $posts[$val['id']]['voteTotal'] = $val['sum']; $posts[$val['id']]['up'] = $val['up']; $posts[$val['id']]['down'] = $val['down']; } $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('link', $idList); $this->assign('commentInfo', $commentInfo); $tagsInfo = BOL_TagService::getInstance()->findTagListByEntityIdList('link', $idList); $this->assign('tagsInfo', $tagsInfo); $tb = array(); foreach ($list as $dto) { $tb[$dto->getId()] = array(array('href' => OW::getRouter()->urlForRoute('link', array('id' => $dto->getId())), 'label' => UTIL_DateTime::formatDate($dto->timestamp))); if ($commentInfo[$dto->getId()]) { $tb[$dto->getId()][] = array('href' => OW::getRouter()->urlForRoute('link', array('id' => $dto->getId())) . "#comments", 'label' => '<span class="ow_outline">' . $commentInfo[$dto->getId()] . '</span> ' . OW::getLanguage()->text('links', 'toolbar_comments')); } if ($tagsInfo[$dto->getId()]) { $tags =& $tagsInfo[$dto->getId()]; $t = OW::getLanguage()->text('links', 'tags'); for ($i = 0; $i < (count($tags) > 3 ? 3 : count($tags)); $i++) { $t .= " <a href=\"" . OW::getRouter()->urlForRoute('links-by-tag', array('list' => 'browse-by-tag')) . "?tag={$tags[$i]}\">{$tags[$i]}</a>" . ($i != 2 ? ',' : ''); } $tb[$dto->getId()][] = array('label' => mb_substr($t, 0, mb_strlen($t) - 1)); } } $this->assign('tb', $tb); if (OW::getUser()->isAuthenticated()) { $userVotes = $voteService->findUserVoteForList($idList, 'link', OW::getUser()->getId()); $this->assign('userVotes', $userVotes); } } $this->assign('list', $posts); $paging = new BASE_CMP_Paging($page, ceil($itemsCount / $rpp), 5); $this->assign('paging', $paging->render()); $this->assign('isAuthenticated', OW::getUser()->isAuthenticated()); }