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

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

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


Revision 1.3 - (show annotations) (download) (as text)
Mon Nov 28 16:15:00 2005 UTC (4 years ago) by ber
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +90 -114 lines
File MIME type: text/x-php
adding recent rewrite of this blog.module as container
NOTE it is most non working, untested and all that.
1 <?php
2 // $Id: blog.module,v 1.236 2005/11/12 11:26:16 dries Exp $
3
4 /**
5 * @file
6 * Enables keeping an easily and regularly updated web page or a blog.
7 */
8
9 /**
10 * Implementation of hook_user().
11 */
12 function blog_user($type, &$edit, &$user) {
13 if ($type == 'view' && user_access('edit own blog', $user)) {
14 $form['blog'] = array(
15 '#type' => 'item', '#title' => t('Blog'),
16 '#value' => l(t('view recent blog entries'), "blog/$user->uid", array('title' => t("Read %username's latest blog entries.", array('%username' => $user->name))))
17 );
18 return array(t('History') => $form);
19 }
20 }
21
22 /**
23 * Implementation of hook_help().
24 */
25 function blog_help($section) {
26 switch ($section) {
27 case 'admin/help#blog':
28 $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>';
29 $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. This page is always ordered chronologically by creation date. Static nodes to not float to the top of this list. The navigation menu has 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>';
30 $output .= t('<p>You can</p>
31 <ul>
32 <li>read your blog via your user profile at <a href="%user">my account</a>.</li>
33 <li>Define what posts can be added to a blog <a href="%admin-settings-types">administer &gt;&gt; settings &gt;&gt; content types</a>.</li>
34 <li>enable the "recent blog posts" block at <a href="%admin-block">administer &gt;&gt; blocks</a> to show the 10 most recent blog posts.</li>
35 </ul>
36 ', array('%user' => url('user'), '%admin-settings-types' => url('admin/settings/types/'), '%admin-block' => url('admin/block')));
37 $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>';
38 return $output;
39 case 'admin/modules#description':
40 return t('Enables keeping an easily and regularly updated web page or a blog.');
41 }
42 }
43
44 /**
45 * Displays an RSS feed containing recent blog entries of a given user.
46 */
47 function blog_feed_user($uid = 0) {
48 global $user;
49
50 if ($uid) {
51 $account = user_load(array('uid' => $uid, 'status' => 1));
52 }
53 else {
54 $account = $user;
55 }
56
57 $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 INNER JOIN {blog} b ON n.nid = b.nid WHERE u.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
58 $channel['title'] = $account->name ."'s blog";
59 $channel['link'] = url("blog/$uid", NULL, NULL, TRUE);
60 $channel['description'] = $term->description;
61 node_feed($result, $channel);
62 }
63
64 /**
65 * Displays an RSS feed containing recent blog entries of all users.
66 */
67 function blog_feed_last() {
68 $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 INNER JOIN {blog} b ON n.nid = b.nid WHERE n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
69 $channel['title'] = variable_get('site_name', 'drupal') .' blogs';
70 $channel['link'] = url('blog', NULL, NULL, TRUE);
71 $channel['description'] = $term->description;
72 node_feed($result, $channel);
73 }
74
75 /**
76 * Menu callback; displays a Drupal page containing recent blog entries.
77 */
78 function blog_page($a = NULL, $b = NULL) {
79
80 if (is_numeric($a)) { // $a is a user ID
81 if ($b == 'feed') {
82 return blog_feed_user($a);
83 }
84 else {
85 return blog_page_user($a);
86 }
87 }
88 else if ($a == 'feed') {
89 return blog_feed_last();
90 }
91 else {
92 return blog_page_last();
93 }
94 }
95
96 /**
97 * Displays a Drupal page containing recent blog entries of a given user.
98 */
99 function blog_page_user($uid) {
100 global $user;
101
102 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
103
104 if ($account->uid) {
105 drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
106
107 $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n INNER JOIN {blog} b ON n.nid = b.nid WHERE 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);
108 while ($node = db_fetch_object($result)) {
109 $output .= node_view(node_load($node->nid), 1);
110 }
111 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
112 $output .= theme('xml_icon', url("blog/$account->uid/feed"));
113
114 drupal_add_link(array('rel' => 'alternate',
115 'type' => 'application/rss+xml',
116 'title' => t('RSS - %title', array('%title' => $title)),
117 'href' => url("blog/$account->uid/feed")));
118 return $output;
119 }
120 else {
121 drupal_not_found();
122 }
123 }
124
125 /**
126 * Displays a Drupal page containing recent blog entries of all users.
127 */
128 function blog_page_last() {
129 global $user;
130
131 $output = '';
132
133 $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n INNER JOIN {blog} b ON n.nid = b.nid WHERE n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
134
135 while ($node = db_fetch_object($result)) {
136 $output .= node_view(node_load($node->nid), 1);
137 }
138 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
139 $output .= theme('xml_icon', url('blog/feed'));
140
141 drupal_add_link(array('rel' => 'alternate',
142 'type' => 'application/rss+xml',
143 'title' => t('RSS - blogs'),
144 'href' => url("blog/feed")));
145 return $output;
146 }
147
148 /**
149 * Implementation of nodeapi
150 */
151 function blog_nodeapi($node, $op) {
152 switch ($op) {
153 case 'view':
154 if ($page) {
155 _blog_set_breadcrumb($node);
156 }
157 break;
158 case 'load':
159 return _blog_load($node);
160 case 'form':
161 return array('in_blog'] => array('#type' => 'checkbox',
162 '#title' => t('Add to my blog'),
163 '#default_value' => $node->in_blog);
164 }
165 }
166
167 /**
168 * Call from nodeapi
169 */
170 function _blog_load($node) {
171
172 }
173 /**
174 * Call from nodeapi
175 */
176 function _blog_set_breadcrumb($node) {
177 // Breadcrumb navigation
178 $breadcrumb[] = array('path' => 'blog', 'title' => t('blogs'));
179 $breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("%name's blog", array('%name' => $node->name)));
180 $breadcrumb[] = array('path' => 'node/'. $node->nid);
181 menu_set_location($breadcrumb);
182 }
183
184 /**
185 * Implementation of hook_link().
186 */
187 function blog_link($type, $node = 0, $main = 0) {
188 $links = array();
189
190 if ($type == 'node' && $node->in_blog) {
191 if (arg(0) != 'blog' || arg(1) != $node->uid) {
192 $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))));
193 }
194 }
195
196 return $links;
197 }
198
199 /**
200 * Implementation of hook_menu().
201 */
202 function blog_menu($may_cache) {
203 global $user;
204 $items = array();
205
206 if ($may_cache) {
207 $items[] = array('path' => 'blog', 'title' => t('blogs'),
208 'callback' => 'blog_page',
209 'access' => user_access('access content'),
210 'type' => MENU_SUGGESTED_ITEM);
211 $items[] = array('path' => 'blog/'. $user->uid, 'title' => t('my blog'),
212 'access' => user_access('edit own blog'),
213 'type' => MENU_DYNAMIC_ITEM);
214 }
215
216 return $items;
217 }
218
219 /**
220 * Implementation of hook_block().
221 *
222 * Displays the most recent 10 blog titles.
223 */
224 function blog_block($op = 'list', $delta = 0) {
225 global $user;
226 if ($op == 'list') {
227 $block[0]['info'] = t('Recent blog posts');
228 return $block;
229 }
230 else if ($op == 'view') {
231 if (user_access('access content')) {
232 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE INNER JOIN {blog} b ON n.nid = b.nid n.status = 1 ORDER BY n.created DESC"), 0, 10);
233 if (db_num_rows($result)) {
234 $block['content'] = node_title_list($result);
235 $block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
236 $block['subject'] = t('Recent blog posts');
237 return $block;
238 }
239 }
240 }
241 }
242
243 /**
244 * API function to determine if a node is in the users blog
245 * @param $node a nod eobject that contains at least a $node->nid
246 * @return boolean TRUE if the node is in the blog,FALSE if it is not.
247 */
248 function blog_in_blog($node) {
249 $result = db_fetch_object(db_query(db_rewrite_sql('SELECT nid FROM {blog} b INNER JOIN {node} ON n.nid = b.nid WHERE b.nid = %d AND n.status = 1'), $node->nid));
250 if ($result->nid) {
251 return TRUE;
252 }
253 }

  ViewVC Help
Powered by ViewVC 1.1.2