public function addLink($userId, $href, $title, $description, $thumbnailUrl, $text = null, $addToFeed = true) { if (!$this->isActive()) { return null; } OW::getCacheManager()->clean(array(LinkDao::CACHE_TAG_LINK_COUNT)); $service = LinkService::getInstance(); $url = mb_ereg_match('^http(s)?:\\/\\/', $href) ? $href : 'http://' . $href; $link = new Link(); $eventParams = array('action' => LinkService::PRIVACY_ACTION_VIEW_LINKS, 'ownerId' => OW::getUser()->getId()); $privacy = OW::getEventManager()->getInstance()->call('plugin.privacy.get_privacy', $eventParams); if (!empty($privacy)) { $link->setPrivacy($privacy); } $link->setUserId($userId); $link->setTimestamp(time()); $link->setUrl($url); $link->setDescription(strip_tags($description)); $title = empty($title) ? $text : $title; $link->setTitle(strip_tags($title)); $service->save($link); if ($addToFeed) { $content = array("format" => null, "vars" => array("status" => $text)); if (!empty($thumbnailUrl)) { $content["format"] = "image_content"; $content["vars"]["image"] = $thumbnailUrl; $content["vars"]["thumbnail"] = $thumbnailUrl; } //Newsfeed $event = new OW_Event('feed.action', array('pluginKey' => 'links', 'entityType' => 'link', 'entityId' => $link->getId(), 'userId' => $link->getUserId()), array("content" => $content)); OW::getEventManager()->trigger($event); } return $link->id; }
public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $service = LinkService::getInstance(); $userId = $params->additionalParamList['entityId']; if ($userId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('links', 'view')) { $this->setVisible(false); return; } /* Check privacy permissions */ $eventParams = array('action' => LinkService::PRIVACY_ACTION_VIEW_LINKS, 'ownerId' => $userId, 'viewerId' => OW::getUser()->getId()); try { OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams); } catch (RedirectException $ex) { $this->setVisible(false); return; } /* */ if ($service->countUserLinks($userId) == 0 && !$params->customizeMode) { $this->setVisible(false); return; } $this->assign('displayname', BOL_UserService::getInstance()->getDisplayName($userId)); $this->assign('username', BOL_UserService::getInstance()->getUsername($userId)); $list = array(); $count = $params->customParamList['count']; $userLinkList = $service->findUserLinkList($userId, 0, $count); $idList = array(); foreach ($userLinkList as $item) { /* Check privacy permissions */ if ($item->userId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('links')) { $eventParams = array('action' => LinkService::PRIVACY_ACTION_VIEW_LINKS, 'ownerId' => $item->userId, 'viewerId' => OW::getUser()->getId()); try { OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams); } catch (RedirectException $ex) { continue; } } /* */ $list[] = $item; $idList[] = $item->id; } $commentInfo = array(); if (!empty($idList)) { $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('link', $idList); $tb = array(); foreach ($list as $key => $item) { if (mb_strlen($item->getDescription()) > 100) { $item->setDescription(UTIL_String::truncate($item->getDescription(), 100, '...')); } $list[$key]->setDescription(strip_tags($item->getDescription())); $tb[$item->getId()] = array(array('label' => '<span class="ow_txt_value">' . $commentInfo[$item->getId()] . '</span> ' . OW::getLanguage()->text('links', 'comments'), 'href' => OW::getRouter()->urlForRoute('link', array('id' => $item->getId()))), array('label' => UTIL_DateTime::formatDate($item->getTimestamp()), 'class' => 'ow_ic_date')); } $this->assign('tb', $tb); } $this->assign('list', $list); $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => OW::getLanguage()->text('base', 'view_all'), 'href' => OW::getRouter()->urlForRoute('links-user', array('user' => BOL_UserService::getInstance()->getUserName($userId)))))); }
public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $service = LinkService::getInstance(); $count = $params->customParamList['count']; $list = $service->findList(0, $count); if ((empty($list) || false && !OW::getUser()->isAuthorized('links', 'add') && !OW::getUser()->isAuthorized('links', 'view')) && !$params->customizeMode) { $this->setVisible(false); return; } $links = array(); $toolbars = array(); $userService = BOL_UserService::getInstance(); $authorIdList = array(); foreach ($list as $dto) { $dto->setUrl(strip_tags($dto->getUrl())); $dto->setTitle(strip_tags($dto->getTitle())); $dto->setDescription(strip_tags($dto->getDescription())); $links[] = array('dto' => $dto); $idList[] = $dto->id; $authorIdList[] = $dto->getUserId(); } $commentInfo = array(); $this->assign('avatars', null); if (!empty($idList)) { $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('link', $idList); $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($authorIdList, true, false); $this->assign('avatars', $avatars); $urls = BOL_UserService::getInstance()->getUserUrlsForList($authorIdList); } $tbars = array(); foreach ($list as $dto) { $tbars[$dto->getId()] = array(array('class' => 'ow_icon_control ow_ic_user', 'href' => !empty($urls[$dto->getUserId()]) ? $urls[$dto->getUserId()] : '#', 'label' => !empty($avatars[$dto->getUserId()]['title']) ? $avatars[$dto->getUserId()]['title'] : ''), array('class' => 'ow_remark ow_ipc_date', 'label' => UTIL_DateTime::formatDate($dto->getTimestamp()))); } $this->assign('tbars', $tbars); $this->assign('commentInfo', $commentInfo); $this->assign('list', $links); if ($service->countAll()) { $toolbar = array(); if (OW::getUser()->isAuthorized('links', 'add')) { $toolbar[] = array('label' => OW::getLanguage()->text('links', 'add_new'), 'href' => OW::getRouter()->urlForRoute('link-save-new')); } if (OW::getUser()->isAuthorized('links', 'view')) { $toolbar[] = array('label' => OW::getLanguage()->text('links', 'go_to_links'), 'href' => Ow::getRouter()->urlForRoute('links')); } if (!empty($toolbar)) { $this->setSettingValue(self::SETTING_TOOLBAR, $toolbar); } } }
public function getService($pluginKey) { switch ($pluginKey) { case 'newsfeed': return NEWSFEED_BOL_Service::getInstance(); case 'blogs': return PostService::getInstance(); case 'groups': return GROUPS_BOL_Service::getInstance(); case 'event': return EVENT_BOL_EventService::getInstance(); case 'links': return LinkService::getInstance(); case 'video': return VIDEO_BOL_ClipService::getInstance(); case 'forum': return FORUM_BOL_ForumService::getInstance(); case 'photo': return PHOTO_BOL_PhotoService::getInstance(); } }
public function countLinks() { return LinkService::getInstance()->countLinks(); }
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) { /** * @var $pl OW_ActionController */ $plugin = OW::getPluginManager()->getPlugin('links'); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $plugin->getKey(), 'main_menu_item'); if (!OW::getUser()->isAuthorized('links', 'view')) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } $id = $params['id']; $service = LinkService::getInstance(); $userService = BOL_UserService::getInstance(); $link = $service->findById($id); if ($link === null) { throw new Redirect404Exception(); } $link->setUrl(strip_tags($link->getUrl())); $link->setTitle(strip_tags($link->getTitle())); $link->setDescription(BASE_CMP_TextFormatter::fromBBtoHtml($link->getDescription())); if (OW::getUser()->isAuthenticated() && $link->getUserId() != OW::getUser()->getId() && !OW::getUser()->isAuthorized('links', 'view')) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } /* Check privacy permissions */ if ($link->userId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('links')) { $eventParams = array('action' => LinkService::PRIVACY_ACTION_VIEW_LINKS, 'ownerId' => $link->userId, 'viewerId' => OW::getUser()->getId()); OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams); } /* */ $this->setPageHeading(htmlspecialchars($link->getTitle())); $this->setPageHeadingIconClass('ow_ic_link'); OW::getDocument()->setTitle(OW::getLanguage()->text('links', 'link_title', array('link_title' => htmlspecialchars($link->getTitle()), 'link_url' => $link->getUrl()))); OW::getDocument()->setDescription(OW::getLanguage()->text('links', 'link_description', array('link_title' => htmlspecialchars($link->getTitle()), 'link_description' => htmlspecialchars(strip_tags($link->getDescription()))))); $this->assign('info', array('dto' => $link, 'link' => mb_ereg_replace('http(s)?:\\/\\/', '', $link->getUrl()))); $userId = OW::getUser()->getId(); $user = !empty($userId) && intval($userId) > 0 ? $userService->findUserById($userId) : null; $this->assign('user', $user); $this->assign('userInfo', array('displayName' => $userService->getDisplayName($link->getUserId()), 'userName' => $userService->getUserName($link->getUserId()))); $this->assign('isModerator', OW::getUser()->isAuthorized('links')); $tb = array(); $toolbarEvent = new BASE_CLASS_EventCollector('links.collect_link_toolbar_items', array('linkId' => $link->id, 'linkDto' => $link)); OW::getEventManager()->trigger($toolbarEvent); foreach ($toolbarEvent->getData() as $toolbarItem) { array_push($tb, $toolbarItem); } if (OW::getUser()->isAuthenticated() && $link->getUserId() != OW::getUser()->getId()) { $js = UTIL_JsGenerator::newInstance()->jQueryEvent('#link_toolbar_flag', 'click', UTIL_JsGenerator::composeJsString('OW.flagContent({$entity}, {$id}, {$title}, {$href}, "links+flags");', array('entity' => 'link', 'id' => $link->getId(), 'title' => htmlspecialchars(json_encode($link->getTitle())), 'href' => OW::getRouter()->urlForRoute('link', array('id' => $link->getId()))))); OW::getDocument()->addOnloadScript($js, 1001); $tb[] = array('label' => OW::getLanguage()->text('base', 'flag'), 'href' => 'javascript://', 'id' => 'link_toolbar_flag'); } if (OW::getUser()->isAuthenticated()) { $isModerator = BOL_AuthorizationService::getInstance()->isModerator(OW::getUser()->getId()); $isGroupAssignedToModerator = BOL_AuthorizationService::getInstance()->isActionAuthorizedForUser(OW::getUser()->getId(), 'links'); $isOwner = OW::getUser()->getId() == $link->getUserId(); if ($isOwner || OW::getUser()->isAdmin() || $isModerator && $isGroupAssignedToModerator) { $tb[] = array('href' => OW::getRouter()->urlForRoute('link-save-edit', array('id' => $link->getId())), 'label' => OW::getLanguage()->text('links', 'toolbar_edit')); $tb[] = array('href' => OW::getRouter()->urlFor('LINKS_CTRL_Save', 'delete', array('id' => $link->getId())), 'click' => "return confirm('" . OW::getLanguage()->text('base', 'are_you_sure') . "')", 'label' => OW::getLanguage()->text('links', 'toolbar_delete')); } } $this->assign('tb', $tb); /* Check comments privacy permissions */ $allow_comments = true; if ($link->userId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('links')) { $eventParams = array('action' => LinkService::PRIVACY_ACTION_COMMENT_LINKS, 'ownerId' => $link->userId, 'viewerId' => OW::getUser()->getId()); try { OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams); } catch (RedirectException $ex) { $allow_comments = false; } } /* */ $cmpParams = new BASE_CommentsParams('links', 'link'); $cmpParams->setEntityId($link->getId())->setOwnerId($link->getUserId())->setDisplayType(1)->setAddComment($allow_comments); $this->addComponent('comments', new BASE_CMP_Comments($cmpParams)); $tags = BOL_TagService::getInstance()->findEntityTagsWithPopularity($link->getId(), 'link'); $tags = $tags !== null ? $tags : array(); $this->addComponent('tagCloud', new BASE_CMP_TagCloud($tags, OW::getRouter()->urlForRoute('links-by-tag'))); }
public function process() { OW::getCacheManager()->clean(array(LinkDao::CACHE_TAG_LINK_COUNT)); $service = LinkService::getInstance(); $data = $this->getValues(); $data['title'] = UTIL_HtmlTag::stripJs($data['title']); $url = mb_ereg_match('^http(s)?:\\/\\/', $data['url']) ? $data['url'] : 'http://' . $data['url']; $this->link->setTimestamp(time())->setUrl($url)->setDescription($data['description'])->setTitle(UTIL_HtmlTag::stripTags($data['title'], $service->getAllowedHtmlTags(), array('*'))); $tags = array(); $isNew = empty($this->link->id); $service->save($this->link); if (intval($this->link->getId()) > 0) { $tags = $data['tags']; } $tagService = BOL_TagService::getInstance(); $tagService->updateEntityTags($this->link->getId(), 'link', $tags); if (!$isNew) { $event = new OW_Event(LinkService::EVENT_EDIT, array('id' => $this->link->getId())); OW::getEventManager()->trigger($event); return; } $eventParams = array('pluginKey' => 'links', 'action' => 'add_link'); if (OW::getEventManager()->call('usercredits.check_balance', $eventParams) === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } //Newsfeed $event = new OW_Event('feed.action', array('pluginKey' => 'links', 'entityType' => 'link', 'entityId' => $this->link->getId(), 'userId' => $this->link->getUserId())); OW::getEventManager()->trigger($event); }
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()); }
public function onFeedAddLike(OW_Event $event) { $params = $event->getParams(); if ($params['entityType'] != 'link') { return; } $linkService = LinkService::getInstance(); $link = $linkService->findById($params['entityId']); $userId = $link->getUserId(); $userName = BOL_UserService::getInstance()->getDisplayName($userId); $userUrl = BOL_UserService::getInstance()->getUserUrl($userId); $userEmbed = '<a href="' . $userUrl . '">' . $userName . '</a>'; if ($userId == $params['userId']) { $string = OW::getLanguage()->text('links', 'feed_activity_owner_link_string_like'); } else { $string = OW::getLanguage()->text('links', 'feed_activity_link_string_like', array('user' => $userEmbed)); } OW::getEventManager()->trigger(new OW_Event('feed.activity', array('activityType' => 'like', 'activityId' => $params['userId'], 'entityId' => $params['entityId'], 'entityType' => $params['entityType'], 'userId' => $params['userId'], 'pluginKey' => 'links'), array('string' => $string))); }