2001-07-11 22:06:24 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-07-11 22:06:24 +00:00
2004-08-21 06:42:38 +00:00
/**
* @file
* Enables keeping an easily and regularly updated web page or a blog.
*/
2004-05-08 07:17:47 +00:00
/**
2005-08-29 19:58:49 +00:00
* Implementation of hook_node_info().
2004-05-08 07:17:47 +00:00
*/
2005-08-29 19:58:49 +00:00
function blog_node_info() {
2005-09-28 12:55:07 +00:00
return array('blog' => array('name' => t('blog entry'), 'base' => 'blog'));
2001-11-01 17:04:20 +00:00
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_perm().
*/
2002-12-10 20:35:20 +00:00
function blog_perm() {
2004-07-13 20:40:46 +00:00
return array('edit own blog');
2002-12-10 20:35:20 +00:00
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_access().
*/
2001-11-01 17:04:20 +00:00
function blog_access($op, $node) {
global $user;
2004-05-08 07:17:47 +00:00
if ($op == 'create') {
2004-07-13 20:40:46 +00:00
return user_access('edit own blog') && $user->uid;
2001-11-01 17:04:20 +00:00
}
2004-07-31 09:30:09 +00:00
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own blog') && ($user->uid == $node->uid)) {
return TRUE;
}
2001-11-01 17:04:20 +00:00
}
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_user().
*/
2002-05-23 14:14:48 +00:00
function blog_user($type, &$edit, &$user) {
2004-07-13 20:40:46 +00:00
if ($type == 'view' && user_access('edit own blog', $user)) {
2005-10-07 06:11:12 +00:00
$form['blog'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'item', '#title' => t('Blog'),
'#value' => l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name))))
2005-10-07 06:11:12 +00:00
);
return array(t('History') => $form);
2002-05-23 14:14:48 +00:00
}
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_help().
*/
2003-08-05 18:33:39 +00:00
function blog_help($section) {
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#blog':
2005-11-01 10:17:34 +00:00
$output = '<p>'. t('The blog module allows registered users to maintain an online weblog (commonly known as a blog), often referred to as an online journal or diary. Blogs are made up of individual posts that are time stamped and are typically viewed by date as you would a diary. Blogs often contain links to webpages users have read and/or agree/disagree with.') .'</p>';
$output .= '<p>'. t('The blog module adds a <em>user blogs</em> navigation link to the site, which takes any visitor to a page that displays the most recent blog entries from all the users on the site. The navigation menu has a <em>create a blog entry</em> link (which takes you to a submission form) and a <em>view personal blog</em> link (which displays your blog entries as other people will see them). The blog module also creates a <em>recent blog posts</em> block that can be enabled.') .'</p>';
$output .= '<p>'. t('If a user has the ability to post blogs, then the import module (news aggregator) will display a blog-it link next to each news item in its lists. Clicking on this takes the user to the blog submission form, with the title, a link to the item, and a link to the source into the body text already in the text box, ready for the user to add a comment or explanation. This actively encourages people to add blog entries about things they see and hear elsewhere in the website and from your syndicated partner sites.') .'</p>';
$output .= t('<p>You can</p>
<ul>
<li>read your blog via your user profile at <a href="%user">my account</a>.</li>
<li>post a blog at <a href="%node-add-blog">create content >> personal blog entry</a>.</li>
<li>administer blog at <a href="%admin-node-configure-types-blog">administer >> content >> configure >> content types >> personal blog entry</a>.</li>
<li>administer blog api at <a href="%admin-settings-blogapi">administer >> settings >> blogapi</a>.</li>
<li>enable the "recent blog posts" block at <a href="%admin-block">administer >> blocks</a> to show the 10 most recent blog posts.</li>
</ul>
', array('%user' => url('user'), '%node-add-blog' => url('node/add/blog'), '%admin-node-configure-types-blog' => url('admin/node/configure/types/blog'), '%admin-settings-blogapi' => url('admin/settings/blogapi'), '%admin-block' => url('admin/block')));
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%blog">Blog page</a>.', array('%blog' => 'http://www.drupal.org/handbook/modules/blog/')) .'</p>';
return $output;
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2004-07-16 08:19:26 +00:00
return t('Enables keeping an easily and regularly updated web page or a blog.');
2004-01-27 18:47:07 +00:00
case 'node/add#blog':
2004-12-07 16:55:38 +00:00
return t("A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. A blog is tightly coupled to the author so each user will have his 'own' blog.");
2003-08-05 18:33:39 +00:00
}
2004-05-08 07:17:47 +00:00
}
2003-05-29 09:15:00 +00:00
2004-05-08 07:17:47 +00:00
/**
* Displays an RSS feed containing recent blog entries of a given user.
*/
2002-11-11 20:59:28 +00:00
function blog_feed_user($uid = 0) {
2001-07-14 13:36:38 +00:00
global $user;
2001-09-16 11:33:14 +00:00
if ($uid) {
2004-05-08 07:17:47 +00:00
$account = user_load(array('uid' => $uid, 'status' => 1));
2001-09-16 11:33:14 +00:00
}
else {
$account = $user;
}
2005-09-18 10:37:57 +00:00
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
2004-05-08 07:17:47 +00:00
$channel['title'] = $account->name ."'s blog";
2004-05-24 18:43:13 +00:00
$channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
2004-05-08 07:17:47 +00:00
$channel['description'] = $term->description;
2002-11-09 16:24:46 +00:00
node_feed($result, $channel);
2001-07-14 13:36:38 +00:00
}
2004-05-08 07:17:47 +00:00
/**
* Displays an RSS feed containing recent blog entries of all users.
*/
2001-07-14 13:36:38 +00:00
function blog_feed_last() {
2005-09-18 10:37:57 +00:00
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {node_revisions} r ON n.vid = r.vid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
2004-05-08 07:17:47 +00:00
$channel['title'] = variable_get('site_name', 'drupal') .' blogs';
2004-08-21 19:37:25 +00:00
$channel['link'] = url('blog', NULL, NULL, TRUE);
2004-05-08 07:17:47 +00:00
$channel['description'] = $term->description;
2002-11-09 16:24:46 +00:00
node_feed($result, $channel);
2001-07-14 13:36:38 +00:00
}
2004-05-08 07:17:47 +00:00
/**
2004-05-17 22:00:06 +00:00
* Menu callback; displays a Drupal page containing recent blog entries.
2004-05-08 07:17:47 +00:00
*/
2005-02-12 09:23:06 +00:00
function blog_page($a = NULL, $b = NULL) {
if (is_numeric($a)) { // $a is a user ID
if ($b == 'feed') {
2005-04-28 19:23:19 +00:00
return blog_feed_user($a);
2005-02-12 09:23:06 +00:00
}
else {
2005-04-28 19:23:19 +00:00
return blog_page_user($a);
2005-02-12 09:23:06 +00:00
}
}
else if ($a == 'feed') {
2005-04-28 19:23:19 +00:00
return blog_feed_last();
2004-05-08 07:17:47 +00:00
}
else {
2005-04-28 19:23:19 +00:00
return blog_page_last();
2004-05-08 07:17:47 +00:00
}
}
/**
* Displays a Drupal page containing recent blog entries of a given user.
*/
2003-09-13 09:17:34 +00:00
function blog_page_user($uid) {
2004-11-24 20:06:10 +00:00
global $user;
2004-05-08 07:17:47 +00:00
$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
2001-07-11 22:06:24 +00:00
2004-10-09 06:52:35 +00:00
if ($account->uid) {
2004-12-15 21:19:42 +00:00
drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
2004-11-24 20:06:10 +00:00
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 = '';
}
2001-07-11 22:06:24 +00:00
2005-01-29 22:02:37 +00:00
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE 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);
2004-10-09 06:52:35 +00:00
while ($node = db_fetch_object($result)) {
2005-07-17 18:29:32 +00:00
$output .= node_view(node_load($node->nid), 1);
2004-10-09 06:52:35 +00:00
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
2005-12-29 04:46:40 +00:00
$output .= theme('feed_icon', url("blog/$account->uid/feed"));
2003-11-25 19:26:21 +00:00
2005-05-31 21:14:27 +00:00
drupal_add_link(array('rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => t('RSS - %title', array('%title' => $title)),
'href' => url("blog/$account->uid/feed")));
2005-04-24 16:34:36 +00:00
return $output;
2004-10-09 06:52:35 +00:00
}
else {
drupal_not_found();
}
2001-07-11 22:06:24 +00:00
}
2004-05-08 07:17:47 +00:00
/**
* Displays a Drupal page containing recent blog entries of all users.
*/
2001-07-14 14:19:45 +00:00
function blog_page_last() {
2003-02-15 11:39:56 +00:00
global $user;
2001-07-11 22:06:24 +00:00
2004-05-08 07:17:47 +00:00
$output = '';
2003-09-13 11:06:29 +00:00
2005-01-29 22:02:37 +00:00
$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.created DESC"), variable_get('default_nodes_main', 10));
2001-08-05 14:33:53 +00:00
2001-11-01 11:00:51 +00:00
while ($node = db_fetch_object($result)) {
2005-07-17 18:29:32 +00:00
$output .= node_view(node_load($node->nid), 1);
2001-07-11 22:06:24 +00:00
}
2004-05-08 07:17:47 +00:00
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
2005-12-29 04:46:40 +00:00
$output .= theme('feed_icon', url('blog/feed'));
2003-11-25 19:26:21 +00:00
2005-05-31 21:14:27 +00:00
drupal_add_link(array('rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => t('RSS - blogs'),
'href' => url("blog/feed")));
2005-04-24 16:34:36 +00:00
return $output;
2001-07-11 22:06:24 +00:00
}
2005-09-23 08:47:13 +00:00
/**
* Implementation of hook_validate().
*/
2005-11-12 02:54:13 +00:00
function blog_validate($node) {
2005-09-23 08:47:13 +00:00
node_validate_title($node);
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_form().
*/
2004-07-04 16:50:02 +00:00
function blog_form(&$node) {
2003-06-02 18:11:54 +00:00
global $nid;
2004-05-08 07:17:47 +00:00
$iid = $_GET['iid'];
2001-11-03 18:38:30 +00:00
2005-09-23 08:47:13 +00:00
2003-09-20 16:08:57 +00:00
if (empty($node->body)) {
2001-11-03 18:38:30 +00:00
/*
** If the user clicked a "blog it" link, we load the data from the
** database and quote it in the blog:
*/
2005-07-17 18:29:32 +00:00
if ($nid && $blog = node_load($nid)) {
2004-08-12 18:00:11 +00:00
$node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']';
2001-11-01 17:04:20 +00:00
}
2004-05-24 19:45:11 +00:00
if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) {
2002-06-10 19:49:16 +00:00
$node->title = $item->title;
2005-05-31 21:14:27 +00:00
// Note: $item->description has been validated on aggregation.
$node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
2001-11-01 17:04:20 +00:00
}
2005-10-07 06:11:12 +00:00
2001-11-01 17:04:20 +00:00
}
2001-07-11 22:06:24 +00:00
2005-11-12 11:26:16 +00:00
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title);
2005-11-23 16:18:28 +00:00
$form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
2005-12-05 09:11:33 +00:00
$form['filter'] = filter_form($node->format);
2005-10-07 06:11:12 +00:00
return $form;
2001-07-11 22:06:24 +00:00
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_view().
*/
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
2003-11-25 19:26:21 +00:00
if ($page) {
2003-09-20 15:11:41 +00:00
// Breadcrumb navigation
2004-06-18 15:04:37 +00:00
$breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
$breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("%name's blog", array('%name' => $node->name)));
$breadcrumb[] = array('path' => 'node/'. $node->nid);
menu_set_location($breadcrumb);
2003-09-20 15:11:41 +00:00
}
2004-10-23 17:18:23 +00:00
$node = node_prepare($node, $teaser);;
2003-09-20 15:11:41 +00:00
}
2004-04-21 13:56:38 +00:00
/**
* Implementation of hook_link().
*/
2005-04-12 19:47:06 +00:00
function blog_link($type, $node = 0, $main = 0) {
2003-04-21 14:55:03 +00:00
$links = array();
2004-04-21 13:56:38 +00:00
if ($type == 'node' && $node->type == 'blog') {
2005-07-29 21:39:18 +00:00
if (arg(0) != 'blog' || arg(1) != $node->uid) {
2004-04-21 13:56:38 +00:00
$links[] = l(t("%username's blog", array('%username' => $node->name)), "blog/$node->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $node->name))));
2001-12-06 17:33:05 +00:00
}
2001-07-14 12:12:41 +00:00
}
2003-04-21 14:55:03 +00:00
return $links;
2001-07-11 22:06:24 +00:00
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2004-09-16 07:17:56 +00:00
function blog_menu($may_cache) {
2004-06-18 15:04:37 +00:00
global $user;
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
$items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'),
'access' => user_access('edit own blog'));
$items[] = array('path' => 'blog', 'title' => t('blogs'),
'callback' => 'blog_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
2005-07-31 08:58:01 +00:00
$items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'),
'access' => user_access('edit own blog'),
2005-07-25 17:18:43 +00:00
'type' => MENU_DYNAMIC_ITEM);
2004-09-16 07:17:56 +00:00
}
2004-06-18 15:04:37 +00:00
return $items;
}
2004-05-08 07:17:47 +00:00
/**
* Implementation of hook_block().
*
* Displays the most recent 10 blog titles.
*/
function blog_block($op = 'list', $delta = 0) {
2001-09-16 11:33:14 +00:00
global $user;
2004-05-08 07:17:47 +00:00
if ($op == 'list') {
2004-07-08 15:09:53 +00:00
$block[0]['info'] = t('Recent blog posts');
2002-11-09 20:51:23 +00:00
return $block;
2002-10-26 15:17:26 +00:00
}
2004-10-31 07:34:47 +00:00
else if ($op == 'view') {
2004-05-08 07:17:47 +00:00
if (user_access('access content')) {
2005-07-02 11:58:16 +00:00
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
}
2002-05-29 17:08:05 +00:00
}
2001-07-11 22:06:24 +00:00
}
}
2005-08-25 21:14:17 +00:00