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

Contents of /contributions/modules/comment_og/comment_og.module

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


Revision 1.9 - (show annotations) (download) (as text)
Wed Nov 4 20:34:59 2009 UTC (3 weeks ago) by chromix
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.8: +88 -288 lines
File MIME type: text/x-php
task #578550 by chromix: total re-write of Comment OG for Drupal 6
1 <?php
2 /**
3 * Implementation of hook_link_alter().
4 * Removes comment link for non-members
5 */
6 function comment_og_link_alter(&$links, $node) {
7 if ($node->comment) {
8 if (isset($node->og_groups)) {
9 if (!og_is_group_member(og_get_group_context())) unset($links['comment_add']);
10 }
11 }
12 }
13
14 /*
15 * Modifies the comment links via a preprocess funtion as described here:
16 * http://drupal.org/node/352020
17 */
18 function comment_og_preprocess_comment(&$variables) {
19 $comment = $variables['comment'];
20
21 //load links for current comment
22 $links = comment_links($comment, FALSE);
23
24 $group = og_get_group_context();
25
26 // if group context
27 if($group) {
28 // remove the reply link for non-group members
29 if (!og_is_group_member($group)) unset($links['comment_reply']);
30 // we add the Group ID to the URL to determin group admin status later
31 if (og_is_group_admin($group))
32 $links['comment_delete'] = array(
33 'title' => t('delete'),
34 'href' => "comment/delete/$comment->cid/$group->nid"
35 );
36 }
37 //reset the links HTML
38 $variables['links'] = theme('links', $links);
39 }
40
41 /**
42 * Implementation of hook_form_alter().
43 */
44 function comment_og_form_alter(&$form, $form_state, $form_id) {
45 if ($form_id == 'comment_form' && isset($form['nid'])) {
46 // if this is group context and you're not a member of this group, disable the comment form
47 if (!og_is_group_member(og_get_group_context())) {
48 $form['comment_filter']['comment'] = array(
49 '#type' => 'textarea',
50 '#title' => t('Comment'),
51 '#rows' => 5,
52 '#disabled' => TRUE,
53 '#description' => t('You must be a member of this group in order to post a comment.'),
54 );
55 if (isset($form['subject'])) unset($form['subject']);
56 if (isset($form['comment_filter']['format'])) unset($form['comment_filter']['format']);
57 if (isset($form['submit'])) unset($form['submit']);
58 if (isset($form['preview'])) unset($form['preview']);
59 if (isset($form['author'])) unset($form['author']);
60 if (isset($form['_author'])) unset($form['_author']);
61 }
62 }
63 }
64
65 /**
66 * Implementation of hook_menu_alter().
67 */
68 function comment_og_menu_alter(&$items) {
69 // allows group admins to delete comments
70 $items['comment/delete'] = array(
71 'title' => 'Delete comment',
72 'page callback' => 'comment_delete',
73 'access callback' => 'comment_og_comment_delete',
74 'access arguments' => array(3),
75 'type' => MENU_CALLBACK,
76 'file' => 'comment.admin.inc',
77 'file path' => drupal_get_path('module','comment'),
78 );
79 }
80
81 /**
82 * Returns true if the acting user is a group admin
83 */
84 function comment_og_comment_delete($gid = NULL) {
85 if ($gid) {
86 $group = node_load($gid);
87 og_load_group($group);
88 return og_is_group_admin($group);
89 }
90 else return user_access('administer comments') && user_access('post comments');
91 }
92
93 ?>

  ViewVC Help
Powered by ViewVC 1.1.2