? nodeapproval.5.patch
Index: nodeapproval.info
===================================================================
RCS file: nodeapproval.info
diff -N nodeapproval.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nodeapproval.info	5 Aug 2007 13:44:09 -0000
@@ -0,0 +1,4 @@
+; $Id$
+name = Node Approval
+description = Reactive moderation of node content. New nodes get published but go onto the list of content needing approval.
+package = Approval
Index: nodeapproval.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeapproval/nodeapproval.module,v
retrieving revision 1.1.2.1
diff -u -F^f -r1.1.2.1 nodeapproval.module
--- nodeapproval.module	29 Nov 2006 17:26:25 -0000	1.1.2.1
+++ nodeapproval.module	5 Aug 2007 13:44:10 -0000
@@ -23,52 +23,53 @@ function nodeapproval_perm() {
 
 /**
  * Implementation of hook_menu
- * 
+ *
  */
 function nodeapproval_menu($may_cache) {
   $items = array();
-  
+
   if ($may_cache) {
     $access = user_access('approve nodes');
 
-    if (!module_exist('commentapproval')) {
+    if (!module_exists('commentapproval')) {
       $items[] = array(
-        'path' => 'admin/approval',
-        'title' => t('approval'),
+        'path' => 'admin/content/approval',
+        'title' => t('Approval'),
+        'description' => t('Approve, disapprove, and delete content'),
         'access' => $access,
         'callback' => 'nodeapproval_admin_overview',
       );
       $items[] = array(
-        'path' => 'admin/approval/node',
-        'title' => t('nodes'),
+        'path' => 'admin/content/approval/node',
+        'title' => t('Nodes'),
         'type' => MENU_DEFAULT_LOCAL_TASK,
-      );      
+      );
     }
     else {
       $items[] = array(
-  	    'path' => 'admin/approval/node',
-  	    'title' => t('nodes'),
-        'callback' => 'nodeapproval_admin_overview', 
+        'path' => 'admin/content/approval/node',
+        'title' => t('Nodes'),
+        'callback' => 'nodeapproval_admin_overview',
         'access' => $access,
         'type' => MENU_LOCAL_TASK,
-  	  );
+      );
     }
     $items[] = array(
-      'path' => 'admin/approval/node/approval', 
-      'title' => t('not yet moderated'),
+      'path' => 'admin/content/approval/node/approval',
+      'title' => t('Not yet moderated'),
       'type' => MENU_DEFAULT_LOCAL_TASK,
       'weight' => -1,
     );
     $items[] = array(
-      'path' => 'admin/approval/node/approve', 
-      'title' => t('approved'),
+      'path' => 'admin/content/approval/node/approve',
+      'title' => t('Approved'),
       'type' => MENU_LOCAL_TASK,
     );
     $items[] = array(
-      'path' => 'admin/approval/node/disapprove', 
-      'title' => t('disapproved'),
+      'path' => 'admin/content/approval/node/disapprove',
+      'title' => t('Disapproved'),
       'type' => MENU_LOCAL_TASK,
-    );   
+    );
   }
   return $items;
 }
@@ -78,30 +79,30 @@ function nodeapproval_menu($may_cache) {
  * any type opt-out of the approval workflow.
  */
 function nodeapproval_form_alter($form_id, &$form) {
-  if (isset($form['type'])) {
-    if ($form['type']['#value'] .'_node_settings' == $form_id) {
-      $form['workflow']['approval_'. $form['type']['#value']] = array(
-        '#type' => 'radios', 
-        '#title' => t('Approval'), 
-        '#default_value' => variable_get('approval_'. $form['type']['#value'], NODEAPPROVAL_ENABLED_BY_DEFAULT),
-        '#options' => array(t('Disabled'), t('Enabled')),
-        '#description' => t('Should %type nodes be subject to approval?', array('%type' => theme('placeholder', $form['type']['#value']))),
-      );
-    }
+  if ($form_id == 'node_type_form' ) {
+    $node_type = $form['old_type']['#value'];
+    $form['workflow']['nodeapproval_settings'] = array(
+      '#type' => 'radios',
+      '#title' => t('Approval'),
+      '#default_value' => variable_get('nodeapproval_settings_'. $node_type, NODEAPPROVAL_ENABLED_BY_DEFAULT),
+      '#options' => array(t('Disabled'), t('Enabled')),
+      '#description' => t('Should %type nodes be subject to approval?', array('%type' => $node_type)),
+    );
   }
 }
 
+
 /**
  * Implementation of hook_nodeapi.
- * 
+ *
  * This implementation deletes node records from the table nodeapproval
  * whenever a node is deleted.
- * 
+ *
  */
 function nodeapproval_nodeapi($node, $op) {
   if ($op == 'delete') {
     db_query("DELETE FROM {nodeapproval} where nid = %d", $node->nid);
-  } 
+  }
 }
 
 
@@ -111,10 +112,10 @@ function nodeapproval_nodeapi($node, $op
 function nodeapproval_operations() {
   $operations = array(
     'approve' => array(
-      'text' => t('Approve the selected nodes'), 
+      'text' => t('Approve the selected nodes'),
       'callback' => 'nodeapproval_do_approval'),
     'disapprove' => array(
-      'text' => t('Disapprove the selected nodes'), 
+      'text' => t('Disapprove the selected nodes'),
       'callback' => 'nodeapproval_do_disapprove'),
   );
   if (user_access('administer nodes')) {
@@ -144,22 +145,26 @@ function nodeapproval_do_disapprove($nid
  * Menu callback; present an administrative node listing.
  */
 function nodeapproval_admin_overview($arg1 = NULL, $arg2 = NULL) {
-  // Check and see which parameter to use based on whether commentapproval is enabled or not
-  $type = module_exist('commentapproval') ? $arg1 : $arg2;
-  
-  $edit = $_POST['edit'];
+  $edit = $_POST;
 
   if ($edit['operation'] == 'delete') {
     return nodeapproval_multiple_delete_confirm();
   }
 
+  return drupal_get_form('nodeapproval_admin_overview_form', $arg1, $arg2);
+}
+
+function nodeapproval_admin_overview_form($arg1 = NULL, $arg2 = NULL){
+  // Check and see which parameter to use based on whether commentapproval is enabled or not
+  $type = module_exists('commentapproval') ? $arg1 : $arg2;
+
   // build an 'Update options' form
   $form['options'] = array(
     '#type' => 'fieldset', '#title' => t('Update options'),
     '#prefix' => '<div class="container-inline">', '#suffix' => '</div>'
   );
   $options = array();
-  
+
   // bind identifier, text and callbacks.
   $operations = nodeapproval_operations();
   // unset the operation for the current screen since the node already has that state
@@ -171,7 +176,6 @@ function nodeapproval_admin_overview($ar
   $form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'approve');
   $form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
 
-
   // Build a table listing the appropriate nodes.
   $form['header'] = array('#type' => 'value', '#value' => array(
     NULL,
@@ -185,18 +189,22 @@ function nodeapproval_admin_overview($ar
     unset($form['header']['#value']['operations']);
   }
 
-  // To looad the nodes that we want to display, we first need a list of
+  // To load the nodes that we want to display, we first need a list of
   // node types that have not opted out of the approval workflow
-  $node_types = array_filter(node_get_types(), create_function('$a', 'return variable_get("approval_". $a, NODEAPPROVAL_ENABLED_BY_DEFAULT);'));
 
+  $types = array_filter(node_get_types(), create_function('$a', 'return variable_get("nodeapproval_settings_". $a->type, NODEAPPROVAL_ENABLED_BY_DEFAULT);'));
+  $node_types = array();
+  foreach($types as $key => $value){
+    $node_types[$key] = $value->type;
+  }
   if (count($node_types) > 0) {
-    $node_types_sql = ' AND n.type IN (\''. implode('\', \'', $node_types). '\')';
+   $node_types_sql = ' AND n.type IN (\''. implode('\', \'', $node_types ). '\')';
   }
   else {
-   drupal_set_message(t('There are no node types which are configured to require approval. You can adjust this setting on individual node types from the %types page.', array('%types' => l(t('content type administration'), 'admin/settings/content-types'))));
-   return ''; 
+    drupal_set_message(t('There are no node types which are configured to require approval. You can adjust this setting on individual node types from the %types page.', array('%types' => l(t('content type administration'), 'admin/settings/content-types'))));
+    return '';
   }
-  
+
   // Build the SQL
   if ($type === NULL) {
     $sql = 'SELECT n.nid, app.approved '.
@@ -215,7 +223,7 @@ function nodeapproval_admin_overview($ar
   }
   $result = pager_query($sql . tablesort_sql($form['header']['#value']), 30, 0, NULL);
 
-    
+
   // $destination is used in the _edit_ link
   $destination = drupal_get_destination();
   while ($row = db_fetch_object($result)) {
@@ -223,8 +231,9 @@ function nodeapproval_admin_overview($ar
     $nodes[$node->nid] = '';
 
     $form['status'][$node->nid] = array('#value' => $node->status == 1 ? t('Published') : t('Unpublished'));
-    $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid, array('title' => truncate_utf8($node->teaser, 128)), NULL, 'node-'. $node->nid));
-    $form['teaser'][$node->nid] = array('#value' => $node->teaser);
+    $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid));
+    $node = node_build_content($node, TRUE);
+    $form['teaser'][$node->nid] = array('#value' => drupal_render($node->content));
     $form['username'][$node->nid] = array('#value' => theme('username', user_load(array('uid' => $node->uid))));
     $form['timestamp'][$node->nid] = array('#value' => format_date($node->created, 'small'));
     if (user_access('administer nodes')) {
@@ -233,7 +242,10 @@ function nodeapproval_admin_overview($ar
   }
   $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
   $form['pager'] = array('#value' => theme('pager', NULL, 30, 0));
-  return drupal_get_form('nodeapproval_admin_overview', $form);
+  $form['#validate']['nodeapproval_admin_overview_validate'] = array();
+  $form['#submit']['nodeapproval_admin_overview_submit'] = array();
+
+  return $form;
 }
 
 
@@ -241,8 +253,12 @@ function nodeapproval_admin_overview($ar
  * List the selected nodes and verify that the admin really wants to delete
  * them.
  */
-function nodeapproval_multiple_delete_confirm() {
-  $edit = $_POST['edit'];
+function nodeapproval_multiple_delete_confirm(){
+  return drupal_get_form('nodeapproval_multiple_delete_confirm_form');
+}
+
+function nodeapproval_multiple_delete_confirm_form() {
+  $edit = $_POST;
 
   $form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
   // array_filter() returns only elements with actual values
@@ -256,16 +272,17 @@ function nodeapproval_multiple_delete_co
     }
   }
   $form['operation'] = array('#type' => 'hidden', '#value' => 'delete');
-
+  $form['#submit']['nodeapproval_multiple_delete_confirm_submit'] = array();
   if (!$node_counter) {
     drupal_set_message(t('There does not appear to be any content to delete or your selected content was deleted by another administrator.'));
-    drupal_goto('admin/approval/node');
+    return 'admin/content/approval';
   }
   else {
-    return confirm_form('nodeapproval_multiple_delete_confirm', $form,
+    return confirm_form( $form,
                         t('Are you sure you want to delete this content and all of its comments?'),
                         'admin/node', t('This action cannot be undone.'),
                         t('Delete content'), t('Cancel'));
+
   }
 }
 
@@ -280,7 +297,7 @@ function nodeapproval_multiple_delete_co
     cache_clear_all();
     drupal_set_message(t('The content has been deleted.'));
   }
-  drupal_goto('admin/approval/node');
+  return 'admin/content/approval';
 }
 
 /**
@@ -309,39 +326,40 @@ function nodeapproval_admin_overview_sub
         if (!is_null($callback)) {
           $callback($nid);
         }
-        
+
         node_invoke_nodeapi(node_load($nid), 'update');
-        
+
         // Add an entry to the watchdog log.
         watchdog('content', t('Node: updated %title.', array('%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid, NULL, NULL, 'node-'. $node->nid));
       }
     }
-    cache_clear_all();
+    cache_clear_all(NULL, 'cache_page');
     drupal_set_message(t('The update ('. check_plain($edit['operation']). ') has been performed.'));
   }
+
 }
 
-function theme_nodeapproval_admin_overview($form) {
+function theme_nodeapproval_admin_overview_form($form) {
   drupal_set_html_head(theme('stylesheet_import', base_path() . drupal_get_path('module', 'nodeapproval') .'/nodeapproval.css'));
-  $output = form_render($form['options']);
+  $output = drupal_render($form['options']);
   if (isset($form['title']) && is_array($form['title'])) {
     foreach (element_children($form['title']) as $key) {
       $row = array();
-      $row[] = form_render($form['nodes'][$key]);
-      $teaser = form_render($form['teaser'][$key]);
+      $row[] = drupal_render($form['nodes'][$key]);
+      $teaser = drupal_render($form['teaser'][$key]);
       if (strlen($teaser) > 512) {
         $class = ' class="node-in-table"';
       }
       else {
         $class = '';
       }
-      $row[] = form_render($form['title'][$key]) . '<div'. $class. '>'. $teaser. '</div>';
-      $row[] = form_render($form['username'][$key]);
-      $row[] = form_render($form['timestamp'][$key]);
+      $row[] = drupal_render($form['title'][$key]) . '<div'. $class. '>'. $teaser. '</div>';
+      $row[] = drupal_render($form['username'][$key]);
+      $row[] = drupal_render($form['timestamp'][$key]);
       if (user_access('administer nodes')) {
-        $row[] = form_render($form['operations'][$key]);
+        $row[] = drupal_render($form['operations'][$key]);
       }
-      $row[] = form_render($form['status'][$key]);
+      $row[] = drupal_render($form['status'][$key]);
       $rows[] = $row;
     }
   }
@@ -352,10 +370,10 @@ function theme_nodeapproval_admin_overvi
   $output .= theme('table', $form['header']['#value'], $rows);
 
   if ($form['pager']['#value']) {
-    $output .= form_render($form['pager']);
+    $output .= drupal_render($form['pager']);
   }
 
-  $output .= form_render($form);
+  $output .= drupal_render($form);
 
   return $output;
-}
\ No newline at end of file
+}
