Beispiel #1
0
 public function __construct()
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $this->setPageHeading(OW::getLanguage()->text('blogs', 'management_page_heading'));
     $this->setPageHeadingIconClass('ow_ic_write');
     $this->language = OW::getLanguage();
     $this->service = PostService::getInstance();
     $this->addComponent('menu', new BLOGS_CMP_ManagementMenu());
 }
Beispiel #2
0
 public function __construct(BASE_CLASS_WidgetParameter $params)
 {
     parent::__construct();
     $service = PostService::getInstance();
     $count = $params->customParamList['count'];
     $previewLength = $params->customParamList['previewLength'];
     $list = $service->findList(0, $count);
     if ((empty($list) || false && !OW::getUser()->isAuthorized('blogs', 'add') && !OW::getUser()->isAuthorized('blogs', 'view')) && !$params->customizeMode) {
         $this->setVisible(false);
         return;
     }
     $posts = array();
     $userService = BOL_UserService::getInstance();
     $postIdList = array();
     foreach ($list as $dto) {
         /* @var $dto Post */
         if (mb_strlen($dto->getTitle()) > 50) {
             $dto->setTitle(UTIL_String::splitWord(UTIL_String::truncate($dto->getTitle(), 50, '...')));
         }
         $text = $service->processPostText($dto->getPost());
         $posts[] = array('dto' => $dto, 'text' => UTIL_String::splitWord(UTIL_String::truncate($text, $previewLength)), 'truncated' => mb_strlen($text) > $previewLength, 'url' => OW::getRouter()->urlForRoute('user-post', array('id' => $dto->getId())));
         $idList[] = $dto->getAuthorId();
         $postIdList[] = $dto->id;
     }
     $commentInfo = array();
     if (!empty($idList)) {
         $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($idList, true, false);
         $this->assign('avatars', $avatars);
         $urls = BOL_UserService::getInstance()->getUserUrlsForList($idList);
         $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('blog-post', $postIdList);
         $toolbars = array();
         foreach ($list as $dto) {
             $toolbars[$dto->getId()] = array(array('class' => 'ow_icon_control ow_ic_user', 'href' => isset($urls[$dto->getAuthorId()]) ? $urls[$dto->getAuthorId()] : '#', 'label' => isset($avatars[$dto->getAuthorId()]['title']) ? $avatars[$dto->getAuthorId()]['title'] : ''), array('class' => 'ow_remark ow_ipc_date', 'label' => UTIL_DateTime::formatDate($dto->getTimestamp())));
         }
         $this->assign('tbars', $toolbars);
     }
     $this->assign('commentInfo', $commentInfo);
     $this->assign('list', $posts);
     if ($service->countPosts() > 0) {
         $toolbar = array();
         if (OW::getUser()->isAuthorized('blogs', 'add')) {
             $toolbar[] = array('label' => OW::getLanguage()->text('blogs', 'add_new'), 'href' => OW::getRouter()->urlForRoute('post-save-new'));
         }
         if (OW::getUser()->isAuthorized('blogs', 'view')) {
             $toolbar[] = array('label' => OW::getLanguage()->text('blogs', 'go_to_blog'), 'href' => Ow::getRouter()->urlForRoute('blogs'));
         }
         if (!empty($toolbar)) {
             $this->setSettingValue(self::SETTING_TOOLBAR, $toolbar);
         }
     }
 }
Beispiel #3
0
 public function __construct(BASE_CLASS_WidgetParameter $paramObj)
 {
     parent::__construct();
     /* @var $service PostService */
     $service = PostService::getInstance();
     $userId = $paramObj->additionalParamList['entityId'];
     if ($userId != OW::getUser()->getId()) {
         $this->isVisible(false);
         return;
     }
     $this->assign('count', (int) $service->countUserPost($userId));
     $this->assign('commentCount', $service->countUserPostComment($userId));
     $this->assign('draftCount', (int) $service->countUserDraft($userId));
 }
Beispiel #4
0
 public function index()
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     $this->setPageHeading(OW::getLanguage()->text('blogs', 'management_page_heading'));
     $this->setPageHeadingIconClass('ow_ic_write');
     $this->addComponent('menu', new BLOGS_CMP_ManagementMenu());
     $service = PostService::getInstance();
     $userId = OW::getUser()->getId();
     $page = empty($_GET['page']) ? 1 : $_GET['page'];
     $this->assign('thisUrl', OW_URL_HOME . OW::getRequest()->getRequestUri());
     $rpp = 5;
     $first = ($page - 1) * $rpp;
     $count = $rpp;
     $list = $service->findUserPostCommentList($userId, $first, $count);
     $authorIdList = array();
     $postList = array();
     foreach ($list as $id => $item) {
         if (!empty($info[$item['userId']])) {
             continue;
         }
         $list[$id]['url'] = OW::getRouter()->urlForRoute('user-post', array('id' => $item['entityId']));
         $postList[$item['entityId']] = $service->findById($item['entityId']);
         $authorIdList[] = $item['userId'];
     }
     $usernameList = array();
     $displayNameList = array();
     $avatarUrlList = array();
     if (!empty($authorIdList)) {
         $userService = BOL_UserService::getInstance();
         $usernameList = $userService->getUserNamesForList($authorIdList);
         $displayNameList = $userService->getDisplayNamesForList($authorIdList);
         $avatarUrlList = BOL_AvatarService::getInstance()->getAvatarsUrlList($authorIdList);
     }
     $this->assign('postList', $postList);
     $this->assign('usernameList', $usernameList);
     $this->assign('displaynameList', $displayNameList);
     $this->assign('avatarUrlList', $avatarUrlList);
     $this->assign('list', $list);
     $itemCount = $service->countUserPostComment($userId);
     $pageCount = ceil($itemCount / $rpp);
     $this->addComponent('paging', new BASE_CMP_Paging($page, $pageCount, 5));
 }
Beispiel #5
0
 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 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);
 }
Beispiel #7
0
 public function process($ctrl)
 {
     OW::getCacheManager()->clean(array(PostDao::CACHE_TAG_POST_COUNT));
     $service = PostService::getInstance();
     /* @var $postDao PostService */
     $data = $this->getValues();
     $data['title'] = UTIL_HtmlTag::stripJs($data['title']);
     $postIsNotPublished = $this->post->getStatus() == 2;
     $text = UTIL_HtmlTag::sanitize($data['post']);
     /* @var $post Post */
     $this->post->setTitle($data['title']);
     $this->post->setPost($text);
     $this->post->setIsDraft($_POST['command'] == 'draft');
     $isCreate = empty($this->post->id);
     if ($isCreate) {
         $this->post->setTimestamp(time());
         //Required to make #698 and #822 work together
         if ($_POST['command'] == 'draft') {
             $this->post->setIsDraft(2);
         }
         BOL_AuthorizationService::getInstance()->trackAction('blogs', 'add_blog');
     } else {
         //If post is not new and saved as draft, remove their item from newsfeed
         if ($_POST['command'] == 'draft') {
             OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'blog-post', 'entityId' => $this->post->id)));
         } else {
             if ($postIsNotPublished) {
                 // Update timestamp if post was published for the first time
                 $this->post->setTimestamp(time());
             }
         }
     }
     $service->save($this->post);
     $tags = array();
     if (intval($this->post->getId()) > 0) {
         $tags = $data['tf'];
         foreach ($tags as $id => $tag) {
             $tags[$id] = UTIL_HtmlTag::stripTags($tag);
         }
     }
     $tagService = BOL_TagService::getInstance();
     $tagService->updateEntityTags($this->post->getId(), 'blog-post', $tags);
     if ($this->post->isDraft()) {
         $tagService->setEntityStatus('blog-post', $this->post->getId(), false);
         if ($isCreate) {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_draft_success_msg'));
         } else {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_draft_success_msg'));
         }
     } else {
         $tagService->setEntityStatus('blog-post', $this->post->getId(), true);
         //Newsfeed
         $event = new OW_Event('feed.action', array('pluginKey' => 'blogs', 'entityType' => 'blog-post', 'entityId' => $this->post->getId(), 'userId' => $this->post->getAuthorId()));
         OW::getEventManager()->trigger($event);
         if ($isCreate) {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_success_msg'));
             OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_ADD, array('postId' => $this->post->getId())));
         } else {
             OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_success_msg'));
             OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_EDIT, array('postId' => $this->post->getId())));
         }
         $ctrl->redirect(OW::getRouter()->urlForRoute('post', array('id' => $this->post->getId())));
     }
 }
Beispiel #8
0
 public function countBlogPosts()
 {
     return PostService::getInstance()->countPosts();
 }
Beispiel #9
0
 public function sosialSharingGetBlogInfo(OW_Event $event)
 {
     $params = $event->getParams();
     $data = $event->getData();
     $data['display'] = false;
     if (empty($params['entityId'])) {
         return;
     }
     if ($params['entityType'] == 'blogs') {
         $blogtDto = PostService::getInstance()->findById($params['entityId']);
         $displaySocialSharing = true;
         try {
             $eventParams = array('action' => 'blogs_view_blog_posts', 'ownerId' => $blogtDto->getAuthorId(), 'viewerId' => 0);
             OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
         } catch (RedirectException $ex) {
             $displaySocialSharing = false;
         }
         if ($displaySocialSharing && (!BOL_AuthorizationService::getInstance()->isActionAuthorizedForGuest('blogs', 'view') || $blogtDto->isDraft())) {
             $displaySocialSharing = false;
         }
         if (!empty($blogtDto)) {
             $data['display'] = $displaySocialSharing;
         }
         $event->setData($data);
     }
 }
Beispiel #10
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
 }
Beispiel #11
0
 public function updateBlogsPrivacy($userId, $privacy)
 {
     $count = $this->countUserPost($userId);
     $entities = PostService::getInstance()->findUserPostList($userId, 0, $count);
     $entityIds = array();
     foreach ($entities as $post) {
         $entityIds[] = $post->getId();
     }
     $status = $privacy == 'everybody' ? true : false;
     $event = new OW_Event('base.update_entity_items_status', array('entityType' => 'blog-post', 'entityIds' => $entityIds, 'status' => $status));
     OW::getEventManager()->trigger($event);
     $this->dao->updateBlogsPrivacy($userId, $privacy);
     OW::getCacheManager()->clean(array(PostDao::CACHE_TAG_POST_COUNT));
 }
Beispiel #12
0
 public function approve($params)
 {
     if (!OW::getUser()->isAuthenticated()) {
         throw new AuthenticateException();
     }
     if (!OW::getUser()->isAuthorized('blogs')) {
         throw new Redirect403Exception();
     }
     //TODO trigger event for content moderation;
     $postId = $params['id'];
     $postDto = PostService::getInstance()->findById($postId);
     if (!$postDto) {
         throw new Redirect404Exception();
     }
     $backUrl = OW::getRouter()->urlForRoute('post', array('id' => $postId));
     $event = new OW_Event("moderation.approve", array("entityType" => PostService::FEED_ENTITY_TYPE, "entityId" => $postId));
     OW::getEventManager()->trigger($event);
     $data = $event->getData();
     if (empty($data)) {
         $this->redirect($backUrl);
     }
     if ($data["message"]) {
         OW::getFeedback()->info($data["message"]);
     } else {
         OW::getFeedback()->error($data["error"]);
     }
     $this->redirect($backUrl);
 }
 private function __construct()
 {
     $this->service = PostService::getInstance();
 }
Beispiel #14
0
 public function __construct(BASE_CLASS_WidgetParameter $params)
 {
     parent::__construct();
     $service = PostService::getInstance();
     if (empty($params->additionalParamList['entityId'])) {
     }
     $userId = $params->additionalParamList['entityId'];
     if ($userId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('blogs', 'view')) {
         $this->setVisible(false);
         return;
     }
     /* Check privacy permissions */
     $eventParams = array('action' => PostService::PRIVACY_ACTION_VIEW_BLOG_POSTS, 'ownerId' => $userId, 'viewerId' => OW::getUser()->getId());
     try {
         OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
     } catch (RedirectException $ex) {
         $this->setVisible(false);
         return;
     }
     /* */
     if ($service->countUserPost($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'];
     $userPostList = $service->findUserPostList($userId, 0, $count);
     foreach ($userPostList as $id => $item) {
         /* Check privacy permissions */
         if ($item->authorId != OW::getUser()->getId() && !OW::getUser()->isAuthorized('blogs')) {
             $eventParams = array('action' => PostService::PRIVACY_ACTION_VIEW_BLOG_POSTS, 'ownerId' => $item->authorId, 'viewerId' => OW::getUser()->getId());
             try {
                 OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
             } catch (RedirectException $ex) {
                 continue;
             }
         }
         /* */
         $list[$id] = $item;
         $list[$id]->setPost(strip_tags($item->getPost()));
         $idList[] = $item->id;
     }
     $commentInfo = array();
     if (!empty($idList)) {
         $commentInfo = BOL_CommentService::getInstance()->findCommentCountForEntityList('blog-post', $idList);
         $tb = array();
         foreach ($list as $key => $item) {
             if (mb_strlen($item->getPost()) > 100) {
                 $list[$key]->setPost(UTIL_String::splitWord(UTIL_String::truncate($item->getPost(), 100, '...')));
             }
             if (mb_strlen($item->getTitle()) > 50) {
                 $list[$key]->setTitle(UTIL_String::splitWord(UTIL_String::truncate($item->getTitle(), 50, '...')));
             }
             if ($commentInfo[$item->getId()] == 0) {
                 $comments_tb_link = array('label' => '', 'href' => '');
             } else {
                 $comments_tb_link = array('label' => '<span class="ow_txt_value">' . $commentInfo[$item->getId()] . '</span> ' . OW::getLanguage()->text('blogs', 'toolbar_comments'), 'href' => OW::getRouter()->urlForRoute('post', array('id' => $item->getId())));
             }
             $tb[$item->getId()] = array($comments_tb_link, array('label' => UTIL_DateTime::formatDate($item->getTimestamp()), 'class' => 'ow_ic_date'));
         }
         $this->assign('tb', $tb);
     }
     $itemList = array();
     foreach ($list as $post) {
         $itemList[] = array('dto' => $post, 'titleHref' => OW::getRouter()->urlForRoute('user-post', array('id' => $post->getId())));
     }
     $this->assign('list', $itemList);
     $user = BOL_UserService::getInstance()->findUserById($userId);
     $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => OW::getLanguage()->text('blogs', 'view_all'), 'href' => OW::getRouter()->urlForRoute('user-blog', array('user' => $user->getUsername())))));
 }
Beispiel #15
0
 private function getData($case, $first, $count)
 {
     $service = PostService::getInstance();
     $list = array();
     $itemsCount = 0;
     switch ($case) {
         case 'most-discussed':
             OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'most_discussed_title'));
             OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'most_discussed_description'));
             $commentService = BOL_CommentService::getInstance();
             $info = array();
             $info = $commentService->findMostCommentedEntityList('blog-post', $first, $count);
             $idList = array();
             foreach ($info as $item) {
                 $idList[] = $item['id'];
             }
             if (empty($idList)) {
                 break;
             }
             $dtoList = $service->findListByIdList($idList);
             foreach ($dtoList as $dto) {
                 if ($dto->isDraft()) {
                     continue;
                 }
                 $info[$dto->id]['dto'] = $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('blog-post');
             break;
         case 'top-rated':
             OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'top_rated_title'));
             OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'top_rated_description'));
             $info = array();
             $info = BOL_RateService::getInstance()->findMostRatedEntityList('blog-post', $first, $count);
             $idList = array();
             foreach ($info as $item) {
                 $idList[] = $item['id'];
             }
             if (empty($idList)) {
                 break;
             }
             $dtoList = $service->findListByIdList($idList);
             foreach ($dtoList as $dto) {
                 if ($dto->isDraft()) {
                     continue;
                 }
                 $list[] = array('dto' => $dto, 'avgScore' => $info[$dto->id]['avgScore'], 'ratesCount' => $info[$dto->id]['ratesCount']);
             }
             function sortTopRated($e, $e2)
             {
                 if ($e['avgScore'] == $e2['avgScore']) {
                     if ($e['ratesCount'] == $e2['ratesCount']) {
                         return 0;
                     }
                     return $e['ratesCount'] < $e2['ratesCount'];
                 }
                 return $e['avgScore'] < $e2['avgScore'];
             }
             usort($list, 'sortTopRated');
             $itemsCount = BOL_RateService::getInstance()->findMostRatedEntityCount('blog-post');
             break;
         case 'browse-by-tag':
             if (empty($_GET['tag'])) {
                 $mostPopularTagsArray = BOL_TagService::getInstance()->findMostPopularTags('blog-post', 20);
                 $mostPopularTags = "";
                 foreach ($mostPopularTagsArray as $tag) {
                     $mostPopularTags .= $tag['label'] . ", ";
                 }
                 OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'browse_by_tag_title'));
                 OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'browse_by_tag_description', array('tags' => $mostPopularTags)));
                 break;
             }
             $info = BOL_TagService::getInstance()->findEntityListByTag('blog-post', UTIL_HtmlTag::stripTags($_GET['tag']), $first, $count);
             $itemsCount = BOL_TagService::getInstance()->findEntityCountByTag('blog-post', UTIL_HtmlTag::stripTags($_GET['tag']));
             foreach ($info as $item) {
                 $idList[] = $item;
             }
             if (empty($idList)) {
                 break;
             }
             $dtoList = $service->findListByIdList($idList);
             function sortByTimestamp($post1, $post2)
             {
                 return $post1->timestamp < $post2->timestamp;
             }
             usort($dtoList, 'sortByTimestamp');
             foreach ($dtoList as $dto) {
                 if ($dto->isDraft()) {
                     continue;
                 }
                 $list[] = array('dto' => $dto);
             }
             OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'browse_by_tag_item_title', array('tag' => UTIL_HtmlTag::stripTags($_GET['tag']))));
             OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'browse_by_tag_item_description', array('tag' => UTIL_HtmlTag::stripTags($_GET['tag']))));
             break;
         case 'latest':
             OW::getDocument()->setTitle(OW::getLanguage()->text('blogs', 'latest_title'));
             OW::getDocument()->setDescription(OW::getLanguage()->text('blogs', 'latest_description'));
             $arr = $service->findList($first, $count);
             foreach ($arr as $item) {
                 $list[] = array('dto' => $item);
             }
             $itemsCount = $service->countPosts();
             break;
     }
     return array($list, $itemsCount);
 }