[ Index ] |
|
Code source de Drupal 5.3 |
1 <?php 2 // $Id: blog.module,v 1.271.2.2 2007/04/23 17:05:11 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_node_info(). 11 */ 12 function blog_node_info() { 13 return array( 14 'blog' => array( 15 'name' => t('Blog entry'), 16 'module' => 'blog', 17 'description' => t('A blog is a regularly updated journal or diary made up of individual posts shown in reversed chronological order. Each member of the site may create and maintain a blog.'), 18 ) 19 ); 20 } 21 22 /** 23 * Implementation of hook_perm(). 24 */ 25 function blog_perm() { 26 return array('edit own blog'); 27 } 28 29 /** 30 * Implementation of hook_access(). 31 */ 32 function blog_access($op, $node) { 33 global $user; 34 35 if ($op == 'create') { 36 return user_access('edit own blog') && $user->uid; 37 } 38 39 if ($op == 'update' || $op == 'delete') { 40 if (user_access('edit own blog') && ($user->uid == $node->uid)) { 41 return TRUE; 42 } 43 } 44 } 45 46 /** 47 * Implementation of hook_user(). 48 */ 49 function blog_user($type, &$edit, &$user) { 50 if ($type == 'view' && user_access('edit own blog', $user)) { 51 $items['blog'] = array('title' => t('Blog'), 52 'value' => l(t('View recent blog entries'), "blog/$user->uid", array('title' => t("Read @username's latest blog entries.", array('@username' => $user->name)))), 53 'class' => 'blog', 54 ); 55 return array(t('History') => $items); 56 } 57 } 58 59 /** 60 * Implementation of hook_help(). 61 */ 62 function blog_help($section) { 63 switch ($section) { 64 case 'admin/help#blog': 65 $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 web pages users have read and/or agree/disagree with.') .'</p>'; 66 $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>'; 67 $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>'; 68 $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@blog">Blog page</a>.', array('@blog' => 'http://drupal.org/handbook/modules/blog/')) .'</p>'; 69 return $output; 70 } 71 } 72 73 /** 74 * Displays an RSS feed containing recent blog entries of a given user. 75 */ 76 function blog_feed_user($uid = 0) { 77 global $user; 78 79 if ($uid) { 80 $account = user_load(array('uid' => $uid, 'status' => 1)); 81 } 82 else { 83 $account = $user; 84 } 85 86 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10)); 87 $channel['title'] = $account->name ."'s blog"; 88 $channel['link'] = url("blog/$uid", NULL, NULL, TRUE); 89 $channel['description'] = $term->description; 90 node_feed($result, $channel); 91 } 92 93 /** 94 * Displays an RSS feed containing recent blog entries of all users. 95 */ 96 function blog_feed_last() { 97 $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10)); 98 $channel['title'] = variable_get('site_name', 'Drupal') .' blogs'; 99 $channel['link'] = url('blog', NULL, NULL, TRUE); 100 $channel['description'] = $term->description; 101 node_feed($result, $channel); 102 } 103 104 /** 105 * Menu callback; displays a Drupal page containing recent blog entries. 106 */ 107 function blog_page($a = NULL, $b = NULL) { 108 109 if (is_numeric($a)) { // $a is a user ID 110 if ($b == 'feed') { 111 return blog_feed_user($a); 112 } 113 else { 114 return blog_page_user($a); 115 } 116 } 117 else if ($a == 'feed') { 118 return blog_feed_last(); 119 } 120 else { 121 return blog_page_last(); 122 } 123 } 124 125 /** 126 * Displays a Drupal page containing recent blog entries of a given user. 127 */ 128 function blog_page_user($uid) { 129 global $user; 130 131 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1)); 132 133 if ($account->uid) { 134 drupal_set_title($title = t("@name's blog", array('@name' => $account->name))); 135 136 if (($account->uid == $user->uid) && user_access('edit own blog')) { 137 $output = '<li>'. l(t('Post new blog entry.'), "node/add/blog") .'</li>'; 138 } 139 else if ($account->uid == $user->uid) { 140 $output = '<li>'. t('You are not allowed to post a new blog entry.') .'</li>'; 141 } 142 143 if ($output) { 144 $output = '<ul>'. $output .'</ul>'; 145 } 146 else { 147 $output = ''; 148 } 149 150 $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.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); 151 while ($node = db_fetch_object($result)) { 152 $output .= node_view(node_load($node->nid), 1); 153 } 154 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); 155 drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); 156 157 return $output; 158 } 159 else { 160 drupal_not_found(); 161 } 162 } 163 164 /** 165 * Displays a Drupal page containing recent blog entries of all users. 166 */ 167 function blog_page_last() { 168 global $user; 169 170 $output = ''; 171 172 $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.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); 173 174 while ($node = db_fetch_object($result)) { 175 $output .= node_view(node_load($node->nid), 1); 176 } 177 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); 178 drupal_add_feed(url('blog/feed'), t('RSS - blogs')); 179 180 return $output; 181 } 182 183 /** 184 * Implementation of hook_form(). 185 */ 186 function blog_form(&$node) { 187 global $nid; 188 $iid = $_GET['iid']; 189 $type = node_get_types('type', $node); 190 191 192 if (empty($node->body)) { 193 /* 194 ** If the user clicked a "blog it" link, we load the data from the 195 ** database and quote it in the blog: 196 */ 197 198 if ($nid && $blog = node_load($nid)) { 199 $node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']'; 200 } 201 202 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))) { 203 $node->title = $item->title; 204 // Note: $item->description has been validated on aggregation. 205 $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"; 206 } 207 208 } 209 210 $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); 211 $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); 212 $form['body_filter']['filter'] = filter_form($node->format); 213 return $form; 214 } 215 216 /** 217 * Implementation of hook_view(). 218 */ 219 function blog_view($node, $teaser = FALSE, $page = FALSE) { 220 if ($page) { 221 // Breadcrumb navigation 222 $breadcrumb[] = array('path' => 'blog', 'title' => t('Blogs')); 223 $breadcrumb[] = array('path' => 'blog/'. $node->uid, 'title' => t("@name's blog", array('@name' => $node->name))); 224 $breadcrumb[] = array('path' => 'node/'. $node->nid); 225 menu_set_location($breadcrumb); 226 } 227 return node_prepare($node, $teaser); 228 } 229 230 /** 231 * Implementation of hook_link(). 232 */ 233 function blog_link($type, $node = NULL, $teaser = FALSE) { 234 $links = array(); 235 236 if ($type == 'node' && $node->type == 'blog') { 237 if (arg(0) != 'blog' || arg(1) != $node->uid) { 238 $links['blog_usernames_blog'] = array( 239 'title' => t("@username's blog", array('@username' => $node->name)), 240 'href' => "blog/$node->uid", 241 'attributes' => array('title' => t("Read @username's latest blog entries.", array('@username' => $node->name))) 242 ); 243 } 244 } 245 246 return $links; 247 } 248 249 /** 250 * Implementation of hook_menu(). 251 */ 252 function blog_menu($may_cache) { 253 global $user; 254 $items = array(); 255 256 if ($may_cache) { 257 $items[] = array('path' => 'blog', 'title' => t('Blogs'), 258 'callback' => 'blog_page', 259 'access' => user_access('access content'), 260 'type' => MENU_SUGGESTED_ITEM); 261 $items[] = array('path' => 'blog/'. $user->uid, 'title' => t('My blog'), 262 'access' => user_access('edit own blog'), 263 'type' => MENU_DYNAMIC_ITEM); 264 } 265 266 return $items; 267 } 268 269 /** 270 * Implementation of hook_block(). 271 * 272 * Displays the most recent 10 blog titles. 273 */ 274 function blog_block($op = 'list', $delta = 0) { 275 global $user; 276 if ($op == 'list') { 277 $block[0]['info'] = t('Recent blog posts'); 278 return $block; 279 } 280 else if ($op == 'view') { 281 if (user_access('access content')) { 282 $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); 283 if (db_num_rows($result)) { 284 $block['content'] = node_title_list($result); 285 $block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>'; 286 $block['subject'] = t('Recent blog posts'); 287 return $block; 288 } 289 } 290 } 291 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 16:20:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |