/** * @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; }
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); }