Exemplo n.º 1
0
 public function index($params)
 {
     $plugin = OW::getPluginManager()->getPlugin('blogs');
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'blogs', 'main_menu_item');
     if (!OW::getUser()->isAdmin() && !OW::getUser()->isAuthorized('blogs', 'view')) {
         $status = BOL_AuthorizationService::getInstance()->getActionStatus('blogs', 'view');
         throw new AuthorizationException($status['msg']);
         return;
     }
     /*
      @var $service PostService
     */
     $service = PostService::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' => 'blogs_view_blog_posts', 'ownerId' => $author->getId(), 'viewerId' => OW::getUser()->getId());
     OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
     /* */
     $displaySocialSharing = true;
     try {
         $eventParams = array('action' => 'blogs_view_blog_posts', 'ownerId' => $author->getId(), 'viewerId' => 0);
         OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
     } catch (RedirectException $ex) {
         $displaySocialSharing = false;
     }
     if ($displaySocialSharing && !BOL_AuthorizationService::getInstance()->isActionAuthorizedForUser(0, 'blogs', 'view')) {
         $displaySocialSharing = false;
     }
     $this->assign('display_social_sharing', $displaySocialSharing);
     $displayName = $userService->getDisplayName($author->getId());
     $this->assign('author', $author);
     $this->assign('username', $author->getUsername());
     $this->assign('displayname', $displayName);
     $this->setPageHeading(OW::getLanguage()->text('blogs', 'user_blog_page_heading', array('name' => $author->getUsername())));
     $this->setPageHeadingIconClass('ow_ic_write');
     $page = !empty($_GET['page']) && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1;
     $rpp = (int) OW::getConfig()->getValue('blogs', 'results_per_page');
     $first = ($page - 1) * $rpp;
     $count = $rpp;
     if (!empty($_GET['month'])) {
         $archive_params = htmlspecialchars($_GET['month']);
         $arr = explode('-', $archive_params);
         $month = $arr[0];
         $year = $arr[1];
         $lb = mktime(null, null, null, $month, 1, $year);
         $ub = mktime(null, null, null, $month + 1, null, $year);
         $list = $service->findUserPostListByPeriod($author->getId(), $lb, $ub, $first, $count);
         $itemsCount = $service->countUserPostByPeriod($author->getId(), $lb, $ub);
         $l = OW::getLanguage();
         $arciveHeaderPart = ', ' . $l->text('base', "month_{$month}") . " {$year} " . $l->text('base', 'archive');
         OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'user_blog_archive_title', array('month_name' => $l->text('base', "month_{$month}"), 'display_name' => $displayName)));
         OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'user_blog_archive_description', array('year' => $year, 'month_name' => $l->text('base', "month_{$month}"), 'display_name' => $displayName)));
     } else {
         $list = $service->findUserPostList($author->getId(), $first, $count);
         $itemsCount = $service->countUserPost($author->getId());
         OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'user_blog_title', array('display_name' => $displayName)));
         OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'user_blog_description', array('display_name' => $displayName)));
     }
     $this->assign('archiveHeaderPart', !empty($arciveHeaderPart) ? $arciveHeaderPart : '');
     $posts = array();
     $commentInfo = array();
     $idList = array();
     foreach ($list as $dto) {
         $idList[] = $dto->getId();
         $dto_post = BASE_CMP_TextFormatter::fromBBtoHtml($dto->getPost());
         $dto->setPost($dto_post);
         $parts = explode('<!--more-->', $dto->getPost());
         if (!empty($parts)) {
             $text = $parts[0];
             //$text = UTIL_HtmlTag::sanitize($text);
         } else {
             $text = $dto->getPost();
         }
         $posts[] = array('id' => $dto->getId(), 'href' => OW::getRouter()->urlForRoute('user-post', array('id' => $dto->getId())), 'title' => UTIL_String::truncate($dto->getTitle(), 65, '...'), 'text' => $text, 'truncated' => count($parts) > 1 ? true : false);
     }
     if (!empty($idList)) {
         $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('blog-post', $idList);
         $this->assign('commentInfo', $commentInfo);
         $tagsInfo = BOL_TagService::getInstance()->findTagListByEntityIdList('blog-post', $idList);
         $this->assign('tagsInfo', $tagsInfo);
         $tb = array();
         foreach ($list as $dto) {
             $tb[$dto->getId()] = array(array('label' => UTIL_DateTime::formatDate($dto->timestamp)));
             //if ( $commentInfo[$dto->getId()] )
             //{
             $tb[$dto->getId()][] = array('href' => OW::getRouter()->urlForRoute('post', array('id' => $dto->getId())), 'label' => '<span class="ow_outline">' . $commentInfo[$dto->getId()] . '</span> ' . OW::getLanguage()->text('blogs', 'toolbar_comments'));
             //}
             if ($tagsInfo[$dto->getId()]) {
                 $tags =& $tagsInfo[$dto->getId()];
                 $t = OW::getLanguage()->text('blogs', 'tags');
                 for ($i = 0; $i < (count($tags) > 3 ? 3 : count($tags)); $i++) {
                     $t .= " <a href=\"" . OW::getRouter()->urlForRoute('blogs.list', 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);
     }
     $this->assign('list', $posts);
     $info = array('lastPost' => $service->findUserLastPost($author->getId()), 'author' => $author);
     $this->assign('info', $info);
     $paging = new BASE_CMP_Paging($page, ceil($itemsCount / $rpp), 5);
     $this->assign('paging', $paging->render());
     $rows = $service->findUserArchiveData($author->getId());
     $archive = array();
     foreach ($rows as $row) {
         if (!array_key_exists($row['y'], $archive)) {
             $archive[$row['y']] = array();
         }
         $archive[$row['y']][] = $row['m'];
     }
     $this->assign('archive', $archive);
     $this->assign('my_drafts_url', OW::getRouter()->urlForRoute('blog-manage-drafts'));
     if (OW::getUser()->isAuthenticated()) {
         $isOwner = $params['user'] == OW::getUser()->getUserObject()->getUsername() ? true : false;
     } else {
         $isOwner = false;
     }
     $this->assign('isOwner', $isOwner);
 }
Exemplo n.º 2
0
 public function index($params)
 {
     $username = !empty($params['user']) ? $params['user'] : '';
     $id = $params['id'];
     $plugin = OW::getPluginManager()->getPlugin('blogs');
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'blogs', 'main_menu_item');
     $service = PostService::getInstance();
     $userService = BOL_UserService::getInstance();
     $this->assign('user', OW::getUser()->getId() !== null ? $userService->findUserById(OW::getUser()->getId()) : null);
     $post = $service->findById($id);
     if ($post === null) {
         throw new Redirect404Exception();
     }
     if ($post->isDraft() && $post->authorId != OW::getUser()->getId()) {
         throw new Redirect404Exception();
     }
     $post->post = BASE_CMP_TextFormatter::fromBBtoHtml($post->post);
     $post->setTitle(strip_tags($post->getTitle()));
     if (!OW::getUser()->isAuthorized('blogs', 'view')) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     if (OW::getUser()->isAuthenticated() && OW::getUser()->getId() != $post->getAuthorId() && !OW::getUser()->isAuthorized('blogs', 'view')) {
         $this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
         return;
     }
     /* Check privacy permissions */
     if ($post->authorId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('blogs')) {
         $eventParams = array('action' => 'blogs_view_blog_posts', 'ownerId' => $post->authorId, 'viewerId' => OW::getUser()->getId());
         OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
     }
     /* */
     $parts = explode('<!--page-->', $post->getPost());
     $page = !empty($_GET['page']) ? $_GET['page'] : 1;
     $count = count($parts);
     if (strlen($username) > 0) {
         $author = $userService->findByUsername($username);
     } else {
         $author = $userService->findUserById($post->getAuthorId());
         $isAuthorExists = !empty($author);
         if ($isAuthorExists) {
             $username = $author->getUsername();
         }
     }
     $this->assign('isAuthorExists', $isAuthorExists);
     if ($isAuthorExists) {
         $displayName = $userService->getDisplayName($author->getId());
         $this->assign('username', $userService->getUserName($author->getId()));
         $this->assign('displayname', $displayName);
         $url = OW::getRouter()->urlForRoute('user-blog', array('user' => $username));
         $this->setPageHeading(OW::getLanguage()->text('blogs', 'view_page_heading', array('url' => $url, 'name' => $displayName, 'postTitle' => htmlspecialchars($post->getTitle()))));
         $this->setPageHeadingIconClass('ow_ic_write');
         OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'blog_post_title', array('post_title' => htmlspecialchars($post->getTitle()), 'display_name' => $displayName)));
         $post_body = UTIL_String::truncate($post->getPost(), 200, '...');
         $postTagsArray = BOL_TagService::getInstance()->findEntityTags($post->getId(), 'blog-post');
         $postTags = "";
         foreach ($postTagsArray as $tag) {
             $postTags .= $tag->label . ", ";
         }
         $postTags = substr($postTags, 0, -2);
         OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'blog_post_description', array('post_body' => htmlspecialchars(strip_tags($post_body)), 'tags' => htmlspecialchars($postTags))));
         //OW::getDocument()->setKeywords(OW::getLanguage()->text('nav', 'page_default_keywords').", ".$postTags);
     }
     $info = array('dto' => $post, 'text' => $parts[$page - 1]);
     $this->assign('info', $info);
     if ($isAuthorExists) {
         //blog navigation
         $prev = $service->findAdjacentUserPost($author->getId(), $post->getId(), 'prev');
         $next = $service->findAdjacentUserPost($author->getId(), $post->getId(), 'next');
         if (!empty($prev)) {
             $prevUser = $userService->findUserById($prev->getAuthorId());
         }
         if (!empty($next)) {
             $nextUser = $userService->findUserById($next->getAuthorId());
         }
         $this->assign('adjasentUrl', array('next' => !empty($nextUser) ? OW::getRouter()->urlForRoute('user-post', array('id' => $next->getId(), 'user' => $nextUser->getUsername())) : '', 'prev' => !empty($prevUser) ? OW::getRouter()->urlForRoute('user-post', array('id' => $prev->getId(), 'user' => $prevUser->getUsername())) : '', 'index' => OW::getRouter()->urlForRoute('user-blog', array('user' => $author->getUsername()))));
     } else {
         $this->assign('adjasentUrl', null);
     }
     //~blog navigation
     //toolbar
     $tb = array();
     $toolbarEvent = new BASE_CLASS_EventCollector('blogs.collect_post_toolbar_items', array('postId' => $post->id, 'postDto' => $post));
     OW::getEventManager()->trigger($toolbarEvent);
     foreach ($toolbarEvent->getData() as $toolbarItem) {
         array_push($tb, $toolbarItem);
     }
     if (OW::getUser()->isAuthenticated() && $post->getAuthorId() != OW::getUser()->getId()) {
         $js = UTIL_JsGenerator::newInstance()->jQueryEvent('#blog_post_toolbar_flag', 'click', UTIL_JsGenerator::composeJsString('OW.flagContent({$entity}, {$id}, {$title}, {$href}, "blogs+flags");', array('entity' => 'blog_post', 'id' => $post->getId(), 'title' => htmlspecialchars(json_encode($post->getTitle())), 'href' => OW::getRouter()->urlForRoute('user-post', array('id' => $post->getId())))));
         OW::getDocument()->addOnloadScript($js, 1001);
         $tb[] = array('label' => OW::getLanguage()->text('base', 'flag'), 'href' => 'javascript://', 'id' => 'blog_post_toolbar_flag');
     }
     if (OW::getUser()->isAuthenticated() && (OW::getUser()->getId() == $post->getAuthorId() || BOL_AuthorizationService::getInstance()->isModerator(OW::getUser()->getId()))) {
         $tb[] = array('href' => OW::getRouter()->urlForRoute('post-save-edit', array('id' => $post->getId())), 'label' => OW::getLanguage()->text('blogs', 'toolbar_edit'));
         $tb[] = array('href' => OW::getRouter()->urlFor('BLOGS_CTRL_Save', 'delete', array('id' => $post->getId())), 'click' => "return confirm('" . OW::getLanguage()->text('base', 'are_you_sure') . "');", 'label' => OW::getLanguage()->text('blogs', 'toolbar_delete'));
     }
     $this->assign('tb', $tb);
     //~toolbar
     $paging = new BASE_CMP_Paging($page, $count, $count);
     //<ARCHIVE-NAVIGATOR>
     $this->assign('paging', $paging->render());
     if ($isAuthorExists) {
         $rows = $service->findUserArchiveData($author->getId());
         $archive = array();
         foreach ($rows as $row) {
             if (!array_key_exists($row['y'], $archive)) {
                 $archive[$row['y']] = array();
             }
             $archive[$row['y']][] = $row['m'];
         }
         $this->assign('archive', $archive);
     }
     //</ARCHIVE-NAVIGATOR>
     if ($isAuthorExists) {
         $this->assign('author', $author);
     }
     $this->assign('isModerator', OW::getUser()->isAuthorized('blogs'));
     if ($isAuthorExists) {
         $this->assign('userBlogUrl', OW::getRouter()->urlForRoute('user-blog', array('user' => $author->getUsername())));
     }
     /* Check comments privacy permissions */
     $allow_comments = true;
     if ($post->authorId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('blogs')) {
         $eventParams = array('action' => 'blogs_comment_blog_posts', 'ownerId' => $post->authorId, 'viewerId' => OW::getUser()->getId());
         try {
             OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
         } catch (RedirectException $ex) {
             $allow_comments = false;
         }
     }
     /* */
     // additional components
     $cmpParams = new BASE_CommentsParams('blogs', 'blog-post');
     $cmpParams->setEntityId($post->getId())->setOwnerId($post->getAuthorId())->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_BOTTOM_FORM_WITH_FULL_LIST)->setAddComment($allow_comments);
     $this->addComponent('comments', new BASE_CMP_Comments($cmpParams));
     $this->assign('avatarUrl', '');
     $tagCloud = new BASE_CMP_EntityTagCloud('blog-post', OW::getRouter()->urlForRoute('blogs.list', array('list' => 'browse-by-tag')));
     $tagCloud->setEntityId($post->getId());
     $rateInfo = new BASE_CMP_Rate('blogs', 'blog-post', $post->getId(), $post->getAuthorId());
     $this->addComponent('rate', $rateInfo);
     $this->addComponent('tagCloud', $tagCloud);
     //~ additional components
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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')));
 }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
 /**
  * Convert BB tegs to html
  * @param  string $txt
  * @param  array $tagList
  *
  * example :
  * $tagList = array(
  *      array(
  *          'tag' => 'a',
  *          'pair' = true,
  *          'attributes' => array( 'href' )
  *      )
  * };
  *
  * @return string
  *
  */
 public static function fromBBtoHtml($txt, array $tagList = null)
 {
     if (empty($tagList)) {
         $tagList = self::$tagList;
     }
     $result = $txt;
     foreach ($tagList as $tag) {
         if (empty($tag['tag']) || !isset($tag['pair'])) {
             continue;
         }
         $tagName = $tag['tag'];
         $pair = $tag['pair'];
         $attributes = !empty($tag['attributes']) && is_array($tag['attributes']) ? $tag['attributes'] : array();
         $pairRegexp = $pair ? '(.*?)?\\[[\\s]*\\/[\\s]*' . $tagName . '\\s*\\]' : '';
         $regexp = '/\\[\\s*' . $tagName . '\\s*.*?\\]' . $pairRegexp . '/s';
         preg_match_all($regexp, $result, $matches);
         if (preg_match_all($regexp, $result, $matches)) {
             foreach ($matches[0] as $key => $match) {
                 $attr = '';
                 $tagString = $match;
                 foreach ($attributes as $attribute) {
                     if (preg_match('/' . $attribute . '=\'.*?\'/', $tagString, $attrMatches)) {
                         $attr .= $attrMatches[0] . ' ';
                     } else {
                         if (preg_match('/' . $attribute . '=".*?"/', $tagString, $attrMatches)) {
                             $attr .= $attrMatches[0] . ' ';
                         }
                     }
                 }
                 $string = '<' . $tagName . ' ' . $attr;
                 if ($pair) {
                     $string .= '>';
                 } else {
                     $string .= '/>';
                 }
                 if ($pair && !empty($matches[1][$key])) {
                     $innerHtml = $matches[1][$key];
                     $string .= $innerHtml . '</' . $tagName . '>';
                 }
                 $result = BASE_CMP_TextFormatter::mbStrReplace($result, $tagString, $string);
             }
         }
     }
     return $result;
 }