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))); }
/** * @param array $items * @param array $options * @param array $extend_data * @return array */ public function prepareView($items, $options = array(), $extend_data = array()) { $extend_options = array_merge($this->extend_options, $options); $extend_data = array_merge($this->extend_data, (array) $extend_data); foreach ($items as &$item) { blogHelper::extendIcon($item); if (!isset($extend_options['link']) || $extend_options['link']) { $item['link'] = blogBlog::getUrl($item, true); } if (!empty($extend_options['escape'])) { $item['name'] = htmlspecialchars($item['name'], ENT_QUOTES, 'utf-8'); $item['link'] = htmlspecialchars($item['link'], ENT_QUOTES, 'utf-8'); } unset($item); } if (isset($options['new']) && $options['new']) { $post_model = new blogPostModel(); $blog_activity = blogActivity::getInstance(); $posts_update = $post_model->getAddedPostCount(blogActivity::getUserActivity(), array_keys($items), true); if ($posts_update) { foreach ($posts_update as $blog_id => $new) { if (isset($items[$blog_id])) { $items[$blog_id]['new_post'] = 0; $post_ids = explode(':', $new); foreach ($post_ids as $post_id) { if ($blog_activity->isNew("b.{$blog_id}", $post_id, isset($options['expire']) ? $options['expire'] : null)) { ++$items[$blog_id]['new_post']; } } if (!$items[$blog_id]['new_post']) { unset($items[$blog_id]['new_post']); } } } } } /** * Prepare blog data * Extend each blog item via plugins data * @event prepare_blogs_frontend * @event prepare_blogs_backend * @param array $items * @param int $items[]['id'] * @return void */ wa()->event('prepare_blogs_' . wa()->getEnv(), $items); return $items; }
protected function getComments($search_options) { if (empty($search_options['post_id'])) { $search_options['post_id'] = null; } if (!isset($search_options['blog_id'])) { $search_options['blog_id'] = array_keys(blogHelper::getAvailable()); } else { if (is_numeric($search_options['blog_id'])) { $search_options['blog_id'] = array((int) $search_options['blog_id']); } else { if (!is_array($search_options['blog_id'])) { $search_options['blog_id'] = array(); } } } if (is_numeric($search_options['filter'])) { $search_options['filter'] = (int) $search_options['filter']; if (in_array($search_options['filter'], $search_options['blog_id'])) { $search_options['blog_id'] = array($search_options['filter']); } else { $search_options['blog_id'] = array(); } } else { if ($search_options['filter'] == 'myposts') { if (empty($search_options['blog_id'])) { $search_options['post_id'] = array(); } else { $post_model = new blogPostModel(); $search_options['post_id'] = array_keys($post_model->select('id')->where('contact_id=? AND blig_id IN (?)', array($this->getUser()->getId(), $search_options['blog_id']))->fetchAll('id')); } } } $search_options['approved'] = true; $comment_model = new blogCommentModel(); return $comment_model->getList($search_options, array("photo_url_20"), array('datetime' => blogActivity::getUserActivity())); }
public function onCount() { $full = !func_get_args(); $app = $this->getApplication(); $user = waSystem::getInstance()->getUser(); $user_id = $user->getId(); $type = explode(':', $user->getSettings($app, 'type_items_count')); $type = array_filter(array_map('trim', $type), 'strlen'); if (!$type) { $type = array('posts', 'comments_to_my_post', 'overdue'); } $activity_datetime = blogActivity::getUserActivity($user_id, false); $blogs = array_keys(blogHelper::getAvailable(false)); $counter = array(); $post_model = new blogPostModel(); if (in_array('posts', $type) && $full && $blogs) { $post_new_count = $post_model->getAddedPostCount($activity_datetime, $blogs); $post_new_count = array_sum($post_new_count); $counter['posts'] = $post_new_count; } else { $counter['posts'] = false; } if (in_array('comments', $type) && $full && $blogs) { $comment_model = new blogCommentModel(); $counter['comments'] = $comment_model->getCount($blogs, null, $activity_datetime, 0); } else { $counter['comments'] = false; } if (in_array('comments_to_my_post', $type) && $full && $blogs) { $comment_model = new blogCommentModel(); $counter['comments_to_my_post'] = $comment_model->getCount($blogs, null, $activity_datetime, 0, $user_id); } else { $counter['comments_to_my_post'] = false; } if (in_array('overdue', $type) && $blogs) { if (!isset($post_model)) { $post_model = new blogPostModel(); } $where = "status = '" . blogPostModel::STATUS_DEADLINE . "'"; $where .= " AND blog_id IN (" . implode(', ', $blogs) . ")"; $where .= " AND contact_id = {$user_id}"; $where .= " AND datetime <= '" . waDateTime::date("Y-m-d") . "'"; $count_overdue = $post_model->select("count(id)")->where($where)->fetchField(); $counter['overdue'] = $count_overdue ? $count_overdue : 0; } else { $counter['overdue'] = false; } $count = array_sum($counter); $url = $this->getBackendUrl(true) . $this->application . '/'; if ($count) { switch ($count) { case $counter['comments']: case $counter['comments_to_my_post']: $url .= '?module=comments'; break; case $counter['overdue']: $url .= '?action=calendar'; break; } } //debug //$counter['type'] = $type; //$counter['activity_datetime'] = $activity_datetime; //$counter['current_datetime'] = date("Y-m-d H:i:s",time()); //waLog::log('$counter = '.var_export($counter,true),"blog-counter-{$user_id}.log"); return array('count' => $count == 0 ? null : $count, 'url' => $url); }
/** * Supplement the items data * * $extend_options * - link: if it false - not add author posts * - plugin: if false suppress plugin provided data * - datetime: * - test: * @param $items * @param array @extend_options * @param array $extend_data * @return mixed */ public function prepareView($items, $extend_options = array(), $extend_data = array()) { $extend_options = array_merge($this->extend_options, (array) $extend_options); $extend_data = array_merge($this->extend_data, (array) $extend_data); $extend_author_link = (!isset($extend_options['link']) || $extend_options['link']) && (!isset($extend_options['author_link']) || $extend_options['author_link']); // get user info & photo by post if ($item = current($items)) { if (isset($item['contact_id']) && (!isset($extend_options['user']) || $extend_options['user'])) { if (!isset($extend_options['user'])) { $extend_options['user'] = array('photo_url_20'); } elseif (!is_array($extend_options['user'])) { $extend_options['user'] = preg_split('/,[\\s]*/', $extend_options['user']); } blogHelper::extendUser($items, $extend_options['user'], $extend_author_link); } if (isset($item['id'])) { if (!empty($extend_options['datetime'])) { $comment_model = new blogCommentModel(); $comment_datetime = $comment_model->getDatetime(array_keys($items)); foreach ($items as $id => &$item) { $item['comment_datetime'] = isset($comment_datetime[$id]) ? $comment_datetime[$id] : 0; unset($item); } } elseif (!isset($extend_options['comments'])) { blogHelper::extendPostComments($items); } elseif ($extend_options['comments']) { $fields = array(); if ($extend_options['comments'] !== true) { foreach ((array) $extend_options['comments'] as $size) { $fields[] = "photo_url_{$size}"; } } $activity_datetime = blogActivity::getUserActivity(); $comment_model = new blogCommentModel(); $comment_options = array('user' => $extend_author_link, 'datetime' => $activity_datetime, 'escape' => !empty($extend_options['escape'])); foreach ($items as $id => &$item) { $item['comments'] = $comment_model->get($id, $fields, $comment_options); $item['comment_count'] = 0; $item['comment_new_count'] = 0; foreach ($item['comments'] as &$comment) { if ($comment['status'] == blogCommentModel::STATUS_PUBLISHED) { ++$item['comment_count']; if (!empty($comment['new'])) { ++$item['comment_new_count']; } } unset($comment); } unset($item); } } if (!empty($extend_options['status'])) { blogHelper::extendPostState($items, $extend_options['status']); } if (!empty($extend_options['rights']) && isset($extend_data['blog'])) { blogHelper::extendRights($items, $extend_data['blog'], wa()->getUser()->getId()); } if (!empty($extend_options['params'])) { $params_model = new blogPostParamsModel(); $params = $params_model->getByField('post_id', array_keys($items), true); } } } if (isset($params)) { foreach ($params as $param) { if (isset($items[$param['post_id']])) { $items[$param['post_id']] += array($param['name'] => $param['value']); } } } foreach ($items as &$item) { #data holders for plugin events handlers $item['plugins'] = array('before' => array(), 'after' => array(), 'post_title' => array(), 'post_title_right' => array()); if (isset($item['blog_id'])) { $blog_id = $item['blog_id']; if (isset($extend_data['blog']) && isset($extend_data['blog'][$blog_id])) { $blog = $extend_data['blog'][$blog_id]; if (isset($blog['url'])) { $item['blog_url'] = $blog['url']; } $item['icon'] = isset($blog['icon_html']) ? $blog['icon_html'] : ''; $item['color'] = isset($blog['color']) ? $blog['color'] : ''; if (isset($blog['status'])) { $item['blog_status'] = $blog['status']; } if (isset($blog['url'])) { $item['blog_url'] = $blog['url']; } if (isset($blog['name'])) { $item['blog_name'] = $blog['name']; } } else { $item['color'] = ''; $item['icon'] = ''; } } if (isset($item['comment_count'])) { /** * Backward compatibility with older themes * @deprecated */ $item['comment_str_translate'] = _w('comment', 'comments', $item['comment_count']); } if (!isset($extend_options['link']) || $extend_options['link']) { if (isset($item['blog_status']) && $item['blog_status'] != blogBlogModel::STATUS_PUBLIC) { $item['link'] = false; } else { $item['link'] = blogPost::getUrl($item); } } if (empty($item['title'])) { $item['title'] = _w("(empty title)"); } if (!empty($extend_options['escape'])) { $item['title'] = htmlspecialchars($item['title'], ENT_QUOTES, 'utf-8'); $item['user']['name'] = htmlspecialchars($item['user']['name'], ENT_QUOTES, 'utf-8'); } unset($item); } if (!isset($extend_options['plugin']) || $extend_options['plugin']) { /** * Prepare post data * Extend each post item via plugins data * @event prepare_posts_frontend * @event prepare_posts_backend * @example public function preparePost(&$items) * { * foreach ($items as &$item) { * $item['post_title'][$this->id] = 'Extra post title html code here'; * } * } * @param array [int][string]mixed $items Post items * @param array [int][string]mixed $items[id] Post item * @param array [int][string]int $items[id]['id'] Post item ID * @param array [int][string][string]string $items[id]['before'][%plugin_id%] Placeholder for plugin %plugin_id% output * @param array [int][string][string]string $items[id]['after'][%plugin_id%] Placeholder for plugin %plugin_id% output * @param array [int][string][string]string $items[id]['post_title'][%plugin_id%] Placeholder for plugin %plugin_id% output * @param array [int][string][string]string $items[id]['post_title_right'][%plugin_id%] Placeholder for plugin %plugin_id% output * @return void */ wa()->event('prepare_posts_' . wa()->getEnv(), $items); } return $items; }
/** * * Get comments for posts * @param array $posts */ public static function extendPostComments(&$posts) { $comment_model = new blogCommentModel(); $post_ids = array_keys($posts); $comment_count = $comment_model->getCount(null, $post_ids); $comment_new_count = $comment_model->getCount(null, $post_ids, blogActivity::getUserActivity()); foreach ($posts as $id => &$post) { $post['comment_count'] = isset($comment_count[$id]) ? $comment_count[$id] : 0; $post['comment_new_count'] = isset($comment_new_count[$id]) ? $comment_new_count[$id] : 0; unset($post); } }
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); }
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; }