diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-07-22 06:48:25 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-07-22 06:48:25 +0000 |
commit | 80213aff3c82593e5f69c1dad3640094a8645dc1 (patch) | |
tree | a3f00b6aa36a0de7a65d27687de0ba6ef3fa2e2d /modules/blog | |
parent | b1285bb9791f6f972552a0fe6969f52e5f7eed95 (diff) | |
download | brdo-80213aff3c82593e5f69c1dad3640094a8645dc1.tar.gz brdo-80213aff3c82593e5f69c1dad3640094a8645dc1.tar.bz2 |
- Patch #159634 by Crell: split the blog module.
Diffstat (limited to 'modules/blog')
-rw-r--r-- | modules/blog/blog.module | 148 | ||||
-rw-r--r-- | modules/blog/blog.pages.inc | 103 |
2 files changed, 128 insertions, 123 deletions
diff --git a/modules/blog/blog.module b/modules/blog/blog.module index d1543d4cf..c6c05e4af 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -72,128 +72,6 @@ function blog_help($path, $arg) { } /** - * Displays an RSS feed containing recent blog entries of a given user. - */ -function blog_feed_user($uid = 0) { - global $user; - - if ($uid) { - $account = user_load(array('uid' => $uid, 'status' => 1)); - } - else { - $account = $user; - } - - $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10)); - $channel['title'] = $account->name ."'s blog"; - $channel['link'] = url("blog/$uid", array('absolute' => TRUE)); - $channel['description'] = $term->description; - - while ($row = db_fetch_object($result)) { - $items[] = $row->nid; - } - node_feed($items, $channel); -} - -/** - * Displays an RSS feed containing recent blog entries of all users. - */ -function blog_feed_last() { - $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10)); - $channel['title'] = variable_get('site_name', 'Drupal') .' blogs'; - $channel['link'] = url('blog', array('absolute' => TRUE)); - $channel['description'] = $term->description; - - while ($row = db_fetch_object($result)) { - $items[] = $row->nid; - } - - node_feed($items, $channel); -} - -/** - * Menu callback; displays a Drupal page containing recent blog entries. - */ -function blog_page($a = NULL, $b = NULL) { - if (is_object($a)) { - $a = $a->uid; - } - - if (is_numeric($a)) { // $a is a user ID - if ($b == 'feed') { - return blog_feed_user($a); - } - else { - return blog_page_user($a); - } - } - else if ($a == 'feed') { - return blog_feed_last(); - } - else { - return blog_page_last(); - } -} - -/** - * Displays a Drupal page containing recent blog entries of a given user. - */ -function blog_page_user($uid) { - global $user; - - $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); - - if (!empty($account->uid)) { - drupal_set_title($title = t("@name's blog", array('@name' => $account->name))); - - if (($account->uid == $user->uid) && user_access('edit own blog')) { - $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>'; - } - else if ($account->uid == $user->uid) { - $output = '<li>'. t('You are not allowed to post a new blog entry.') .'</li>'; - } - - if ($output) { - $output = '<ul>'. $output .'</ul>'; - } - else { - $output = ''; - } - - $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); - while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); - } - $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); - drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); - - return $output; - } - else { - drupal_not_found(); - } -} - -/** - * Displays a Drupal page containing recent blog entries of all users. - */ -function blog_page_last() { - global $user; - - $output = ''; - - $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); - - while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); - } - $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); - drupal_add_feed(url('blog/feed'), t('RSS - blogs')); - - return $output; -} - -/** * Implementation of hook_form(). */ function blog_form(&$node) { @@ -264,14 +142,37 @@ function blog_link($type, $node = NULL, $teaser = FALSE) { function blog_menu() { $items['blog'] = array( 'title' => 'Blogs', - 'page callback' => 'blog_page', + 'page callback' => 'blog_page_last', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, + 'file' => 'blog.pages.inc', + ); + $items['blog/%user/view'] = array( + 'title' => 'Blogs', + 'page callback' => 'blog_page_user', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'blog.pages.inc', ); $items['blog/%user_current'] = array( 'title' => 'My blog', 'page arguments' => array(1), 'access arguments' => array('edit own blog'), + 'file' => 'blog.pages.inc', + ); + $items['blog/%user/feed'] = array( + 'title' => 'Blogs', + 'page callback' => 'blog_feed_user', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'blog.pages.inc', + ); + $items['blog/feed'] = array( + 'title' => 'Blogs', + 'page callback' => 'blog_feed_last', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'blog.pages.inc', ); return $items; @@ -300,3 +201,4 @@ function blog_block($op = 'list', $delta = 0) { } } } + diff --git a/modules/blog/blog.pages.inc b/modules/blog/blog.pages.inc new file mode 100644 index 000000000..996db4d57 --- /dev/null +++ b/modules/blog/blog.pages.inc @@ -0,0 +1,103 @@ +<?php +// $Id$ + +/** + * @file + * Page callback file for the blog module. + */ + +/** + * Menu callback; displays a Drupal page containing recent blog entries of a given user. + */ +function blog_page_user($account) { + global $user; + + $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); + + if (!empty($account->uid)) { + drupal_set_title($title = t("@name's blog", array('@name' => $account->name))); + + if (($account->uid == $user->uid) && user_access('edit own blog')) { + $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>'; + } + else if ($account->uid == $user->uid) { + $output = '<li>'. t('You are not allowed to post a new blog entry.') .'</li>'; + } + + if ($output) { + $output = '<ul>'. $output .'</ul>'; + } + else { + $output = ''; + } + + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); + while ($node = db_fetch_object($result)) { + $output .= node_view(node_load($node->nid), 1); + } + $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); + drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); + + return $output; + } + else { + drupal_not_found(); + } +} + +/** + * Menu callback; displays a Drupal page containing recent blog entries of all users. + */ +function blog_page_last() { + global $user; + + $output = ''; + + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); + + while ($node = db_fetch_object($result)) { + $output .= node_view(node_load($node->nid), 1); + } + $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); + drupal_add_feed(url('blog/feed'), t('RSS - blogs')); + + return $output; +} + +/** + * Menu callback; displays an RSS feed containing recent blog entries of a given user. + */ +function blog_feed_user($uid = 0) { + global $user; + + if ($uid) { + $account = user_load(array('uid' => $uid, 'status' => 1)); + } + else { + $account = $user; + } + + $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10)); + $channel['title'] = $account->name ."'s blog"; + $channel['link'] = url("blog/$uid", array('absolute' => TRUE)); + + while ($row = db_fetch_object($result)) { + $items[] = $row->nid; + } + node_feed($items, $channel); +} + +/** + * Menu callback; displays an RSS feed containing recent blog entries of all users. + */ +function blog_feed_last() { + $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10)); + $channel['title'] = variable_get('site_name', 'Drupal') .' blogs'; + $channel['link'] = url('blog', array('absolute' => TRUE)); + + while ($row = db_fetch_object($result)) { + $items[] = $row->nid; + } + + node_feed($items, $channel); +} |