/[drupal]/contributions/modules/bloginfo/bloginfo.module
ViewVC logotype

Contents of /contributions/modules/bloginfo/bloginfo.module

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


Revision 1.11 - (show annotations) (download) (as text)
Sat Oct 25 01:33:30 2008 UTC (13 months ago) by yettyn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +6 -7 lines
File MIME type: text/x-php
Simplify the db call for the bloginfo content, there can only be one...
1 <?php
2 // $Id: bloginfo.module,v 1.10 2008/10/16 22:24:35 yettyn Exp $
3
4 /**
5 * @file
6 * The Blog title and description module.
7 *
8 */
9
10 // hook_help
11 function bloginfo_help($path, $arg) {
12 switch ($path) {
13 case 'admin/help#bloginfo':
14 $output = '<p>'. t('This module allows bloggers to have a title and description for their blog that is seperate from their username. This is similar to the title and descriptioin of blogs such as those at blogspot.com provided by blogger.') .'</p>';
15 $output .= '<p>'. t('The title and description is displayed in a block and is editable in a users \'my account\' options.') .'</p>';
16 return $output;
17 }
18 }
19
20 // hook_perm
21 function bloginfo_perm() {
22 return array(
23 'administer bloginfo' => array(
24 'title' => t('Administer bloginfo'),
25 'description' => t('Determine if user can administer the blog information module'),
26 ),
27 'edit own bloginfo' => array(
28 'title' => t('Edit own bloginfo'),
29 'description' => t('To set if user can edit own blog information'),
30 )
31 );
32 }
33
34 /**
35 * Implementation of hook_user().
36 */
37 function bloginfo_user_update(&$edit, &$account, $category = NULL) {
38 return bloginfo_save_bloginfo($edit, $account, $category);
39 }
40 function bloginfo_user_insert(&$edit, &$account, $category = NULL) {
41 return bloginfo_save_bloginfo($edit, $account, $category);
42 }
43 function bloginfo_user_form(&$edit, &$account, $category = NULL) {
44 return bloginfo_form_bloginfo($edit, $account, $category);
45 }
46 function bloginfo_user_delete(&$edit, &$account, $category = NULL) {
47 $num_deleted = db_delete('bloginfo')
48 ->condition('uid', $account->uid)
49 ->execute();
50 }
51
52 /**
53 * Implementation of hook_menu_alter().
54 */
55 function bloginfo_menu_alter(&$callbacks) {
56 // Use wrapper function instead of blog_page_user() so the page title
57 // can be set.
58 $callbacks['blog/%user_current']['page callback'] = 'bloginfo_page_user';
59 // Use wrapper function instead of blog_feed_user() so the feed title
60 // can be set.
61 $callbacks['blog/%user/feed']['page callback'] = 'bloginfo_feed_user';
62 }
63
64 /**
65 * Implementation of hook_block().
66 */
67 function bloginfo_block($op = 'list', $delta = 0, $edit = array()) {
68 if ($op == 'list') {
69 $blocks['bloginfo'] = array(
70 'info' => t('Blog information'),
71 );
72 $blocks['blogroll'] = array(
73 'info' => t('Blogroll by blog title'),
74 );
75 return $blocks;
76 }
77 else if ($op == 'view') {
78 switch($delta) {
79 case 'bloginfo':
80 if ($node = menu_get_object());
81 if (((arg(0) == 'blog' && is_numeric(arg(1))) || $node->type == 'blog')) {
82 if (arg(0) == 'blog') $authorid = arg(1);
83 else if ($node->type == 'blog') $authorid = $node->uid;
84 $count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $authorid,))->fetchField();
85 if ($count == 1) {
86 $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $authorid,));
87 $bloginfo = $results->fetch(PDO::FETCH_OBJ);
88 $block['subject'] = check_plain($bloginfo->title);
89 $block['content'] = theme('bloginfo_block', $bloginfo->description, $bloginfo->format, $authorid);
90 return $block;
91 }
92 }
93 break;
94 case 'blogroll':
95 $results = db_query("SELECT uid, title FROM {bloginfo} WHERE title <> :title ORDER BY title ASC", array(':title' => '',));
96 foreach ($results as $item) {
97 $output[] = l($item->title, 'blog/'. $item->uid);
98 }
99 $block['subject'] = t('Blog Listing');
100 $block['content'] = theme('item_list', $output);
101 return $block;
102 break;
103 }
104 }
105 }
106
107 /**
108 * Implementation of hook_link_alter().
109 */
110 function bloginfo_link_alter(&$links, $node) {
111 foreach ($links AS $module => &$link) {
112 if ($module == 'blog_usernames_blog') {
113 $count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $node->uid)->fetchField();
114 if ($count == 1) {
115 $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $node->uid,));
116 $bloginfo = $results->fetch(PDO::FETCH_OBJ);
117 $link['title'] = strlen($bloginfo->title) ? $bloginfo->title : $link['title'];
118 }
119 }
120 }
121 }
122
123 /**
124 * Implementation of hook_theme()
125 */
126 function bloginfo_theme() {
127 return array(
128 'bloginfo_block' => array(
129 'arguments' => array('description', 'format', 'author'),
130 ),
131 );
132 }
133
134 /**
135 * Theme Function: Theme bloginfo block content
136 */
137 function theme_bloginfo_block($description, $format, $author) {
138 return check_markup($description, $format, FALSE);
139 }
140
141 /**
142 * Helper function: create the form on the user settings page
143 */
144 function bloginfo_form_bloginfo($edit, $account, $category) {
145 if ($category == 'account' && is_numeric(arg(1)) && (user_access('edit own bloginfo') || user_access('administer bloginfo'))) {
146 $bloginfo = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => arg(1),))->fetch();
147 $mybloginfo['title'] = !empty($bloginfo->title) ? $bloginfo->title : '';
148 $mybloginfo['description'] = !empty($bloginfo->description) ? $bloginfo->description : '';
149 $mybloginfo['format'] = !empty($bloginfo->format) ? $bloginfo->format : '';
150
151 $fields['bloginfo_settings'] = array(
152 '#type' => 'fieldset',
153 '#title' => t('Blog Information'),
154 '#weight' => 5);
155 $fields['bloginfo_settings']['Title'] = array(
156 '#type' => 'textfield',
157 '#title' => t('Blog Title'),
158 '#maxlength' => 128,
159 '#default_value' => $mybloginfo['title'],
160 '#description' => t('Your blog title will display on your blog and blog posts.'));
161 $fields['bloginfo_settings']['Description'] = array(
162 '#type' => 'textarea',
163 '#title' => t('Blog Description'),
164 '#default_value' => $mybloginfo['description'],
165 '#description' => t('Your blog description will display on your blog and blog posts.'));
166 $fields['bloginfo_settings']['desc_format'] = filter_form($mybloginfo['format']);
167 return $fields;
168 }//end if
169 }//end function bloginfo_form_bloginfo()
170
171 /**
172 * Helper function: insert bloginfo into the database
173 */
174 function bloginfo_save_bloginfo(&$edit, &$user, $category) {
175 if ($category == 'account') {
176 //TODO: if (menu_get_object('user)...
177 if ( arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0 && arg(2) == 'edit') {
178 //??$results = db_query('SELECT uid FROM {bloginfo} WHERE uid = :uid', array(':uid' => arg(1),));
179
180 //This is to update where info already exists in the database
181 if (db_query('SELECT COUNT(uid) FROM {bloginfo} WHERE uid = %d', arg(1))->fetchField() == 1) {
182 db_update('bloginfo')
183 ->fields(array('title' => $edit['Title'], 'description' => $edit['Description'], 'format' => $edit['format'],))
184 ->condition('uid', arg(1))
185 ->execute();
186 }
187
188 //This adds it to the database for the first time
189 else {
190 $id = db_insert('bloginfo')
191 ->fields(array(
192 'uid' => arg(1),
193 'title' => $edit['Title'],
194 'description' => $edit['Description'],
195 'format' => $edit['format'],
196 ))
197 ->execute();
198 }
199 }
200 }
201 }
202
203 /**
204 * Wrapper for blog_page_user(). Sets the page title if available.
205 */
206 function bloginfo_page_user($account) {
207 $output = blog_page_user($account);
208
209 $count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,))->fetchField();
210 if ($count == 1) {
211 $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,));
212 $bloginfo = $results->fetch(PDO::FETCH_OBJ);
213
214 if (strlen($bloginfo->title)) {
215 drupal_set_title($bloginfo->title);
216 }
217 }
218
219 return $output;
220 }
221
222 /**
223 * Menu callback; displays an RSS feed containing recent blog entries of all users.
224 *
225 * Customization of blog_feed_user().
226 */
227 function bloginfo_feed_user($account) {
228 $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"), $account->uid, 0, variable_get('feed_default_items', 10));
229 $channel['title'] = $account->name ."'s blog";
230 $channel['link'] = url('blog/'. $account->uid, array('absolute' => TRUE));
231
232 $items = array();
233 foreach ($result as $row) {
234 $items[] = $row->nid;
235 }
236
237 $count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,))->fetchField();
238 if ($count == 1) {
239 $results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,));
240 $bloginfo = $results->fetch(PDO::FETCH_OBJ);
241
242 $channel['title'] = strlen($bloginfo->title) ? $bloginfo->title : $channel['title'];
243 $channel['description'] = $bloginfo->description;
244 }
245
246 node_feed($items, $channel);
247 }

  ViewVC Help
Powered by ViewVC 1.1.2