cms/drupal/modules/blog/blog.pages.inc
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @file
       
     5  * Page callback file for the blog module.
       
     6  */
       
     7 
       
     8 /**
       
     9  * Menu callback; displays a Drupal page containing recent blog entries of a given user.
       
    10  */
       
    11 function blog_page_user($account) {
       
    12   global $user;
       
    13 
       
    14   drupal_set_title($title = t("@name's blog", array('@name' => format_username($account))), PASS_THROUGH);
       
    15 
       
    16   $build = array();
       
    17 
       
    18   $query = db_select('node', 'n')->extend('PagerDefault');
       
    19   $nids = $query
       
    20     ->fields('n', array('nid', 'sticky', 'created'))
       
    21     ->condition('type', 'blog')
       
    22     ->condition('uid', $account->uid)
       
    23     ->condition('status', 1)
       
    24     ->orderBy('sticky', 'DESC')
       
    25     ->orderBy('created', 'DESC')
       
    26     ->limit(variable_get('default_nodes_main', 10))
       
    27     ->addTag('node_access')
       
    28     ->execute()
       
    29     ->fetchCol();
       
    30 
       
    31   if (!empty($nids)) {
       
    32     $nodes = node_load_multiple($nids);
       
    33     $build += node_view_multiple($nodes);
       
    34     $build['pager'] = array(
       
    35       '#theme' => 'pager',
       
    36       '#weight' => 5,
       
    37     );
       
    38   }
       
    39   else {
       
    40     if ($account->uid == $user->uid) {
       
    41       drupal_set_message(t('You have not created any blog entries.'));
       
    42     }
       
    43     else {
       
    44       drupal_set_message(t('!author has not created any blog entries.', array('!author' => theme('username', array('account' => $account)))));
       
    45     }
       
    46   }
       
    47   drupal_add_feed('blog/' . $account->uid . '/feed', t('RSS - !title', array('!title' => $title)));
       
    48 
       
    49   return $build;
       
    50 }
       
    51 
       
    52 /**
       
    53  * Menu callback; displays a Drupal page containing recent blog entries of all users.
       
    54  */
       
    55 function blog_page_last() {
       
    56   global $user;
       
    57   $build = array();
       
    58 
       
    59   $query = db_select('node', 'n')->extend('PagerDefault');
       
    60   $nids = $query
       
    61     ->fields('n', array('nid', 'sticky', 'created'))
       
    62     ->condition('type', 'blog')
       
    63     ->condition('status', 1)
       
    64     ->orderBy('sticky', 'DESC')
       
    65     ->orderBy('created', 'DESC')
       
    66     ->limit(variable_get('default_nodes_main', 10))
       
    67     ->addTag('node_access')
       
    68     ->execute()
       
    69     ->fetchCol();
       
    70 
       
    71   if (!empty($nids)) {
       
    72     $nodes = node_load_multiple($nids);
       
    73     $build += node_view_multiple($nodes);
       
    74     $build['pager'] = array(
       
    75       '#theme' => 'pager',
       
    76       '#weight' => 5,
       
    77     );
       
    78   }
       
    79   else {
       
    80     drupal_set_message(t('No blog entries have been created.'));
       
    81   }
       
    82   drupal_add_feed('blog/feed', t('RSS - blogs'));
       
    83 
       
    84   return $build;
       
    85 }
       
    86 
       
    87 /**
       
    88  * Menu callback; displays an RSS feed containing recent blog entries of a given user.
       
    89  */
       
    90 function blog_feed_user($account) {
       
    91 
       
    92   $nids = db_select('node', 'n')
       
    93     ->fields('n', array('nid', 'created'))
       
    94     ->condition('type', 'blog')
       
    95     ->condition('uid', $account->uid)
       
    96     ->condition('status', 1)
       
    97     ->orderBy('created', 'DESC')
       
    98     ->range(0, variable_get('feed_default_items', 10))
       
    99     ->addTag('node_access')
       
   100     ->execute()
       
   101     ->fetchCol();
       
   102 
       
   103   $channel['title'] = t("!name's blog", array('!name' => format_username($account)));
       
   104   $channel['link'] = url('blog/' . $account->uid, array('absolute' => TRUE));
       
   105 
       
   106   node_feed($nids, $channel);
       
   107 }
       
   108 
       
   109 /**
       
   110  * Menu callback; displays an RSS feed containing recent blog entries of all users.
       
   111  */
       
   112 function blog_feed_last() {
       
   113   $nids = db_select('node', 'n')
       
   114     ->fields('n', array('nid', 'created'))
       
   115     ->condition('type', 'blog')
       
   116     ->condition('status', 1)
       
   117     ->orderBy('created', 'DESC')
       
   118     ->range(0, variable_get('feed_default_items', 10))
       
   119     ->addTag('node_access')
       
   120     ->execute()
       
   121     ->fetchCol();
       
   122 
       
   123   $channel['title'] = t('!site_name blogs', array('!site_name' => variable_get('site_name', 'Drupal')));
       
   124   $channel['link'] = url('blog', array('absolute' => TRUE));
       
   125 
       
   126   node_feed($nids, $channel);
       
   127 }