*/ /** * Implementation of hook_menu(). **/ function moderation_menu() { $items = array(); $items['node/%/log'] = array( 'title' => 'Log', 'page callback' => 'moderation_log', 'page arguments' => array('node', 1), 'access arguments' => array('administer nodes'), 'type' => MENU_LOCAL_TASK, 'file' => 'moderation.moderation.inc', ); $items['admin/content/node/moderation'] = array( 'title' => 'Moderation', 'page callback' => 'moderation_node_queue', 'access arguments' => array('administer nodes'), 'type' => MENU_LOCAL_TASK, 'file' => 'moderation.moderation.inc', ); $items['admin/content/node/log'] = array( 'title' => 'Log', 'page callback' => 'moderation_log', 'access arguments' => array('administer nodes'), 'page arguments' => array('node'), 'type' => MENU_LOCAL_TASK, 'file' => 'moderation.moderation.inc', 'weight' => 1, ); $items['admin/content/comment/moderation'] = array( 'title' => 'Moderation', 'page callback' => 'moderation_comment_queue', 'access arguments' => array('administer comments'), 'type' => MENU_LOCAL_TASK, 'file' => 'moderation.moderation.inc', ); $items['admin/content/comment/log'] = array( 'title' => 'Log', 'page callback' => 'moderation_log', 'page arguments' => array('comment'), 'access arguments' => array('administer comments'), 'type' => MENU_LOCAL_TASK, 'file' => 'moderation.moderation.inc', 'weight' => 1, ); $items['admin/settings/moderation'] = array( 'title' => 'Content moderation', 'description' => 'Configure the moderation queue.', 'page callback' => 'drupal_get_form', 'page arguments' => array('moderation_admin_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'moderation.admin.inc', ); $items['moderation/%/%/%/%'] = array( 'page callback' => 'moderation_callback_switch', 'page arguments' => array(1, 2, 3, 4), 'access callback' => 'moderation_moderation_access_callback', 'access arguments' => array(1), 'type' => MENU_CALLBACK, 'file' => 'moderation.pages.inc', ); return $items; } /** * Implementation of hook_theme(). */ function moderation_theme() { return array( 'moderation_node_preview' => array( 'arguments' => array( 'node', ), ), ); } function moderation_moderation_access_callback($arg1) { $access = ($arg1 == 'node' AND user_access('administer nodes')) || ($arg1 == 'comment' AND user_access('administer comments')) ? TRUE : FALSE; return $access; } /** * Implementation of hook_nodeapi */ function moderation_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'load': if (in_array($node->type, variable_get('moderation_moderated_types', array()))) { return db_fetch_array(db_query("SELECT status as moderate FROM {moderation_moderation} mm WHERE mm.obj_type = 'node' AND mm.obj_id = %d", $node->nid)); } case 'update' : case 'insert' : if (moderation_is_moderated_type($node->type)) { db_query("DELETE FROM {moderation_moderation} WHERE obj_id=%d AND obj_type='node'", $node->nid); db_query("INSERT INTO {moderation_moderation} SET obj_id=%d, obj_type='node', status=%d", $node->nid, $node->moderate); } break; case 'delete': db_query("DELETE FROM {moderation} WHERE obj_type='node' AND obj_id=%d", $node->nid); db_query("DELETE FROM {moderation_moderation} WHERE obj_type='node' AND obj_id=%d", $node->nid); break; } } /** * Implementation of hook_comment(). */ function moderation_comment(&$a1, $op) { switch ($op) { case 'insert': case 'update': db_query("DELETE FROM {moderation_moderation} WHERE obj_id=%d AND obj_type='comment'", $a1['cid']); db_query("INSERT INTO {moderation_moderation} SET obj_id=%d, obj_type='comment', status=%d", $a1['cid'], $a1['moderate']); break; case 'delete': db_query("DELETE FROM {moderation} WHERE obj_type='comment' AND obj_id=%d", $a1['cid']); db_query("DELETE FROM {moderation_moderation} WHERE obj_type='comment' AND obj_id=%d", $a1['cid']); break; } } function moderation_is_moderated_type($type) { $types = variable_get('moderation_moderated_types', array()); return ($types[$type]); } /** * Implementation of hook_form_alter(). */ function moderation_form_alter(&$form, &$form_state, $form_id) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { if (moderation_is_moderated_type($form['type']['#value'])) { if (user_access('administer nodes')) { $form['options']['moderate'] = array( '#type' => 'checkbox', '#title' => t('Has been moderated'), '#default_value' => $form['#node']->moderate, '#weight' => 24, '#description' => t('Check to remove from moderation queue, uncheck to add it to the queue.'), ); } } } } /** * Implementation of hook_form_comment_form_alter(). */ function moderation_form_comment_form_alter(&$form, &$form_state) { if (user_access('administer nodes')) { $status = db_result(db_query("SELECT status FROM {moderation_moderation} WHERE obj_id=%d AND obj_type='comment'", $form['cid']['#value'])); $form['admin']['moderate'] = array( '#type' => 'checkbox', '#title' => 'Has been moderated', '#default_value' => $status, '#weight' => -1, '#description' => t('Check to remove from moderation queue, uncheck to add it to the queue.'), ); } } /* /** * Display a node preview for display during node creation and editing. * * @param $node * The node object which is being previewed. */ function theme_moderation_node_preview($node) { $output = '
'; if ($node->teaser && $node->teaser != $node->body) { $output .= '

'. t('Preview trimmed version') .'

'; $output .= node_view(drupal_clone($node), 1, FALSE, 0); $output .= '

'. t('Preview full version') .'

'; $output .= node_view($node, 0, FALSE, 0); } else { $output .= node_view($node, 0, FALSE, 0); } $output .= "
\n"; return $output; }