You are here

function _site_map_blogs in Site map 7

Same name and namespace in other branches
  1. 8 site_map.module \_site_map_blogs()
  2. 5 site_map.module \_site_map_blogs()
  3. 6.2 site_map.module \_site_map_blogs()
  4. 6 site_map.module \_site_map_blogs()

Render the latest blogs.

Return value

string Returns HTML string of site map for blogs.

1 call to _site_map_blogs()
template_preprocess_site_map in includes/site_map.theme.inc
Preprocesses the variables for site-map.tpl.php.

File

./site_map.module, line 270
site_map.module

Code

function _site_map_blogs() {
  $output = '';
  $class = array();
  $options = array();
  if (module_exists('blog')) {
    $title = t('Blogs');
    $output = '<div class="description">' . t('Community blog and recent blog authors at %sn.', array(
      '%sn' => variable_get('site_name', 'Drupal'),
    )) . '</div>';
    $blog_link = l(t('All blogs'), 'blog');
    if (variable_get('site_map_show_rss_links', 1) != 0) {
      $rss_link = theme('site_map_feed_icon', array(
        'url' => 'blog/feed',
        'name' => 'all blogs',
      ));
      if (variable_get('site_map_show_rss_links', 1) == 1) {
        $blog_link .= ' ' . $rss_link;
      }
      else {
        $class[] = 'site-map-rss-left';
        $blog_link = $rss_link . ' ' . $blog_link;
      }
    }
    _site_map_set_option($options, 'site_map_show_titles', 1, 1, 'show_titles', TRUE);
    $blogs = array();
    $blogs[] = $blog_link;
    $query = db_select('node', 'n');
    $query
      ->join('users', 'u', 'u.uid = n.uid');
    $query
      ->fields('u', array(
      'uid',
      'name',
    ));
    $query
      ->addExpression('COUNT(u.uid)', 'numitems');
    $query
      ->condition('n.type', 'blog')
      ->condition('n.status', 1)
      ->groupBy('u.uid')
      ->groupBy('u.name')
      ->orderBy('numitems', 'DESC')
      ->orderBy('u.name', 'ASC')
      ->range(0, 10);
    $query
      ->addTag('node_access');
    $query
      ->distinct();
    $result = $query
      ->execute();
    foreach ($result as $blog) {
      if ($blog->uid == 0) {
        $blog->name = t('Anonymous');
      }
      $blog_item = t('<a href="@url">@name\'s blog</a> (@num_items)', array(
        '@url' => "blog/{$blog->uid}",
        '@name' => $blog->name,
        '@num_items' => $blog->numitems,
      ));
      if (variable_get('site_map_show_rss_links', 1) != 0) {
        $rss_link = theme('site_map_feed_icon', array(
          'url' => "blog/{$blog->uid}/feed",
          'name' => $blog->name . '\'s blog',
        ));
        if (variable_get('site_map_show_rss_links', 1) == 1) {
          $blog_item .= ' ' . $rss_link;
        }
        else {
          $blog_item = $rss_link . ' ' . $blog_item;
        }
      }
      $blogs[] = $blog_item;
    }
    $class[] = 'site-map-box-blog';
    $attributes = array(
      'class' => $class,
    );
    $output .= theme('item_list', array(
      'items' => $blogs,
    ));
    $output = theme('site_map_box', array(
      'title' => $title,
      'content' => $output,
      'attributes' => $attributes,
      'options' => $options,
    ));
  }
  return $output;
}