/**
  *
  * Get object instance
  * @param int $time
  * @return blogActivity
  */
 public static function getInstance($time = null)
 {
     if (!is_object(self::$instance)) {
         self::$instance = new self($time);
     }
     return self::$instance;
 }
 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)));
 }
Example #3
0
 /**
  * @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()));
 }
Example #5
0
 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);
 }
 /**
  *
  * Update blog post item
  * @param int $id
  * @param array $data
  * @param array $current_data
  * @throws waException
  * @return int post id
  */
 public function updateItem($id, $data = array(), $current_data = array())
 {
     $plugin = array();
     $contact_id = wa()->getUser()->getId();
     foreach ($data as $field => $value) {
         if (!isset($this->fields[$field]) || $field == $this->id) {
             if (isset($data['plugin'])) {
                 $plugin = $data['plugin'];
             }
             unset($data[$field]);
         }
     }
     if ($id) {
         if (!$current_data) {
             $current_data = $this->getByField(array($this->id => $id));
             if (!$current_data) {
                 throw new waException(_w('Post not found'), 404);
             }
         }
         if (!$contact_id) {
             //use author id for cron task
             $contact_id = $current_data['contact_id'];
         }
     } else {
         $current_data = array();
         if (empty($data['contact_id'])) {
             $data['contact_id'] = $contact_id;
         } else {
             blogHelper::checkRights($data['blog_id'], $contact_id, $contact_id != $data['contact_id'] ? blogRightConfig::RIGHT_FULL : blogRightConfig::RIGHT_READ_WRITE);
         }
     }
     //check rights for non admin
     $source_data = array('contact_id' => isset($current_data['contact_id']) ? $current_data['contact_id'] : $data['contact_id'], 'blog_id' => isset($current_data['blog_id']) ? $current_data['blog_id'] : $data['blog_id']);
     $target_data = array('contact_id' => isset($data['contact_id']) ? $data['contact_id'] : $source_data['contact_id'], 'blog_id' => isset($data['blog_id']) ? $data['blog_id'] : $source_data['blog_id']);
     //check editor rights
     blogHelper::checkRights($source_data['blog_id'], $contact_id);
     //change blog
     if ($source_data['blog_id'] != $target_data['blog_id']) {
         //check editor rights for target blog
         blogHelper::checkRights($target_data['blog_id'], $contact_id, $contact_id != $target_data['contact_id'] ? blogRightConfig::RIGHT_FULL : blogRightConfig::RIGHT_READ_WRITE);
         //check (new) author rights
         if ($contact_id != $target_data['contact_id']) {
             //skip it = for admin it allowed
             //blogHelper::checkRights($target_data['blog_id'],$target_data['contact_id']);
         }
     } else {
         //check new author rights
         if ($contact_id != $target_data['contact_id'] && $target_data['contact_id'] != $source_data['contact_id']) {
             blogHelper::checkRights($target_data['blog_id'], $target_data['contact_id']);
         }
     }
     //status changes
     if (isset($data['status'])) {
         switch ($data['status']) {
             case self::STATUS_PUBLISHED:
                 if (!isset($data['datetime']) || !$data['datetime']) {
                     if (!isset($current_data['datetime']) || !$current_data['datetime']) {
                         $data['datetime'] = date("Y-m-d H:i:s");
                     } elseif (isset($current_data['status']) && !in_array($current_data['status'], array(self::STATUS_PUBLISHED, self::STATUS_SCHEDULED))) {
                         $data['datetime'] = date("Y-m-d H:i:s");
                     } else {
                         unset($data['datetime']);
                     }
                 }
                 break;
             case self::STATUS_DRAFT:
                 if (!isset($data['datetime']) || !$data['datetime']) {
                     if (!isset($current_data['datetime']) || !$current_data['datetime']) {
                         $data['datetime'] = date("Y-m-d H:i:s");
                     } else {
                         unset($data['datetime']);
                     }
                 }
                 break;
             case self::STATUS_SCHEDULED:
                 if (!isset($data['datetime']) || !$data['datetime']) {
                     unset($data['datetime']);
                 }
                 break;
             case self::STATUS_DEADLINE:
                 if (!isset($data['datetime']) || !$data['datetime'] || is_array($data['datetime']) && !$data['datetime'][0]) {
                     $data['status'] = self::STATUS_DRAFT;
                     $data['datetime'] = date("Y-m-d H:i:s");
                 }
                 break;
         }
     }
     if (!$id && (!isset($data['contact_id']) || !$data['contact_id'])) {
         $data['contact_id'] = wa()->getUser()->getId();
     }
     if (isset($data['url']) && strlen($data['url'])) {
         if (substr($data['url'], -1) == '/') {
             $data['url'] = preg_replace('~\\/+$~', '', $data['url']);
         }
         if (strpos($data['url'], '/') !== false) {
             throw new waException(_w('URL must not contain /'));
         }
         if ($this->checkUrl($data['url'], $id)) {
             throw new waException(_w('This address is already in use') . ' ' . $data['url']);
         }
     } else {
         //$data['url'] = blogHelper::transliterate($data['url']);
     }
     $edit = $id ? true : false;
     $event_map = array(0 => array(0 => array('post_presave', 'post_save'), self::STATUS_PUBLISHED => array('post_prepublish', 'post_publish'), self::STATUS_SCHEDULED => array('post_preshedule', 'post_shedule'), self::STATUS_DEADLINE => array('post_presave', 'post_save'), self::STATUS_DRAFT => array('post_presave', 'post_save')), self::STATUS_DRAFT => array(0 => array('post_presave', 'post_save'), self::STATUS_PUBLISHED => array('post_prepublish', 'post_publish'), self::STATUS_SCHEDULED => array('post_preshedule', 'post_shedule'), self::STATUS_DEADLINE => array('post_presave', 'post_save'), self::STATUS_DRAFT => array('post_presave', 'post_save')), self::STATUS_DEADLINE => array(0 => array('post_presave', 'post_save'), self::STATUS_PUBLISHED => array('post_prepublish', 'post_publish'), self::STATUS_SCHEDULED => array('post_preshedule', 'post_shedule'), self::STATUS_DEADLINE => array('post_presave', 'post_save'), self::STATUS_DRAFT => array('post_presave', 'post_save')), self::STATUS_SCHEDULED => array(0 => array('post_presave', 'post_save'), self::STATUS_PUBLISHED => array('post_prepublish', 'post_publish'), self::STATUS_SCHEDULED => array('post_presave', 'post_save'), self::STATUS_DEADLINE => array('post_presave', 'post_save'), self::STATUS_DRAFT => array('post_presave', 'post_save')), self::STATUS_PUBLISHED => array(0 => array('post_presave', 'post_save'), self::STATUS_PUBLISHED => array('post_presave', 'post_save'), self::STATUS_SCHEDULED => array('post_preshedule', 'post_shedule'), self::STATUS_DEADLINE => array('post_presave', 'post_save'), self::STATUS_DRAFT => array('post_presave', 'post_save')));
     $events = $event_map[isset($current_data['status']) ? $current_data['status'] : 0][isset($data['status']) ? $data['status'] : 0];
     $data['plugin'] = $plugin;
     /**
      * @event post_prepublish
      * @event post_preshedule
      * @event post_presave
      * @param array [string]mixed $data
      * @param array [string]int $data['id']
      * @param array [string][string]mixed $data['plugin']['%plugin_id']
      * @return array[%plugin_id%][%field%]string Error message for field %field%
      */
     $errors = wa()->event(array_shift($events), $data);
     if ($id) {
         if ($source_data['blog_id'] != $target_data['blog_id']) {
             $comment_model = new blogCommentModel();
             $comment_model->updateByField('post_id', $id, array('blog_id' => $target_data['blog_id']));
         }
         $this->updateById($id, $data);
         $data[$this->id] = $id;
     } else {
         $id = $this->insert($data);
         blogActivity::setUserActivity();
         $data[$this->id] = $id;
         if (!isset($data['url']) || strlen($data['url']) == 0) {
             $this->updateById($id, array('url' => $id));
         }
     }
     //status changed
     //blog_id changed
     $data = array_merge($current_data, $data);
     $blog_model = new blogBlogModel();
     if ($edit) {
         //unpublish
         if ($current_data['status'] == self::STATUS_PUBLISHED && $data['status'] != self::STATUS_PUBLISHED) {
             $blog_model->updateQty($data['blog_id'], '-1');
             //publish
         } elseif ($current_data['status'] != self::STATUS_PUBLISHED && $data['status'] == self::STATUS_PUBLISHED) {
             $blog_model->updateQty($data['blog_id'], '+1');
             //move
         } elseif (isset($current_data['blog_id']) && $current_data['status'] == self::STATUS_PUBLISHED && $data['status'] == self::STATUS_PUBLISHED && $current_data['blog_id'] != $data['blog_id']) {
             $blog_model->updateQty($data['blog_id'], '+1');
             $blog_model->updateQty($current_data['blog_id'], '-1');
         }
     } else {
         if ($data['status'] == self::STATUS_PUBLISHED) {
             $blog_model->updateQty($data['blog_id'], '+1');
         }
     }
     /**
      * @event post_publish
      * @event post_shedule
      * @event post_save
      * @param array [string]mixed $data
      * @param array [string]int $data['id']
      * @param array [string][string]mixed $data['plugin']['%plugin_id']
      * @return void
      */
     wa()->event(array_shift($events), $data);
     return $id;
 }
Example #7
0
 /**
  *
  * 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 add($comment, $parent = null)
 {
     if (!isset($comment['ip']) && ($ip = waRequest::getIp())) {
         $ip = ip2long($ip);
         if ($ip > 2147483647) {
             $ip -= 4294967296.0;
         }
         $comment['ip'] = $ip;
     }
     if (!isset($comment['datetime'])) {
         $comment['datetime'] = date('Y-m-d H:i:s');
     }
     if (isset($comment['site']) && $comment['site']) {
         if (!preg_match('@^https?://@', $comment['site'])) {
             $comment['site'] = 'http://' . $comment['site'];
         }
     }
     $comment[$this->parent] = $parent;
     blogActivity::setUserActivity();
     /**
      * @event comment_presave_frontend
      * @event comment_presave_backend
      * @param array $comment
      * @param int $comment.id
      * @param int $comment.parent
      * @return void
      */
     wa()->event('comment_presave_' . wa()->getEnv(), $comment);
     $comment['id'] = parent::add($comment, $parent);
     /**
      * @event comment_save_frontend
      * @event comment_save_backend
      * @param array $comment
      * @param int $comment.id
      * @param int $comment.parent
      * @return void
      */
     wa()->event('comment_save_' . wa()->getEnv(), $comment);
     return $comment['id'];
 }
Example #9
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);
 }
 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;
 }