public function index() { if (!OW::getUser()->isAuthorized('links', 'view')) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } $this->assign('addNew_isAuthorized', OW::getUser()->isAuthenticated() && OW::getUser()->isAuthorized('links', 'add')); 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; } $this->setPageHeading(OW::getLanguage()->text('links', 'list_page_heading')); $this->setPageHeadingIconClass('ow_ic_link'); $plugin = OW::getPluginManager()->getPlugin('links'); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $plugin->getKey(), 'main_menu_item'); if (false === strstr($_SERVER['REQUEST_URI'], 'browse-by-tag')) { $isBrowseByTagCase = false; } else { $this->assign('tag', empty($_GET['tag']) ? '' : strip_tags($_GET['tag'])); $isBrowseByTagCase = true; } $this->assign('isBrowseByTagCase', $isBrowseByTagCase); $tagCloud = new BASE_CMP_EntityTagCloud('link', OW::getRouter()->urlForRoute('links-by-tag')); if ($isBrowseByTagCase) { $tagCloud->setTemplate(OW::getPluginManager()->getPlugin('base')->getCmpViewDir() . 'big_tag_cloud.html'); } $this->addComponent('tagCloud', $tagCloud); $tagSearch = new BASE_CMP_TagSearch(OW::getRouter()->urlForRoute('links-by-tag')); $this->addComponent('tagSearch', $tagSearch); //~~ $menu = new BASE_CMP_ContentMenu($this->getMenuItems()); $this->assign('menu', $menu->render()); $service = LinkService::getInstance(); $rpp = (int) OW::getConfig()->getValue('links', 'results_per_page'); $page = !empty($_GET['page']) && (int) $_GET['page'] ? (int) $_GET['page'] : 1; $first = ($page - 1) * $rpp; $count = $rpp; $list = array(); $itemsCount = 0; list($list, $itemsCount) = $this->getData($first, $count); $descLength = 120; //$this->assign('descLength', $descLength); $titleLength = 50; $this->assign('titleLength', $titleLength); $voteService = BOL_VoteService::getInstance(); $idList = array(); $links = array(); $voteTotall = array(); $authorIdList = array(); $commentTotall = array(); foreach ($list as $item) { $link = $item['dto']; $link->setUrl(strip_tags($link->getUrl())); $link->setTitle(strip_tags($link->getTitle())); $description = BASE_CMP_TextFormatter::fromBBtoHtml($link->getDescription()); $description = strip_tags($description); if (strlen($description) > $descLength) { $description = UTIL_String::truncate($description, $descLength, '...'); $description .= ' <a href="' . OW::getRouter()->urlForRoute('link', array('id' => $link->getId())) . '" class="ow_lbutton">' . OW::getLanguage()->text('base', 'more') . '</a>'; } $link->setDescription($description); $links[$link->getId()] = array('dto' => $link); $idList[] = $link->getId(); $authorIdList[] = $link->getUserId(); } $ulist = BOL_UserService::getInstance()->getUserNamesForList($authorIdList); $nlist = BOL_UserService::getInstance()->getDisplayNamesForList($authorIdList); $this->assign('usernameList', $ulist); $this->assign('nameList', $nlist); if (!empty($idList)) { $commentTotall = BOL_CommentService::getInstance()->findCommentCountForEntityList('link', $idList); $voteTotall = $voteService->findTotalVotesResultForList($idList, 'link'); $tagsInfo = BOL_TagService::getInstance()->findTagListByEntityIdList('link', $idList); $this->assign('tagsInfo', $tagsInfo); $toolbars = array(); foreach ($list as $item) { $dto = $item['dto']; $toolbars[$dto->id] = array(); $userId = $dto->userId; $toolbars[$dto->id][] = array('class' => ' ow_icon_control ow_ic_user', 'label' => !empty($nlist[$userId]) ? $nlist[$userId] : OW::getLanguage()->text('base', 'deleted_user'), 'href' => !empty($ulist[$userId]) ? BOL_UserService::getInstance()->getUserUrlForUsername($ulist[$userId]) : '#'); $toolbars[$dto->id][] = array('href' => OW::getRouter()->urlForRoute('link', array('id' => $dto->id)), 'label' => UTIL_DateTime::formatDate($dto->timestamp)); if ($commentTotall[$dto->id]) { $toolbars[$dto->id][] = array('href' => OW::getRouter()->urlForRoute('link', array('id' => $dto->id)) . "#comments", 'label' => '<span class="ow_txt_value">' . $commentTotall[$dto->id] . '</span> ' . OW::getLanguage()->text('links', 'toolbar_comments')); } if (empty($tagsInfo[$dto->id])) { continue; } $value = OW::getLanguage()->text('links', 'tags') . ' '; $c = 0; foreach ($tagsInfo[$dto->id] as $tag) { if ($c == 3) { break; } $value .= '<a href="' . OW::getRouter()->urlForRoute('links-by-tag') . "?tag={$tag}" . "\">{$tag}</a>, "; $c++; } $value = mb_substr($value, 0, mb_strlen($value) - 2); $toolbars[$dto->id][] = array('label' => $value); } if (OW::getUser()->isAuthenticated()) { $userVotes = $voteService->findUserVoteForList($idList, 'link', OW::getUser()->getId()); $this->assign('userVotes', $userVotes); } $this->assign('tb', $toolbars); } foreach ($voteTotall as $val) { $links[$val['id']]['isVoted'] = true; $links[$val['id']]['voteTotal'] = $val['sum']; $links[$val['id']]['up'] = $val['up']; $links[$val['id']]['down'] = $val['down']; } $this->assign('commentTotall', $commentTotall); $this->assign('list', $links); $this->assign('url_new_link', OW::getRouter()->urlForRoute('link-save-new')); $paging = new BASE_CMP_Paging($page, ceil($itemsCount / $rpp), 5); $this->assign('paging', $paging->render()); $this->assign('isAuthenticated', OW::getUser()->isAuthenticated()); }
public function index($params) { if (empty($params['list'])) { $params['list'] = 'latest'; } $plugin = OW::getPluginManager()->getPlugin('blogs'); OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'blogs', 'main_menu_item'); $this->setPageHeading(OW::getLanguage()->text('blogs', 'list_page_heading')); $this->setPageHeadingIconClass('ow_ic_write'); if (!OW::getUser()->isAdmin() && !OW::getUser()->isAuthorized('blogs', 'view')) { $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html'); return; } /* @var $service PostService */ $service = PostService::getInstance(); $page = !empty($_GET['page']) && intval($_GET['page']) > 0 ? $_GET['page'] : 1; $this->assign('addNew_isAuthorized', OW::getUser()->isAuthenticated() && OW::getUser()->isAuthorized('blogs', 'add')); $rpp = (int) OW::getConfig()->getValue('blogs', 'results_per_page'); $first = ($page - 1) * $rpp; $count = $rpp; $case = $params['list']; if (!in_array($case, array('latest', 'browse-by-tag', 'most-discussed', 'top-rated'))) { throw new Redirect404Exception(); } $showList = true; $isBrowseByTagCase = $case == 'browse-by-tag'; $contentMenu = $this->getContentMenu(); $contentMenu->getElement($case)->setActive(true); $this->addComponent('menu', $contentMenu); $this->assign('isBrowseByTagCase', $isBrowseByTagCase); $tagSearch = new BASE_CMP_TagSearch(OW::getRouter()->urlForRoute('blogs.list', array('list' => 'browse-by-tag'))); $this->addComponent('tagSearch', $tagSearch); $tagCloud = new BASE_CMP_EntityTagCloud('blog-post', OW::getRouter()->urlForRoute('blogs.list', array('list' => 'browse-by-tag'))); if ($isBrowseByTagCase) { $tagCloud->setTemplate(OW::getPluginManager()->getPlugin('base')->getCmpViewDir() . 'big_tag_cloud.html'); $tag = !empty($_GET['tag']) ? UTIL_HtmlTag::stripTags($_GET['tag']) : ''; $this->assign('tag', $tag); if (empty($tag)) { $showList = false; } } $this->addComponent('tagCloud', $tagCloud); $this->assign('showList', $showList); $list = array(); $itemsCount = 0; list($list, $itemsCount) = $this->getData($case, $first, $count); $posts = array(); $toolbars = array(); $userService = BOL_UserService::getInstance(); $authorIdList = array(); $previewLength = 50; foreach ($list as $item) { $dto = $item['dto']; $dto->setPost($dto->getPost()); $dto->setTitle(UTIL_String::truncate(strip_tags($dto->getTitle()), 65, '...')); $text = explode("<!--more-->", $dto->getPost()); $isPreview = count($text) > 1; if (!$isPreview) { $text = explode('<!--page-->', $text[0]); $showMore = count($text) > 1; } else { $showMore = true; } $text = $text[0]; $posts[] = array('dto' => $dto, 'text' => $text, 'showMore' => $showMore, 'url' => OW::getRouter()->urlForRoute('user-post', array('id' => $dto->getId()))); $authorIdList[] = $dto->authorId; $idList[] = $dto->getId(); } if (!empty($idList)) { $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($authorIdList, true, false); $this->assign('avatars', $avatars); $nlist = array(); foreach ($avatars as $userId => $avatar) { $nlist[$userId] = $avatar['title']; } $urls = BOL_UserService::getInstance()->getUserUrlsForList($authorIdList); $this->assign('toolbars', $this->getToolbar($idList, $list, $urls, $nlist)); } $this->assign('list', $posts); $this->assign('url_new_post', OW::getRouter()->urlForRoute('post-save-new')); $paging = new BASE_CMP_Paging($page, ceil($itemsCount / $rpp), 5); $this->addComponent('paging', $paging); }