コード例 #1
0
 public function execute()
 {
     if (blogPhotosBridge::isEnabled()) {
         $this->uploadToPhotosApp();
     } else {
         $this->uploadToFilder();
     }
 }
コード例 #2
0
ファイル: blogPost.action.php プロジェクト: Lazary/webasyst
 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);
 }
コード例 #3
0
 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');
 }
コード例 #4
0
 public function execute()
 {
     $is_admin = $this->getUser()->isAdmin($this->getApp());
     $storage = $this->getStorage();
     if (waRequest::post('save')) {
         $this->save();
         $save_id = rand(10000, 99999);
         $storage->write('blog_setttings_save_id', $save_id);
         $this->redirect(array('module' => 'settings', 'save' => $save_id));
     }
     if ($is_admin) {
         $e_g = blogHelper::getAvailable();
         reset($e_g);
         $user = $this->getUser();
         $this->view->assign('e_g', current($e_g));
         $this->view->assign('user_email', $user->get('email', 'default'));
         // Checking if have saved now
         $save_id = $storage->read('blog_setttings_save_id');
     }
     // Checking if have saved now
     $save_id = $storage->read('blog_setttings_save_id');
     if ($save_id && $save_id == waRequest::get('save', 0)) {
         $storage->del('blog_setttings_save_id');
         $this->view->assign('saved', 1);
     }
     $this->getResponse()->setTitle(_w('Blog settings page'));
     $this->setLayout(new blogDefaultLayout());
     $this->view->assign('user_settings', $res = $this->getUserSettings());
     if ($is_admin) {
         $this->view->assign('backend_settings', $this->getFrontendSettings());
         // to mislead potential foes, apparently...
         $this->view->assign('routing_settings_url', blogHelper::getRouteSettingsUrl());
         $this->view->assign('photos_app_available', blogPhotosBridge::isAvailable());
     }
     $app_settings_model = new waAppSettingsModel();
     $this->view->assign('last_reminder_cron_time', $app_settings_model->get('blog', 'last_reminder_cron_time'));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog reminder');
 }
コード例 #5
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);
 }
コード例 #6
0
 /**
  * Prepare for saving posted post and return it
  *
  * @return array prepared post
  *
  */
 private function getPreparedPost()
 {
     $post = array('id' => waRequest::post('post_id', null, waRequest::TYPE_INT), 'title' => substr(waRequest::post('title', '', waRequest::TYPE_STRING_TRIM), 0, 255), 'text' => waRequest::post('text'), 'blog_id' => waRequest::post('blog_id'), 'contact_id' => waRequest::post('contact_id'), 'datetime' => waRequest::post('datetime'), 'url' => waRequest::post('url', '', waRequest::TYPE_STRING_TRIM), 'draft' => waRequest::post('draft'), 'comments_allowed' => max(0, min(1, waRequest::post('comments_allowed', 0, waRequest::TYPE_INT))), 'public' => waRequest::post('public'), 'schedule_datetime' => waRequest::post('schedule_datetime'), 'meta_title' => waRequest::post('meta_title', null, waRequest::TYPE_STRING_TRIM), 'meta_keywords' => waRequest::post('meta_keywords', null, waRequest::TYPE_STRING_TRIM), 'meta_description' => waRequest::post('meta_description', null, waRequest::TYPE_STRING_TRIM), 'album_id' => waRequest::post('album_id', null, waRequest::TYPE_INT), 'album_link_type' => waRequest::post('album_link_type', null, waRequest::TYPE_STRING_TRIM));
     if ($post['album_id'] && blogPhotosBridge::isAvailable()) {
         wa('photos');
         $album_model = new photosAlbumModel();
         $album = $album_model->getById($post['album_id']);
         if (!$album) {
             $album = $post['album_id'] = null;
         } else {
             if ($album['status'] <= 0) {
                 $post['album_link_type'] = null;
             }
         }
     } else {
         $post['album_id'] = null;
     }
     if (!$post['album_id']) {
         $post['album_id'] = $post['album_link_type'] = null;
     } else {
         if ($post['album_link_type'] != 'photos') {
             $post['album_link_type'] = 'blog';
         }
     }
     $this->inline = waRequest::post('inline', false);
     if (waRequest::post('scheduled') && !empty($post['schedule_datetime'])) {
         $post['datetime'] = $post['schedule_datetime'];
     }
     if (!is_null($post['datetime'])) {
         $post['datetime'] = (array) $post['datetime'];
         if (count($post['datetime']) == 3) {
             $post['datetime'][1] = (int) $post['datetime'][1];
             $post['datetime'][2] = (int) $post['datetime'][2];
             $date_time = $post['datetime'][0] . ' ' . $post['datetime'][1] . ':' . $post['datetime'][2];
         } else {
             $date_time = implode(' ', $post['datetime']);
         }
         $post['datetime'] = $date_time;
     }
     if (waRequest::post('draft')) {
         $post['status'] = blogPostModel::STATUS_DRAFT;
         $this->operation = self::OPERATION_SAVE_DRAFT;
     } else {
         if (waRequest::post('deadline')) {
             if ($post['datetime']) {
                 $post['status'] = blogPostModel::STATUS_DEADLINE;
                 $this->operation = self::OPERATION_SET_DEADLINE;
             } else {
                 $post['status'] = blogPostModel::STATUS_DRAFT;
                 $this->operation = self::OPERATION_SAVE_DRAFT;
             }
         } else {
             if (waRequest::post('scheduled')) {
                 $post['status'] = blogPostModel::STATUS_SCHEDULED;
             } else {
                 if (waRequest::post('published')) {
                     $post['status'] = blogPostModel::STATUS_PUBLISHED;
                     $this->operation = self::OPERATION_PUBLISH;
                 } else {
                     if (waRequest::post('unpublish')) {
                         $post['status'] = blogPostModel::STATUS_DRAFT;
                         $this->operation = self::OPERATION_UNPUBLISH;
                     } else {
                         if ($post['id'] && waRequest::issetPost('delete')) {
                             $this->operation = self::OPERATION_DELETE;
                         } else {
                             if (waRequest::issetPost("schedule_cancel")) {
                                 $this->operation = self::OPERATION_CANCEL_SCHEDULE;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!isset($post['status'])) {
         if ($post['id']) {
             $post['status'] = $this->post_model->select('status')->where('id = i:id', array('id' => $post['id']))->fetchField('status');
         } else {
             $post['status'] = blogPostModel::STATUS_DRAFT;
         }
     }
     $blog_model = new blogBlogModel();
     $blog = $blog_model->getById($post['blog_id']);
     $post['blog_status'] = $blog['status'];
     $post['plugin'] = (array) waRequest::post('plugin', null);
     foreach ($post['plugin'] as $k => &$plugin_data) {
         if (!is_array($plugin_data)) {
             $plugin_data = trim($plugin_data);
         }
     }
     return $post;
 }
コード例 #7
0
 public function execute()
 {
     $post_id = waRequest::get('id', null, waRequest::TYPE_INT);
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable();
     if (!$blogs) {
         $this->setTemplate('BlogNotFound');
         return;
     }
     $blogs = $blog_model->prepareView($blogs);
     $post_model = new blogPostModel();
     if ($post_id) {
         // edit post
         $post = $post_model->getById($post_id);
         if (!$post) {
             throw new waException(_w('Post not found'), 404);
         }
         //check rights
         if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != $this->getUser()->getId()) {
             throw new waRightsException(_w('Access denied'));
         }
         $post['datetime'] = $post['datetime'] >= 1971 ? $post['datetime'] : '';
         $blog_id = $post['blog_id'];
         $blog = $blogs[$blog_id];
         $title = trim(sprintf(_w('Editing post %s'), $post['title']));
     } else {
         // add post
         $date = waRequest::get('date', '');
         $blog = $this->getAllowedBlog($blogs, wa()->getStorage()->read('blog_last_id'));
         if (!$blog) {
             throw new waRightsException(_w('Access denied'));
         }
         $blog_id = $blog['id'];
         $post = array('status' => $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT, 'title' => $this->getRequest()->post('title', '', waRequest::TYPE_STRING_TRIM), 'text' => $this->getRequest()->post('text', '', waRequest::TYPE_STRING_TRIM), 'continued_text' => null, 'categories' => array(), 'contact_id' => wa()->getUser()->getId(), 'blog_id' => $blog_id) + $post_model->getEmptyRow();
         $title = _w('Adding new post');
     }
     // Album tree
     $albums = array();
     $photos_frontend_url = null;
     if (blogPhotosBridge::isAvailable()) {
         if ($post['album_link_type'] != 'photos') {
             $post['album_link_type'] = 'blog';
         }
         wa('photos');
         $album_model = new photosAlbumModel();
         $albums = $album_model->getAlbums();
         foreach ($albums as &$a) {
             if ($a['status'] == 1) {
                 $a['frontend_link'] = photosFrontendAlbum::getLink($a);
             } else {
                 $a['frontend_link'] = '';
             }
         }
         unset($a);
     }
     // Frontend URLs for this post
     $album_link_type = $post['album_link_type'];
     $post['album_link_type'] = 'blog';
     $all_links = blogPostModel::getPureUrls($post);
     $post['album_link_type'] = $album_link_type;
     $post['other_links'] = $all_links;
     $post['link'] = array_shift($post['other_links']);
     $post['remaining_time'] = null;
     if ($post['status'] == blogPostModel::STATUS_SCHEDULED && $post['datetime']) {
         $post['remaining_time'] = $this->calculateRemainingTime($post['datetime']);
     }
     if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
         $users = blogHelper::getAuthors($post['blog_id']);
     } else {
         $user = $this->getUser();
         $users = array($user->getId() => $user->getName());
     }
     // preview hash for all type of drafts
     if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
         $options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
         $preview_hash = blogPostModel::getPreviewHash($options);
         $this->view->assign('preview_hash', base64_encode($preview_hash . $options['user_id']));
     }
     $this->view->assign('albums', $albums);
     $this->view->assign('no_settlements', !wa()->getRouteUrl('blog/'));
     $this->view->assign('params', $this->getPostParams($post['id']));
     $this->view->assign('blog', $blog);
     $this->view->assign('users', $users);
     $this->view->assign('blogs', $blogs);
     $allow_change_blog = 0;
     foreach ($blogs as $blog_item) {
         if ($blog_item['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
             ++$allow_change_blog;
         }
     }
     $this->view->assign('allow_change_blog', $allow_change_blog);
     $this->view->assign('post_id', $post_id);
     $this->view->assign('datetime_timezone', waDateTime::date("T", null, wa()->getUser()->getTimezone()));
     /**
      * Backend post edit page
      * UI hook allow extends post edit page
      * @event backend_post_edit
      * @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%]['sidebar'] Plugin sidebar html output
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Plugin toolbar html output
      * @return array[string][string]string $return[%plugin_id%]['editor_tab'] Plugin editor tab html output
      */
     $this->view->assign('backend_post_edit', wa()->event('backend_post_edit', $post, array('sidebar', 'toolbar', 'editor_tab')));
     $app_settings = new waAppSettingsModel();
     $show_comments = $app_settings->get($this->getApp(), 'show_comments', true);
     $this->view->assign('show_comments', $show_comments);
     $this->view->assign('post', $post);
     /**
      * @deprecated
      * For backward compatibility reason
      */
     $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog'));
     $this->view->assign('last_schedule_cron_time', waSystem::getSetting('last_schedule_cron_time', 0, 'blog'));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog schedule');
     $this->setLayout(new blogDefaultLayout());
     $this->getResponse()->setTitle($title);
 }
コード例 #8
0
 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();
     $post_title = htmlspecialchars_decode($post['title'], ENT_QUOTES);
     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);
     }
     // meta title override default title
     if ($post['meta_title']) {
         $this->getResponse()->setTitle($post['meta_title']);
     }
     $this->getResponse()->setMeta('keywords', $post['meta_keywords']);
     $this->getResponse()->setMeta('description', $post['meta_description']);
     $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);
     $posts = array(&$post);
     blogPhotosBridge::loadAlbums($posts);
     /**
      * 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%]['footer']
      */
     $this->view->assign('frontend_post', wa()->event('frontend_post', $post, array('footer')));
     $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'));
     $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);
 }
コード例 #9
0
 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);
     blogPhotosBridge::loadAlbums($posts);
     $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));
     }
 }