diff -urp /Users/wmostrey/Desktop/usercomment.old/usercomment.info ./usercomment.info --- /Users/wmostrey/Desktop/usercomment.old/usercomment.info 2007-12-14 13:10:52.000000000 +0100 +++ ./usercomment.info 2008-09-16 11:29:41.000000000 +0200 @@ -1,11 +1,5 @@ -; $Id $ +; $Id$ name = "User Comment" -description = "This module gives users some additional comment administration rights on content they create." -dependencies = comment -version = "$Name: DRUPAL-5 $" - -; Information added by drupal.org packaging script on 2007-12-14 -version = "5.x-1.x-dev" -project = "usercomment" -datestamp = "1197634252" - +description = "Give users comment administration rights on content they create." +dependencies[] = comment +core = 6.x \ No newline at end of file diff -urp /Users/wmostrey/Desktop/usercomment.old/usercomment.module ./usercomment.module --- /Users/wmostrey/Desktop/usercomment.old/usercomment.module 2007-12-14 02:17:47.000000000 +0100 +++ ./usercomment.module 2008-09-16 12:41:12.000000000 +0200 @@ -1,12 +1,12 @@ $comment['subject'], '@comment' => $comment['comment'], '@commenter' => $comment['name'], - '@link' => url('node/' . $node->nid, NULL, NULL, TRUE), + '@link' => url('node/'. $node->nid, NULL, NULL, TRUE), '@site' => variable_get("site_name", "Drupal"), '@siteurl' => $GLOBALS["base_url"], ); @@ -50,7 +50,7 @@ function usercomment_comment(&$comment, $message = t($message, $replacements); $site_mail = variable_get('site_mail', ""); if (!strlen($site_mail)) { - if (user_access('administer nodes')){ + if (user_access('administer nodes')) { drupal_set_message(t('You should create an administrator mail address for your site! Do it here.', array('%url' => url('admin/settings/site-information'))), 'error'); } $site_mail = 'nobody@localhost'; @@ -62,11 +62,11 @@ function usercomment_comment(&$comment, } } -/* +/** * Implementation of hook_help() */ -function usercomment_help($section) { - switch ($section) { +function usercomment_help($path, $arg) { + switch ($path) { case 'admin/help#usercomment': return t('

This module lets users delete comments on own nodes they create without giving them full comment administration access. Permissions are on a per node type basis, so it\'s a great way to, e.g., allow users to administer comments on their own blogs. Additionally, you can configure this module to force comments on selected node types to be approved before they get published. As with delete rights, this is administered by users so you don\'t have to do it yourself.

'); break; @@ -76,7 +76,7 @@ function usercomment_help($section) { } } -/* +/** * Implementation of hook_link() */ function usercomment_link($type, $comment = NULL, $teaser = FALSE) { @@ -87,7 +87,7 @@ function usercomment_link($type, $commen if (usercomment_access_check($comment->cid)) { $links['usercomment_delete'] = array( 'title' => t('delete'), - 'href' => 'usercomment/delete/' . $comment->cid, + 'href' => 'usercomment/delete/'. $comment->cid, ); } if (usercomment_access_check($comment->cid, 'approve', 'link')) { @@ -95,68 +95,63 @@ function usercomment_link($type, $commen if ($comment->status == COMMENT_NOT_PUBLISHED) { $links['usercomment_approve'] = array( 'title' => t('approve'), - 'href' => 'usercomment/approve/' . $comment->cid, + 'href' => 'usercomment/approve/'. $comment->cid, ); } } return $links; } -/* +/** * Implementation of hook_menu() */ -function usercomment_menu($may_cache) { +function usercomment_menu() { global $user; $items = array(); + $items['admin/content/comment/usercomment'] = array( + 'title' => 'Approval email', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('usercomment_admin_settings'), + 'type' => MENU_LOCAL_TASK, + 'access arguments' => array('administer comments'), + 'weight' => 20, + ); + $items['usercomment/delete'] = array( + 'type' => MENU_CALLBACK, + 'page callback' => 'comment_delete', + 'access callback' => usercomment_menu_access, + 'access arguments' => array('delete', $user), + 'file path' => drupal_get_path('module', 'comment'), + 'file' => 'comment.admin.inc', + ); + $items['usercomment/approve'] = array( + 'type' => MENU_CALLBACK, + 'page callback' => 'usercomment_approve', + 'page arguments' => array($comment, $node), + 'access callback' => usercomment_menu_access, + 'access arguments' => array('approve', $user), + ); + return $items; +} - if ($may_cache) { - $items[] = array( - 'path' => 'admin/content/comment/usercomment', - 'title' => t('Approval email'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'usercomment_admin_settings', - 'type' => MENU_LOCAL_TASK, - 'access' => 1, - 'weight' => 20, - ); - } - else { - if (arg(0) == "usercomment" && is_numeric(arg(2))) { - $op = arg(1); - $cid = arg(2); - $comment = _comment_load($cid); - $node = node_load($comment->nid); - switch ($op) { - case 'approve': - $callback = 'usercomment_approve'; - $callback_args = array( - $comment, - $node, - ); - $access = ($user->uid == $node->uid || user_access('administer comments')); - break; - case 'delete': - $callback = 'comment_delete'; - $callback_args = array(); - $access = usercomment_access_check($cid); - break; - } - $details = array ( - 'path' => 'usercomment/' . $op, - 'callback' => $callback, - 'type' => MENU_CALLBACK, - 'access' => 1, - ); - if (! empty($callback_args)) { - $details['callback arguments'] = $callback_args; - } - $items[] = $details; - } +/** + * Define menu access permission + */ +function usercomment_menu_access($op, $user) { + $cid = arg(2); + if(!empty($cid)) { + $comment = _comment_load($cid); + $node = node_load($comment->nid); + } + switch ($op) { + case 'approve': + return ($user->uid == $node->uid || user_access('administer comments')); + case 'delete': + return ($user->uid == $node->uid || usercomment_access_check($comment->cid)); } - return $items; } -/* +/** * Implementation of hook_nodeapi() */ function usercomment_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { @@ -167,20 +162,20 @@ function usercomment_nodeapi(&$node, $op } } -/* +/** * Implementation of hook_perm() */ function usercomment_perm() { $perms = array(); $perms[] = 'post comments with no usercomment checking'; foreach (node_get_types() as $node) { - $perms[] = 'delete comments on own ' . check_plain($node->type) . ' content'; - $perms[] = 'approve comments on own ' . check_plain($node->type) . ' content'; + $perms[] = 'delete comments on own '. check_plain($node->type) .' content'; + $perms[] = 'approve comments on own '. check_plain($node->type) .' content'; } return $perms; } -/* +/** * Implementation of hook_user() */ function usercomment_user($op, &$edit, &$account, $category = NULL) { @@ -193,12 +188,12 @@ function usercomment_user($op, &$edit, & '#weight' => 5, '#collapsible' => 1, ); - foreach (node_get_types() as $node) { - if (user_access('approve comments on own ' . $node->type . ' content', $account )) { - $form['usercomment_settings']['usercomment_approve_' . $node->type] = array( + foreach (node_get_types() as $node) { + if (user_access('approve comments on own '. $node->type .' content', $account )) { + $form['usercomment_settings']['usercomment_approve_'. $node->type] = array( '#type' => 'checkbox', - '#title' => t('Skip ' . $node->type . ' approvals'), - '#default_value' => isset($edit['usercomment_approve_' . $node->type]) ? $edit['usercomment_approve_' . $node->type] : 1, + '#title' => t('Skip '. $node->type .' approvals'), + '#default_value' => isset($edit['usercomment_approve_'. $node->type]) ? $edit['usercomment_approve_'. $node->type] : 1, '#description' => t('If you check this, other non admin users will be able to post comments on your content without prior approval. Admin users, however, will be able to post comments without approval.'), ); } @@ -215,7 +210,7 @@ function usercomment_user($op, &$edit, & } } -/* +/** * This function returns the count of unapproved notes for a specified node * * @param $nid - numeric node id @@ -227,7 +222,7 @@ function usercomment_count_unapproved($n return (int)$count; } -/* +/** * This function determines whether the specified user needs to approve comments on the specified node type * * @param $nodetype - text string specifying the name of a node type @@ -264,7 +259,7 @@ function usercomment_requires_approval($ } } -/* +/** * This function checks access perms */ function usercomment_access_check($cid, $op = 'delete', $type = '') { @@ -296,28 +291,29 @@ function usercomment_access_check($cid, } return $access; } - $check = (user_access('approve comments on own ' . $thisnode->type . ' content') && $thisnode->uid != $user->uid); + $check = (user_access('approve comments on own'. $thisnode->type .' content') && $thisnode->uid != $user->uid); break; case 'link': default: - $check = user_access('approve comments on own ' . $thisnode->type . ' content'); + $check = user_access('approve comments on own '. $thisnode->type .' content'); break; } break; case 'delete': default: - $check = (user_access('delete comments on own ' . $thisnode->type . ' content') && $thisnode->uid == $user->uid); + $check = (user_access('delete comments on own '. $thisnode->type .' content') && $thisnode->uid == $user->uid); break; } if ($check) { return TRUE; - } else { + } + else { return FALSE; } } } -/* +/** * This function generates the approval page */ function usercomment_approve($comment, $node) { @@ -338,10 +334,10 @@ function usercomment_approve($comment, $ } drupal_set_message($status_msg); - drupal_goto ('node/' . $node->nid); + drupal_goto('node/'. $node->nid); } -/* +/** * This function is a modified copy of comment_render() * * I had to modify b/c comment_render() didn't let me get comments that @@ -351,7 +347,7 @@ function usercomment_approve($comment, $ */ function usercomment_comment_render($node) { $content = ''; - $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d'; + $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d AND c.status = %d'; $query_args[] = $node->nid; $query_args[] = COMMENT_NOT_PUBLISHED; $result = db_query($query, $query_args); @@ -372,7 +368,7 @@ function usercomment_comment_render($nod return $content; } -/* +/** * Generate the usercomment admin settings form */ function usercomment_admin_settings() { @@ -416,7 +412,7 @@ function usercomment_admin_settings() { '#default_value' => $msg_php, '#cols' => 60, '#rows' => 6, - '#description' => '

'. t('Advanced Usage Only: PHP code that returns the text of the status message. Should not include <?php ?> delimiters.') .'

' . '

' . t('Note: if set, this will override any Approval queue message text set above.') . '

', + '#description' => '

'. t('Advanced Usage Only: PHP code that returns the text of the status message. Should not include <?php ?> delimiters.') .'

'. t('Note: if set, this will override any Approval queue message text set above.') .'

', ); $form['usercomment_text']['usercomment_msg_approved'] = array( @@ -439,12 +435,12 @@ function usercomment_admin_settings() { '#default_value' => $msg_php, '#cols' => 60, '#rows' => 6, - '#description' => '

'. t('Advanced Usage Only: PHP code that returns the text of the status message. Should not include <?php ?> delimiters.') .'

' . '

' . t('Note: if set, this will override any Approval queue message text set above.') . '

', + '#description' => '

'. t('Advanced Usage Only: PHP code that returns the text of the status message. Should not include <?php ?> delimiters.') .'

'. t('Note: if set, this will override any Approval queue message text set above.') .'

', ); return system_settings_form($form); } -/* +/** * This function defines the default message sent out by this module */ function usercomment_mail_message_default() { @@ -464,12 +460,12 @@ The @site team END; } -/* +/** * This function generates the approval form */ function usercomment_approval_form($node) { global $user; - if ($user->uid == $node->uid && user_access('approve comments on own ' . $node->type . ' content')) { + if ($user->uid == $node->uid && user_access('approve comments on own '. $node->type .' content')) { $content = usercomment_comment_render($node); if (! empty($content)) { return theme('usercomment', $content); @@ -480,7 +476,18 @@ function usercomment_approval_form($node } } -/* +/** + * Implementation of hook_theme(). + */ +function usercomment_theme() { + return array( + 'usercomment' => array( + 'arguments' => array($content), + ), + ); +} + +/** * Theme out the usercomment form */ function theme_usercomment($content) { @@ -490,7 +497,7 @@ function theme_usercomment($content) { return $output; } -/* +/** * Theme out the empty usercomment form */ function theme_usercomment_empty() {