public function execute()
 {
     $routes = $this->getRoutes();
     $app_id = wa()->getApp();
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url'));
     foreach ($routes as $route) {
         $lastmod = null;
         $this->routing->setRoute($route);
         $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0;
         $default_blog_id = max(0, $default_blog_id);
         $extend_options = array('datetime' => true);
         $extend_data = array('blog' => $blogs);
         foreach ($blogs as $blog_id => $blog) {
             if (!$default_blog_id || $blog_id == $default_blog_id) {
                 $search_options = array('blog_id' => $blog_id);
                 $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id');
                 foreach ($posts as $post) {
                     $post['blog_url'] = $blog['url'];
                     $post_lastmod = strtotime($post['datetime']);
                     $lastmod = max($lastmod, $post_lastmod);
                     if (!empty($post['comment_datetime'])) {
                         $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime']));
                     }
                     $this->addUrl($post['link'], $post_lastmod);
                 }
             }
         }
         $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true), $lastmod);
     }
 }
 public function defaultAction()
 {
     // When viewed from a public dashboard, pretend we're logged in
     $old_user = $user = $this->getUser();
     if (wa()->getUser()->getId() != $user->getId()) {
         $old_user = wa()->getUser();
         wa()->setUser($user);
     }
     $filter = $this->getSettings('filter', 'all');
     $blogs = blogHelper::getAvailable();
     $blog_ids = array_keys($blogs);
     $comments = $this->getComments(array('blog_id' => $blog_ids, 'filter' => $filter, 'offset' => 0, 'limit' => 6));
     wa()->setUser($old_user);
     // get related posts info
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     $post_model = new blogPostModel();
     $extend_data = array('blog' => $blogs);
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     $this->display(array('blogs' => $blogs, 'posts' => $posts, 'comments' => $comments, 'filter' => $filter));
 }
 public function defaultAction()
 {
     // When viewed from a public dashboard, pretend we're logged in
     $old_user = $user = $this->getUser();
     if (wa()->getUser()->getId() != $user->getId()) {
         $old_user = wa()->getUser();
         wa()->setUser($user);
     }
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable(wa()->getUser());
     $blog_id = $this->getSettings('blog_id');
     if ($blog_id && !empty($blogs[$blog_id])) {
         $blog_ids = array($blog_id);
     } else {
         $blog_ids = array_keys($blogs);
     }
     $post_model = new blogPostModel();
     $posts = $post_model->search(array('blog_id' => $blog_ids), array('status' => 'view', 'author_link' => false, 'rights' => true, 'text' => 'cut'), array('blog' => $blogs))->fetchSearchPage(1, 1);
     wa()->setUser($old_user);
     $post = reset($posts);
     $blog = false;
     if ($post && !empty($blogs[$post['blog_id']])) {
         $blog = $blogs[$post['blog_id']];
     }
     $this->display(array('blog' => $blog, 'post' => $post));
 }
Esempio n. 4
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()
 {
     $contact_photo_size = 20;
     $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page')));
     $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
     $blog_models = new blogBlogModel();
     $user = $this->getUser();
     $blogs = blogHelper::getAvailable();
     $comment_model = new blogCommentModel();
     $offset = $comments_per_page * ($page - 1);
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $comments = $comment_model->getList($offset, $comments_per_page, $blog_ids, $fields, $prepare_options);
     $comments_all_count = $comment_model->getCount($blog_ids, null, null, null, null, null);
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     $comments_count = ($page - 1) * $comments_per_page + count($comments);
     if ($page == 1) {
         $this->setLayout(new blogDefaultLayout());
         $this->getResponse()->setTitle(_w('Comments'));
     }
     /**
      * Backend comments view page
      * UI hook allow extends backend comments view page
      * @event backend_comments
      * @param array[int][string]mixed $comments
      * @param array[int][string]int $comments[%id%][id] comment id
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html
      */
     $this->view->assign('backend_comments', wa()->event('backend_comments', $comments));
     $this->view->assign('comments', $comments);
     $this->view->assign('comments_count', $comments_count);
     $this->view->assign('comments_total_count', $comments_all_count);
     $this->view->assign('comments_per_page', $comments_per_page);
     $this->view->assign('pages', ceil($comments_all_count / $comments_per_page));
     $this->view->assign('page', $page);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     $this->view->assign('current_contact_id', $user->getId());
     $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size)));
 }
Esempio n. 6
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');
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $post_model = new blogPostModel();
     $post = $post_model->search(array('id' => $id))->fetchSearchItem();
     if ($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);
         }
         $this->response = $post;
     } else {
         throw new waAPIException('invalid_param', 'Post not found', 404);
     }
 }
 public function execute()
 {
     $hash = $this->get('hash');
     $offset = waRequest::get('offset', 0, 'int');
     if ($offset < 0) {
         throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero');
     }
     $limit = waRequest::get('limit', 100, 'int');
     if ($limit < 0) {
         throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero');
     }
     if ($limit > 1000) {
         throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000');
     }
     $options = array();
     $hash = explode('/', trim($hash, '/'));
     $hash[1] = isset($hash[1]) ? $hash[1] : '';
     switch ($hash[0]) {
         case 'blog':
             $options['blog_id'] = (int) $hash[1];
             break;
         case 'contact':
         case 'author':
             $options['contact_id'] = (int) $hash[1];
             break;
         case 'search':
             $options['text'] = $hash[1];
             break;
         case 'tag':
             // use plugin
             $options['plugin'] = array('tag' => $hash[1]);
             break;
     }
     if ($options) {
         $post_model = new blogPostModel();
         $posts = $post_model->search($options)->fetchSearch($offset, $limit);
     } else {
         $posts = array();
     }
     $this->response['count'] = count($posts);
     $this->response['offset'] = $offset;
     $this->response['limit'] = $limit;
     $this->response['posts'] = array_values($posts);
 }
 public function execute()
 {
     $routes = $this->getRoutes();
     $app_id = wa()->getApp();
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $page_model = new blogPageModel();
     $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url'));
     $real_domain = $this->routing->getDomain(null, true, false);
     foreach ($routes as $route) {
         $lastmod = null;
         $this->routing->setRoute($route);
         $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0;
         $default_blog_id = max(0, $default_blog_id);
         $extend_options = array('datetime' => true);
         $extend_data = array('blog' => $blogs);
         foreach ($blogs as $blog_id => $blog) {
             if (!$default_blog_id || $blog_id == $default_blog_id) {
                 $search_options = array('blog_id' => $blog_id);
                 $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id');
                 foreach ($posts as $post) {
                     $post['blog_url'] = $blog['url'];
                     $post_lastmod = strtotime($post['datetime']);
                     $lastmod = max($lastmod, $post_lastmod);
                     if (!empty($post['comment_datetime'])) {
                         $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime']));
                     }
                     $this->addUrl($post['link'], $post_lastmod);
                 }
             }
         }
         // pages
         $main_url = wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain);
         $domain = $this->routing->getDomain(null, true);
         $sql = "SELECT full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . '
                 WHERE status = 1 AND domain = s:domain AND route = s:route';
         $pages = $page_model->query($sql, array('domain' => $domain, 'route' => $route['url']))->fetchAll();
         foreach ($pages as $p) {
             $this->addUrl($main_url . $p['full_url'], $p['update_datetime'] ? $p['update_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.6);
         }
         $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain), $lastmod, self::CHANGE_DAILY, 1.0);
     }
 }
 public function defaultAction()
 {
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable(wa()->getUser());
     $blog_id = $this->getSettings('blog_id');
     if ($blog_id && !empty($blogs[$blog_id])) {
         $blog_ids = array($blog_id);
     } else {
         $blog_ids = array_keys($blogs);
     }
     $search_options = array('blog_id' => $blog_ids);
     $extend_options = array('status' => 'view', 'author_link' => false, 'rights' => true, 'text' => 'cut');
     $post_model = new blogPostModel();
     $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchPage(1, 1);
     $post = reset($posts);
     $blog = false;
     if ($post && !empty($blogs[$post['blog_id']])) {
         $blog = $blogs[$post['blog_id']];
     }
     $this->display(array('blog' => $blog, 'post' => $post));
 }
 /**
  * protected backend preview
  * @throws waException
  * @return void
  */
 public function backendExecute()
 {
     $post_id = waRequest::param('post_id', false, waRequest::TYPE_INT);
     if ($post_id) {
         $post_model = new blogPostModel();
         $show_comments = $this->appSettings('show_comments', true);
         $photo_sizes = array(50, 20);
         $search_options = array('id' => $post_id, 'status' => false);
         if (!$this->getUser()->isAdmin($this->getApp())) {
             $search_options['contact_id'] = $this->getUser()->getId();
         }
         $post = $post_model->search($search_options, array('comments' => false))->fetchSearchItem();
     }
     if (!isset($post)) {
         throw new waException(_w('Post not found'), 404);
     }
     $this->view->assign('post', $post);
 }
 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));
     }
 }
Esempio n. 13
0
 public function execute()
 {
     $user = $this->getUser();
     $filter = waRequest::get('filter');
     $contact_settings = new waContactSettingsModel();
     if (!$filter) {
         $filter = $contact_settings->getOne($user->getId(), $this->getAppId(), 'comments_filter');
         if (!$filter) {
             $filter = 'myposts';
         }
     } else {
         $contact_settings->set($user->getId(), $this->getAppId(), 'comments_filter', $filter);
     }
     $contact_photo_size = 20;
     $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page')));
     $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
     $blogs = blogHelper::getAvailable();
     $offset = $comments_per_page * ($page - 1);
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $data = $this->getComments(array('offset' => $offset, 'limit' => $comments_per_page, 'blog_id' => $blog_ids, 'filter' => $filter), $fields, $prepare_options);
     $comments = $data['comments'];
     $comments_all_count = $data['comments_all_count'];
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     $comments_count = ($page - 1) * $comments_per_page + count($comments);
     if ($page == 1) {
         $this->setLayout(new blogDefaultLayout());
         $this->getResponse()->setTitle(_w('Comments'));
     }
     /**
      * Backend comments view page
      * UI hook allow extends backend comments view page
      * @event backend_comments
      * @param array[int][string]mixed $comments
      * @param array[int][string]int $comments[%id%][id] comment id
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html
      */
     $this->view->assign('backend_comments', wa()->event('backend_comments', $comments, array('toolbar')));
     $this->view->assign('comments', $comments);
     $this->view->assign('comments_count', $comments_count);
     $this->view->assign('comments_total_count', $comments_all_count);
     $this->view->assign('comments_per_page', $comments_per_page);
     $this->view->assign('pages', ceil($comments_all_count / $comments_per_page));
     $this->view->assign('page', $page);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     $this->view->assign('current_contact_id', $user->getId());
     $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size)));
     $this->view->assign('filter', $filter);
     $yet_authors_exist = false;
     if ($blogs) {
         $yet_authors_exist = !!$post_model->select('contact_id')->where('blog_id IN (' . implode(',', $blog_ids) . ') AND contact_id != ' . $user->getId())->limit(1)->fetchField();
     }
     $this->view->assign('blogs', $blogs);
     $this->view->assign('yet_authors_exist', $yet_authors_exist);
 }
 public function execute()
 {
     $this->user = $this->getUser();
     $blog_id = waRequest::get('blog', null, 'int');
     $post_id = waRequest::get('id', null, 'int');
     $request = waRequest::get();
     $module = waRequest::get('module');
     $action = waRequest::get('action');
     if (!$action) {
         $action = waRequest::get('module');
     }
     $view_all_posts = waRequest::get('all', null) !== null || empty($request);
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable($this->user, array(), null, array('new' => true, 'expire' => 1, 'link' => false));
     $blog_ids = array_keys($blogs);
     $comment_model = new blogCommentModel();
     $comment_count = $comment_model->getCount($blog_ids);
     $activity_datetime = blogActivity::getUserActivity();
     $comment_new_count = $comment_model->getCount($blog_ids, null, $activity_datetime, 1);
     $post_count = 0;
     $new_post_count = 0;
     $writable_blogs = false;
     foreach ($blogs as $blog) {
         $post_count += $blog['qty'];
         if ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
             $writable_blogs = true;
         }
         if (isset($blog['new_post']) && $blog['new_post'] > 0) {
             $new_post_count += $blog['new_post'];
         }
     }
     if ($writable_blogs) {
         $post_model = new blogPostModel();
         $search_options = array('status' => array(blogPostModel::STATUS_DRAFT, blogPostModel::STATUS_DEADLINE, blogPostModel::STATUS_SCHEDULED));
         if (!$this->user->isAdmin($this->getApp())) {
             $search_options['contact_id'] = $this->user->getId();
         }
         $search_options['sort'] = 'overdue';
         $drafts = $post_model->search($search_options, array('status' => true, 'link' => false, 'plugin' => false, 'comments' => false), array('blog' => $blogs))->fetchSearchAll(false);
         $where = "status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime <= '" . waDateTime::date("Y-m-d") . "'";
         if (!$this->getUser()->isAdmin($this->getApp())) {
             $where .= " AND contact_id = {$this->getUser()->getId()}";
             $where .= " AND blog_id IN (" . implode(', ', array_keys($blogs)) . ")";
         }
         $count_overdue = $post_model->select("count(id)")->where($where)->fetchField();
         $count_overdue = $count_overdue ? $count_overdue : 0;
     } else {
         $drafts = false;
         $count_overdue = false;
     }
     /**
      * Extend backend sidebar
      * Add extra sidebar items (menu items, additional sections, system output)
      * @event backend_sidebar
      * @example #event handler example
      * public function sidebarAction()
      * {
      *     $output = array();
      *
      *     #add external link into sidebar menu
      *     $output['menu']='<li>
      *         <a href="http://www.webasyst.com">
      *             http://www.webasyst.com
      *         </a>
      *     </li>';
      *
      *     #add section into sidebar menu
      *     $output['section']='';
      *
      *     #add system link into sidebar menu
      *     $output['system']='';
      *
      *     return $output;
      * }
      * @return array[string][string]string $return[%plugin_id%]['menu'] Single menu items
      * @return array[string][string]string $return[%plugin_id%]['section'] Sections menu items
      * @return array[string][string]string $return[%plugin_id%]['system'] Extra menu items
      */
     $this->view->assign('backend_sidebar', wa()->event('backend_sidebar'));
     $this->view->assign('blog_id', $blog_id);
     $this->view->assign('blogs', $blogs);
     $this->view->assign('view_all_posts', $view_all_posts);
     $this->view->assign('action', $action);
     $this->view->assign('module', $module);
     $this->view->assign('post_id', $post_id);
     $this->view->assign('new_post', waRequest::get('action') == 'edit' && waRequest::get('id') == '');
     $this->view->assign('drafts', $drafts);
     $this->view->assign('comment_count', $comment_count);
     $this->view->assign('comment_new_count', $comment_new_count);
     $this->view->assign('post_count', $post_count);
     $this->view->assign('new_post_count', $new_post_count);
     $this->view->assign('count_draft_overdue', $count_overdue);
     $this->view->assign('writable_blogs', $writable_blogs);
 }
Esempio n. 15
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 comments($blog_id = null, $limit = 10)
 {
     $contact_photo_size = 20;
     $limit = max(1, intval($limit));
     $blogs = blogHelper::getAvailable(true, $blog_id);
     $comment_model = new blogCommentModel();
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $comments = $comment_model->getList(0, $limit, $blog_ids, $fields);
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     self::escape($comments, array('*' => array('posts' => array('text' => true), 'plugins' => true)));
     return $comments;
 }
 public function execute()
 {
     $this->getResponse()->setTitle(_w('Calendar'));
     $this->setLayout(new blogDefaultLayout());
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $blogs = $blog_model->getAvailable($this->getUser());
     $timezone = wa()->getUser()->getTimezone();
     // Y-m-d -> 2011-01-01
     $month_date = waRequest::get("month");
     if (!$month_date) {
         $month_date = waDateTime::date("Y-m", null, $timezone);
     } elseif ($month_date <= "1970" || $month_date >= "2033" || !strtotime($month_date)) {
         $this->redirect("?action=calendar");
     }
     $month_date = strtotime($month_date);
     $days_count = date("t", $month_date);
     // Numeric representation of the day of the week
     $first_day = date("w", $month_date);
     $last_day = date("w", strtotime(date("Y-m-{$days_count}", $month_date)));
     // first day is 'Sunday'
     if (waLocale::getFirstDay() == 7) {
         $first_day += 1;
         $last_day += 1;
     }
     $first_day = $first_day == 0 ? 6 : $first_day - 1;
     $last_day = $last_day == 0 ? 0 : 7 - $last_day;
     $date_start = strtotime("-" . $first_day . " days", $month_date);
     $date_end = strtotime("+" . ($days_count + $last_day) . " days", $month_date);
     $search_options = array();
     $search_options['datetime'] = array(date("Y-m-d", $date_start), date("Y-m-d", $date_end));
     $search_options['blog_id'] = array_keys($blogs);
     $search_options['status'] = false;
     if (!$this->getUser()->isAdmin($this->getApp())) {
         $search_options['contact_id'] = $this->getUser()->getId();
     }
     $extend_options = array('status' => true, 'user' => false, 'rights' => true);
     $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchAll(false);
     $current_date_start = $date_start;
     $days = array();
     do {
         $week = (int) date("W", $current_date_start);
         $day = (int) date("w", $current_date_start);
         if (waLocale::getFirstDay() == 7 && $day == 0) {
             $week = (int) date("W", strtotime("+1 week", $current_date_start));
         }
         if (!isset($days[$week])) {
             $days[$week] = array();
         }
         $days[$week][$day] = array("date" => array('day' => date("j", $current_date_start), 'month' => date("n", $current_date_start), 'date' => date("Y-m-d", $current_date_start)), "posts" => array());
         $current_date_start = strtotime("+1 days", $current_date_start);
     } while ($date_end > $current_date_start);
     foreach ($posts as $post) {
         #post.datetime cast to user timezone
         $week = (int) waDateTime::date("W", $post['datetime'], $timezone);
         $day = (int) waDateTime::date("w", $post['datetime'], $timezone);
         $days[$week][$day]["posts"][] = $post;
     }
     $now_date = waDateTime::date("Y-m-d", null, $timezone);
     $where = '';
     $search = false;
     if ($this->getUser()->isAdmin($this->getApp())) {
         $search = true;
     } else {
         $writeable = array();
         $full = array();
         foreach ($blogs as $id => $blog) {
             if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
                 $full[] = $id;
             } elseif ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
                 $writeable[] = $id;
             }
         }
         $contact_where = array();
         if ($full) {
             $contact_where[] = "blog_id IN (" . implode(', ', $full) . ")";
         }
         if ($writeable) {
             $contact_where[] .= "contact_id = {$this->getUser()->getId()} AND blog_id IN (" . implode(', ', $writeable) . ")";
         }
         if ($contact_where) {
             $search = true;
             $where .= ' AND ( (' . implode(') OR (', $contact_where) . ' ) )';
         }
     }
     if ($search) {
         $posts_overdue_prev = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime < '" . date("Y-m-d", $date_start) . "' " . $where)->limit(1)->fetchField('cnt');
         $posts_overdue_next = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime > '" . date("Y-m-d", $date_end) . "' AND datetime < '" . $now_date . "'" . $where)->limit(1)->fetchField('cnt');
         $prev_overdue = $posts_overdue_prev ? true : false;
         $next_overdue = $posts_overdue_next ? true : false;
     } else {
         $prev_overdue = false;
         $next_overdue = false;
     }
     $months = array(1 => _ws('January'), 2 => _ws('February'), 3 => _ws('March'), 4 => _ws('April'), 5 => _ws('May'), 6 => _ws('June'), 7 => _ws('July'), 8 => _ws('August'), 9 => _ws('September'), 10 => _ws('October'), 11 => _ws('November'), 12 => _ws('December'));
     $current_year = date('Y', $month_date);
     $current_month = date('Y', $month_date);
     $boundaries = $post_model->select("MIN(datetime) as min, MAX(datetime) as max")->fetch();
     if ($boundaries) {
         $years = range(min(date('Y', strtotime($boundaries['min'])), $current_year), max(date('Y', strtotime($boundaries['max'])), $current_year, date('Y')));
     } else {
         $now_year = date('Y');
         $years = range(min($current_year, $now_year), max($current_year, $now_year));
     }
     $this->view->assign("prev_overdue", $prev_overdue);
     $this->view->assign("next_overdue", $next_overdue);
     $this->view->assign("allow_add", $search);
     $this->view->assign("days", $days);
     $this->view->assign("week_first_sunday", waLocale::getFirstDay() == 7);
     $this->view->assign("current_month", date("n", $month_date));
     $this->view->assign("current_year", date("Y", $month_date));
     $this->view->assign("prev_month", date("Y-m", strtotime("-1 month", $month_date)));
     $this->view->assign("next_month", date("Y-m", strtotime("+1 month", $month_date)));
     $this->view->assign("years", $years);
     $this->view->assign("months", $months);
     // cast to user timezone
     $this->view->assign("today", waDateTime::date("j", null, $timezone));
     $this->view->assign("today_month", waDateTime::date("n", null, $timezone));
     $this->nocache();
 }