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

Contents of /contributions/modules/blog_addons/blog_addons.module

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


Revision 1.4 - (show annotations) (download) (as text)
Fri May 30 23:13:42 2008 UTC (17 months, 4 weeks ago) by chajecki
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /* test */
3 /**
4 * Implementation of hook_perm().
5 */
6 function blog_addons_perm()
7 {
8 return array( 'administer blog_addons', );
9 }
10
11 /**
12 * Implementation of hook_menu().
13 */
14 function blog_addons_menu($may_cache) {
15 global $user;
16 $items = array();
17
18 $items[] = array(
19 'path' => 'blogs',
20 'title' => t(''),
21 'callback' => 'blog_addons_bloggers',
22 'access' => user_access('access content'),
23 'type' => MENU_CALLBACK,
24 );
25 $items[] = array(
26 'path' => 'blog',
27 'title' => t(''),
28 'callback' => 'blog_addons_bloggers',
29 'access' => user_access('access content'),
30 'type' => MENU_CALLBACK,
31 );
32
33 $items[] = array(
34 'path' => 'blogs/bloggers',
35 'title' => t('Bloggers'),
36 'callback' => 'blog_addons_bloggers',
37 'access' => user_access('access content'),
38 'type' => MENU_DEFAULT_LOCAL_TASK,
39 'weight' => -10,
40 );
41
42 $items[] = array(
43 'path' => 'blogs/posts',
44 'title' => t('Blog Posts'),
45 'callback' => 'blog_addons_recentposts',
46 'access' => user_access('access content'),
47 'type' => MENU_LOCAL_TASK,
48 'weight' => -10,
49 );
50
51 if (arg(0) == 'blog')// && is_numeric(arg(2)))
52 {
53 if (is_numeric(arg(2)))
54 $path = 'blog/'. arg(1) . '/' . arg(2);
55 else
56 $path = 'blog/' . arg(1);
57
58 if (is_numeric(arg(3)))
59 {
60 $path .= '/' . arg(3);
61 if (is_numeric(arg(4)))
62 $path .= '/' . arg(4);
63 }
64 $account = user_load(array('uid' => arg(1) ));
65
66 $items[] = array(
67 'path' => $path,
68 'title' => t($account->name . '\'s blog'),
69 'callback' => 'blog_addons_page',
70 'callback arguments' => array(arg(2),arg(3),arg(4),arg(1)),
71 'access' => user_access('access content'),
72 'type' => MENU_CALLBACK_ITEM,
73 'weight' => -1,
74 );
75 }
76
77 $items[] = array('path' => 'admin/settings/blog_addons',
78 'title' => t('Blog AddOns'),
79 'description' => t('Configure default behavior of blog_addonsmodule.'),
80 'access' => user_access('administer blog_addons'),
81 'callback' => 'drupal_get_form',
82 'callback arguments' => array('blog_addons_settings'));
83
84 return $items;
85 }
86
87 function blog_addons_bloggers()
88 {
89 $pager_attrib = array("sort" => variable_get('blog_addons_sort', 'nposts'), 'order' => variable_get('blog_addons_order', 'DESC'));
90
91 if (isset($_GET['order']))
92 {
93 $pager_attrib['order'] = ($_GET['order'] == 'desc') ? 'desc' : 'asc';
94 }
95
96 if (isset($_GET['sort']))
97 {
98 switch($_GET['sort'])
99 {
100 case 'name':
101 $pager_attrib['sort'] = ($_GET['sort'] == 'name') ? 'name' : 'name';
102 break;
103 case 'nposts':
104 $pager_attrib['sort'] = ($_GET['sort'] == 'nposts') ? 'nposts' : 'nposts';
105 break;
106 default:
107 $pager_attrib['sort'] = 'name';
108 break;
109 }
110 }
111 switch ($pager_attrib['sort'])
112 {
113 case 'name':
114 $sortby = " ORDER BY u.name " . $pager_attrib['order'] . " ";
115 break;
116 case 'nposts':
117 $sortby = " ORDER BY nposts " . $pager_attrib['order'] . " ";
118 break;
119 default:
120 $sortby = " ORDER By u.name ASC ";
121 break;
122 }
123
124 $query = "SELECT COUNT(DISTINCT(u.name)) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.type = 'blog'";
125 $counts = db_rewrite_sql($query);
126
127 $query = "SELECT u.name, COUNT(n.uid) AS nposts FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status=1 AND n.type = 'blog' GROUP BY u.uid " . $sortby;
128 $result = pager_query(db_rewrite_sql($query), variable_get('blog_addons_nbloggers', 20),0,$counts);
129
130 blog_addons_show_bloggers($result,$pager_attrib );
131 }
132
133 function blog_addons_show_bloggers($result, $attrib = array("sort" => 'name', 'order' => 'ASC'))
134 {
135 drupal_set_title(t('Bloggers'));
136 drupal_add_css(drupal_get_path('module', 'blog_addons').'/blog_addons.css');
137 global $pager_total_items;
138 $order = ($attrib['order'] == "desc" || $attrib['order'] == "DESC")?"asc":"desc";
139 $sort_attr = array("title"=>t("Click a second time to reverse the sort order"));
140 $content .= '<div class="blog_addons-sort">Sort by:';
141 $content .= "[".l(t("Name"),$_GET['q'],$sort_attr,"&sort=name&order=$order");
142 $content .= "][".l(t("Number of posts"),$_GET['q'],$sort_attr,"&sort=nposts&order=$order");
143 $content .= "]</div><br> ";
144
145 while ($blogger = db_fetch_object($result))
146 {
147 $content .= l($blogger->name,'blog/'.$blogger->name) . " (" . $blogger->nposts . ") <br>";
148 }
149
150 $content .= theme('pager',0,variable_get('blog_addons_nbloggers', 20));
151 print theme('page',$content);
152 }
153
154 function blog_addons_recentposts()
155 {
156 $pager_attrib = array("sort" => variable_get('blog_addons_sort', 'date'), 'order' => variable_get('blog_addons_order', 'DESC'));
157
158 if (isset($_GET['order']))
159 {
160 $pager_attrib['order'] = ($_GET['order'] == 'desc') ? 'desc' : 'asc';
161 }
162
163 if (isset($_GET['sort']))
164 {
165 switch($_GET['sort'])
166 {
167 case 'date':
168 $pager_attrib['sort'] = ($_GET['sort'] == 'date') ? 'date' : 'date';
169 break;
170 default:
171 $pager_attrib['sort'] = 'date';
172 break;
173 }
174 }
175
176 switch ($pager_attrib['sort'])
177 {
178 case 'date':
179 $sortby = " ORDER BY n.created " . $pager_attrib['order'] . " ";
180 break;
181 default:
182 $sortby = " ORDER By n.created ASC ";
183 break;
184 }
185
186 $query = "SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 " . $sortby;
187 $result = pager_query(db_rewrite_sql($query), variable_get('blog_addons_nposts', 10),0);
188 blog_addons_show_recentposts($result,$pager_attrib );
189 }
190
191 function blog_addons_show_recentposts($result, $attrib = array("sort" => 'date', 'order' => 'ASC'))
192 {
193 drupal_add_css(drupal_get_path('module', 'blog_addons').'/blog_addons.css');
194 global $pager_total_items;
195
196 $order = ($attrib['order'] == "desc" || $attrib['order'] == "DESC")?"asc":"desc";
197 $sort_attr = array("title"=>t("Click a second time to reverse the sort order"));
198 $content .= '<div class="blog_addons-sort">Sort by:';
199 $content .= "[".l(t("Date"),$_GET['q'],$sort_attr,"&sort=date&order=$order");
200 $content .= "]</div> <br> ";
201
202 drupal_set_title(t('Blog posts'));
203
204 while ($blogentry = db_fetch_object($result))
205 {
206 $content .= node_view(node_load($blogentry->nid),1);
207 }
208
209 $content .= theme('pager',0,variable_get('blog_addons_nposts', 10));
210 print theme('page',$content);
211 }
212
213
214 function blog_addons_block($op='list', $delta=0 )
215 {
216 global $user;
217 if ($op == 'list')
218 {
219 $block[0]['title'] = t('BLOGS');
220 $block[0]['info'] = t('Blog navigation menu');
221 $block[0]['content'] = t('');
222 $block[0]['pages'] = 'blog*';
223 $block[0]['visibility'] = '1';
224 return $block;
225 }
226 else if ($op == 'view')
227 {
228 if (arg(0) == 'blog')
229 {
230 if (is_numeric(arg(1)))
231 $account = user_load(array('uid' => arg(1)));
232 else
233 $account = user_load(array('name' => arg(1)));
234 }
235 else if (arg(0) == 'node')
236 {
237 if (is_numeric(arg(1)))
238 {
239 $node = node_load(arg(1));
240 if ($node->type == 'blog')
241 $account = user_load(array('uid' => $node->uid));
242 }
243 }
244
245 if (!isset($account->uid))
246 $account = $user;
247
248 if ( (((arg(0) == 'blogs')||(arg(0) == 'blog')) && !arg(1)) || (((arg(0) == 'blogs')||(arg(0) == 'blog')) && (arg(1)=='posts')) )
249 {
250 $bcontent .= "<ul>";
251 $bcontent .= "<li>" . l(t("My blog"),'blog/'. $user->name) . "</li>";
252 $bcontent .= "<li>" . l('Post new blog entry','node/add/blog') . "</li>";
253 $bcontent .= "<li>Top bloggers </li>";
254 $query = "SELECT u.name, COUNT(n.uid) AS nposts FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status=1 AND n.type = 'blog' GROUP BY u.uid ORDER BY nposts DESC LIMIT " . variable_get('blog_addons_ntopbloggers', 5);
255 $result = db_query(db_rewrite_sql($query));
256 $bcontent .= "<ul>";
257
258 while ($blogger = db_fetch_object($result))
259 {
260 $bcontent .= "<li> " . l($blogger->name,'blog/'.$blogger->name) . " (" . $blogger->nposts . ") </li>";
261 }
262 $more_attr = array("title"=>t("Click for more bloggers"));
263 $bcontent .= "<li>" . l(t("more ..."),'blogs/blogs',$more_attr,"&sort=nposts&order=desc") . "</li>";
264 $bcontent .= "</ul>";
265 $bcontent .= "<li>" . l(t("Recent posts"),'blogs/posts',array(),"&sort=date&order=desc") . "</li>";
266
267 $bcontent .= "</ul>";
268
269 $block['title'] = t('Blogs');
270 $block['content'] = $bcontent;
271 return $block;
272 }
273 else
274 {
275 $query = "SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = " . $account->uid . " ORDER By n.created DESC ";
276 $result = db_query(db_rewrite_sql($query));
277 $bcontent .= "<ul>";
278 $bcontent .= "<li>" . l($account->name . '\'s home page', 'blog/' . $account->name) . "</li>";
279 if ($user->uid == $account->uid)
280 {
281 $bcontent .= "<li>" . l('Post new blog entry','node/add/blog') . "</li>";
282 }
283 $bcontent .= "<li> Posts </li>";
284 $bcontent .= "<ul>";
285
286 while ($postdate = db_fetch_object($result))
287 {
288 $year = date('Y', $postdate->created);
289 $month = date('F', $postdate->created);
290 $month_numeric = date('m', $postdate->created);
291 $day = date('j', $postdate->created);
292
293 if ($year != $lastyear)
294 {
295 if (isset($lastyear))
296 $bcontent .= "</ul>";
297 $bcontent .= "<li>" . l($year,'blog/' . $account->name . '/' . $year) . "</li><ul>";
298 }
299 if ($month != $lastmonth)
300 {
301 $limit = " AND YEAR(FROM_UNIXTIME(n.created)) = " . $year;
302 $limit .= " AND MONTH(FROM_UNIXTIME(n.created)) = " . $month_numeric;
303 $query = "SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = " . $account->uid . $limit . " ORDER By n.created DESC ";
304 $postpermonth = mysql_num_rows(db_query($query));
305
306 $bcontent .= "<li>" . l($month,'blog/' . $account->name . '/' . $year . '/' . $month_numeric) . " (" . $postpermonth . ") </li>";
307 $lastmonth = $month;
308 }
309
310 $lastyear = $year;
311 }
312
313 $bcontent .= "</ul>";
314 $bcontent .= "</ul>";
315 if ($user->uid != $account->uid)
316 {
317 $bcontent .= "<li>" . l(t("My blog"),'blog/'. $user->name) . "</li>";
318 $bcontent .= "<li>" . l('Post new blog entry','node/add/blog') . "</li>";
319 }
320 $bcontent .= "<li>" . l('All blogs', 'blogs') . "</li>";
321 $bcontent .= "</ul>";
322 }
323
324 $block['title'] = t($account->name . '\'s blog');
325 $block['content'] = $bcontent;
326 return $block;
327 }
328
329
330 }
331
332
333 function blog_addons_page($year = NULL, $month = NULL, $day = NULL, $user)
334 {
335 //global $pager_total_items;
336 $pager_attrib = array("sort" => variable_get('blog_addons_sort', 'date'), 'order' => variable_get('blog_addons_order', 'DESC'));
337
338 $pager_attrib = array("sort" => variable_get('blog_addons_sort', 'date'), 'order' => variable_get('blog_addons_order', 'DESC'));
339
340 if (isset($_GET['order']))
341 {
342 $pager_attrib['order'] = ($_GET['order'] == 'desc') ? 'desc' : 'asc';
343 }
344
345 if (isset($_GET['sort']))
346 {
347 switch($_GET['sort'])
348 {
349 case 'date':
350 $pager_attrib['sort'] = ($_GET['sort'] == 'date') ? 'date' : 'date';
351 break;
352 case 'title':
353 $pager_attrib['sort'] = ($_GET['sort'] == 'title') ? 'title' : 'title';
354 break;
355 default:
356 $pager_attrib['sort'] = 'date';
357 break;
358 }
359 }
360
361 switch ($pager_attrib['sort']) {
362 case 'date':
363 $sortby = " ORDER BY n.created " . $pager_attrib['order'] . " ";
364 break;
365 case 'title':
366 $sortby = " ORDER BY n.title " . $pager_attrib['order'] . " ";
367 break;
368 default:
369 $sortby = " ORDER By n.created ASC ";
370 break;
371 } //end switch
372
373
374 if ($year)
375 {
376 $title = $user . "'s blog entries posted on " ;
377 if($day)
378 {
379 $title .= $day . '/';
380 }
381
382 if($month)
383 {
384 $title .= $month . '/';
385 }
386 $title .= $year;
387
388 }
389 drupal_set_title($title);
390
391 if (is_numeric($user))
392 $tempuser = user_load(array('uid' => $user));
393 else
394 $tempuser = user_load(array('name' => $user));
395
396 if ($year)
397 $limit = " AND YEAR(FROM_UNIXTIME(n.created)) = " . $year;
398 if (is_numeric($month))
399 $limit .= " AND MONTH(FROM_UNIXTIME(n.created)) = " . $month;
400 if (is_numeric($day))
401 $limit .= " AND DAY(FROM_UNIXTIME(n.created)) = " . $day;
402
403 $query = "SELECT n.nid, n.created, YEAR(FROM_UNIXTIME(n.created)) AS year, MONTH(FROM_UNIXTIME(n.created)) AS month, DAY(FROM_UNIXTIME(n.created)) AS day FROM {node} n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = " . $tempuser->uid . " " . $limit . $sortby;
404
405 $result = pager_query($query,variable_get('blog_addons_nposts_userhomepage', 20));
406
407 blog_addons_page_results($result,$pager_attrib);
408
409 }
410
411 function blog_addons_page_results($result, $attrib = array("sort" => 'title', 'order' => 'ASC'))
412 {
413 $order = ($attrib['order'] == "desc" || $attrib['order'] == "DESC")?"asc":"desc";
414 $sort_attr = array("title"=>t("Click a second time to reverse the sort order"));
415 $output .= '<div class="blog_addons-sort">Sort by:';
416 $output .= "[".l(t("Title"),$_GET['q'],$sort_attr,"&sort=title&order=$order");
417 $output .= "][".l(t("Date"),$_GET['q'],$sort_attr,"&sort=date&order=$order");
418 $output .= "]</div><br> ";
419
420 $output .= "<ul>";
421 while ($postdate = db_fetch_object($result))
422 {
423 $month = date('F', $postdate->created);
424 $node = node_load($postdate->nid);
425 $output .= "<li>" . l($node->title,'node/' . $node->nid) . ' - ' . $month . ' ' . $postdate->day . '., ' . $postdate->year . "</li>";
426 }
427 $output .= "</ul>";
428 $output .= theme('pager',0,variable_get('blog_addons_nposts_userhomepage', 20));
429 print theme('page',$output);
430 }
431
432
433 /**
434 * Implementation of hook_settings().
435 */
436 function blog_addons_settings()
437 {
438
439 $form['blog_addons_nbloggers'] = array(
440 '#type' => 'textfield',
441 '#title' => t('Number of bloggers displayed per page'),
442 '#default_value' => variable_get('blog_addons_nbloggers', 20),
443 '#size' => 4,
444 '#maxlength' => 4,
445 '#description' => 'This sets the number of bloggers per page displayed on the front page. ',
446 );
447 $form['blog_addons_nposts'] = array(
448 '#type' => 'textfield',
449 '#title' => t('Number of posts displayed per page'),
450 '#default_value' => variable_get('blog_addons_nposts', 10),
451 '#size' => 4,
452 '#maxlength' => 4,
453 '#description' => 'This sets the number of posts per page displayed on the front page. ',
454 );
455
456 $form['blog_addons_ntopbloggers'] = array(
457 '#type' => 'textfield',
458 '#title' => t('Number of top bloggers displayed in the menu'),
459 '#default_value' => variable_get('blog_addons_ntopbloggers', 5),
460 '#size' => 4,
461 '#maxlength' => 4,
462 '#description' => 'This sets the number of top bloggers in blog navigation menu . ',
463 );
464
465 $form['blog_addons_nposts_userhomepage'] = array(
466 '#type' => 'textfield',
467 '#title' => t('Number of posts on the blogger home page '),
468 '#default_value' => variable_get('blog_addons_nposts_userhomepage', 20),
469 '#size' => 4,
470 '#maxlength' => 4,
471 '#description' => 'This sets the number of posts on the blogger hope page . ',
472 );
473
474 menu_rebuild();
475 return system_settings_form($form);
476
477 }

  ViewVC Help
Powered by ViewVC 1.1.2