? modr8.nodeops.patch Index: modr8.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.module,v retrieving revision 1.25 diff -u -p -r1.25 modr8.module --- modr8.module 21 Oct 2008 15:14:07 -0000 1.25 +++ modr8.module 4 Feb 2009 01:44:13 -0000 @@ -293,3 +293,148 @@ function theme_modr8_message($teaser = F } $already_messaged = TRUE; } + +/** + * Implementation of hook_node_operations(). + */ +function modr8_node_operations() { + return array( + 'modr8_approve' => array( + 'label' => t('Approve moderated nodes'), + 'callback' => 'modr8_bulk_approve', + ), + 'modr8_delete' => array( + 'label' => t('Delete moderated nodes'), + 'callback' => 'modr8_bulk_delete', + ), + 'modr8_moderate' => array( + 'label' => t('Mark for moderation'), + 'callback' => 'modr8_bulk_moderate', + ), + ); +} + +/** + * Node operations API Function + * Mark the specified nodes for moderation. + * + * @param $nodes + * An array of node ids. + */ +function modr8_bulk_moderate($nodes) { + foreach($nodes as $nid) { + $node = node_load($nid); + modr8_moderate_node($node); + } +} + +/** + * Node operations API Function + * Approve the specified nodes. + * + * @param $nodes + * An array of node ids. + */ +function modr8_bulk_approve($nodes) { + foreach($nodes as $nid) { + $node = node_load($nid); + modr8_approve_node($node); + } +} + +/** + * Node operations API Function + * Delete the specified nodes. + * + * @param $nodes + * An array of node ids. + */ +function modr8_bulk_delete($nodes) { + foreach($nodes as $nid) { + $node = node_load($nid); + modr8_delete_node($node); + } +} + +/** + * Public API function to place the given node into moderation. + * + * @param $node + * The node to moderate. + */ +function modr8_moderate_node($node) { + db_query('UPDATE {node} SET moderate = %d WHERE nid = %d', 1, $nid); + return db_affected_rows(); +} + +/** + * Public API function to approve the given node. + * + * @param $node + * The node to approve. + * @param $note + * An optional note to be used in emails being sent out. + */ +function modr8_approve_node($node, $note = NULL) { + module_load_include('inc', 'modr8', 'modr8_admin'); + $values = _modr8_build_values($node, $note); + if (variable_get('modr8_send_approve', FALSE)) { + $message = modr8_usermail('approve', $node->nid, $values); + } + + $publish = ''; + if (user_access('administer nodes')) { + $publish = ', status = 1'; + } + + db_query('UPDATE {node} SET moderate = 0 '. $publish .' WHERE nid = %d', $node->nid); + drupal_set_message(t('The %type with title %title has been approved.', array('%title' => $node->title, '%type' => $node->type))); + cache_clear_all(); + modr8_log_action('approve', $node->nid, $values, $message); +} + +/** + * Public API function to delete the given node. + * + * @param $node + * The node to delete. + * @param $note + * An optional note to be used in emails being sent out. + */ +function modr8_delete_node($node, $note = NULL) { + module_load_include('inc', 'modr8', 'modr8_admin'); + $values = _modr8_build_values($node, $note); + if (variable_get('modr8_send_deny', FALSE)) { + $message = modr8_usermail('deny', $node->nid, $values); + } + + node_delete($node->nid); + // drupal does its own message + modr8_log_action('delete', $node->nid, $values, $message); +} + +/** + * Build the values array needed for so many internal functions. + * + * @param $node + * The node in the current context. + * @param $note + * An optional note to be used in emails being sent out. + */ +function _modr8_build_values($node, $note = NULL) { + $log_link = ''; + $events = db_query("SELECT modid FROM {modr8_log} WHERE nid = %d", $node->nid); + $count = db_result(db_query("SELECT COUNT(modid) FROM {modr8_log} WHERE nid = %d", $node->nid)); + if ($count) { + $url = ($count == 1) ? ('admin/reports/modr8/event/'. db_result($events)) : ('node/'. $node->nid .'/modr8/'); + $message = format_plural($count, 'See the 1 moderation log event for this post', 'Overview of the @count moderation log events for this post'); + $log_link .= l($message, $url); + } + return array( + 'note' => $note, + 'author_uid' => $node->uid, + 'log_link' => $log_link, + 'title' => check_plain($node->title), + 'type' => node_get_types('name', $node), + ); +} Index: modr8_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8_admin.inc,v retrieving revision 1.25 diff -u -p -r1.25 modr8_admin.inc --- modr8_admin.inc 3 Feb 2009 23:33:37 -0000 1.25 +++ modr8_admin.inc 4 Feb 2009 01:44:13 -0000 @@ -337,28 +337,16 @@ function theme_modr8_form(&$form) { function modr8_form_submit($form, &$form_state) { foreach ($form_state['values'] as $nid => $values) { $message = ''; + $node = node_load($nid); switch ($values['ops']) { case 'approve': - if (variable_get('modr8_send_approve', FALSE)) { - $message = modr8_usermail('approve', $nid, $values); - } - $publish = ''; - if (user_access('administer nodes')) { - $publish = ', status = 1'; - } - db_query('UPDATE {node} SET moderate = 0 '. $publish .' WHERE nid = %d', $nid); - drupal_set_message(t('The %type with title %title has been approved.', array('%title' => $values['title'], '%type' => $values['type']))); - cache_clear_all(); - modr8_log_action('approve', $nid, $values, $message); + modr8_approve_node($node, $value); break; + case 'delete': - if (variable_get('modr8_send_deny', FALSE)) { - $message = modr8_usermail('deny', $nid, $values); - } - node_delete($nid); - // drupal does its own message - modr8_log_action('delete', $nid, $values, $message); + modr8_delete_node($node, $value); break; + case 'nada': if (variable_get('modr8_send_noact', FALSE) && !empty($values['note'])) { $message = modr8_usermail('nada', $nid, $values);