/[drupal]/drupal/modules/blog/blog.module
ViewVC logotype

Contents of /drupal/modules/blog/blog.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.340 - (show annotations) (download) (as text)
Sun Nov 1 21:26:44 2009 UTC (3 weeks, 6 days ago) by webchick
Branch: MAIN
Changes since 1.339: +5 -5 lines
File MIME type: text/x-php
#192056 by effulgentsia, Dave Cohen, andypost, hswong3i, geodaniel, pwolanin, and dahacouk: Ensure user's raw login name is never output directly.
1 <?php
2 // $Id: blog.module,v 1.339 2009/11/01 12:11:10 dries Exp $
3
4 /**
5 * @file
6 * Enables multi-user blogs.
7 */
8
9 /**
10 * Implement hook_node_info().
11 */
12 function blog_node_info() {
13 return array(
14 'blog' => array(
15 'name' => t('Blog entry'),
16 'base' => 'blog',
17 'description' => t('Use for multi-user blogs. Every user gets a personal blog.'),
18 )
19 );
20 }
21
22 /**
23 * Implement hook_user_view().
24 */
25 function blog_user_view($account) {
26 if (user_access('create blog content', $account)) {
27 $account->content['summary']['blog'] = array(
28 '#type' => 'user_profile_item',
29 '#title' => t('Blog'),
30 '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))),
31 '#attributes' => array('class' => array('blog')),
32 );
33 }
34 }
35
36 /**
37 * Implement hook_help().
38 */
39 function blog_help($path, $arg) {
40 switch ($path) {
41 case 'admin/help#blog':
42 $output = '<p>' . t('The blog module allows registered users to maintain an online journal, or <em>blog</em>. Blogs are made up of individual <em>blog entries</em>, and the blog entries are most often displayed in descending order by creation time.') . '</p>';
43 $output .= '<p>' . t("There is an (optional) <em>Blogs</em> menu item added to the Navigation menu, which displays all blogs available on your site, and a <em>My blog</em> item displaying the current user's blog entries. The <em>Blog entry</em> menu item under <em>Add new content</em> allows new blog entries to be created.") . '</p>';
44 $output .= '<p>' . t('Each blog entry is displayed with an automatic link to other blogs created by the same user. By default, blog entries have comments enabled and are automatically promoted to the site front page. The blog module also creates a <em>Recent blog posts</em> block that may be enabled at the <a href="@blocks">blocks administration page</a>.', array('@blocks' => url('admin/structure/block'))) . '</p>';
45 $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@blog">Blog module</a>.', array('@blog' => 'http://drupal.org/handbook/modules/blog/')) . '</p>';
46 return $output;
47 }
48 }
49
50 /**
51 * Implement hook_form().
52 */
53 function blog_form(stdClass $node, $form_state) {
54 return node_content_form($node, $form_state);
55 }
56
57 /**
58 * Implement hook_view().
59 */
60 function blog_view(stdClass $node, $build_mode) {
61 if ((bool)menu_get_object()) {
62 // Breadcrumb navigation.
63 drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => format_username($node))), 'blog/' . $node->uid)));
64 }
65 return $node;
66 }
67
68 /**
69 * Implement hook_node_view().
70 */
71 function blog_node_view(stdClass $node, $build_mode = 'full') {
72 if ($build_mode != 'rss') {
73 if ($node->type == 'blog' && arg(0) != 'blog' || arg(1) != $node->uid) {
74 $links['blog_usernames_blog'] = array(
75 'title' => t("!username's blog", array('!username' => format_username($node))),
76 'href' => "blog/$node->uid",
77 'attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($node)))),
78 );
79 $node->content['links']['blog'] = array(
80 '#theme' => 'links',
81 '#links' => $links,
82 '#attributes' => array('class' => array('links', 'inline')),
83 );
84 }
85 }
86 }
87
88 /**
89 * Implement hook_menu().
90 */
91 function blog_menu() {
92 $items['blog'] = array(
93 'title' => 'Blogs',
94 'page callback' => 'blog_page_last',
95 'access arguments' => array('access content'),
96 'type' => MENU_SUGGESTED_ITEM,
97 'file' => 'blog.pages.inc',
98 );
99 $items['blog/%user_uid_optional'] = array(
100 'title' => 'My blog',
101 'page callback' => 'blog_page_user',
102 'page arguments' => array(1),
103 'access callback' => 'blog_page_user_access',
104 'access arguments' => array(1),
105 'file' => 'blog.pages.inc',
106 );
107 $items['blog/%user/feed'] = array(
108 'title' => 'Blogs',
109 'page callback' => 'blog_feed_user',
110 'page arguments' => array(1),
111 'access callback' => 'blog_page_user_access',
112 'access arguments' => array(1),
113 'type' => MENU_CALLBACK,
114 'file' => 'blog.pages.inc',
115 );
116 $items['blog/feed'] = array(
117 'title' => 'Blogs',
118 'page callback' => 'blog_feed_last',
119 'access arguments' => array('access content'),
120 'type' => MENU_CALLBACK,
121 'file' => 'blog.pages.inc',
122 );
123
124 return $items;
125 }
126
127 /**
128 * Access callback for user blog pages.
129 */
130 function blog_page_user_access($account) {
131 // The visitor must be able to access the site's content.
132 // For a blog to 'exist' the user must either be able to
133 // create new blog entries, or it must have existing posts.
134 return $account->uid && user_access('access content') && (user_access('create blog content', $account) || _blog_post_exists($account));
135 }
136
137 /**
138 * Helper function to determine if a user has blog posts already.
139 */
140 function _blog_post_exists($account) {
141 return (bool)db_select('node', 'n')
142 ->fields('n', array('nid'))
143 ->condition('type', 'blog')
144 ->condition('uid', $account->uid)
145 ->condition('status', 1)
146 ->range(0, 1)
147 ->addTag('node_access')
148 ->execute()
149 ->fetchField();
150 }
151
152 /**
153 * Implement hook_block_info().
154 */
155 function blog_block_info() {
156 $block['recent']['info'] = t('Recent blog posts');
157 return $block;
158 }
159
160 /**
161 * Implement hook_block_view().
162 *
163 * Displays the most recent 10 blog titles.
164 */
165 function blog_block_view($delta = '') {
166 global $user;
167
168 if (user_access('access content')) {
169 $result = db_select('node', 'n')
170 ->fields('n', array('nid', 'title', 'created'))
171 ->condition('type', 'blog')
172 ->condition('status', 1)
173 ->orderBy('created', 'DESC')
174 ->range(0, 10)
175 ->addTag('node_access')
176 ->execute();
177
178 if ($node_title_list = node_title_list($result)) {
179 $block['content'] = $node_title_list;
180 $block['content'] .= theme('more_link', array('url' => url('blog'), 'title' => t('Read the latest blog entries.')));
181 $block['subject'] = t('Recent blog posts');
182 return $block;
183 }
184 }
185 }
186
187 /**
188 * Implements hook_rdf_mapping().
189 */
190 function blog_rdf_mapping() {
191 return array(
192 array(
193 'type' => 'node',
194 'bundle' => 'blog',
195 'mapping' => array(
196 'rdftype' => array('sioct:Weblog'),
197 ),
198 ),
199 );
200 }

  ViewVC Help
Powered by ViewVC 1.1.2