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 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))); }
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 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; }