Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/README.txt,v
retrieving revision 1.1
diff -u -r1.1 README.txt
--- README.txt	19 Aug 2008 16:14:43 -0000	1.1
+++ README.txt	14 Jul 2009 23:41:47 -0000
@@ -25,6 +25,12 @@
   administer > site building > modules
 
 
+PERMISSIONS
+-----------
+* filter and manage site content - gives access to the CMF page.
+* view user content list - gives access to the user page.
+
+
 USE
 ---
 1. The functional page to filter and administer content can be found by navigating to:
Index: both.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/both.inc,v
retrieving revision 1.2.2.4
diff -u -r1.2.2.4 both.inc
--- both.inc	12 Mar 2009 12:39:19 -0000	1.2.2.4
+++ both.inc	14 Jul 2009 23:35:28 -0000
@@ -13,7 +13,6 @@
  * @warning For more information on licensing, read the LICENCE.txt file.
  */
 
-
 /**
  * Defines the form for mixed content administration filter results.
  *
@@ -24,7 +23,6 @@
  * @return array with forms properties 
  */
 function cmf_admin_both_form() {
-
   $destination = drupal_get_destination();
 
   // build an 'Update options' form
@@ -32,28 +30,27 @@
     $form['options'] = array(
       '#type' => 'fieldset', '#title' => t('Update options'),
       '#prefix' => '<div class="container-inline">', '#suffix' => '</div>'
-    );
+      );
     $form['options']['operation'] = array(
       '#type' => 'select', 
       '#options' => array(
-                      'publish' => t('Publish'), 
-                      'unpublish' => t('Unpublish'), 
-                      'delete' => t('Delete'),
-                    ), 
+        'publish' => t('Publish'), 
+        'unpublish' => t('Unpublish'), 
+        'delete' => t('Delete'),
+        ), 
       '#default_value' => 'publish'
-    );
+      );
     $form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
   }
 
-  // load the objects that we want to display
+  // Load the objects that we want to display.
   $form['header'] = array(
     '#type'  => 'value', 
     '#value' => cmf_build_header(),
-  );
-  
+    );
 
   $result = cmf_perform_query($form['header']['#value']);
-  // build a table listing the appropriate objects
+  // Build a table listing the appropriate objects.
   while ($object = db_fetch_object($result)) {
     if ($object->cid == 0) {
       $objects['n-'. $object->nid] = '';
@@ -61,7 +58,7 @@
       array('attributes' => array('title' => truncate_utf8($object->body, drupal_strlen($object->body))),
       'fragment' => 'node-'. $object->nid)) .' '. theme('mark', node_mark($object->nid, $object->changed)));
       $form['kind']['n-'. $object->nid] = array('#value' => _cmf_get_img('node', t('node')));
-      $form['type']['n-'. $object->nid] =  $object->type == 'forum' ? array('#value' => '<p title="'. 
+      $form['type']['n-'. $object->nid] = $object->type == 'forum' ? array('#value' => '<p title="'. 
         _cmf_get_forum($object->nid) .'">'. check_plain(node_get_types('name', $object)) .'</p>') : 
         array('#value' =>  check_plain(node_get_types('name', $object)));
       if (!(arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0)) {
@@ -73,7 +70,7 @@
         'small'));
       if (user_access('filter and manage site content')) {
         $form['operations']['n-'. $object->nid] = array('#value' => l(_cmf_get_img('edit', 
-          t('edit')) .' '. t('edit'), 'node/'. $object->nid .'/edit', array('html' => TRUE)));
+          t('edit')) .' '. t('edit'), 'node/'. $object->nid .'/edit', array('query' => $destination, 'html' => TRUE)));
       }
     }
     else{
@@ -94,12 +91,11 @@
         'small'));
       if (user_access('filter and manage site content')) {
         $form['operations']['c-'. $object->cid] = array('#value' => l(_cmf_get_img('edit', 
-          t('edit')) .' '. t('edit'), 'comment/edit/'. $object->cid, array('html' => TRUE)));
+          t('edit')) .' '. t('edit'), 'comment/edit/'. $object->cid, array('query' => $destination, 'html' => TRUE)));
       }
     }
   }
 
-
   if (user_access('filter and manage site content')) {
     $form['objects'] = array('#type' => 'checkboxes', '#options' => $objects);
   }
@@ -108,7 +104,6 @@
   return $form;
 }
 
-
 /** 
  * Form validation before submit. \n
  * We can't execute any 'Update options' if no objects were selected.
@@ -119,7 +114,7 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_both_form_validate($form, &$form_state) {
   $form_state['values']['objects'] = array_diff($form_state['values']['objects'], array(0));
   if (count($form_state['values']['objects']) == 0) {
@@ -128,7 +123,6 @@
   }
 }
 
-
 /** 
  * Handle post-validation form submission. \n
  * Execute the chosen 'Update option' on the selected objects, such as
@@ -140,10 +134,9 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_both_form_submit($form, &$form_state) {
-  
-  // queries building
+  // Query building.
   switch ($form_state['values']['operation']) {
     case 'publish':
         $node_query    = 'UPDATE {node} SET status = 1 WHERE nid = %d';
@@ -159,13 +152,13 @@
       break;
   }
 
-  // perform queries
+  // Perform queries.
   foreach ($form_state['values']['objects'] as $flag) {
     if ($flag) {
       $object = explode('-', $flag);
       $kind   = $object[0];
       $value  = $object[1];
-      
+
       if ($kind == 'n') {
         db_query($node_query, $value);
       }
@@ -176,7 +169,6 @@
         _comment_update_node_statistics($comment->nid);
         // Allow modules to respond to the updating of a comment.
         comment_invoke_comment($comment, $form_state['values']['operation']);
-
       }
     }
   }
@@ -191,14 +183,13 @@
   }
 }
 
-
 /** 
  * Theme results table.
  *
  * @ingroup themable
  *
  * @return table with filter results
- */ 
+ */
 function theme_cmf_admin_both_form($form) {
   $output = drupal_render($form['options']);
 
Index: cmf.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/cmf.module,v
retrieving revision 1.2.2.4
diff -u -r1.2.2.4 cmf.module
--- cmf.module	12 Mar 2009 12:39:19 -0000	1.2.2.4
+++ cmf.module	15 Jul 2009 01:06:21 -0000
@@ -1,6 +1,5 @@
 <?php
 // $Id: cmf.module,v 1.2.2.4 2009/03/12 12:39:19 nunoveloso18 Exp $
-
 /**
  * @file
  * @brief Content management filter module file
@@ -9,86 +8,63 @@
  *
  * @attention Copyright (C) 2008 Nuno Veloso <nunoveloso18 (at) gmail (dot) com>
  * @author Nuno André Veloso Matias (http://www.nunoveloso.org)
- *
- * @warning For more information on licensing, read the LICENCE.txt file.
  */
 
-
 /**
  * Implementation of hook_help().
  */
 function cmf_help($path, $arg) {
-
-  $output = '';
-
   switch ($section) {
-
     case "admin/help#cmf":
-
-      $output .= '<p>'.  t('This module adds an easier way for administrators to filter the 
-        content on a Drupal site for administration purposes.') .'</p>';
-
-      $output .= '<p>'.  t('It\'s an improvement over the content page in the administration area 
-        of Drupal. It can show on the same page nodes and comments and adds new filters like role 
-        and author.') .'</p>';
-
+      $output = '<p>'. t("This module adds an easier way for administrators to filter the content on a Drupal site for administration purposes.") .'</p>';
+      $output .= '<p>'. t("It's an improvement over the content page in the administration area of Drupal. It can show on the same page nodes and comments and adds new filters like role and author.") .'</p>';
       break;
   }
   return $output;
 } 
-
-
 /**
  * Implementation of hook_perm().
  */
 function cmf_perm() {
-  return array('admin cmf module', 'filter and manage site content', 'view user content list');
+  return array('filter and manage site content', 'view user content list');
 }
-
-
 /**
  * Implementation of hook_menu().
  */
 function cmf_menu() {
   $items = array();
   
-	$items['admin/content/filter'] = array(
-		'title' => 'Content Management Filter',
-		'description' => 'All-in-one advanced filter and management of your site content.',
-		'page callback' => 'cmf_admin_content_page',
-		'access arguments' => array('filter and manage site content'),
-	);
-
-	$items['user/%/cmf'] = array(
-		'title' => 'CMF',
-		'description' => 'User-specific content management filter',
-		'page callback' => 'cmf_admin_content_page',
-		'access callback' => '_cmf_userspace_perms',
-		'access arguments' => array('filter and manage site content', 'view user content list'),
-		'type' => MENU_LOCAL_TASK,
-	);
+  $items['admin/content/filter'] = array(
+    'title' => 'Content Management Filter',
+    'description' => 'All-in-one advanced filter and management of your site content.',
+    'page callback' => 'cmf_admin_content_page',
+    'access arguments' => array('filter and manage site content'),
+    );
+
+  $items['user/%/cmf'] = array(
+    'title' => 'CMF',
+    'description' => 'User-specific content management filter',
+    'page callback' => 'cmf_admin_content_page',
+    'access callback' => '_cmf_userspace_perms',
+    'access arguments' => array('filter and manage site content', 'view user content list'),
+    'type' => MENU_LOCAL_TASK,
+    );
 
   return $items;
 }
-
-
 /** 
  * Called when user goes to example.com/admin/content/filter
  *
  * @return the HTML generated from the $form data structure
- */ 
+ */
 function cmf_admin_content_page() {
-  
   if (!isset($_SESSION['cmf_content_kind'])) {
     $_SESSION['cmf_content_kind'] = 'node';
   }
-  
   if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
     $true = TRUE;
   }
-
   $output = drupal_get_form('cmf_filter_form', $true);
-
   // Call the form first, to allow for the form_values array to be populated.
   switch ($_SESSION['cmf_content_kind']) {
     case 'node':
@@ -108,18 +84,15 @@
         $output .= drupal_get_form('cmf_admin_comments_form');
       }
       break;
+
     case 'both':
       $output .= drupal_get_form('cmf_admin_both_form');
   }
-
   return $output;
 }
-
-
-/**********************
-*  FILTERS            *
-**********************/ 
-
+/**
+ * FILTERS
+ */
 /**
  * Defines the form for content administration filters.
  *
@@ -133,13 +106,12 @@
   $session = &$_SESSION['cmf_overview_filter'];
   $session = is_array($session) ? $session : array();
   $filters = cmf_filters($true);
-
   // general settings display (max rows & content kind)
   $form['general'] = array('#type' => 'fieldset',
     '#title' => t('General Settings'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
-  ); 
+    ); 
   $form['general']['max-rows'] = array(
     '#type' => 'textfield', 
     '#title' => t('Max rows'),
@@ -147,54 +119,64 @@
     '#default_value' => isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50,
     '#prefix' => '<div class="container-inline">',
     '#suffix' => '</div>',
-  );
+    );
   $form['general']['kind'] = array(
     '#type' => 'select', 
     '#title' => t('Content'),
     '#options' => array('node' => t('node'), 'comment' => t('comment'), 'both' => t('both')), 
-    '#default_value' => isset($_SESSION['cmf_content_kind']) ? $_SESSION['cmf_content_kind'] : 
-                        'node',
+    '#default_value' => isset($_SESSION['cmf_content_kind']) ? $_SESSION['cmf_content_kind'] : 'node',
     '#prefix' => '<div class="container-inline">',
-  );
+    );
   $form['general']['buttons']['apply'] = array(
     '#type' => 'submit', 
      '#value' => t('Apply'),
     '#suffix' => '</div>',
-  );
-
+    );
 
   $i = 0;
   $form['filters'] = array('#type' => 'fieldset',
     '#title' => t('Show only items where'),
     '#theme' => 'node_filters',
-  );
+    );
+
   foreach ($session as $filter) {
     list($type, $value) = $filter;
     if ($type == 'category') {
       // Load term name from DB rather than search and parse options array.
-      $value = module_invoke('taxonomy', 'get_term', $value);
+      $value = taxonomy_get_term($value);
       $value = $value->name;
     }
+    elseif ($type == 'title') {
+      // Just sanitize it and add quotes.
+      $value = "'". $value ."'";
+    }
     else {
       $value = $filters[$type]['options'][$value];
     }
-    // avoid not applicable filter verbose
-    if ($true && !($type == 'user' || $type == 'blocked' || $type == 'role')) {
-      $string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : 
-        '<strong>%a</strong> is <strong>%b</strong>');
-      $form['filters']['current'][] = array('#value' => t($string, 
-        array('%a' => $filters[$type]['title'] , '%b' => $value)));
+    // Avoid not applicable filter verbose. Note '%' does check_plain.
+    if ($type == 'title') {
+      if ($i++) {
+        $form['filters']['current'][] = array('#value' => t('<em>and</em> where <strong>%a</strong> contains <strong>%b</strong>', array('%a' => $filters[$type]['title'], '%b' => $value)));
+       }
+       else {
+        $form['filters']['current'][] = array('#value' => t('<strong>%a</strong> contains <strong>%b</strong>', array('%a' => $filters[$type]['title'], '%b' => $value)));
+      }
     }
     else {
-      $string = ($i++ ? '<em>and</em> where <strong>%a</strong> is <strong>%b</strong>' : 
-        '<strong>%a</strong> is <strong>%b</strong>');
-      $form['filters']['current'][] = array('#value' => t($string, 
-        array('%a' => $filters[$type]['title'] , '%b' => $value)));    
+      if ($i++) {
+        $form['filters']['current'][] = array('#value' => t('<em>and</em> where <strong>%a</strong> is <strong>%b</strong>', array('%a' => $filters[$type]['title'], '%b' => $value)));
+       }
+       else {
+        $form['filters']['current'][] = array('#value' => t('<strong>%a</strong> is <strong>%b</strong>', array('%a' => $filters[$type]['title'], '%b' => $value)));
+      }
     }
-    // those ifs remove the respective option if it is already being filtered on.
+    // These ifs remove the respective option if it is already being filtered on.
     if ($type == 'type') {
       unset($filters['type']);
     }
+    if ($type == 'title') {
+      unset($filters['title']);
+    }
     if ($type == 'user') {
       unset($filters['users']);
       unset($filters['user']);
@@ -206,47 +188,52 @@
       unset($filters['role']);
     }
   }
-
   // preparing select boxes
   foreach ($filters as $key => $filter) {
     $names[$key] = $filter['title'];
-
     switch ($key) {
       case 'user':
         $form['filters']['status'][$key] = array(
           '#type'     => 'select', 
           '#options'  => $filter['options'], 
 //          '#disabled' => TRUE,
-        );
+          );
         break;
-        
+
       case 'users':
         $form['filters']['status'][$key] = array(
           '#type'              => 'textfield', 
           '#autocomplete_path' => 'user/autocomplete', 
-          '#size'              => 20,
-        );
+          '#size'              => 37,
+          );
         break;
-        
+
+      case 'title':
+        $form['filters']['status'][$key] = array(
+          '#type' => 'textfield', 
+          '#size' => 37,
+          );
+        break;
+
       default: 
         $form['filters']['status'][$key] = array(
           '#type'    => 'select', 
           '#options' => $filter['options'],
-        );
+          );
     }
   }
-  // building radio buttons
+  // Building radio buttons.
   $keyz = array_keys($names);
   $form['filters']['filter'] = array(
     '#type'          => 'radios',
     '#options'       => $names,
     '#default_value' => $keyz[0],
-  );
-  // building buttons depending on the filter state
+    );
+  // Building buttons depending on the filter state.
   $form['filters']['buttons']['submit'] = array(
     '#type'  => 'submit', 
     '#value' => (count($session) ? t('Refine') : t('Filter')),
-  );
+    );
   if (count($session)) {
     $form['filters']['buttons']['undo'] = array(
       '#type'  => 'submit', 
@@ -257,11 +244,9 @@
       '#value' => t('Reset'),
     );
   }
-
   return $form;
 }
 
-
 /** 
  * Handle post-validation form submission.
  *
@@ -270,7 +255,7 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_filter_form_submit($form, &$form_state) {
   $filters = cmf_filters();
 /* TODO The 'op' element in the form values is deprecated.
@@ -282,44 +267,41 @@
   switch ($form_state['values']['op']) {
     case t('Filter'):
     case t('Refine'):
-    
       if (isset($form_state['values']['filter'])) {
         $filter = $form_state['values']['filter'];
-
-        // convert AJAX search value to select box value
+        // Convert AJAX search value to select box value.
         if ($filter == 'users') {
           $users = cmf_get_users('name');
-          
-          $uid = db_result(db_query('
-            SELECT uid
-            FROM {users}
-            WHERE name = "%s"',
-            $form_state['values']['users']
-          ));
-
+          $uid = db_result(db_query('SELECT uid FROM {users} WHERE name = "%s"', $form_state['values']['users']));
           $form_state['values']['user'] = $uid;
-          
           $filter = 'user';
         }
 
+        if ($filter == 'title') {
+          $string = $form_state['values']['title'];
+          $filters['title']['options'][$string] = $string;
+        }
+
         // Flatten the options array to accommodate hierarchical/nested options.
         $flat_options = form_options_flatten($filters[$filter]['options']);
-
-        if (isset($flat_options[$form_state['values'][$filter]])) {
+        if (isset($flat_options[$form_state['values'][$filter]]) || $filter == 'title') {
           $_SESSION['cmf_overview_filter'][] = array($filter, $form_state['values'][$filter]);
         }
       }
       break;
+
     case t('Undo'):
       array_pop($_SESSION['cmf_overview_filter']);
       break;
+
     case t('Reset'):
       $_SESSION['cmf_overview_filter'] = array();
       break;
+
     case t('Apply'):
       $_SESSION['cmf_max_rows'] = $form_state['values']['max-rows'];
       $_SESSION['cmf_content_kind'] = $form_state['values']['kind'];
-      
+
       if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
         $form_state['redirect'] = 'user/'. arg(1) .'/cmf';
       }
@@ -347,7 +329,6 @@
   return $output;
 }
 
-
 /**
  * List node administration filters that can be applied.
  *
@@ -355,17 +336,26 @@
  * @return array with filter properties
  */
 function cmf_filters($true = NULL) {
-  // Regular filters
-  $filters['status'] = array('title' => t('node status'),
-    'options' => array('status-1'   => t('published'),     'status-0' => t('not published'),
-                       'promote-1'  => t('promoted'),      'promote-0' => t('not promoted'),
-                       'sticky-1'   => t('sticky'),        'sticky-0' => t('not sticky')));
+  // Regular filters.
+  $filters['status'] = array(
+    'title' => t('node status'),
+    'options' => array(
+      'status-1' => t('published'),
+      'status-0' => t('not published'),
+      'promote-1' => t('promoted'),
+      'promote-0' => t('not promoted'),
+      'sticky-1'   => t('sticky'),
+      'sticky-0' => t('not sticky'),
+      ),
+    );
   $filters['type'] = array('title' => t('node type'), 'options' => node_get_types('names'));
-  // The taxonomy filter
+  // The taxonomy filter.
   if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) {
     $filters['category'] = array('title' => t('category'), 'options' => $taxonomy);
   }
-  // cmf filters
+  // Cmf filters.
+  $filters['title'] = array('title' => t('title/subject'));
+  // Don't show these on the user page.
   if (!$true) {
     $filters['user'] = array('title' => t('user list'), 'options' => cmf_get_users('names'));
     $filters['users'] = array('title' => t('user name'));
@@ -376,19 +366,16 @@
   return $filters;
 }
 
-
-/**********************
-*  QUERIES            *
-**********************/
-
+/**
+ *  QUERIES
+ */
 /** 
  * Build the variable parts of the query to be performed regarding the filter status.
  *
- * @return associative array with WHERE JOIN qury parts and respective arguments
- */ 
+ * @return associative array with WHERE JOIN query parts and respective arguments
+ */
 function cmf_build_filter_query() {
   $filters = cmf_filters();
-
   // Build query
   $where = $args = array();
   $join = '';
@@ -400,24 +387,34 @@
         list($key, $value) = explode('-', $value, 2);
         $where[] = 'n.'. $key .' = %d';
         break;
+
       case 'category':
         $table = "tn$index";
         $where[] = "$table.tid = %d";
         $join .= "INNER JOIN {term_node} $table ON n.nid = $table.nid ";
         break;
+
       case 'type':
         $where[] = "n.type = '%s'";
         break;
+
       case 'user':
         $where[] = "u.uid = %d"; 
         break;
+
       case 'role':
         $where[] = "u.uid = ur.uid AND ur.rid = %d"; 
         $join .= "INNER JOIN {users_roles} ur ON u.uid = ur.uid ";
         break;
+
+      case 'title':
+        $where[] = "n.title LIKE ('%%%s%%')"; 
+        break;
+
       case 'users':
         $where[] = "u.name = '%s'"; 
         break;
+
       case 'blocked':
         $where[] = "u.status = %d AND u.uid != 0";
         break;
@@ -425,20 +422,16 @@
     $args[] = $value;
   }
   $where = count($where) ? 'WHERE '. implode(' AND ', $where) : '';
-
   return array('where' => $where, 'join' => $join, 'args' => $args);
 }
 
-
 /** 
  * Build the header of the result table.
  *
  * @return array respecting tablesort_sql()
- */ 
+ */
 function cmf_build_header() {
-
   $header = array();
-
   if (user_access('filter and manage site content')) {
     $header[] = theme('table_select_header_cell');
   }
@@ -454,6 +447,7 @@
       $header[] = array('data' => t('Status'), 'field' => 'status');
       $header[] = array('data' => t('Time'), 'field' => 'created', 'sort' => 'desc');
       break;
+
     case 'comment':
       $header[] = array('data' => t('Subject'), 'field' => 'subject');
       $header[] = array('data' => t('Kind'));
@@ -464,6 +458,7 @@
       $header[] = array('data' => t('Status'), 'field' => 'status');
       $header[] = array('data' => t('Time'), 'field' => 'created', 'sort' => 'desc');
       break;
+
     case 'both':
       $header[] = array('data' => t('Title') .'/'. t('Subject'), 'field' => 'title');
       $header[] = array('data' => t('Kind'));
@@ -482,105 +477,101 @@
   return $header;
 }
 
-
 /** 
  * Permform adjusted query.
  *
  * @param array respecting tablesort_sql()
  * @return result of permormed query
- */ 
+ */
 function cmf_perform_query($header, $kind = NULL) {
-
   $filter = cmf_build_filter_query();  
-
   if (is_null($kind)) {
     $kind = $_SESSION['cmf_content_kind'];
   }
-  
+
   if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
     $filter['where'] .= ' AND u.uid = '. arg(1);
   }
 
   switch ($kind) {
     case 'node':
-      return pager_query('
-        SELECT n.nid, n.title, n.type, u.name AS username, u.uid, n.status, n.created, n.changed
-        FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '. $filter['join'] . 
-        $filter['where'] . 
-        tablesort_sql($header), 
+      return pager_query('SELECT n.nid, n.title, n.type, u.name AS username, u.uid, n.status, n.created, n.changed
+        FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '
+        . $filter['join']
+        . $filter['where']
+        . tablesort_sql($header), 
         isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, NULL, $filter['args']
       );
       break;
+
     case 'comment':
-      return pager_query('
-        SELECT c.cid, c.subject, c.nid, c.comment, c.timestamp AS created, c.status, c.name, 
+      return pager_query('SELECT c.cid, c.subject, c.nid, c.comment, c.timestamp AS created, c.status, c.name, 
           c.homepage, u.name AS username, u.uid, n.type
-        FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid 
-          '. $filter['join'] . 
-        $filter['where'] . 
-        tablesort_sql($header), 
+        FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid '
+        . $filter['join']
+        . $filter['where']
+        . tablesort_sql($header), 
         isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, NULL, $filter['args']
       );
       break;
+
     case 'both':
       $args = array_merge($filter['args'], $filter['args']);
-      return pager_query('
-        SELECT 0 AS cid, n.nid, n.title, NULL AS comment, n.type, u.name AS username, u.uid, 
-          n.status, n.created, n.changed
-        FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '. $filter['join'] . 
-        $filter['where'] .' 
-        UNION
-        SELECT c.cid, c.nid, c.subject AS title, c.comment, n.type, u.name AS username, u.uid, 
+      $where = $filter['where'];
+      $cwhere = str_replace(array('n.title', 'n.uid'), array('c.subject', 'c.uid'), $where);
+      $count_query = 'SELECT ('
+        .'SELECT COUNT(*) FROM {node} n'
+        .' INNER JOIN {users} u ON n.uid = u.uid '
+        . $filter['join']
+        .' '. $where
+        .') + ('
+        .'SELECT COUNT(*) FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid '
+        .' INNER JOIN {users} u ON u.uid = c.uid '
+        . $filter['join']
+        .' '. $cwhere
+        .') AS count';
+      return pager_query('SELECT 0 AS cid, n.nid, n.title, NULL AS comment, n.type, u.name AS username,
+        u.uid, n.status, n.created, n.changed
+        FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '
+        . $filter['join'] 
+        .' '. $where
+        .' UNION SELECT c.cid, c.nid, c.subject AS title, c.comment, n.type, u.name AS username, u.uid, 
           c.status, c.timestamp AS created, 0 AS changed
-        FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid 
-          '. $filter['join'] .
-        $filter['where'] . 
-        tablesort_sql($header), 
-        isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, NULL, $args
+        FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid '
+        . $filter['join']
+        .' '. $cwhere
+        . tablesort_sql($header), 
+        isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, $count_query, $args
       );
       break;
   }
 }
 
-
-/**********************
-*  RESULTS            *
-**********************/
-
+/**
+ *  RESULTS
+ */
 module_load_include('inc', 'cmf', '/node');
-
 module_load_include('inc', 'cmf', '/comment');
-
 module_load_include('inc', 'cmf', '/both');
 
-
-/**********************
-*  AUX                *
-**********************/
-
+/*
+ *  AUX
+ */
 /**
- * Builds a list of available users
+ * Builds a list of available users.
  *
  * @param the format in which to return the list
  * @return array of all available users
  */
 function cmf_get_users($op) {
-
   switch ($op) {
     case 'names':
-      $result = db_query('
-        SELECT uid, name
-        FROM {users}
-        WHERE uid != 0
-        ORDER BY name'
-      );
-
+      $result = db_query('SELECT uid, name FROM {users} WHERE uid <> 0 ORDER BY name');
       break;
   }
   
   $users    = array();
-  $users[0] = variable_get('anonymous', NULL);
-
+  $users[0] = variable_get('anonymous', t('anonymous'));
   while ($user = db_fetch_object($result)) {
     $users[$user->uid] = $user->name;
   }
@@ -588,7 +579,6 @@
   return $users;
 }
 
-
 /**
  * Builds a list of available roles
  *
@@ -596,20 +586,12 @@
  * @return array of all available roles
  */
 function cmf_get_roles($op) {
-
   switch ($op) {
     case 'names':
-      $result = db_query('
-        SELECT *
-        FROM {role}
-        ORDER BY name'
-      );
-
+      $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
       break;
   }
-
   $roles = array();
-
   while ($role = db_fetch_object($result)) {
     $roles[$role->rid] = $role->name;
   }
@@ -617,7 +599,6 @@
   return $roles;
 }
 
-
 /**
  * Get the html code of an image
  *
@@ -625,20 +606,16 @@
  * @return html tag img
  */
 function _cmf_get_img($action, $title) {
-
   $path =  base_path() . drupal_get_path('module', 'cmf') .'/images/'. $action .'.png';
-
   if ($title == NULL) {
     $html = '<img src="'. $path .'" alt="untitled image" />';
   }
   else {
     $html = '<img src="'. $path .'" title="'. $title .'" alt="'. $title .'" />';
   }
-
   return $html;
 }
 
-
 /** 
  * Theme (node) type cell on table result.
  *
@@ -646,24 +623,16 @@
  *
  * @param 0 or node type key
  * @return formated (node) type
- */ 
+ */
 function theme_cmf_type($type) { 
-
-  return db_result(db_query('
-    SELECT name
-    FROM {node_type}
-    WHERE type = "%s"',
-    $type
-  ));
-
+  return db_result(db_query('SELECT name FROM {node_type} WHERE type = "%s"', $type));
 } 
 
-
 /** 
  * Implementation of hook_theme().
  *
  * @ingroup themable
- */ 
+ */
 function cmf_theme() { 
   return array(
     'cmf_filter_form' => array(
@@ -693,7 +662,6 @@
   );
 }
 
-
 /** 
  * Theme user cell on table result.
  *
@@ -701,26 +669,21 @@
  *
  * @param user ID
  * @return clickable username with status
- */ 
+ */
 function theme_cmf_user($uid) { 
-
   if ($uid == 0) {
-    return variable_get('anonymous', NULL);
+    return variable_get('anonymous', t('anonymous'));
   }
-
   $result = db_query('
     SELECT name, status
     FROM {users}
     WHERE uid = %d',
     $uid
   );
-
   $user = db_fetch_array($result);
-
   $url_alias = _cmf_get_user_path($uid);
   
   $url = $url_alias ? $url_alias : 'user/'. $uid;
-
   if ($user['status']) {
     $output .= l($user['name'], $url, array());
   }
@@ -728,11 +691,9 @@
     $output .= l(_cmf_get_img('blocked', t('blocked')) .' '. $user['name'], $url, array(),
       NULL, NULL, FALSE, TRUE);  
   }
-
   return $output; 
 } 
 
-
 /** 
  * Get the alias path to a user profile
  *
@@ -740,7 +701,6 @@
  * @return the relative URL of the user profile
  */
 function _cmf_get_user_path($uid) {
-
   return db_result(db_query("
     SELECT dst
     FROM {url_alias}
@@ -749,7 +709,6 @@
   ));
 }
 
-
 /** 
  * Check user permissions to see menu itme under example.com/user/UID/cmf
  *
@@ -761,7 +720,6 @@
   return (user_access($manage_access) || user_access($view_access));
 }
 
-
 /** 
  * Get the term for a forum node
  *
@@ -769,15 +727,11 @@
  * @return the name and forum description
  */
 function _cmf_get_forum($nid) {
-
-	$node = node_load($nid);
-
+  $path = array();
+  $node = node_load($nid);
   $parents = taxonomy_get_parents_all($node->tid);
-
-	foreach ($parents as $parent) {
+  foreach ($parents as $parent) {
     $path[] = $parent->name;
-	}
-
-	return implode(' > ', array_reverse($path));
-
-}
\ No newline at end of file
+  }
+  return implode(' > ', array_reverse($path));
+}
Index: comment.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/comment.inc,v
retrieving revision 1.2.2.5
diff -u -r1.2.2.5 comment.inc
--- comment.inc	12 Mar 2009 16:59:07 -0000	1.2.2.5
+++ comment.inc	14 Jul 2009 23:41:03 -0000
@@ -13,7 +13,6 @@
  * @warning For more information on licensing, read the LICENCE.txt file.
  */
 
-
 /**
  * Defines the form for comments administration filter results.
  *
@@ -24,15 +23,16 @@
  * @return array with forms properties 
  */
 function cmf_admin_comments_form() {
-
   $destination = drupal_get_destination();
 
-  // build an 'Update options' form
+  // Build an 'Update options' form.
   if (user_access('filter and manage site content')) {
     $form['options'] = array(
-      '#type' => 'fieldset', '#title' => t('Update options'),
-      '#prefix' => '<div class="container-inline">', '#suffix' => '</div>'
-    );
+      '#type' => 'fieldset',
+      '#title' => t('Update options'),
+      '#prefix' => '<div class="container-inline">',
+      '#suffix' => '</div>',
+      );
     $options = array();
     foreach (comment_operations() as $key => $value) {
       $options[$key] = $value[0];
@@ -41,18 +41,18 @@
       '#type' => 'select', 
       '#options' => $options, 
       '#default_value' => 'publish',
-    );
+      );
     $form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
   }
-  
-    // load the comments that we want to display
+
+    // Load the comments that we want to display.
     $form['header'] = array(
       '#type'  => 'value', 
       '#value' => cmf_build_header(),
     );
 
   $result = cmf_perform_query($form['header']['#value']);
-  // build a table listing the appropriate comments
+  // Build a table listing the appropriate comments.
   while ($comment = db_fetch_object($result)) {
     $comments[$comment->cid] = '';
     $form['title'][$comment->cid] = array('#value' => l($comment->subject, 'node/'. $comment->nid, 
@@ -70,10 +70,10 @@
     $form['created'][$comment->cid] = array('#value' => format_date($comment->created, 'small'));
     if (user_access('filter and manage site content')) {
       $form['operations'][$comment->cid] = array('#value' => l(_cmf_get_img('edit', t('edit')) .' '. 
-        t('edit'), 'comment/edit/'. $comment->cid, array('html' => TRUE)));
+        t('edit'), 'comment/edit/'. $comment->cid, array('query' => $destination, 'html' => TRUE)));
     }
   }
-  
+
   if (user_access('filter and manage site content')) {
     $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments);
   }
@@ -82,7 +82,6 @@
   return $form;
 }
 
-
 /** 
  * Form validation before submit. \n
  * We can't execute any 'Update options' if no comments were selected.
@@ -93,7 +92,7 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_comments_form_validate($form, &$form_state) {
   $form_state['values']['comments'] = array_diff($form_state['values']['comments'], array(0));
   if (count($form_state['values']['comments']) == 0) {
@@ -102,7 +101,6 @@
   }
 }
 
-
 /** 
  * Handle post-validation form submission. \n
  * Execute the chosen 'Update option' on the selected comments, such as
@@ -114,15 +112,15 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_comments_form_submit($form, &$form_state) {
   $operations = comment_operations();
   if ($operations[$form_state['values']['operation']][1]) {
-    // extract the appropriate database query operation
+    // Extract the appropriate database query operation.
     $query = $operations[$form_state['values']['operation']][1];
     foreach ($form_state['values']['comments'] as $cid => $value) {
       if ($value) {
-        // perform the update action, then refresh node statistics
+        // Perform the update action, then refresh node statistics.
         db_query($query, $cid);
         $comment = _comment_load($cid);
         _comment_update_node_statistics($comment->nid);
@@ -142,14 +140,13 @@
   }
 }
 
-
 /** 
  * Theme results table.
  *
  * @ingroup themable
  *
  * @return table with filter results
- */ 
+ */
 function theme_cmf_admin_comments_form($form) {
   $output = drupal_render($form['options']);
   if (isset($form['title']) && is_array($form['title'])) {
Index: node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/node.inc,v
retrieving revision 1.2.2.5
diff -u -r1.2.2.5 node.inc
--- node.inc	12 Mar 2009 16:59:07 -0000	1.2.2.5
+++ node.inc	14 Jul 2009 23:37:15 -0000
@@ -13,7 +13,6 @@
  * @warning For more information on licensing, read the LICENCE.txt file.
  */
 
-
 /**
  * Defines the form for nodes administration filter results.
  *
@@ -24,7 +23,6 @@
  * @return array with forms properties 
  */
 function cmf_admin_nodes_form() {
-
   $destination = drupal_get_destination();
 
   // build an 'Update options' form
@@ -50,14 +48,14 @@
     '#type'  => 'value', 
     '#value' => cmf_build_header(),
   );
-  
+
   $result = cmf_perform_query($form['header']['#value']);
   // build a table listing the appropriate nodes
   while ($node = db_fetch_object($result)) {
     $nodes[$node->nid] = '';
     $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid,
       array('attributes' => array('title' => truncate_utf8($node->body, drupal_strlen($node->body))),
-      'fragment' => 'node-'. $node->nid)) .' '.theme('mark', node_mark($node->nid, $node->changed)));
+      'fragment' => 'node-'. $node->nid)) .' '. theme('mark', node_mark($node->nid, $node->changed)));
     $form['kind'][$node->nid] = array('#value' => _cmf_get_img('node', t('node')));
     $form['type'][$node->nid] = $node->type == 'forum' ? array('#value' => '<p title="'. 
       _cmf_get_forum($node->nid) .'">'. check_plain(node_get_types('name', $node)) .'</p>') : 
@@ -70,7 +68,7 @@
     $form['created'][$node->nid] = array('#value' => format_date($node->created, 'small'));
     if (user_access('filter and manage site content')) {
       $form['operations'][$node->nid] = array('#value' => l(_cmf_get_img('edit', t('edit')) .' '. 
-        t('edit'), 'node/'. $node->nid .'/edit', array('html' => TRUE)));
+        t('edit'), 'node/'. $node->nid .'/edit', array('query' => $destination, 'html' => TRUE)));
     }
   }
 
@@ -78,11 +76,10 @@
     $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
   }
   $form['pager'] = array('#value' => theme('pager', NULL, $_SESSION['cmf_max_rows'], 0));
-  
+
   return $form;
 }
 
-
 /** 
  * Form validation before submit. \n
  * We can't execute any 'Update options' if no nodes were selected.
@@ -93,7 +90,7 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_nodes_form_validate($form, &$form_state) {
   $nodes = array_filter($form_state['values']['nodes']);
   if (count($nodes) == 0) {
@@ -101,7 +98,6 @@
   }
 }
 
-
 /** 
  * Handle post-validation form submission. \n
  * Execute the chosen 'Update option' on the selected nodes, such as
@@ -113,7 +109,7 @@
  *
  * @param the ID of the passed form
  * @param array with the form properties values
- */ 
+ */
 function cmf_admin_nodes_form_submit($form, &$form_state) {
   $operations = module_invoke_all('node_operations');
   $operation = $operations[$form_state['values']['operation']];
@@ -141,14 +137,13 @@
   }
 }
 
-
 /** 
  * Theme results table.
  *
  * @ingroup themable
  *
  * @return table with filter results
- */ 
+ */
 function theme_cmf_admin_nodes_form($form) {
   $output = drupal_render($form['options']);
   if (isset($form['title']) && is_array($form['title'])) {
@@ -183,4 +178,4 @@
   $output .= drupal_render($form);
 
   return $output;
-}
\ No newline at end of file
+}

