? .DS_Store
? flag_content.patch
Index: flag_content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_content/flag_content.install,v
retrieving revision 1.2
diff -u -r1.2 flag_content.install
--- flag_content.install	11 Oct 2006 10:51:46 -0000	1.2
+++ flag_content.install	26 Nov 2006 06:44:13 -0000
@@ -5,19 +5,19 @@
     case 'mysql':
     case 'mysqli':
       $result = db_query("
-        CREATE TABLE flag_content  (
+        CREATE TABLE {flag_content}  (
           nid       INT NOT NULL,
-          timestamp INT,
-          PRIMARY KEY (nid)
+          uid       INT NOT NULL,
+          timestamp INT
           ) /*!40100 DEFAULT CHARACTER SET utf8 */;
         ");
       break;
     case 'pgsql':
       $result = db_query("
-        CREATE TABLE flag_content (
+        CREATE TABLE {flag_content} (
           nid INTEGER PRIMARY KEY,
-          timestamp INTEGER
-          )
+          uid INTEGTER NOT NULL,
+          timestamp INTEGER )
         ");
       break;
   }
@@ -29,3 +29,29 @@
     drupal_set_message(t("flag_content module database table creation failure. Please view the flag_content module folder and read the README.txt"), 'error');    
   }
 }
+
+function flag_content_update_1() {
+  $result = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      if (!db_table_exists('flag_content')) {
+        $result[] = db_query("RENAME TABLE flag_content TO {flag_content}");
+      }
+      $result[] = db_query("ALTER TABLE {flag_content} ADD uid INTEGER NOT NULL");
+      $result[] = db_query("DROP INDEX nid ON {flag_content}");
+      $result[] = db_query("CREATE UNIQUE INDEX nid_uid ON {flag_content} (nid, uid)");
+      break;
+    case 'pgsql':
+      if (!db_table_exists('flag_content')) {
+        $result[] = db_query("ALTER TABLE flag_content RENAME to {flag_content}");
+      }
+      db_add_column($result, 'flag_content', 'uid', 'INT', $attributes = array('NOT NULL' => TRUE, 'default' => 0));
+      break;
+  }
+  return $result;
+}
+
+function flag_content_uninstall() {
+  db_query("DROP TABLE {flag_content};");
+}
\ No newline at end of file
Index: flag_content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_content/flag_content.module,v
retrieving revision 1.4
diff -u -r1.4 flag_content.module
--- flag_content.module	10 Oct 2006 23:43:28 -0000	1.4
+++ flag_content.module	26 Nov 2006 06:44:13 -0000
@@ -1,17 +1,10 @@
 <?php
 // $Id: flag_content.module,v 1.4 2006/10/10 23:43:28 kbahey Exp $
-define('FLAG_CONTENT_NODE_TYPE',   'flag_content_node_type_');
-define('FLAG_CONTENT_PERM_ADD',    'flag content');
-define('FLAG_CONTENT_PERM_MANAGE', 'manage flagged list');
-define('FLAG_CONTENT_EMAIL',       'flag_content_email');
-
-function flag_content_help($section) {
-  switch ($section) {
-    case 'admin/help#flag_content':
-    case 'admin/modules#description':
-      return t('Allow users to flag content for the attention of the administrator.');
-  }
-}
+define('FLAG_CONTENT_NODE_TYPE',        'flag_content_node_type_');
+define('FLAG_CONTENT_PERM_ADD',         'flag content');
+define('FLAG_CONTENT_PERM_MANAGE',      'manage flagged list');
+define('FLAG_CONTENT_EMAIL',            'flag_content_email');
+define('FLAG_CONTENT_EMAIL_THRESHOLD',  'flag_content_email_threshold');
 
 function flag_content_perm() {
   return array(FLAG_CONTENT_PERM_ADD, FLAG_CONTENT_PERM_MANAGE);
@@ -35,9 +28,30 @@
     );
 
     $items[] = array(
-      'path'     => 'flag_content/view',
+      'path'     => 'admin/content/flagged',
+      'callback' => 'flag_content_view',
+      'title'    => t('Flagged content'),
+      'description'  => t("A listing of content flagged as offensive by your site's users."),
+      'access'   => user_access(FLAG_CONTENT_PERM_MANAGE),
+    );
+
+    $items[] = array(
+      'path'     => 'admin/content/flagged/view',
       'callback' => 'flag_content_view',
-      'title'    => t('flagged items'),
+      'type'     => MENU_DEFAULT_LOCAL_TASK,
+      'title'    => t('View'),
+      'description'  => t("A listing of content flagged as offensive by your site's users."),
+      'access'   => user_access(FLAG_CONTENT_PERM_MANAGE),
+      'weight'   => -10,
+    );
+
+    $items[] = array(
+      'path'     => 'admin/content/flagged/settings',
+      'title'    => t('Settings'),
+      'description' => t('Allow users to flag content for the attention of the administrator.'),
+      'type'     => MENU_LOCAL_TASK,
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'flag_content_settings',
       'access'   => user_access(FLAG_CONTENT_PERM_MANAGE),
     );
   }
@@ -52,7 +66,7 @@
     '#title' => t('Enable flagging for these content types'),
   );
 
-  foreach(node_get_types() as $type => $name) {
+  foreach(node_get_types('names') as $type => $name) {
     $form[$set][FLAG_CONTENT_NODE_TYPE . $type] = array(
       '#type' => 'checkbox',
       '#title' => $name,
@@ -67,6 +81,14 @@
     '#title' => t('Advanced options'),
   );
 
+  $form[$set][FLAG_CONTENT_EMAIL_THRESHOLD] = array(
+    '#type' => 'select',
+    '#title' => t('Email threshold'),
+    '#options' => array(1 => 1, 10 => 10, 25 => 25, 50 => 50, 100 => 100),
+    '#default_value' => variable_get(FLAG_CONTENT_EMAIL_THRESHOLD, 25),
+    '#description' => t('The number of times content must be flagged as offensive before administrators are emailed.'),
+  );
+
   $form[$set][FLAG_CONTENT_EMAIL] = array(
     '#type' => 'textfield',
     '#title' => t('Email address'),
@@ -77,7 +99,7 @@
     '#description' => t('Email address to send alerts on flagged items to.'),
   );
 
-  return $form;
+  return system_settings_form($form);
 }
 
 function flag_content_link($type, $node = null, $teaser = false) {
@@ -88,18 +110,27 @@
     if (variable_get(FLAG_CONTENT_NODE_TYPE . $node->type, 0)) {
       if ($user->uid) {
         if (user_access(FLAG_CONTENT_PERM_ADD)) {
-          if (!_flag_content_check($node->nid)) {
+          $flag_count = user_access(FLAG_CONTENT_PERM_MANAGE) ? _flag_content_check($node->nid) : _flag_content_check($node->nid, $user->uid);
+          if (!$flag_count) {
             // Not already flagged, flag it for admin
-            $links[] = l(t('flag as offensive'), "flag_content/add/$node->nid");
+            $links['unflag_content'] = array(
+              'title' => t('Flag as offensive'),
+              'href' => "flag_content/add/$node->nid",
+            );
           }
           else {
             // If has admin privileges, show an unflag link
             if (user_access(FLAG_CONTENT_PERM_MANAGE)) {
-              $links[] = l(t('unflag'), "flag_content/unflag/$node->nid");
+              $links['flagged_content'] = array(
+                'title' => t('Flagged !count times', array('!count' => $flag_count)),
+              );
             }
             else {
               // Otherwise just show it as flagged
-              $links[] = t('flagged as offensive');
+              $links['unflag_content'] = array(
+                'title' => t('Unflag'),
+                'href' => "flag_content/unflag/$node->nid",
+              );
             }
           }
         }
@@ -109,28 +140,33 @@
   return $links;
 }
 
-function flag_content_add() {
-  $nid = (int)arg(2);
-  if ($nid) {
+function flag_content_add($nid) {
+  global $user;
+  if (is_numeric($nid)) {
     // Insert the data into the table
-    db_query("INSERT INTO {flag_content} (nid, timestamp) VALUES (%d, %d)", $nid, time());
+    db_query("INSERT INTO {flag_content} (nid, uid, timestamp) VALUES (%d, %d, %d)", $nid, $user->uid, time());
     // Prepare the data
     $node = node_load($nid);
+
     // Email the admin
-    theme('flag_content_mail', $node);
+    if (_flag_content_check($nid) >= variable_get(FLAG_CONTENT_EMAIL_THRESHOLD, 25)) {
+      theme('flag_content_mail', $node);
+    }
+
     // Give feedback to the user
     drupal_set_message(t('The item was flagged for the administrator'));
   }
   drupal_goto("node/$nid");
 }  
 
-function flag_content_unflag() {
+function flag_content_unflag($all = FALSE) {
+  global $user;
   $nid = (int)arg(2);
   if ($nid) {
-    _flag_content_unflag($nid);
+    _flag_content_unflag($nid, $user->uid);
     drupal_set_message(t('The item was unflagged.'));
   }
-  drupal_goto('flag_content/view');
+  drupal_goto('admin/content/flagged');
 }
 
 function flag_content_view() {
@@ -139,22 +175,35 @@
 
 function theme_flag_content_view($list = array()) {
   $rows = array();
-  $header = array(t('Title'), t('Author'), t('Date'), t('Operations'));
+  $header = array(t('Title'), t('Author'), t('Complaints'), t('Date'), t('Operations'));
   if (count($list)) {
     foreach($list as $nid => $data) {
       $title = l($data['title'], "node/$nid");
       $author = $data['author'];
+      $count = $data['count'];
       $user = theme('username', $data['author']);
       $timestamp = format_date($data['timestamp'], 'custom', 'Y-m-d H:i');
-      $ops = l(t('edit'),   "node/$nid/edit");
-      $ops .= ' ' . l(t('unflag'), "flag_content/unflag/$nid");
-      $ops .= ' ' . l(t('delete'), "node/$nid/delete");
+      $ops = array(
+        array(
+          'title' => t('Edit'),
+          'href'  => "node/$nid/edit",
+        ),
+        array(
+          'title' => t('Unflag'),
+          'href'  => "flag_content/unflag/$nid",
+        ),
+        array(
+          'title' => t('Delete'),
+          'href'  => "node/$nid/delete",
+        ),
+      );
 
       $rows[] = array('data' => array_merge(
         array($title),
         array($user),
+        array($count),
         array($timestamp),
-        array($ops)));
+        array(theme('links', $ops))));
     }
   }
   else {
@@ -172,19 +221,26 @@
   }
 }
 
-function _flag_content_unflag($nid) {
-  db_query("DELETE FROM {flag_content} WHERE nid = %d", $nid);
+function _flag_content_unflag($nid, $uid = NULL) {
+  if (isset($uid)) {
+    db_query("DELETE FROM {flag_content} WHERE nid = %d AND uid = %d", $nid, $uid);
+  }
+  else {
+    db_query("DELETE FROM {flag_content} WHERE nid = %d", $nid);
+  }
 }
 
-function _flag_content_get() {
+function _flag_content_get($uid = NULL) {
   $rows = array();
-  $sql = "SELECT n.nid, n.title, n.uid, f.timestamp
+  $sql = "SELECT n.nid, MAX(n.title) as title, MAX(n.uid) as uid, COUNT(f.nid) as flag_count, MAX(f.timestamp) as timestamp
     FROM {node} n INNER JOIN {flag_content} f USING(nid)
-    ORDER by f.timestamp ASC";
+    GROUP BY n.nid 
+    ORDER by flag_count DESC";
   $result = db_query($sql);
   while ($data = db_fetch_object($result)) {
     $rows[$data->nid] = array(
       'title' => $data->title,
+      'count' => $data->flag_count,
       'author' => user_load(array('uid' => $data->uid)),
       'timestamp' => $data->timestamp,
       );
@@ -192,9 +248,14 @@
   return $rows;
 }
 
-function _flag_content_check($nid) {
-  $sql = "SELECT COUNT(*) FROM {flag_content} WHERE nid = %d";
-  return db_result(db_query($sql, $nid));
+function _flag_content_check($nid, $uid = NULL) {
+  if (isset($uid)) {
+    $sql = "SELECT COUNT(*) FROM {flag_content} WHERE nid = %d AND uid = %d";
+  }
+  else {
+    $sql = "SELECT COUNT(*) FROM {flag_content} WHERE nid = %d";
+  }
+  return db_result(db_query($sql, $nid, $uid));
 }
 
 function theme_flag_content_mail($node) {
@@ -216,11 +277,11 @@
     ));
 
   $body .= t("\n\nManage the flagged items list at %manage",
-    array('%manage' => $base_url . url("/flag_content/view")));
+    array('%manage' => $base_url . url("/admin/content/flagged")));
 
   // Send the e-mail to the recipients:
   $headers = "From: $user->name <$from>\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
-  user_mail($to, $subject, $body, $headers);
+  drupal_mail('flag_content_notify', $to, $subject, $body, $headers);
 
   // Log the operation:
   watchdog('mail', t("%name flagged item $node->nid for review.",
