Index: nmoderation.info
===================================================================
RCS file: nmoderation.info
diff -N nmoderation.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nmoderation.info	2 Apr 2007 06:29:31 -0000	1.1
@@ -0,0 +1,4 @@
+; $Id: nmoderation.info,v 1.1 2007/04/02 06:29:31 eaton Exp $
+name = Nmoderation
+description = Allows users to moderate nodes.
+dependencies = votingapi
Index: nmoderation.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nmoderation/nmoderation.module,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- nmoderation.module	20 Jun 2006 20:40:30 -0000	1.30
+++ nmoderation.module	2 Apr 2007 06:30:24 -0000	1.31
@@ -1,5 +1,5 @@
 <?php
-// $Id: nmoderation.module,v 1.30 2006/06/20 20:40:30 eaton Exp $
+// $Id: nmoderation.module,v 1.31 2007/04/02 06:30:24 eaton Exp $
 
 /**
  * @file
@@ -21,6 +21,17 @@
 }
 
 function nmoderation_menu($may_cache) {
+
+$items[] = array(
+    'path' => 'admin/settings/nmoderation',
+    'title' => t('Nmoderation'),
+    'description' => t('Moderate nodes.'),
+    'callback' => 'drupal_get_form',
+    'callback arguments' => array('nmoderation_admin_settings'),
+    'access' => user_access('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM, // optional
+   );
+   
   if ($may_cache) {
     $access = user_access('administer node moderation votes');
     $items[] = array('path' => 'admin/nmoderation', 'title' => t('node moderation'),
@@ -51,8 +62,8 @@
       'callback' => 'nmoderation_list_all', 'weight' => 5, 'access' => user_access('administer node moderation votes'));
   }
   else {
-  	if (arg(0) == 'node' && is_numeric(arg(1))) {
-  	  $access = user_access('administer node moderation votes') || user_access('view node moderation votes');
+    if (arg(0) == 'node' && is_numeric(arg(1))) {
+    $access = user_access('administer node moderation votes') || user_access('view node moderation votes');
       $items[] = array('path' => 'node/'. arg(1). '/nmoderation', 'title' => t('votes'),
         'type' => MENU_LOCAL_TASK, 'callback' => 'nmoderation_list_node', 'weight' => 5, 'access' => $access, 'callback arguments' => array(arg(1)));
     }
@@ -113,6 +124,11 @@
 
 function nmoderation_matrix_settings() {
   $output .= '<h3>Node Moderation vote/value matrix</h3>';
+  $output .= drupal_get_form('nmoderation_matrix_settings_form', $form_id);
+  return $output;
+}
+
+function nmoderation_matrix_settings_form() {
   $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%'");
   $role_names = array();
   while ($role = db_fetch_object($result)) {
@@ -152,11 +168,10 @@
     '#value' => $role_names,
   );
 
-  $output .= drupal_get_form('nmoderation_matrix_form', $form);
-  return $output;
+  return $form;
 }
 
-function nmoderation_matrix_form_submit($form_id, $form_values) {
+function nmoderation_matrix_settings_form_submit($form_id, $form_values) {
   // db_query('DELETE FROM {nmoderation_roles} ');
   foreach (element_children($form_values['votes']) as $mid) {
     foreach (element_children($form_values['votes'][$mid]) as $rid) {
@@ -169,14 +184,14 @@
   drupal_set_message(t('the vote values have been saved.'));
 }
 
-function theme_nmoderation_matrix_form(&$form) {
+function theme_nmoderation_matrix__settings_form(&$form) {
   $role_names = $form['role_names']['#value'];
   $header = array_merge(array(t('votes')), array_values($role_names));
 
   foreach (element_children($form['votes']) as $mid) {
     $row = array();
     foreach (element_children($form['votes'][$mid]) as $rid) {
-      $row[] = form_render($form['votes'][$mid][$rid]);
+      $row[] = drupal_render($form['votes'][$mid][$rid]);
     }
     $rows[] = $row;
   }
@@ -187,7 +202,7 @@
   }
 
   $output = theme('table', $header, $rows);
-  $output .= form_render($form);
+  $output .= drupal_render($form);
   return $output;
 }
 
@@ -196,7 +211,11 @@
  */
 function nmoderation_role_settings() {
   $output .= '<h3>Initial node scores</h3>';
-  
+  $output .= drupal_get_form('nmoderation_role_settings_form', $form_id);
+  return $output;
+}
+
+ function nmoderation_role_settings_form() {
   $start_values = variable_get('nmoderation_roles', array());
   
   $result = db_query("SELECT r.rid, r.name FROM {role} r, {permission} p WHERE r.rid = p.rid AND p.perm LIKE '%moderate nodes%' ORDER BY r.rid");
@@ -216,15 +235,14 @@
     '#value' => t('Save scores')
   );
 
-  $output .= drupal_get_form('nmoderation_role_form', $form);
-  return $output;
+  return $form;
 }
 
-function nmoderation_role_form_validate($form_id, $form_values) {
+function nmoderation_role_settings_form_validate($form_id, $form_values) {
   // make sure everything is numeric/int
 }
 
-function nmoderation_role_form_submit($form_id, $form_values) {
+function nmoderation_role_settings_form_submit($form_id, $form_values) {
     $new_values = array();
     foreach (element_children($form_values['role']) as $rid) {
       $new_values[$rid] = $form_values['role'][$rid]['#value'];
@@ -233,7 +251,7 @@
     drupal_set_message(t('the node moderation scores have been saved.'));
 }
 
-function theme_nmoderation_role_form(&$form) {
+function theme_nmoderation_role_settings_form(&$form) {
   $header = array(t('user role'), t('initial score'));
 
   $rows = array();
@@ -241,20 +259,26 @@
     $row = array();
     $row[] = $form['role'][$rid]['#title'];
     unset($form['role'][$rid]['#title']);
-    $row[] = form_render($form['role'][$rid]);
+    $row[] = drupal_render($form['role'][$rid]);
     $rows[] = $row;
   }
 
   $output = theme('table', $header, $rows);
-  $output .= form_render($form);
+  $output .= drupal_render($form);
   return $output;
 }
 
 /**
  * Menu callback; displays page for assigning names to vote values.
  */
-function nmoderation_vote_settings() {
+
+ function nmoderation_vote_settings() {
   $output .= '<h3>'. t('Node moderation votes overview') .'</h3>';
+  $output = drupal_get_form('nmoderation_vote_settings_form', $form_id);
+  return $output;
+}
+
+ function nmoderation_vote_settings_form() {
 
   // load up and show any vote types previously defined.
   $result = db_query('SELECT mid, vote, weight FROM {nmoderation_votes} ORDER BY weight');
@@ -301,15 +325,14 @@
     '#value' => t('Save changes'),
   );
 
-  $output = drupal_get_form('nmoderation_vote_form', $form);
-  return $output;
+  return $form;
 }
 
-function nmoderation_vote_form_validate($form_id, $form_values) {
+function nmoderation_vote_settings_form_validate($form_id, $form_values) {
   // make sure $weight is an int and $vote is markup clean, no injections.
 }
 
-function nmoderation_vote_form_submit($form_id, $form_values) {
+function nmoderation_vote_settings_form_submit($form_id, $form_values) {
   // loop through the fields for old votes, update or delete as necessary.
   foreach (element_children($form_values['old']) as $mid) {
     if ($form_values['old'][$mid]['delete'] == 1) {
@@ -330,31 +353,36 @@
   drupal_goto('admin/nmoderation/votes'); // do this because we want the form completely rebuilt.
 }
 
-function theme_nmoderation_vote_form(&$form) {
+function theme_nmoderation_vote_settings_form(&$form) {
   $header = array(t('votes'), t('weight'), t('delete'));
   
   // render the existing-vote fields.
   foreach (element_children($form['old']) as $mid) {
     $row = array();
-    $row[] = form_render($form['old'][$mid]['vote']);
-    $row[] = form_render($form['old'][$mid]['weight']);
-    $row[] = form_render($form['old'][$mid]['delete']);
+    $row[] = drupal_render($form['old'][$mid]['vote']);
+    $row[] = drupal_render($form['old'][$mid]['weight']);
+    $row[] = drupal_render($form['old'][$mid]['delete']);
     $rows[] = $row;
   }
 
   // render the add-a-vote fields.
   $row = array();
-  $row[] = form_render($form['new']['vote']);
-  $row[] = form_render($form['new']['weight']);
+  $row[] = drupal_render($form['new']['vote']);
+  $row[] = drupal_render($form['new']['weight']);
   $row[] = '';
   $rows[] = $row;
   
   $output .= theme('table', $header, $rows);
-  $output .= form_render($form);
+  $output .= drupal_render($form);
+  return $output;
+}
+ 
+function nmoderation_moderation($content_type, $content_id, $vote, $title= NULL) {
+  $output = drupal_get_form('nmoderation_moderation_form', $form_id, $content_type, $content_id, $vote, $title= NULL);
   return $output;
 }
 
-function nmoderation_get_moderation_form($content_type, $content_id, $vote, $title= NULL) {
+function nmoderation_moderation_form($content_type, $content_id, $vote, $title= NULL) {
   global $user;
   static $votes;
 
@@ -441,7 +469,7 @@
 function theme_nmoderation_moderation_form($form) {
   // We aren't actually going to do anything fancy, but it's here
   // in case folks want to override it for a given theme.
-  $output = form_render($form);
+  $output = drupal_render($form);
   return $output;
 }
 
@@ -464,7 +492,7 @@
   // may only edit own vote if you are not an admin
   if ($user->uid == $vote->uid || user_access('administer node moderation votes')) {
     $node = node_load($vote->content_id);
-    $form = nmoderation_get_moderation_form('node', $node->nid, $vote, t('Edit vote'));
+    $form = nmoderation_moderation_form('node', $node->nid, $vote, t('Edit vote'));
     
     if ($vote->uid != $user->uid) {
       $form['username'] = array(
@@ -482,7 +510,8 @@
       '#weight' => -1,
     );
 
-    $output .= drupal_get_form('nmoderation_moderation_form', $form);
+    //$output .= drupal_get_form('nmoderation_moderation_form');
+    $output .= drupal_get_form('nmoderation_moderation_form', 'node', $node->nid, $vote, t('Edit vote'));
     return $output;
   }
   else {
@@ -493,7 +522,7 @@
 function nmoderation_uservote_delete($vote_id) {
   $form['vote_id'] = array('#type' => 'value', '#value' => $vote_id);
   $output = confirm_form(
-    'nmoderation_delete_confirm',
+    //'nmoderation_delete_confirm',
     $form,
     t('Are you sure you want to delete this vote?'),
     $_GET['destination'] ? $_GET['destination'] : 'nmoderation/voted',
@@ -501,6 +530,7 @@
     t('Delete Vote'),
     t('Cancel') 
   );
+  var_export($output);
   return $output;
 }
 
@@ -551,7 +581,7 @@
   );
   $cols = 2;
   $title = t('my unmoderated nodes');
-  $types = implode("','", variable_get('nmoderation_node_types', array_flip(node_get_types())));
+  $types = implode("','", variable_get('nmoderation_node_types', node_get_types()));
   $sql = "SELECT n.nid, n.created, u.name, n.title, n.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {votingapi_vote} v ON n.nid = v.content_id AND v.content_type = '$content_type' AND v.uid = $user->uid WHERE n.type IN ('$types') AND n.status = 1 AND ISNULL(v.vote_id)";
   $min = time()-24*3600*variable_get('nmoderation_vote_interval', 7);
   $sql .= " AND n.created > $min";
@@ -677,16 +707,16 @@
   return $output;
 }
 
-function nmoderation_settings() {
+function nmoderation_admin_settings() {
   $promote = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100));
-  $unpublish = drupal_map_assoc(array(-1, -2, -3, -4, -5, -6, -7, -8, -8, -10, -11, -12, -13, -14, -15, -20, -25, -30));
+  $unpublish = drupal_map_assoc(array(-1, -2, -3, -4, -5, -6, -7, -8, -8, -10, -11, -12, -13, -14, -15, -20, -25, -30, -100));
   $interval = drupal_map_assoc(range(1,60));
 
   $form['nmoderation_node_types'] = array(
     '#type' => 'select',
     '#title' => t('Node Types'),
     '#default_value' => variable_get('nmoderation_node_types', node_get_types()),
-    '#options' => node_get_types(),
+    '#options' => node_get_types('names'),
     '#description' => t('Select the node types upon which accept node moderation votes.'),
     '#extra' => 0,
     '#multiple' => 1,
@@ -713,7 +743,7 @@
     '#description' => t('The number of days since the creation of a node when we allow voting.'),
   );
 
-  return $form;
+   return system_settings_form($form);
 }
 
 
@@ -742,9 +772,7 @@
           else {
             $title = t('Add vote');
           }
-          if ($frm = nmoderation_get_moderation_form('node', $node->nid, $vote, $title)) {
-            $node->body .= drupal_get_form('nmoderation_moderation_form', $frm);
-          }
+             $node->content['body']['#value'] .= drupal_get_form('nmoderation_moderation_form', 'node', $node->nid, $vote, $title);
         }
         break;
   }
