/[drupal]/contributions/sandbox/ber/blog/blog.patch
ViewVC logotype

Contents of /contributions/sandbox/ber/blog/blog.patch

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


Revision 1.3 - (show annotations) (download) (as text)
Thu Mar 24 18:51:26 2005 UTC (4 years, 8 months ago) by ber
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +305 -225 lines
File MIME type: text/x-patch
updating to keep in sync
1 --- modules/blog.module 2005-02-21 12:41:39.000000000 +0100
2 +++ ../contributions/sandbox/ber/blog/blog.module 2005-03-18 16:27:23.000000000 +0100
3 @@ -1,43 +1,12 @@
4 <?php
5 -// $Id: blog.module,v 1.213 2005/02/12 09:23:06 dries Exp $
6 +// $Id: blog.module,v 1.2 2005/03/18 15:27:23 ber Exp $
7
8 /**
9 * @file
10 - * Enables keeping an easily and regularly updated web page or a blog.
11 + * Enables keeping a community blog.
12 */
13
14 /**
15 - * Implementation of hook_node_name().
16 - */
17 -function blog_node_name($node) {
18 - return t('personal blog entry');
19 -}
20 -
21 -/**
22 - * Implementation of hook_perm().
23 - */
24 -function blog_perm() {
25 - return array('edit own blog');
26 -}
27 -
28 -/**
29 - * Implementation of hook_access().
30 - */
31 -function blog_access($op, $node) {
32 - global $user;
33 -
34 - if ($op == 'create') {
35 - return user_access('edit own blog') && $user->uid;
36 - }
37 -
38 - if ($op == 'update' || $op == 'delete') {
39 - if (user_access('edit own blog') && ($user->uid == $node->uid)) {
40 - return TRUE;
41 - }
42 - }
43 -}
44 -
45 -/**
46 * Implementation of hook_user().
47 */
48 function blog_user($type, &$edit, &$user) {
49 @@ -55,16 +24,23 @@ function blog_help($section) {
50 return t("
51 <p>Drupal's blog module allows registered users to maintain an online weblog (commonly known as a blog), often referred to as an online journal or diary. These can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption.</p>
52 <p>Blogs are made up of individual entries (nodes) that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen and/or agree/disagree with. A typical example of a long term blog can be seen at %scripting-com.</p>
53 - <p>The blog module adds a \"user blogs\" 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. Personal user menus gain a \"create a blog entry\" link (which takes you to a submission form) and a \"view personal blog\" link (which displays your blog entries as other people will see them). On the bottom of each of your own blog entries, there is an \"edit this blog entry\" link that lets you edit or delete that entry.</p>
54 + <p>The blog module adds a \"user blogs\" 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. Personal user menus gain a \"view personal blog\" link (which displays your blog entries as other people will see them). On the bottom of each of your own blog entries, there is an \"edit this blog entry\" link that lets you edit or delete that entry.</p>
55 <p>If a user has the ability to post blogs, then the import module (news aggregator) will display a blog-it link <strong>(b)</strong> next to each news item in its lists. Click on this and you will be taken 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 you to add your explanation. This actively encourages people to add blog entries about things they see and hear elsewhere in the Drupal site and from your syndicated partner sites.</p>", array('%scripting-com' => '<a href="http://www.scripting.com/">http://www.scripting.com/</a>'));
56 case 'admin/modules#description':
57 - return t('Enables keeping an easily and regularly updated web page or a blog.');
58 + return t('Enables keeping a community blog');
59 case 'node/add#blog':
60 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.");
61 }
62 }
63
64 /**
65 + * Implementation of hook_perm().
66 + */
67 +function blog_perm() {
68 + return array('edit own blog');
69 +}
70 +
71 +/**
72 * Displays an RSS feed containing recent blog entries of a given user.
73 */
74 function blog_feed_user($uid = 0) {
75 @@ -77,7 +53,7 @@ function blog_feed_user($uid = 0) {
76 $account = $user;
77 }
78
79 - $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n 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, 15);
80 + $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {blog} b on b.nid = n.nid WHERE b.nid AND u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, 15);
81 $channel['title'] = $account->name ."'s blog";
82 $channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
83 $channel['description'] = $term->description;
84 @@ -88,7 +64,7 @@ function blog_feed_user($uid = 0) {
85 * Displays an RSS feed containing recent blog entries of all users.
86 */
87 function blog_feed_last() {
88 - $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
89 + $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.teaser, n.created, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {blog} b on b.nid = n.nid WHERE b.nid AND n.status = 1 ORDER BY n.created DESC"), 0, 15);
90 $channel['title'] = variable_get('site_name', 'drupal') .' blogs';
91 $channel['link'] = url('blog', NULL, NULL, TRUE);
92 $channel['description'] = $term->description;
93 @@ -99,8 +75,8 @@ function blog_feed_last() {
94 * Menu callback; displays a Drupal page containing recent blog entries.
95 */
96 function blog_page($a = NULL, $b = NULL) {
97 -
98 - if (is_numeric($a)) { // $a is a user ID
99 + if (is_numeric($a) && user_access('edit own blog', user_load(array('uid'=>$a))) ) {
100 + //$a is a user ID, the user is allowed to have a blog.
101 if ($b == 'feed') {
102 blog_feed_user($a);
103 }
104 @@ -124,16 +100,9 @@ function blog_page_user($uid) {
105
106 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
107
108 - if ($account->uid) {
109 + if ($account->uid && user_access('edit own blog', $account)) {
110 drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
111
112 - if (($account->uid == $user->uid) && user_access('edit own blog')) {
113 - $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>';
114 - }
115 - else if ($account->uid == $user->uid) {
116 - $output = '<li>'. t('You are not allowed to post a new blog entry.') .'</li>';
117 - }
118 -
119 if ($output) {
120 $output = '<ul>'. $output .'</ul>';
121 }
122 @@ -141,7 +110,7 @@ function blog_page_user($uid) {
123 $output = '';
124 }
125
126 - $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);
127 + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n INNER JOIN {blog} b on b.nid = n.nid WHERE b.nid 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);
128 while ($node = db_fetch_object($result)) {
129 $output .= node_view(node_load(array('nid' => $node->nid)), 1);
130 }
131 @@ -164,11 +133,12 @@ function blog_page_last() {
132
133 $output = '';
134
135 - $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));
136 + $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n INNER JOIN {blog} b on b.nid = n.nid WHERE b.nid AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
137
138 while ($node = db_fetch_object($result)) {
139 $output .= node_view(node_load(array('nid' => $node->nid)), 1);
140 }
141 +
142 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
143 $output .= theme('xml_icon', url('blog/feed'));
144
145 @@ -177,50 +147,81 @@ function blog_page_last() {
146 }
147
148 /**
149 - * Implementation of hook_form().
150 + * Implementation of hook_nodeapi().
151 */
152 -function blog_form(&$node) {
153 - global $nid;
154 - $iid = $_GET['iid'];
155 -
156 - if (empty($node->body)) {
157 - /*
158 - ** If the user clicked a "blog it" link, we load the data from the
159 - ** database and quote it in the blog:
160 - */
161 -
162 - if ($nid && $blog = node_load(array('nid' => $nid))) {
163 - $node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']';
164 - }
165 -
166 - 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))) {
167 - $node->title = $item->title;
168 - $node->body = "<a href=\"$item->link\">$item->title</a> - <em>". $item->description ."</em> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
169 - }
170 - }
171 -
172 - if (function_exists('taxonomy_node_form')) {
173 - $output .= implode('', taxonomy_node_form('blog', $node));
174 +function blog_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
175 + switch ($op) {
176 + case 'form post':
177 + if (user_access('edit own blog')) {
178 + $checked = ( $node->node_in_blog ? TRUE : (_blog_node_in_blog($node->nid) ? TRUE : FALSE ));
179 + return form_checkbox(t('Add to my blog'), 'node_in_blog', 1, $checked, t('Checking this box will make this node show up in your blog'));
180 + }
181 + break;
182 + case 'insert':
183 + if (user_access('edit own blog') && $node->node_in_blog) {
184 + //Checking user access, to prevent people hacking the POST variables.
185 + _blog_insert($node->nid);
186 + }
187 + break;
188 + case 'update':
189 + if (user_access('edit own blog') && $node->node_in_blog && !_blog_node_in_blog($node->nid)) {
190 + //The node was not yet in your blog, but should be there now.
191 + _blog_insert($node->nid);
192 + }
193 + elseif (user_access('edit own blog') && !$node->node_in_blog && _blog_node_in_blog($node->nid)) {
194 + //The node was in the blog, but should now be removed
195 + _blog_delete($node->nid);
196 + }
197 + break;
198 + case 'delete':
199 + _blog_delete($node->nid);
200 + break;
201 + case 'view':
202 + if (_blog_node_in_blog($node->nid)) {
203 + blog_breadcrumb($node);
204 + }
205 + break;
206 + default:
207 + break;
208 }
209 +}
210
211 - $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
212 - $output .= filter_form('format', $node->format);
213 +/**
214 + * Helper for nodeapi delete
215 + */
216 +function _blog_insert($nid) {
217 + db_query('INSERT INTO {blog} (nid) VALUES(%d)', $nid);
218 + drupal_set_message(t('The article was added to your blog'));
219 +}
220
221 - return $output;
222 +/**
223 + * Helper for nodeapi delete
224 + */
225 +function _blog_delete($nid) {
226 + db_query('DELETE FROM {blog} WHERE %d', $nid);
227 + drupal_set_message(t('The article was removed from your blog'));
228 }
229
230 /**
231 - * Implementation of hook_view().
232 + * General helper looks if a node is in a blog
233 */
234 -function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
235 - if ($page) {
236 - // Breadcrumb navigation
237 - $breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
238 - $breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("%name's blog", array('%name' => $node->name)));
239 - $breadcrumb[] = array('path' => 'node/'. $node->nid);
240 - menu_set_location($breadcrumb);
241 +function _blog_node_in_blog($nid, $uid = NULL) {
242 + if ($uid) {
243 + return db_fetch_object(db_query('SELECT b.nid FROM {blog} b INNER JOIN {node} n ON n.nid = b.nid WHERE n.uid = %d AND nid = %d', $uid, $nid));
244 + }
245 + else {
246 + return db_fetch_object(db_query('SELECT nid FROM {blog} WHERE nid = %d', $nid));
247 }
248 - $node = node_prepare($node, $teaser);;
249 +}
250 +
251 +/**
252 + * Set the breadcrumb navigation
253 + */
254 +function blog_breadcrumb(&$node) {
255 + $breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
256 + $breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("%name's blog", array('%name' => $node->name)));
257 + $breadcrumb[] = array('path' => 'node/'. $node->nid);
258 + menu_set_location($breadcrumb);
259 }
260
261 /**
262 @@ -229,7 +230,7 @@ function blog_view(&$node, $teaser = FAL
263 function blog_link($type, $node = 0, $main) {
264 $links = array();
265
266 - if ($type == 'node' && $node->type == 'blog') {
267 + if ($type == 'node' && _blog_node_in_blog($node->nid)) {
268 if (arg(0) != 'blog' && arg(1) != $node->uid) {
269 $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))));
270 }
271 @@ -242,18 +243,14 @@ function blog_link($type, $node = 0, $ma
272 * Implementation of hook_menu().
273 */
274 function blog_menu($may_cache) {
275 - global $user;
276 $items = array();
277
278 if ($may_cache) {
279 - $items[] = array('path' => 'node/add/blog', 'title' => t('blog entry'),
280 - 'access' => user_access('edit own blog'));
281 $items[] = array('path' => 'blog', 'title' => t('blogs'),
282 'callback' => 'blog_page',
283 'access' => user_access('access content'),
284 'type' => MENU_SUGGESTED_ITEM);
285 }
286 -
287 return $items;
288 }
289
290 @@ -263,14 +260,13 @@ function blog_menu($may_cache) {
291 * Displays the most recent 10 blog titles.
292 */
293 function blog_block($op = 'list', $delta = 0) {
294 - global $user;
295 if ($op == 'list') {
296 $block[0]['info'] = t('Recent blog posts');
297 return $block;
298 }
299 else if ($op == 'view') {
300 if (user_access('access content')) {
301 - $block['content'] = node_title_list(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));
302 + $block['content'] = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n INNER JOIN {blog} b on b.nid = n.nid WHERE b.nid AND n.status = 1 ORDER BY n.created DESC"), 0, 10));
303 $block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
304 $block['subject'] = t('Recent blog posts');
305 }

  ViewVC Help
Powered by ViewVC 1.1.2