示例#1
0
 public function execute()
 {
     $post_id = max(0, waRequest::get('id', 0, waRequest::TYPE_INT));
     if (!$post_id) {
         throw new waException(_w('Post not found'), 404);
     }
     $post_model = new blogPostModel();
     $search_options = array('id' => $post_id);
     $extend_options = array('comments' => array(20), 'user' => array('photo_url_50'), 'status' => 'view');
     $post = $post_model->search($search_options, $extend_options)->fetchSearchItem();
     if (!$post) {
         throw new waException(_w('Post not found'), 404);
     }
     $post['rights'] = $this->getRights("blog.{$post['blog_id']}");
     $posts = array(&$post);
     blogHelper::extendRights($posts, array(), $this->getUser()->getId());
     blogPhotosBridge::loadAlbums($posts);
     if (isset($post['comments']) && $post['comments']) {
         $post['comments'] = blogCommentModel::extendRights($post['comments'], array($post_id => $post));
     }
     $blog_model = new blogBlogModel();
     $blog = $blog_model->getById($post['blog_id']);
     if ($blog['status'] != blogBlogModel::STATUS_PUBLIC || $post['status'] != blogPostModel::STATUS_PUBLISHED) {
         blogHelper::checkRights($post['blog_id'], true, blogRightConfig::RIGHT_READ);
     }
     $items = $blog_model->prepareView(array($blog));
     $blog = array_shift($items);
     $this->setLayout(new blogDefaultLayout());
     $this->getResponse()->setTitle($post['title']);
     /**
      * Backend post view page
      * UI hook allow extends post view page
      * @event backend_post
      * @param array[string]mixed $post Current page post item data
      * @param array[string]int $post['id'] Post ID
      * @param array[string]int $post['blog_id'] Post blog ID
      * @return array[string][string]string $backend_post['%plugin_id%']['footer'] Plugin %plugin_id% footer html
      */
     $this->view->assign('backend_post', wa()->event('backend_post', $post, array('footer')));
     $user = $this->getUser();
     $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto(20)));
     $this->view->assign('blog_id', $blog['id']);
     $this->view->assign('blog', $blog);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     if ($this->getConfig()->getOption('can_use_smarty')) {
         try {
             $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
         } catch (SmartyException $ex) {
             $post['text'] = blogPost::handleTemplateException($ex, $post);
         }
     }
     $this->view->assign('post', $post);
 }
 public function execute()
 {
     $rss_author_tag = null;
     if ($blog_id = $this->getRequest()->param('blog_id')) {
         $rss_posts_number = max(1, $this->appSettings('rss_posts_number', 10));
         $rss_author_tag = $this->appSettings('rss_author_tag');
         $options = array();
         $data = array();
         switch ($rss_author_tag) {
             case 'blog':
                 $blog_model = new blogBlogModel();
                 $data['blog'] = $blog_model->getByField(array('id' => $blog_id), 'id');
                 break;
             default:
                 $data['blog'] = blogHelper::getAvailable();
                 break;
         }
         $options['params'] = true;
         $options['user'] = '******';
         $post_model = new blogPostModel();
         $posts = $post_model->search(array('blog_id' => $blog_id), $options, $data)->fetchSearchPage(1, $rss_posts_number);
         blogPhotosBridge::loadAlbums($posts);
     } else {
         $posts = array();
     }
     $link = wa()->getRouteUrl('blog/frontend', array(), true);
     $rss_link = wa()->getRouteUrl('blog/frontend/rss', array(), true);
     $title = waRequest::param('rss_title') ? waRequest::param('rss_title') : wa()->accountName();
     $this->view->assign('info', array('title' => $title, 'link' => $link, 'description' => '', 'language' => 'ru', 'pubDate' => date(DATE_RSS), 'lastBuildDate' => date(DATE_RSS), 'self' => $rss_link));
     $this->view->assign('blog_name', $this->getResponse()->getTitle());
     $this->view->assign('rss_author_tag', $rss_author_tag);
     if ($this->getConfig()->getOption('can_use_smarty')) {
         foreach ($posts as &$post) {
             try {
                 $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
             } catch (SmartyException $ex) {
                 $post['text'] = blogPost::handleTemplateException($ex, $post);
             }
         }
         unset($post);
     }
     foreach ($posts as &$post) {
         if (is_array($post['user']['email'])) {
             $post['user']['email'] = reset($post['user']['email']);
         }
     }
     unset($post);
     $this->view->assign('posts', $posts);
     $this->getResponse()->addHeader('Content-Type', 'application/rss+xml; charset=utf-8');
 }
 public function frontendExecute()
 {
     $post_slug = waRequest::param('post_url', false, waRequest::TYPE_STRING_TRIM);
     $storage = wa()->getStorage();
     $post_model = new blogPostModel();
     $show_comments = $this->appSettings('show_comments', true);
     $request_captcha = $show_comments && $this->appSettings('request_captcha', true);
     $require_authorization = $show_comments && $this->appSettings('require_authorization', false);
     $available = blogHelper::getAvailable();
     // it's preview
     $hash = waRequest::get('preview');
     $post = $post_model->search(array('url' => $post_slug, 'status' => $hash ? false : blogPostModel::STATUS_PUBLISHED), array('comments' => $show_comments ? array(50, 20) : false, 'params' => true, 'escape' => true), array('blog' => $available))->fetchSearchItem();
     if (!$post) {
         throw new waException(_w('Post not found'), 404);
     }
     if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
         $hash = base64_decode($hash);
         list($hash, $user_id) = array(substr($hash, 0, 32), substr($hash, 32));
         $options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => $user_id);
         $preview_cached_options = $storage->read('preview');
         $preview_cached_post_options = isset($preview_cached_options['post_id']) ? $preview_cached_options['post_id'] : null;
         if ($preview_cached_post_options && $preview_cached_post_options != $options) {
             $preview_cached_post_options = null;
         }
         if (!$preview_cached_post_options) {
             if ($hash == blogPostModel::getPreviewHash($options, false, false)) {
                 $preview_cached_options['post_id'] = $preview_cached_post_options = $options;
                 $storage->write('preview', $preview_cached_options);
             }
         }
         if (!$preview_cached_post_options) {
             throw new waException(_w('Post not found'), 404);
         }
         if (!$this->checkAuthorRightsToBlog($user_id, $post)) {
             throw new waException(_w('Post not found'), 404);
         }
     }
     $title = $this->getResponse()->getTitle();
     if ($this->getRequest()->param('title_type', 'blog_post') == 'blog_post') {
         if ($title) {
             $this->getResponse()->setTitle($title . " » " . $post['title']);
         } elseif (isset($available[$post['blog_id']]) && ($title = $available[$post['blog_id']]['title'])) {
             $this->getResponse()->setTitle($title . " » " . $post['title']);
         } else {
             $this->getResponse()->setTitle($post['title']);
         }
     } else {
         $this->getResponse()->setTitle($post['title']);
     }
     $blog_id = (array) $this->getRequest()->param('blog_id');
     if (!in_array($post['blog_id'], $blog_id)) {
         if ($this->getRequest()->param('blog_url_type') == 0) {
             if (isset($available[$post['blog_id']])) {
                 $this->redirect($post['link'], 301);
             }
         }
         throw new waException(_w('Post not found'), 404);
     }
     $this->getRequest()->setParam('blog_id', $post['blog_id']);
     if (isset($post['comments']) && !empty($post['comments'])) {
         $depth = 1000;
         foreach ($post['comments'] as $key => $comment) {
             if ($comment['status'] == blogCommentModel::STATUS_DELETED) {
                 if ($comment['depth'] < $depth) {
                     $depth = $comment['depth'];
                 }
                 unset($post['comments'][$key]);
                 continue;
             }
             if ($comment['depth'] > $depth) {
                 unset($post['comments'][$key]);
             } else {
                 $depth = 1000;
             }
         }
     }
     $errors = array();
     $form = array();
     if ($storage->read('errors') !== null) {
         $errors = $storage->read('errors');
         $form = $storage->read('form');
         $storage->remove('errors');
         $storage->remove('form');
     }
     $post['comment_link'] = blogPost::getUrl($post, 'comment');
     $post['link'] = blogPost::getUrl($post);
     /**
      * Frontend post view page
      * UI hook allow extends frontend post view page
      * @event frontend_post
      * @param array[string]mixed $post
      * @param array[string]int $post['id']
      * @param array[string]int $post['blog_id']
      * @return array[string][string]string $return[%plugin_id%]
      * @return array[string][string]string $return[%plugin_id%]['footer']
      */
     $this->view->assign('frontend_post', wa()->event('frontend_post', $post));
     $this->view->assign('errors', $errors);
     $this->view->assign('form', $form);
     $this->view->assign('show_comments', $show_comments);
     $this->view->assign('request_captcha', $request_captcha);
     $this->view->assign('require_authorization', $require_authorization);
     $this->view->assign('theme', waRequest::param('theme', 'default'));
     $app_url = wa()->getAppStaticUrl();
     $root_url = wa()->getRootUrl();
     $storage = wa()->getStorage();
     $current_auth = $storage->read('auth_user_data');
     $current_auth_source = $current_auth ? $current_auth['source'] : null;
     $this->view->assign('current_auth_source', $current_auth_source);
     $this->view->assign('current_auth', $current_auth, true);
     $adapters = wa()->getAuthAdapters();
     $this->view->assign('auth_adapters', $adapters);
     $this->view->getHelper()->globals($this->getRequest()->param());
     if ($this->getConfig()->getOption('can_use_smarty')) {
         try {
             $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
         } catch (SmartyException $ex) {
             $post['text'] = blogPost::handleTemplateException($ex, $post);
         }
     }
     $this->view->assign('post', $post);
 }
示例#4
0
 public function execute()
 {
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable($this->getUser());
     $stream = array('all_posts' => false);
     $title_suffix = '';
     $search_options = array();
     // native search
     if ($text = waRequest::get('text', '')) {
         $text = urldecode($text);
         $search_options['text'] = $text;
         $title_suffix = " / {$text}";
     }
     // plugins' search
     if ($plugin = waRequest::get('search', false)) {
         $search_options["plugin"] = array();
         if (is_array($plugin)) {
             foreach ($plugin as $plugin_id => $plugin_params) {
                 $search_options["plugin"][$plugin_id] = $plugin_params;
             }
         } else {
             $search_options["plugin"][$plugin] = waRequest::get($plugin, true);
         }
     }
     if ($blog_id = max(0, waRequest::get('blog', null, waRequest::TYPE_INT))) {
         if (!isset($blogs[$blog_id])) {
             throw new waException(_w('Blog not found'), 404);
         }
         wa()->getStorage()->write('blog_last_id', $blog_id);
         $blog =& $blogs[$blog_id];
         $stream['title'] = $blog['name'];
         $stream['link'] = $this->getUrl($blog);
         $stream['blog'] = $blog;
         $search_options['blog_id'] = $blog_id;
     } else {
         if (empty($search_options["plugin"])) {
             $stream['title'] = _w('All posts');
             $stream['link'] = $this->getUrl();
             $stream['all_posts'] = true;
         } else {
             $stream['title'] = '';
             $stream['link'] = '';
         }
         $stream['blog'] = null;
         $search_options['blog_id'] = array_keys($blogs);
     }
     $this->getResponse()->setTitle($stream['title'] . $title_suffix);
     $search = false;
     $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
     $posts_per_page = max(1, intval($this->getConfig()->getOption('posts_per_page')));
     $extend_options = array();
     $extend_options['status'] = 'view';
     $extend_options['author_link'] = false;
     $extend_options['rights'] = true;
     if (!$this->getRequest()->isMobile()) {
         $extend_options['text'] = 'cut';
     }
     $post_model = new blogPostModel();
     $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchPage($page, $posts_per_page);
     // Add photo albums to posts
     blogPhotosBridge::loadAlbums($posts);
     if ($page == 1) {
         $stream['title'] = $this->getResponse()->getTitle();
         $this->chooseLayout();
         $this->view->assign('search', $plugin ? urldecode(http_build_query(array('search' => $plugin))) : null);
         /**
          * Backend posts stream view page
          * UI hook allow extends backend posts view page
          * @event backend_stream
          * @param array[string]mixed $stream Array of stream properties
          * @param array[string]array $stream['blog'] Related blog data array or null
          * @param array[string]string $stream['title'] Stream title
          * @param array[string]string $stream['link'] Stream link
          * @return array[string][string]string $return['%plugin_id%']['menu'] Stream context menu html
          */
         $this->view->assign('backend_stream', wa()->event('backend_stream', $stream, array('menu')));
     }
     $posts_count = ($page - 1) * $posts_per_page + count($posts);
     $import_link = null;
     if ($posts_count <= 0 && !empty($stream['all_posts'])) {
         // When import plugin is installed, show its link on the welcome page
         $plugins = wa()->getConfig()->getPlugins();
         if (!empty($plugins['import'])) {
             $import_link = wa()->getUrl() . '?module=plugins#/settings/custom/import/';
         }
     }
     $this->view->assign('blogs', $blogs);
     $this->view->assign('blog_id', $blog_id);
     $this->view->assign('text', $text);
     $this->view->assign('stream', $stream);
     $this->view->assign('page', $page);
     $this->view->assign('pages', $post_model->pageCount());
     $this->view->assign('posts_total_count', $post_model->searchCount());
     $this->view->assign('posts_count', $posts_count);
     $this->view->assign('import_link', $import_link);
     $this->view->assign('posts_per_page', $posts_per_page);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     if ($this->getConfig()->getOption('can_use_smarty')) {
         foreach ($posts as &$post) {
             try {
                 $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
             } catch (SmartyException $ex) {
                 $post['text'] = blogPost::handleTemplateException($ex, $post);
             }
         }
         unset($post);
     }
     $this->view->assign('posts', $posts);
 }
 public function execute()
 {
     if ($this->getRequest()->param('blog_id') === false) {
         throw new waException(_w('Blog not found'), 404);
     }
     $this->view->getHelper()->globals($this->getRequest()->param());
     $posts_per_page = max(1, intval($this->getConfig()->getOption('posts_per_page')));
     $post_model = new blogPostModel();
     $options = array();
     if (!$this->appSettings('show_comments', true)) {
         $options['comments'] = false;
     }
     $options['params'] = true;
     $options['text'] = 'cut';
     $options['escape'] = true;
     $is_search = false;
     if (isset($this->search_params["search"])) {
         $plugin = $this->search_params["search"];
         if (!isset($this->search_params["plugin"])) {
             $this->search_params["plugin"] = array();
         }
         if (isset($this->search_params[$plugin])) {
             $this->search_params["plugin"][$plugin] = $this->search_params[$plugin];
             $is_search = true;
         }
     }
     $query = $this->getRequest()->get('query', '', waRequest::TYPE_STRING_TRIM);
     if ($query) {
         $this->search_params['text'] = urldecode($query);
         $options['highlighted'] = true;
     }
     $blogs = blogHelper::getAvailable();
     $posts = $post_model->search($this->search_params, $options, array('blog' => $blogs))->fetchSearchPage($this->page, $posts_per_page);
     $stream_title = false;
     if (isset($this->search_params['contact_id'])) {
         if (count($posts)) {
             reset($posts);
             $post = current($posts);
             $name = $post['user']['name'];
             $is_search = true;
         } else {
             if ($contact = blogHelper::getContactInfo($this->search_params['contact_id'])) {
                 $name = htmlentities($contact['name'], ENT_QUOTES, 'utf-8');
                 $is_search = true;
             } else {
                 throw new waException(_w('Blog not found'), 404);
             }
         }
         $stream_title = sprintf(_w('Posts by %s'), $name);
         $this->getResponse()->setTitle($stream_title);
     } elseif ($is_search) {
         $stream_title = $this->getResponse()->getTitle();
     } elseif (isset($this->search_params['year'])) {
         $stream_title = '';
         if (isset($this->search_params['day'])) {
             $stream_title .= intval($this->search_params['day']) . ' ';
         }
         if (isset($this->search_params['month'])) {
             $stream_title .= _ws(date("F", gmmktime(0, 0, 0, intval($this->search_params['month']), 1))) . ' ';
         }
         $stream_title .= $this->search_params['year'] . ' — ' . $this->getResponse()->getTitle();
         $this->getResponse()->setTitle($stream_title);
     } else {
         if (!empty($this->search_params['text'])) {
             $stream_title = urldecode($this->search_params['text']);
             $this->getResponse()->setTitle($stream_title);
             $is_search = true;
         }
     }
     $this->view->assign('stream_title', $stream_title);
     $pages = $post_model->pageCount();
     $url = wa()->getRouteUrl('blog/frontend', $this->search_params, true);
     if ($pages && $pages < $this->page) {
         $page = min($pages, $this->page);
         $redirect = $url . ($page > 1 ? "?page={$page}" : '');
         $this->getResponse()->redirect($redirect, 302);
     }
     if ($layout = $this->getLayout()) {
         $links = array();
         if ($pages > $this->page) {
             $page = $this->page + 1;
             $links['next'] = "{$url}?page={$page}";
         }
         if ($this->page > 1) {
             $page = $this->page - 1;
             $links['prev'] = $url . ($page > 1 ? "?page={$page}" : '');
         }
         $layout->assign('links', $links);
         if (!$is_search) {
             /*
              * @deprecated fix assigning sidebar_timeline for next version of blog
              * */
             $layout->assign('sidebar_timeline', $post_model->getTimeline($this->search_params['blog_id'], $blogs, $this->search_params));
         }
         if (isset($this->search_params['contact_id'])) {
             $layout->assign('action_info', array('search' => array('contact_id' => $this->search_params['contact_id'])));
         }
         $layout->assign('is_search', $is_search);
     }
     $this->view->assign('is_search', $is_search);
     $this->view->assign('page', $this->page);
     $this->view->assign('is_lazyloading', $this->is_lazyloading);
     $this->view->assign('pages', $pages);
     $this->view->assign('post_count', $post_model->searchCount());
     $this->view->assign('show_comments', !isset($options['comments']) || $options['comments']);
     $this->view->assign('posts_per_page', $posts_per_page);
     $this->view->assign('blog_query', $query);
     /**
      * Backward compatibility with older themes
      * @deprecated
      */
     $this->view->assign('is_concrete_blog', waRequest::param('blog_url') ? true : false);
     $this->view->assign('layout_type', $this->is_lazyloading ? 'lazyloading' : ($this->page > 1 ? 'page' : 'default'));
     if ($this->getConfig()->getOption('can_use_smarty')) {
         foreach ($posts as &$post) {
             try {
                 $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
             } catch (SmartyException $ex) {
                 $post['text'] = blogPost::handleTemplateException($ex, $post);
             }
         }
         unset($post);
     }
     $this->view->assign('posts', $posts);
     if ($this->cache_time && false) {
         $this->cache->set(array_keys($posts));
     }
 }