You are here

function related_blog_block_view in Util 7

Same name and namespace in other branches
  1. 6.3 contribs/related_blog/related_blog.module \related_blog_block_view()

Implements hook_block_view().

File

contribs/related_blog/related_blog.module, line 24
Provides block to show blog of node's author.

Code

function related_blog_block_view($delta = 0) {
  $block = array();
  switch ($delta) {
    case 'related_blog':

      // Make sure it makes sense to show this.
      // That is, not on node add/edit, etc.
      if (arg(2)) {
        return $block;
      }

      // Get the currently displayed node.
      $node = menu_get_object();

      // See blog_page_user().
      $build = array();
      $query = db_select('node', 'n')
        ->extend('PagerDefault');
      $nids = $query
        ->fields('n', array(
        'nid',
        'sticky',
        'created',
      ))
        ->condition('type', 'blog')
        ->condition('uid', $node->uid)
        ->condition('nid', $node->nid, '<>')
        ->condition('status', 1)
        ->orderBy('sticky', 'DESC')
        ->orderBy('created', 'DESC')
        ->limit(variable_get('related_blog_count', variable_get('default_nodes_main', 10)))
        ->addTag('node_access')
        ->execute()
        ->fetchCol();
      if (!empty($nids)) {
        $nodes = node_load_multiple($nids);
        $build += node_view_multiple($nodes, 'related_blog');
        $build['pager'] = array(
          '#theme' => 'pager',
          '#weight' => 5,
        );
      }
      else {
        $account = user_load($node->uid);
        drupal_set_message(t('!author has not created any blog entries.', array(
          '!author' => theme('username', array(
            'account' => $account,
          )),
        )));
      }
      $block['content'] = $build;
      break;
  }
  return $block;
}