Index: flag_content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_content/flag_content.install,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 flag_content.install
--- flag_content.install	7 Jan 2007 19:03:00 -0000	1.1.2.2
+++ flag_content.install	28 Mar 2007 18:50:27 -0000
@@ -21,11 +21,28 @@ function flag_content_install() {
         ");
       break;
   }
-  
+
   if ($result) {
-    drupal_set_message(t("flag_content module database tables created successfully."));  
+    drupal_set_message(t("flag_content module database tables created successfully."));
   }
   else {
-    drupal_set_message(t("flag_content module database table creation failure. Please view the flag_content module folder and read the README.txt"), 'error');    
+    drupal_set_message(t("flag_content module database table creation failure. Please view the flag_content module folder and read the README.txt"), 'error');
   }
 }
+
+/**
+ *  Add ability to flag anything.
+ *  Date: 03-28-07
+ */
+function flag_content_update_1() {
+  $ret = array();
+  
+  $ret[] = update_sql("ALTER TABLE {flag_content} CHANGE nid eid INT( 11 ) NOT NULL");
+  $ret[] = update_sql("ALTER TABLE {flag_content} ADD type VARCHAR( 25 ) NOT NULL AFTER eid");
+  $ret[] = update_sql("ALTER TABLE {flag_content} ADD fid INT( 11 ) NOT NULL FIRST");
+  $ret[] = update_sql("ALTER TABLE {flag_content} DROP PRIMARY KEY");
+  $ret[] = update_sql("ALTER TABLE {flag_content} ADD PRIMARY KEY ( fid )");
+  $ret[] = update_sql("ALTER TABLE {flag_content} ADD INDEX ( eid , type , timestamp )");
+  
+  return $ret;
+}
Index: flag_content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_content/flag_content.module,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 flag_content.module
--- flag_content.module	19 Feb 2007 03:30:46 -0000	1.1.2.6
+++ flag_content.module	28 Mar 2007 18:50:27 -0000
@@ -8,6 +8,7 @@ define('FLAG_CONTENT_PERM_ADD',    'flag
 define('FLAG_CONTENT_PERM_MANAGE', 'manage flagged list');
 define('FLAG_CONTENT_EMAIL',       'flag_content_email');
 define('FLAG_CONTENT_ADD_REL',     'flag_content_add_rel');
+define('FLAG_CONTENT_USER',     'flag_content_user');
 
 function flag_content_help($section) {
   switch ($section) {
@@ -64,6 +65,17 @@ function flag_content_settings() {
       '#default_value' => variable_get(FLAG_CONTENT_NODE_TYPE . $type, 0),
     );
   }
+  $set = 'user';
+  $form[$set] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Enable flagging on users'),
+  );
+  $form[$set][FLAG_CONTENT_USER] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Flag users'),
+    '#return_value' => 1,
+    '#default_value' => variable_get(FLAG_CONTENT_USER, 0),
+  );
 
   $set = 'advanced';
   $form[$set] = array(
@@ -92,83 +104,179 @@ function flag_content_settings() {
   return $form;
 }
 
-function flag_content_link($type, $node = null, $teaser = false) {
+/**
+ *  Implementation of hook_user().
+ */
+function flag_content_user($op, &$edit, &$account, $category = NULL) {
+  switch ($op) {
+    case 'view':
+      $fields = array();
+      $links = flag_content_link('user', $account);
+      foreach ($links as $link) {
+        $fields[t('Flag user')][] = array(
+          'title' => t(''),
+          'class' => 'flag_content_user',
+          'value' => $link
+        );
+      }
+      return $fields;
+  }
+}
+
+/**
+ *  Implementation of hook_comment().
+ */
+function flag_content_comment($a1, $op) {
+  switch ($op) {
+    case 'view':
+      // TODO: ...
+      // $links = flag_content_link('comment', $a1); 
+      break;
+  }
+}
+
+/**
+ *  Implementation of hook_link().
+ *  $entry is actually $node but since this is supporting both users and nodes, we call it $entry (eventually support comments?)
+ */
+function flag_content_link($type, $entry = null, $teaser = false) {
   global $user;
   $links = array();
-  //if ($type == 'node' && !$teaser) {
-  if ($type == 'node') {
-    if (variable_get(FLAG_CONTENT_NODE_TYPE . $node->type, 0)) {
-      if ($user->uid) {
-        if (user_access(FLAG_CONTENT_PERM_ADD)) {
-          $options = array('class' => 'flag_content');
-          if (variable_get(FLAG_CONTENT_ADD_REL, 0)) {
-            $options['rel'] = 'nofollow';
-          }
-
-          if (!_flag_content_check($node->nid)) {
-            // Not already flagged, flag it for admin
-            $links[] = l(t('flag as offensive'), "flag_content/add/$node->nid", $options);
-          }
-          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", $options);
-            }
-            else {
-              // Otherwise just show it as flagged
-              $links[] = t('flagged as offensive');
-            }
-          }
+  
+  // Do not allow users to flag themselves.
+  if ($type == 'user' && $entry->uid == $user->uid) {
+    return $links;
+  }
+  
+  if (user_access(FLAG_CONTENT_PERM_ADD) && $user->uid) {
+    switch ($type) {
+      case 'node':
+        if (variable_get(FLAG_CONTENT_NODE_TYPE . $entry->type, 0)) {
+          $eid = $entry->nid;
+        }
+        break;
+      case 'user':
+        if (variable_get(FLAG_CONTENT_USER, 0)) {
+          $eid = $entry->uid;
         }
+        break;
+      case 'comment':
+        // TODO: ...
+        break;
+    }
+    
+    $options = array('class' => 'flag_content');
+    if (variable_get(FLAG_CONTENT_ADD_REL, 0)) {
+      $options['rel'] = 'nofollow';
+    }
+
+    if ($eid && !_flag_content_check($eid, $type)) {
+      // Not already flagged, flag it for admin
+      $links[] = l(t('flag as offensive'), "flag_content/add/$eid/$type", $options, drupal_get_destination());
+    }
+    else {
+      // If has admin privileges, show an unflag link
+      if (user_access(FLAG_CONTENT_PERM_MANAGE)) {
+        $links[] = l(t('unflag'), "flag_content/unflag/$eid/$type", $options, drupal_get_destination());
+      }
+      else {
+        // Otherwise just show it as flagged
+        $links[] = t('flagged as offensive');
       }
     }
   }
+  
   return $links;
 }
 
-function flag_content_add($nid = 0) {
-  $node = node_load($nid);
-
-  $form['nid'] = array('#type' => 'hidden', '#value' => $nid);
+function flag_content_add($eid = 0, $type = 'node') {
+  switch ($type) {
+    case 'node':
+      $node = node_load($eid);
+      $title = $node->title;
+      $type_label = $node->type;
+      break;
+    case 'user':
+      $account = user_load(array('uid' => $eid));
+      $title = $account->name;
+      $type_label = $type;
+      break;
+    case 'comment':
+      // TODO: ...
+      break;
+  }
+  
+  $form['eid'] = array('#type' => 'hidden', '#value' => $eid);
+  $form['type'] = array('#type' => 'hidden', '#value' => $type);
   return confirm_form('flag_content_add',
     $form,
-    t('Are you sure you want to flag %type %title', array('%type' => $node->type, '%title' => theme('placeholder', $node->title))),
-    $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
+    t('Are you sure you want to flag the %type %title', array('%type' => $type_label, '%title' => theme('placeholder', $title))),
+    $_GET['destination'] ? $_GET['destination'] : $type .'/'. $eid,
     t(''),
     t('Flag'), t('Cancel'));
 }
 
 function flag_content_add_submit($form_id, $form_values) {
-  $nid = $form_values['nid'];
-  if ($nid) {
+  $eid = $form_values['eid'];
+  $type = $form_values['type'];
+  if ($eid && $type) {
     // Insert the data into the table
-    db_query('INSERT INTO {flag_content} (nid, timestamp) VALUES (%d, %d)', $nid, time());
+    $fid = db_next_id('{flag_content}_fid');
+    db_query("INSERT INTO {flag_content} (fid, eid, type, timestamp) VALUES (%d, %d, '%s', %d)", $fid, $eid, $type, time());
     // Prepare the data
-    $node = node_load($nid);
+    switch ($type) {
+      case 'node':
+        $entry = node_load(array('nid' => $eid));
+        break;    
+      case 'user':
+        $entry = user_load(array('uid' => $eid));
+        break;
+      case 'comment':
+        // TODO: ...
+        break;
+    }
+    
     // Email the admin
-    theme('flag_content_mail', $node);
+    theme('flag_content_mail', $entry, $type);
     // Give feedback to the user
     drupal_set_message(t('The item was flagged for the administrator'));
   }
-  return "node/$nid";
-}  
+  
+  return $_GET['destination'] ? $_GET['destination'] : $type .'/'. $eid;
+}
 
-function flag_content_unflag($nid = 0) {
-  $node = node_load($nid);
+function flag_content_unflag($eid = 0, $type = 'node') {
+  switch ($type) {
+    case 'node':
+      $node = node_load($eid);
+      $title = $node->title;
+      $type_label = $node->type;
+      break;
+    case 'user':
+      $account = user_load(array('uid' => $eid));
+      $title = $account->name;
+      $type_label = $type;
+      break;
+    case 'comment':
+      // TODO: ...
+      break;
+  }
 
-  $form['nid'] = array('#type' => 'hidden', '#value' => $nid);
+  $form['eid'] = array('#type' => 'hidden', '#value' => $eid);
+  $form['type'] = array('#type' => 'hidden', '#value' => $type);
   return confirm_form('flag_content_unflag',
     $form,
-    t('Are you sure you want to unflag %type %title', array('%type' => $node->type, '%title' => theme('placeholder', $node->title))),
-    $_GET['destination'] ? $_GET['destination'] : 'node/'. $node->nid,
+    t('Are you sure you want to unflag the %type %title', array('%type' => $type_label, '%title' => theme('placeholder', $title))),
+    $_GET['destination'] ? $_GET['destination'] : $type. '/'. $eid,
     t(''),
     t('Unflag'), t('Cancel'));
 }
 
 function flag_content_unflag_submit($form_id, $form_values) {
-  $nid = $form_values['nid'];
-  if ($nid) {
-    _flag_content_unflag($nid);
+  $eid = $form_values['eid'];
+  $type = $form_values['type'];
+  if ($eid && $type) {
+    _flag_content_unflag($eid, $type);
     drupal_set_message(t('The item was unflagged.'));
   }
   return 'flag_content/view';
@@ -180,22 +288,29 @@ function flag_content_view() {
 
 function theme_flag_content_view($list = array()) {
   $rows = array();
-  $header = array(t('Title'), t('Author'), t('Date'), t('Operations'));
-  if (count($list)) {
-    foreach($list as $nid => $data) {
-      $title = l($data['title'], "node/$nid");
-      $author = $data['author'];
-      $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");
-
-      $rows[] = array('data' => array_merge(
-        array($title),
-        array($user),
-        array($timestamp),
-        array($ops)));
+  $header = array(t('Item'), t('Type'), t('Date'), t('Operations'));
+  if (!empty($list)) {
+    foreach($list as $entry) {
+      switch ($entry->type) {
+        case 'node':
+          $node = node_load(array('nid' => $entry->eid));
+          $title = l($node->title, 'node/'. $node->nid, array('title' => $node->title)); 
+          $author = theme('username', user_load(array('uid' => $node->uid)));
+          $item = t('%title - (author: %author)', array('%title' => $title, '%author' => $author));
+          break;
+        case 'user':
+          $item = theme('username', user_load(array('uid' => $entry->eid)));
+          break;
+        case 'comment':
+          // TODO: ...
+          break;
+      }
+      
+      $timestamp = format_date($entry->timestamp, 'custom', 'Y-m-d H:i');
+      $ops = l(t('edit %type', array('%type' => $node->type ? $node->type : $entry->type)), "$entry->type/$entry->eid/edit");
+      $ops .= ' ' . l(t('unflag'), "flag_content/unflag/$entry->eid/$entry->type");
+      $ops .= ' ' . l(t('delete'), "$entry->type/$entry->eid/delete");
+      $rows[] = array($item, $node->type ? $node->type : $entry->type, $timestamp, $ops);
     }
   }
   else {
@@ -213,57 +328,66 @@ function flag_content_nodeapi(&$node, $o
   }
 }
 
-function _flag_content_unflag($nid) {
-  db_query("DELETE FROM {flag_content} WHERE nid = %d", $nid);
+function _flag_content_unflag($eid, $type = 'node') {
+  db_query("DELETE FROM {flag_content} WHERE eid = %d AND type = '%s'", $eid, $type);
 }
 
 function _flag_content_get() {
   $rows = array();
-  $sql = "SELECT n.nid, n.title, n.uid, f.timestamp
-    FROM {node} n INNER JOIN {flag_content} f USING(nid)
-    ORDER by f.timestamp ASC";
+  $sql = "SELECT eid, type, timestamp FROM {flag_content} ORDER BY timestamp ASC";
   $result = db_query($sql);
-  while ($data = db_fetch_object($result)) {
-    $rows[$data->nid] = array(
-      'title' => $data->title,
-      'author' => user_load(array('uid' => $data->uid)),
-      'timestamp' => $data->timestamp,
-      );
+  while ($row = db_fetch_object($result)) {
+    $rows[$row->eid] = $row;
   }
   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($eid, $type = 'node') {  
+  global $user;
+  
+  return db_result(db_query("SELECT COUNT(*) FROM {flag_content} WHERE eid = %d AND type = '%s'", $eid, $type));
 }
 
-function theme_flag_content_mail($node) {
-  global $user, $base_url;
+function theme_flag_content_mail($entry, $type = 'node') {
+  global $user;
   
+  switch ($type) {
+    case 'node':
+      $title = $entry->title;
+      $eid = $entry->nid;
+      break;
+    case 'user':
+      $title = $entry->name;
+      $eid = $entry->uid;
+      break;
+    case 'comment':
+      // TODO: ...
+      break;
+  }
+  $base_url = 'http://'. $_SERVER['HTTP_HOST'];
   $site = variable_get('site_name', 'drupal site');
   $to = variable_get(FLAG_CONTENT_EMAIL, variable_get('site_mail', ini_get('sendmail_from')));
   $from = $user->mail;
-  $subject = "[Flag]: [$node->title] from [$site]";
+  $subject = "[Flag]: [$title] from [$site]";
   $body  = t("The following user flagged an item for your review.\n\nUser: %name (%user_url)",
     array(
       '%name'     => $user->name,
-      '%user_url' => $base_url . url("/user/$user->uid"),
+      '%user_url' => $base_url . url("user/$user->uid"),
       ));
-  $body .= t("\nItem: %title (%node_url)",
+  $body .= t("\nItem: %title (%entry_url)",
     array(
-      '%title'    => $node->title,
-      '%node_url' => $base_url . url("/node/$node->nid"),
+      '%title'    => $title,
+      '%entry_url' => $base_url . url("$type/$eid"),
     ));
 
   $body .= t("\n\nManage the flagged items list at %manage",
-    array('%manage' => $base_url . url("/flag_content/view")));
+    array('%manage' => $base_url . url("flag_content/view")));
 
   // 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);
 
   // Log the operation:
-  watchdog('mail', t("%name flagged item $node->nid for review.",
-    array ('%name' => theme('placeholder', $user->name ." <$from>"))));
+  watchdog('mail', t("%name flagged item %entry for review.",
+    array ('%name' => theme('placeholder', $user->name ." <$from>"), '%entry' => l($title, $type .'/'. $eid))));
 }
