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

Contents of /contributions/modules/comments_page/comments_page.module

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


Revision 1.1 - (show annotations) (download) (as text)
Sun Oct 28 11:37:57 2007 UTC (2 years, 1 month ago) by mjmalloy
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: comments_page.module,v 1.0 2007/10/28 11:00:00 mjmalloy Exp $
3
4 /**
5 * Implementation of hook_menu().
6 */
7 function comments_page_menu($may_cache) {
8 global $user;
9 $items = array();
10
11 if (!$may_cache) {
12 $items[] = array(
13 'path' => 'comments',
14 'title' => t('Comments'),
15 'callback' => 'comments_page',
16 'access' => TRUE,
17 'type' => MENU_SUGGESTED_ITEM
18 );
19 $items[] = array(
20 'path' => 'comments/'. $user->uid,
21 'title' => t('Users comments'),
22 'access' => TRUE,
23 'type' => MENU_DYNAMIC_ITEM
24 );
25 }
26
27 return $items;
28 }
29
30 /**
31 * Menu callback; displays a Drupal page containing recent comments.
32 */
33 function comments_page($a = NULL, $b = NULL) {
34 if (is_numeric($a)) { // $a is a user ID
35 return comments_page_user($a);
36 }
37 else {
38 return comments_page_last();
39 }
40 }
41
42 /**
43 * Displays a Drupal page containing recent comments of a given user.
44 */
45 function comments_page_user($uid) {
46 global $user;
47 $account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
48 if ($account->uid) {
49 drupal_set_title($title = t("@name's comments", array('@name' => $account->name)));
50 $output = '';
51 $result = pager_query(db_rewrite_sql("SELECT c.comment, c.cid, c.nid, c.uid, c.timestamp, n.title, u.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON c.uid = u.uid WHERE c.uid = %d AND n.status = 1 ORDER BY c.timestamp DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
52 while ($comment = db_fetch_object($result)) {
53 $output .= '<div class="node">';
54 $output .= '<div class="node-content">';
55 $output .= '<h2 class="title">'.l($comment->title, "node/".$comment->nid, array('title' => $comment->title)).'</h2>';
56 $output .= '<div class="node-author node-content-top">'.l(check_plain($comment->name), "user/".$comment->uid, array('title' => $comment->name."'s profile")).'</div>';
57 $output .= '<div class="node-date node-content-top">'.format_date($comment->timestamp, 'custom', "F jS, Y").'</div>';
58 $output .= '<div class="clear"></div>';
59 $output .= '<div class="content">';
60 $output .= check_markup($comment->comment);
61 $output .= l('View Comment', "node/".$comment->nid, NULL, NULL, "comment-$comment->cid");
62 $output .= '</div>';
63 $output .= '</div>';
64 $output .= '</div>';
65 }
66 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
67 return $output;
68 }
69 }
70
71 /**
72 * Displays a Drupal page containing recent comments of all users.
73 */
74 function comments_page_last() {
75 global $user;
76 $output = '';
77 $result = pager_query(db_rewrite_sql("SELECT c.comment, c.cid, c.nid, c.uid, c.timestamp, n.title, u.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON c.uid = u.uid WHERE n.status = 1 ORDER BY c.timestamp DESC"), variable_get('default_nodes_main', 10));
78 while ($comment = db_fetch_object($result)) {
79 $output .= '<div class="node">';
80 $output .= '<div class="node-content">';
81 $output .= '<h2 class="title">'.l($comment->title, "node/".$comment->nid, array('title' => $comment->title)).'</h2>';
82 $output .= '<div class="node-author node-content-top">'.l(check_plain($comment->name), "comments/".$comment->uid, array('title' => $comment->name."'s comments")).'</div>';
83 $output .= '<div class="node-date node-content-top">'.format_date($comment->timestamp, 'custom', "F jS, Y").'</div>';
84 $output .= '<div class="clear"></div>';
85 $output .= '<div class="content">';
86 $output .= check_markup($comment->comment);
87 $output .= l('View Comment', "node/".$comment->nid, NULL, NULL, "comment-$comment->cid");
88 $output .= '</div>';
89 $output .= '</div>';
90 $output .= '</div>';
91 }
92 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
93 return $output;
94 }

  ViewVC Help
Powered by ViewVC 1.1.2