Simpletest Coverage - modules/blog/blog.module

1 <?php
2 // $Id: blog.module,v 1.329 2009/08/12 12:36:04 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_permission().
24 */
25 function blog_permission() {
26 return node_list_permissions('blog');
27 }
28
29 /**
30 * Implement hook_access().
31 */
32 function blog_access($op, $node, $account) {
33 switch ($op) {
34 case 'create':
35 // Anonymous users cannot post even if they have the permission.
36 return user_access('create blog content', $account) && $account->uid;
37 case 'update':
38 return user_access('edit any blog content', $account) || (user_access('edit own blog content', $account) && ($node->uid == $account->uid));
39 case 'delete':
40 return user_access('delete any blog content', $account) || (user_access('delete own blog content', $account) && ($node->uid == $account->uid));
41 }
42 }
43
44 /**
45 * Implement hook_user_view().
46 */
47 function blog_user_view($account) {
48 if (user_access('create blog content', $account)) {
49 $account->content['summary']['blog'] = array(
50 '#type' => 'user_profile_item',
51 '#title' => t('Blog'),
52 '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $account->name))))),
53 '#attributes' => array('class' => 'blog'),
54 );
55 }
56 }
57
58 /**
59 * Implement hook_help().
60 */
61 function blog_help($path, $arg) {
62 switch ($path) {
63 case 'admin/help#blog':
64 $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>';
65 $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>';
66 $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>';
67 $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>';
68 return $output;
69 }
70 }
71
72 /**
73 * Implement hook_form().
74 */
75 function blog_form($node, $form_state) {
76 return node_content_form($node, $form_state);
77 }
78
79 /**
80 * Implement hook_view().
81 */
82 function blog_view($node, $build_mode) {
83 if ((bool)menu_get_object()) {
84 // Breadcrumb navigation.
85 drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('Blogs'), 'blog'), l(t("!name's blog", array('!name' => $node->name)), 'blog/' . $node->uid)));
86 }
87 return $node;
88 }
89
90 /**
91 * Implement hook_node_view().
92 */
93 function blog_node_view($node, $build_mode = 'full') {
94 if ($build_mode != 'rss') {
95 if ($node->type == 'blog' && arg(0) != 'blog' || arg(1) != $node->uid) {
96 $links['blog_usernames_blog'] = array(
97 'title' => t("!username's blog", array('!username' => $node->name)),
98 'href' => "blog/$node->uid",
99 'attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => $node->name))),
100 );
101 $node->content['links']['blog'] = array(
102 '#theme' => 'links',
103 '#links' => $links,
104 '#attributes' => array('class' => 'links inline'),
105 );
106 }
107 }
108 }
109
110 /**
111 * Implement hook_menu().
112 */
113 function blog_menu() {
114 $items['blog'] = array(
115 'title' => 'Blogs',
116 'page callback' => 'blog_page_last',
117 'access arguments' => array('access content'),
118 'type' => MENU_SUGGESTED_ITEM,
119 );
120 $items['blog/%user_uid_optional'] = array(
121 'title' => 'My blog',
122 'page callback' => 'blog_page_user',
123 'page arguments' => array(1),
124 'access callback' => 'blog_page_user_access',
125 'access arguments' => array(1),
126 );
127 $items['blog/%user/feed'] = array(
128 'title' => 'Blogs',
129 'page callback' => 'blog_feed_user',
130 'page arguments' => array(1),
131 'access callback' => 'blog_page_user_access',
132 'access arguments' => array(1),
133 'type' => MENU_CALLBACK,
134 );
135 $items['blog/feed'] = array(
136 'title' => 'Blogs',
137 'page callback' => 'blog_feed_last',
138 'access arguments' => array('access content'),
139 'type' => MENU_CALLBACK,
140 );
141
142 return $items;
143 }
144
145 /**
146 * Access callback for user blog pages.
147 */
148 function blog_page_user_access($account) {
149 // The visitor must be able to access the site's content.
150 // For a blog to 'exist' the user must either be able to
151 // create new blog entries, or it must have existing posts.
152 return $account->uid && user_access('access content') && (user_access('create blog content', $account) || _blog_post_exists($account));
153 }
154
155 /**
156 * Helper function to determine if a user has blog posts already.
157 */
158 function _blog_post_exists($account) {
159 return (bool)db_select('node', 'n')
160 ->fields('n', array('nid'))
161 ->condition('type', 'blog')
162 ->condition('uid', $account->uid)
163 ->condition('status', 1)
164 ->range(0, 1)
165 ->addTag('node_access')
166 ->execute()
167 ->fetchField();
168 }
169
170 /**
171 * Implement hook_block_list().
172 */
173 function blog_block_list() {
174 $block['recent']['info'] = t('Recent blog posts');
175 return $block;
176 }
177
178 /**
179 * Implement hook_block_view().
180 *
181 * Displays the most recent 10 blog titles.
182 */
183 function blog_block_view($delta = '') {
184 global $user;
185
186 if (user_access('access content')) {
187 $result = db_select('node', 'n')
188 ->fields('n', array('nid', 'title', 'created'))
189 ->condition('type', 'blog')
190 ->condition('status', 1)
191 ->orderBy('created', 'DESC')
192 ->range(0, 10)
193 ->addTag('node_access')
194 ->execute();
195
196 if ($node_title_list = node_title_list($result)) {
197 $block['content'] = $node_title_list;
198 $block['content'] .= theme('more_link', url('blog'), t('Read the latest blog entries.'));
199 $block['subject'] = t('Recent blog posts');
200 return $block;
201 }
202 }
203 }
204
205

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.