function _site_map_blogs in Site map 8
Same name and namespace in other branches
- 5 site_map.module \_site_map_blogs()
- 6.2 site_map.module \_site_map_blogs()
- 6 site_map.module \_site_map_blogs()
- 7 site_map.module \_site_map_blogs()
Render the latest blogs.
Return value
string Returns HTML string of site map for blogs.
File
- ./
site_map.module, line 125 - Provides a site map functionality.
Code
function _site_map_blogs() {
$config = \Drupal::config('site_map.settings');
$output = '';
$class = array();
$options = array();
if (\Drupal::service('module_handler')
->moduleExists('blog')) {
$title = t('Blogs');
$output = '<div class="description">' . t('Community blog and recent blog authors at %sn.', array(
'%sn' => \Drupal::config('system.site')
->get('name'),
)) . '</div>';
$blog_link = \Drupal::l(t('All blogs'), Url::fromUri('base://' . 'blog'));
if ($config
->get('show_rss_links') != 0) {
$feed_icon = array(
'#theme' => 'site_map_feed_icon',
'#url' => 'blog/feed',
'#name' => 'all blogs',
);
$rss_link = drupal_render($feed_icon);
if ($config
->get('show_rss_links') == 1) {
$blog_link .= ' ' . $rss_link;
}
else {
$class[] = 'site-map-rss-left';
$blog_link = $rss_link . ' ' . $blog_link;
}
}
\Drupal::service('site_map.helper')
->setOption($options, 'show_titles', 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) {
$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 ($config
->get('show_rss_links') != 0) {
$feed_icon = array(
'#theme' => 'site_map_feed_icon',
'#url' => "blog/{$blog->uid}/feed",
);
$rss_link = drupal_render($feed_icon);
if ($config
->get('show_rss_links') == 1) {
$blog_item .= ' ' . $rss_link;
}
else {
$blog_item = $rss_link . ' ' . $blog_item;
}
}
$blogs[] = $blog_item;
}
$class[] = 'site-map-box-blog';
$attributes = array(
'class' => $class,
);
$blog_list = array(
'#theme' => 'item_list',
'#items' => $blogs,
);
$output .= drupal_render($blog_list);
$site_map_box = array(
'#theme' => 'site_map_box',
'#title' => $title,
'#content' => $output,
'#attributes' => $attributes,
'#options' => $options,
);
$output = drupal_render($site_map_box);
}
return $output;
}