? 5x_modr8_update-1.txt ? 5x_modr8_update-2.txt ? 5x_modr8_update-3.txt ? admin_inc_moder8_1.txt Index: modr8.info =================================================================== RCS file: modr8.info diff -N modr8.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modr8.info 30 Oct 2006 04:10:35 -0000 @@ -0,0 +1,3 @@ +; $Id$ +name = Modr8 +description = Easy, dedicated moderation of content Index: modr8.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.module,v retrieving revision 1.1 diff -u -p -u -p -r1.1 modr8.module --- modr8.module 24 Aug 2006 05:44:00 -0000 1.1 +++ modr8.module 30 Oct 2006 04:10:35 -0000 @@ -5,9 +5,6 @@ * @file * Easy dedicated content moderation * - * @todo - * - add comment moderation (separate tab) - * - prepare for 4.8 by maintaining a separate table and some nodeapi stuff */ /** @@ -16,9 +13,7 @@ function modr8_help($section) { switch ($section) { case 'admin/help#modr8': - return t('TODO: Create admin help text.'); - case 'admin/modules#description': - return t('Moderation of content'); + return '

'. t("Easy, dedicated moderation of content. Assign the 'moderate content' permission to one or mode user roles. Set up the default moderation option for each node type."). '

'; // OPTIONAL: Add additional cases for other paths that should display help text. } } @@ -32,11 +27,19 @@ function modr8_menu($may_cache) { if ($may_cache) { $items[] = array( - 'path' => 'admin/modr8', + 'path' => 'admin/content/modr8', 'title' => t('moderate content'), + 'description' => t('Moderate content (approve/delete).'), 'access' => user_access('moderate content'), 'callback' => 'modr8_page', ); + $items[] = array( + 'path' => 'admin/settings/modr8', + 'title' => t('Modr8 settings'), + 'description' => t('configure content moderation.'), + 'callback' => 'modr8_settings', + 'access' => user_access('administer site configuration'), + ); } return $items; @@ -50,115 +53,85 @@ function modr8_perm() { } /** - * Implementation of hook_settings(). + * menu callback for settings form. */ function modr8_settings() { - $form['modr8_default_option'] = array( - '#type' => 'radios', - '#title' => t('Which action option should be selected by default?'), - '#options' => array( - 'approve' => t('approve'), - 'delete' => t('delete'), - 'nada' => t('no action'), - ), - '#default_value' => variable_get('modr8_default_option', 'nada'), - ); - - $form['modr8_nodes_per_page'] = array( - '#type' => 'select', - '#title' => t('How many nodes should be displayed per page?'), - '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 50, 75, 100, 150, 200)), - '#default_value' => variable_get('modr8_nodes_per_page', 10), - ); - $form['text'] = array( - '#type' => 'fieldset', - '#title' => t('email'), - ); - - $form['text']['modr8_send_approve'] = array( - '#type' => 'checkbox', - '#title' => t('Send approval messages'), - '#default_value' => variable_get('modr8_send_approve', FALSE), - ); - - $form['text']['modr8_accepted_subject'] = array( - '#type' => 'textfield', - '#title' => t('Acceptance Email Subject'), - '#default_value' => variable_get('modr8_accepted_subject', "[%site] %title has been approved"), - ); - - $macros = implode(', ', array_keys(modr8_replacements())); - - $accept_default = modr8_accept_default(); - - $form['text']['modr8_accepted_text'] = array( - '#type' => 'textarea', - '#title' => t('Acceptance Email'), - '#default_value' => variable_get('modr8_accepted_text', $accept_default), - '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), - ); - - $form['text']['modr8_send_deny'] = array( - '#type' => 'checkbox', - '#title' => t('Send denial messages'), - '#default_value' => variable_get('modr8_send_deny', FALSE), - ); - $form['text']['modr8_denial_subject'] = array( - '#type' => 'textfield', - '#title' => t('Denail Email Subject'), - '#default_value' => variable_get('modr8_denial_subject', "[%site] %title has been denied"), - ); + require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc'; - $denial_default = modr8_denial_default(); - - $form['text']['modr8_denial_text'] = array( - '#type' => 'textarea', - '#title' => t('Denial Email'), - '#default_value' => variable_get('modr8_denial_text', $denial_default), - '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), - ); - - return $form; + return drupal_get_form('modr8_settings_form'); } /** * Implementation of hook_nodeapi */ function modr8_nodeapi(&$node, $op, $teaser = NULL, $page = NULL){ - // add messages here... - if ($node->moderate) { - switch ($op) { - case 'view': - if ($teaser) { - $node->teaser = theme('modr8_message', TRUE, $node->type, $op) . $node->teaser; - } - else { - $node->body = theme('modr8_message', FALSE, $node->type, $op) . $node->body; - } - break; - case 'update' : - case 'insert' : - theme('modr8_message', FALSE, $node->type, $op); - } - } - elseif($op == 'submit'){ + // add messages here.. + switch ($op) { + case 'load': + return db_fetch_array(db_query('SELECT n.moderate FROM {node} n WHERE n.nid = %d', $node->nid)); + case 'prepare': + if (!isset($node->nid)) {//a new node + $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); + $node->moderate = in_array('moderate', $node_options); + } + break; + case 'view': + if ($node->moderate) { + $node->content['modr8_message'] = array( + '#value' => theme('modr8_message', $teaser, $node->type, $op), + '#weight' => -100, + ); + } + break; + case 'update' : + case 'insert' : + db_query('UPDATE {node} SET moderate = %d WHERE nid = %d', $node->moderate, $node->nid); + if ($node->moderate) { //cut this? + theme('modr8_message', FALSE, $node->type, $op); + } + break; + case 'submit': + break; + //TODO- change this - probably not necessary or needs to be re-thought // if not administrator, go BACK into moderation upon editing - if (!user_access('administer nodes') && in_array('moderate', variable_get('node_options_'. $node->type, array()))){ - $node->moderate = TRUE; - theme('modr8_message', FALSE, $node->type, $op); - } + if (!user_access('administer nodes') && in_array('moderate', variable_get('node_options_'. $node->type, array()))){ + $node->moderate = TRUE; + theme('modr8_message', FALSE, $node->type, $op); + } } } function modr8_form_alter($form_id, &$form){ - $type = $form['#node']->type; - if ($form_id == $type.'_node_form') { - if (in_array('moderate', variable_get('node_options_'. $type, array()))){ - $form['submit']['#suffix'] .= '
'. - t(' This %type will be submitted for moderation and will not be accessible to other users until it has been approved.', - array('%type' => node_get_name($type))) .'
'; - } + + if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { + $type = $form['type']['#value']; + $access = (user_access('administer nodes') || user_access('moderate content')); + $suffix = '
'; + if ($access) { + $form['moderate'] = array( + '#type' => 'checkbox', + '#title' => t('In moderation queue'), + '#default_value' => $form['#node']->moderate, + '#weight' => 24,); + $suffix .= t('This %type will be placed in moderation if the %moderate checkbox is selected.', + array('%type' => node_get_types('name', $form['#node']), '%moderate' => t('In moderation queue'))); + $form['submit']['#suffix'] .= $suffix .'
'; + } + else { + $form['moderate'] = array( + '#type' => 'value', + '#value' => $form['#node']->moderate, + ); + if ($form['#node']->moderate) { + $suffix .= t('This %type will be submitted for moderation and will not be accessible to other users until it has been approved.', + array('%type' => node_get_types('name', $form['#node']))); + $form['submit']['#suffix'] .= $suffix .''; + } + } + } + elseif ($form_id == 'node_type_form') { + $form['workflow']['node_options']['#options']['moderate'] = t('In moderation queue'); } } @@ -166,204 +139,62 @@ function modr8_form_alter($form_id, &$fo * Menu callback; displays the content moderation form. */ function modr8_page() { + require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc'; - $form = array( - '#theme' => 'moder8_form', - '#tree' => TRUE, - ); - $result = pager_query('SELECT nid FROM {node} WHERE moderate = 1 ORDER BY created DESC', variable_get('modr8_nodes_per_page', 10)); - while ($r = db_fetch_object($result)) { - $node = node_load($r->nid); - $teaser = node_view($node, TRUE, FALSE, FALSE); - $form[$node->nid] = array( - '#tree' => TRUE, - ); - $form[$node->nid]['ops'] = array( - '#type' => 'radios', - '#options' => array( - 'approve' => t('approve'), - 'delete' => t('delete'), - 'nada' => t('no action'), - ), - '#default_value' => variable_get('modr8_default_option', 'nada'), - ); - if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { - $form[$node->nid]['note'] = array( - '#type' => 'textarea', - '#title' => t('note to author'), - '#cols' => 10, // keep it narrow - ); - } - $form[$node->nid]['preview'] = array( - '#type' => 'markup', - '#value' => $teaser - ); - $form[$node->nid]['title'] = array( - '#type' => 'value', - '#value' => check_plain($node->title), - ); - - $form[$node->nid]['type'] = array( - '#type' => 'value', - '#value' => node_get_name($node), - ); - } - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - $output = drupal_get_form('moder8_form', $form); + $output = drupal_get_form('modr8_form'); $output .= theme('pager'); return $output; } /** - * Themes the content moderation form. - */ -function theme_moder8_form(&$form) { - $headers = array( - t('operations'), - t('content') - ); - foreach (element_children($form) as $key) { - // Only do this for nodes; not the submit button. - if (is_numeric($key)) { - $row = array(); - if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { - $note_field = form_render($form[$key]['note']); - } - $row[] = array( - 'data' => form_render($form[$key]['ops']) . $note_field, - 'style' => 'vertical-align:top;' - ); - $row[] = array( - 'data' => form_render($form[$key]['preview']), - 'style' => 'vertical-align:top;', - ); - $rows[] = $row; - } - } - $output = theme('table', $headers, $rows); - $output .= form_render($form); - - return $output; -} - -/** - * Form submit handler, which approves or deletes the node. + * Implementation of hook_db_rewrite_sql(). */ -function moder8_form_submit($form_id, $form_values) { - foreach ($form_values as $nid => $values) { - switch ($values['ops']) { - case 'approve': - if(variable_get('modr8_send_approve', FALSE)){ - modr8_usermail('approve', $nid, $values); +function modr8_db_rewrite_sql($query, $primary_table, $primary_field, $args) { + switch ($primary_field) { + case 'nid': + // this query deals with node objects + $access = (user_access('administer nodes') || user_access('moderate content')); + if (!$access) { + global $user; + $return = array(); + if ($primary_table != 'n') { + $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid"; } - db_query('UPDATE {node} SET moderate = 0 WHERE nid = %d', $nid); - drupal_set_message(t('The %type %title has been approved.', array('%title' => theme('placeholder', $values['title']), '%type' => $values['type']))); - break; - case 'delete': - if(variable_get('modr8_send_deny', FALSE)){ - modr8_usermail('deny', $nid, $values); - } - node_delete($nid); - // drupal does its own message - break; - } - } -} - -function modr8_usermail($op, $nid, $values){ - $node = node_load($nid); - - if (is_object($node)) { - - switch ($op) { - case 'approve': - $subject = variable_get('modr8_accepted_subject', '[%site] %title has been approved'); - $message = variable_get('modr8_accepted_text', modr8_accept_default()); - $optype = t('approval'); - break; - case 'deny': - $subject = variable_get('modr8_denial_subject', '[%site] %title has been denied'); - $message = variable_get('modr8_denial_text', modr8_denial_default()); - $optype = t('denial'); - break; - } - - // get the user info for author - $account = user_load(array('uid' => $node->uid)); - - $note = theme('modr8_note', $values['note']); - - // eval the replacements - $replacements_raw = modr8_replacements(); - foreach ($replacements_raw as $key => $val) { - eval('$replacements["$key"] = '. $val .';'); - } - - // replace the macros - $subject = strtr($subject, $replacements); - $message = strtr($message, $replacements); - - $site_mail = variable_get('site_mail', ""); - if (!strlen($site_mail)) { - drupal_set_message(t('You should create an administrator mail address for your site! Do it here.', array('%url' => url('admin/settings'))), 'error'); - $site_mail = 'nobody@localhost'; - } - $header = "From: ". $site_mail ."\r\n"; - // send the email - if (user_mail($account->mail, $subject, $message, $header)) { - drupal_set_message(t('%type message was sent to %username', array('%type' => $optype, '%username' => $account->name))); - } - else { - drupal_set_message(t('There was a problem sending the %type message to %username', array('%type' => $optype, '%username' => $account->name)), 'error'); + $return['where'] = "(moderate != 1 OR n.uid = $user->uid)"; + return $return; + } + break; + case 'tid': + // this query deals with taxonomy objects + break; + case 'vid': + // this query deals with vocabulary objects + break; + } +} + +/** + * Implementation of hook_block(). + */ +function modr8_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $blocks[0]['info'] = t('Content moderator block'); + return $blocks; + } + elseif ($op == 'view') { + if (user_access('moderate content')){ + $block['subject'] = t('moderation queue'); + $count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.changed DESC'))); + $sql = db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.changed DESC'); + $result = db_query_range($sql,0,6); + $content = '

'. l(t('@items in moderation',array('@items' => format_plural($count, '1 node', '@count nodes'))),'admin/content/modr8'). '

'; + $content .= node_title_list($result, t('Recent additions:')); + $block['content'] = $content; + return $block; } } - else { - drupal_set_message(t('An error occurred when trying to load this content.')); // this probably won't ever get called - } -} - -function modr8_accept_default() { - return t( -'Your %type entry entitled "%title" has been approved by our content moderator! Other visitors to %site will now be able to view it. - -You can visit %node_url to view it yourself. - -%note - -Regards, -The %site team'); -} - -function modr8_denial_default() { - return t( -'Your %type entry entitled "%title" has been denied by our content moderator. The content has been deleted from our site. - -%note - -Regards, -The %site team'); } -function modr8_replacements(){ - return array( - '%title' => '$node->title', - '%teaser' => '$node->teaser', - '%body' => '$node->body', - '%short_date' => 'format_date($node->created, "short")', - '%medium_date' => 'format_date($node->created, "medium")', - '%long_date' => 'format_date($node->created, "long")', - '%type' => 'node_get_name($node)', - '%node_url' => 'url("node/". $node->nid, NULL, NULL, TRUE)', - '%author_name' => '$account->name', - '%author_mail' => '$account->mail', - '%author_url' => 'url("user/". $account->uid, NULL, NULL, TRUE)', - '%site' => 'variable_get("site_name", "Drupal")', - '%note' => '$note', - ); -} function theme_modr8_note($note){ if ($note){ @@ -378,7 +209,7 @@ function theme_modr8_message($teaser = F return '
'. t('pending moderation') .'
'; } else { - drupal_set_message('The post has been submitted for moderation and won\'t be accessible until it has been approved.'); + drupal_set_message(t('The post has been submitted for moderation and won\'t be accessible until it has been approved.'), 'error'); return ''; } } \ No newline at end of file Index: modr8_admin.inc =================================================================== RCS file: modr8_admin.inc diff -N modr8_admin.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modr8_admin.inc 30 Oct 2006 04:10:36 -0000 @@ -0,0 +1,272 @@ + 'radios', + '#title' => t('Which action option should be selected by default?'), + '#options' => array( + 'approve' => t('approve'), + 'delete' => t('delete'), + 'nada' => t('no action'), + ), + '#default_value' => variable_get('modr8_default_option', 'nada'), + ); + + $form['modr8_nodes_per_page'] = array( + '#type' => 'select', + '#title' => t('How many nodes should be displayed per page?'), + '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 50, 75, 100, 150, 200)), + '#default_value' => variable_get('modr8_nodes_per_page', 10), + ); + $form['text'] = array( + '#type' => 'fieldset', + '#title' => t('email'), + ); + + $form['text']['modr8_send_approve'] = array( + '#type' => 'checkbox', + '#title' => t('Send approval messages'), + '#default_value' => variable_get('modr8_send_approve', FALSE), + ); + + $form['text']['modr8_accepted_subject'] = array( + '#type' => 'textfield', + '#title' => t('Acceptance Email Subject'), + '#default_value' => variable_get('modr8_accepted_subject', "[%site] %title has been approved"), + ); + + $macros = implode(', ', array_keys(modr8_replacements())); + + $accept_default = modr8_accept_default(); + + $form['text']['modr8_accepted_text'] = array( + '#type' => 'textarea', + '#title' => t('Acceptance Email'), + '#default_value' => variable_get('modr8_accepted_text', $accept_default), + '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), + ); + + $form['text']['modr8_send_deny'] = array( + '#type' => 'checkbox', + '#title' => t('Send denial messages'), + '#default_value' => variable_get('modr8_send_deny', FALSE), + ); + + $form['text']['modr8_denial_subject'] = array( + '#type' => 'textfield', + '#title' => t('Denail Email Subject'), + '#default_value' => variable_get('modr8_denial_subject', "[%site] %title has been denied"), + ); + + $denial_default = modr8_denial_default(); + + $form['text']['modr8_denial_text'] = array( + '#type' => 'textarea', + '#title' => t('Denial Email'), + '#default_value' => variable_get('modr8_denial_text', $denial_default), + '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), + ); + + return system_settings_form($form); +} + +function modr8_form() { + + $form = array( + '#theme' => 'modr8_form', + '#tree' => TRUE, + ); + $result = pager_query(db_rewrite_sql('SELECT nid FROM {node} n WHERE moderate = 1 ORDER BY created DESC'), variable_get('modr8_nodes_per_page', 10)); + while ($r = db_fetch_object($result)) { + $node = node_load($r->nid); + $teaser = node_view($node, TRUE, FALSE, FALSE); + $form[$node->nid] = array( + '#tree' => TRUE, + ); + $form[$node->nid]['ops'] = array( + '#type' => 'radios', + '#options' => array( + 'approve' => t('approve'), + 'delete' => t('delete'), + 'nada' => t('no action'), + ), + '#default_value' => variable_get('modr8_default_option', 'nada'), + ); + if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { + $form[$node->nid]['note'] = array( + '#type' => 'textarea', + '#title' => t('note to author'), + '#cols' => 10, // keep it narrow + ); + } + $form[$node->nid]['preview'] = array( + '#type' => 'markup', + '#value' => $teaser + ); + $form[$node->nid]['title'] = array( + '#type' => 'value', + '#value' => check_plain($node->title), + ); + + $form[$node->nid]['type'] = array( + '#type' => 'value', + '#value' => node_get_types('name', $node), + ); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; +} + +/** + * Themes the content moderation form. + */ +function theme_modr8_form(&$form) { + $headers = array( + t('operations'), + t('content') + ); + foreach (element_children($form) as $key) { + // Only do this for nodes; not the submit button. + if (is_numeric($key)) { + $row = array(); + if (variable_get('modr8_send_approve', FALSE) || variable_get('modr8_send_deny', FALSE)) { + $note_field = drupal_render($form[$key]['note']); + } + $row[] = array( + 'data' => drupal_render($form[$key]['ops']) . $note_field, + 'style' => 'vertical-align:top;' + ); + $row[] = array( + 'data' => drupal_render($form[$key]['preview']), + 'style' => 'vertical-align:top;', + ); + $rows[] = $row; + } + } + $output = theme('table', $headers, $rows); + $output .= drupal_render($form); + + return $output; +} + +/** + * Form submit handler, which approves or deletes the node. + */ +function modr8_form_submit($form_id, $form_values) { + foreach ($form_values as $nid => $values) { + switch ($values['ops']) { + case 'approve': + if(variable_get('modr8_send_approve', FALSE)){ + modr8_usermail('approve', $nid, $values); + } + db_query('UPDATE {node} SET moderate = 0 WHERE nid = %d', $nid); + drupal_set_message(t('The %type with title %title has been approved.', array('%title' => $values['title'], '%type' => $values['type']))); + break; + case 'delete': + if(variable_get('modr8_send_deny', FALSE)){ + modr8_usermail('deny', $nid, $values); + } + node_delete($nid); + // drupal does its own message + break; + } + } +} + +function modr8_usermail($op, $nid, $values){ + $node = node_load($nid); + + if (is_object($node)) { + + switch ($op) { + case 'approve': + $subject = variable_get('modr8_accepted_subject', '[%site] %title has been approved'); + $message = variable_get('modr8_accepted_text', modr8_accept_default()); + $optype = t('approval'); + break; + case 'deny': + $subject = variable_get('modr8_denial_subject', '[%site] %title has been denied'); + $message = variable_get('modr8_denial_text', modr8_denial_default()); + $optype = t('denial'); + break; + } + + // get the user info for author + $account = user_load(array('uid' => $node->uid)); + + $note = theme('modr8_note', $values['note']); + + // eval the replacements + $replacements_raw = modr8_replacements(); + foreach ($replacements_raw as $key => $val) { + eval('$replacements["$key"] = '. $val .';'); + } + + // replace the macros + $subject = strtr($subject, $replacements); + $message = strtr($message, $replacements); + + $sendmail_from = ini_get('sendmail_from'); + $site_mail = variable_get('site_mail', $sendmail_from); + if (!strlen($site_mail) || $site_mail == $sendmail_from) { + drupal_set_message(t('You should create an administrator mail address for your site! Do it here.', array('%url' => url('admin/settings'))), 'error'); + } + // send the email + if (drupal_mail('modr8_usermail',$account->mail, $subject, $message, $site_mail)) { + drupal_set_message(t('%type message was sent to %username', array('%type' => $optype, '%username' => $account->name))); + } + else { + drupal_set_message(t('There was a problem sending the %type message to %username', array('%type' => $optype, '%username' => $account->name)), 'error'); + } + } + else { + drupal_set_message(t('An error occurred when trying to load this content.')); // this probably won't ever get called + } +} + +function modr8_replacements(){ + return array( + '%title' => '$node->title', + '%teaser' => '$node->teaser', + '%body' => '$node->body', + '%short_date' => 'format_date($node->created, "short")', + '%medium_date' => 'format_date($node->created, "medium")', + '%long_date' => 'format_date($node->created, "long")', + '%type' => 'node_get_name($node)', + '%node_url' => 'url("node/". $node->nid, NULL, NULL, TRUE)', + '%author_name' => '$account->name', + '%author_mail' => '$account->mail', + '%author_url' => 'url("user/". $account->uid, NULL, NULL, TRUE)', + '%site' => 'variable_get("site_name", "Drupal")', + '%note' => '$note', + ); +} + +function modr8_accept_default() { + return t( +'Your %type entry entitled "%title" has been approved by our content moderator! Other visitors to %site will now be able to view it. + +You can visit %node_url to view it yourself. + +%note + +Regards, +The %site team'); +} + +function modr8_denial_default() { + return t( +'Your %type entry entitled "%title" has been denied by our content moderator. The content has been deleted from our site. + +%note + +Regards, +The %site team'); +} +