diff --git a/abuse-page.tpl.php b/abuse-page.tpl.php
index a27f7b2..508fff5 100644
--- a/abuse-page.tpl.php
+++ b/abuse-page.tpl.php
@@ -14,18 +14,20 @@
 <div id="message-wrapper" class="message status"></div>
 <ul class="abuse-report-list">
   <?php foreach ($reports as $report): ?>
-  <?php print theme('abuse_report', array('object' => $report)); ?>
+    <?php print theme('abuse_report', array('object' => $report)); ?>
   <?php endforeach; ?>
 </ul>
 
 <?php // hide the controls for the main abuse page on the individual ticket page ?>
 <?php if (!preg_match('/^admin\/abuse\/status/i', request_path())): ?>
-<div id="abuse-report-list-controls">
-	<?php print l(t('Get More Tickets'), request_path()); ?>
-</div>
+  <div id="abuse-report-list-controls">
+    <?php print l(t('Get More Tickets'), request_path()); ?>
+  </div>
 <?php endif; ?>
 
+<!--
 <?php print theme('pager', array(), 10, 0); ?>
 <?php $total = count($reports); ?>
 <?php pager_default_initialize($total, 1, $element = 0); ?>
 <?php print theme('pager', array('quantity' => $total)); ?>
+-->
diff --git a/abuse-report.tpl.php b/abuse-report.tpl.php
index da0d0f2..3153954 100644
--- a/abuse-report.tpl.php
+++ b/abuse-report.tpl.php
@@ -6,7 +6,6 @@
  *
  *  * Available variables:
  * - $object: The content that requires moderation
- * - $account: Account of user that created content
  * - $offences: Total offences by account
  * - $warnings: Total email warnings sent to account
  * - $moderate: Moderation form
@@ -20,9 +19,9 @@
     <h2><?php print l($object->title, $object->path['URL'], array('query' => $object->path['QUERY'], 'fragment' => $object->path['BREADCRUMB'])); ?></h2>
     <dl>
       <dt><?php print t('Type:'); ?></dt>
-      <dd><?php //print $object->type === 'comment' ? t('Comment') : node_type_get_types('name', $object->content_type); ?></dd>
+      <dd><?php print drupal_ucfirst($object->content_type); ?></dd>
       <dt><?php print t('Status:'); ?></dt>
-      <dd><?php print isset($object->abuse_status_string) ? $object->abuse_status_string : 'N/A'; ?></dd>
+      <dd><?php print $object->abuse_status_string; ?></dd>
       <?php if (variable_get('abuse_assigned_moderators', FALSE)): ?>
         <dt><?php print t('Assigned To:'); ?></dt>
         <dd><?php print $object->abuse_assigned_to_name; ?></dd>
@@ -31,24 +30,24 @@
     <?php if (!empty($object->description)): ?>
       <p><?php print $object->description[$object->language][0]['safe_value']; ?></p>
     <?php endif; ?>
-    <h4><?php print t('By: !username', array('!username' => theme('username', array('user' => $account)))); ?></h4>
+    <h4><?php print t('By: !username', array('!username' => theme('username', array('account' => $object->account)))); ?></h4>
     <dl>
       <dt><?php print t('Email'); ?>:</dt>
-      <dd><?php print $account->mail; ?></dd>
+      <dd><?php print $object->account->mail; ?></dd>
       <dt><?php print t('Age'); ?>:</dt>
-      <dd><?php print theme('age', $account->uid); ?></dd>
+      <dd><?php print theme('age', $object->account->uid); ?></dd>
       <dt><?php print t('Offences'); ?>:</dt>
       <dd><?php print $offences; ?></dd>
       <dt><?php print t('Warnings'); ?>:</dt>
       <dd><?php print $warnings; ?></dd>
     </dl>
     <ul class="links">
-      <li><?php print l(t('Edit Account'), 'user/'. $account->uid .'/edit'); ?></li>
-      <li><?php print l(t('View Account History'), 'admin/abuse/status/user/'. $account->uid); ?></li>
+      <li><?php print l(t('Edit Account'), 'user/'. $object->account->uid .'/edit'); ?></li>
+      <li><?php print l(t('View Account History'), 'admin/abuse/status/user/'. $object->account->uid); ?></li>
     </ul>
   </div>
   <div class="actions">
-    <?php //print $moderate; ?>
+    <?php print render($moderate); ?>
   </div>
   <div class="details clear-block">
     <div class="column column-first">
@@ -88,8 +87,8 @@
         <dt><?php print t('Flags'); ?></dt>
         <?php if (count($object->reports)): ?>
           <?php foreach ($object->reports as $report): ?>
-          <dd>
-              <strong><?php print strcasecmp($report->name, t('Watchlist')) == 0 ? t('Watchlist') : theme("username", $report); ?></strong> &mdash;
+            <dd>
+              <strong><?php print strcasecmp($report->name, t('Watchlist')) == 0 ? t('Watchlist') : theme('username', array('account' => $object->account)); ?></strong> &mdash;
               <?php print format_date($report->created); ?>:<br />
               <?php print check_plain(urldecode($report->body)); ?>
             </dd>
diff --git a/abuse.admin.inc b/abuse.admin.inc
index 46665b9..39e28b0 100644
--- a/abuse.admin.inc
+++ b/abuse.admin.inc
@@ -25,11 +25,11 @@ function abuse_admin_settings($form, &$form_state) {
     '#collapsed' => FALSE,
   );
   foreach (node_type_get_types() as $type => $name) {
-    $form['contenttypes'][ABUSE_CONTENT_NODE_TYPE . $type] = array(
+    $form['contenttypes'][ABUSE_ENTITY_TYPE . $type] = array(
       '#title' => $name->type,
       '#type' => 'checkbox',
       '#return_value' => 1,
-      '#default_value' => variable_get(ABUSE_CONTENT_NODE_TYPE . $type, 0),
+      '#default_value' => variable_get(ABUSE_ENTITY_TYPE . $type, 0),
     );
   }
   $form['contenttypes'][ABUSE_CONTENT_COMMENTS] = array(
@@ -374,11 +374,11 @@ function abuse_admin_moderate($status = array(), $assigned_to_uid = FALSE) {
 
   $reports = array();
   foreach ($result as $object) {
-    $obj = _abuse_load($object);
+    $obj = _abuse_load($object->type, $object->oid);
     $reports[] = $obj;
   }
   // TODO Please change this theme call to use an associative array for the $variables parameter.
-  $content = theme('abuse_page', $reports, $limit);
+  $content = theme('abuse_page', array('reports' => $reports, 'limit' => $limit));
   return $content;
 }
 
@@ -404,8 +404,8 @@ function abuse_admin_status($type, $oid) {
     return abuse_admin_user($oid);
   }
   // @TODO This is not correct
-  $object = _abuse_load($oid, $type);
-  if ($object->oid) {
+  $object = _abuse_load($type, $oid);
+  if ($oid) {
     $reports[] = $object;
   }
   else {
@@ -612,17 +612,15 @@ function abuse_admin_unban_user($account) {
  * @todo Please document this function.
  * @see http://drupal.org/node/1354
  */
-function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid = NULL, $inline = FALSE) {
-  $object = _abuse_load($type, $oid);
-  if (!isset($object)) {
-    return drupal_not_found();
-  }
-
+function abuse_admin_moderate_content($form, &$form_state, $object, $inline = FALSE) {
   global $user;
+
+  // TODO: What's this for?
   static $run_once;
+
   $form = array();
-  $form['#validate'][] = 'abuse_admin_moderate_content_validate';
-  $form['#submit'][] = 'abuse_admin_moderate_content_submit';
+  $form['#validate'] = array('abuse_admin_moderate_content_validate');
+  $form['#submit'] = array('abuse_admin_moderate_content_submit');
 
   if (!$inline) {
     $form['target'] = array(
@@ -631,12 +629,14 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
       '#prefix' => '<div id="message-wrapper" class="message status">',
       '#suffix' => '</div>',
     );
+
+    // TODO: Agian. What's this for?
     $run_once = TRUE;
   }
 
   $form['object_type'] = array(
     '#type' => 'hidden',
-    '#value' => $object->type,
+    '#value' => $object->entity_type,
   );
   $form['object_oid'] = array(
     '#type' => 'hidden',
@@ -650,7 +650,7 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
   if ($inline) {
     $form['redirect'] = array(
       '#type' => 'hidden',
-      '#value' => $_GET['q'],
+      '#value' => $object->link,
     );
   }
 
@@ -660,20 +660,23 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     '#attributes' => array(
-      'class' => 'abuse-report-allow',
+      'class' => array(
+        'abuse-report-allow',
+      ),
     ),
   );
   $form['allow']['message'] = array(
     '#type' => 'item',
     '#value' => t('Are you sure you want to allow "@content"?', array('@content' => $object->title)),
     '#attributes' => array(
-      'class' => 'confirm',
+      'class' => array(
+        'confirm',
+      ),
     ),
   );
   $form['allow']['allow'] = array(
     '#type' => 'submit',
     '#value' => t('allow'),
-    //'#ahah' => $temp,
   );
 
   $form['remove'] = array(
@@ -682,14 +685,19 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     '#attributes' => array(
-      'class' => 'abuse-report-remove',
+      'class' => array(
+        'abuse-report-remove',
+      ),
     ),
   );
+
   $form['remove']['message'] = array(
     '#type' => 'item',
     '#value' => t('Are you sure you want to remove "@content"?', array('@content' => $object->title)),
     '#attributes' => array(
-      'class' => 'confirm',
+      'class' => array(
+        'confirm',
+      ),
     ),
   );
   $form['remove']['remove'] = array(
@@ -710,7 +718,9 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     '#attributes' => array(
-      'class' => 'abuse-report-warn-and-allow',
+      'class' => array(
+        'abuse-report-warn-and-allow',
+      ),
     ),
   );
 
@@ -720,9 +730,12 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     '#attributes' => array(
-      'class' => 'abuse-report-warn-and-remove',
+      'class' => array(
+        'abuse-report-warn-and-remove',
+      ),
     ),
   );
+
   $form['warn']['allow']['allow_subject'] = $form['warn']['remove']['remove_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Warning subject'),
@@ -731,6 +744,7 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#rows' => 10,
     '#required' => TRUE,
   );
+
   $form['warn']['allow']['allow_body'] = $form['warn']['remove']['remove_body'] = array(
     '#type' => 'textarea',
     '#title' => t('Warning body'),
@@ -739,6 +753,7 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#required' => TRUE,
     '#description' => t('available fields are !title, !url, !name, and !id. You can copy from the list below.'),
   );
+
   $tmp_content = "<div class=\"clear-block\"><dl class=\"warning-templates\">\n";
   $reasons = _abuse_reasons();
   foreach ($reasons as $key => $reason) {
@@ -752,6 +767,7 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
     '#type' => 'item',
     '#value' => $tmp_content,
   );
+
   $form['warn']['allow']['allow_warn'] = array(
     '#type' => 'submit',
     '#value' => t('warn and allow'),
@@ -765,18 +781,22 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
   if ($user->uid !== $object->uid && $object->uid > 1) {
     $form['ban'] = array(
       '#type' => 'fieldset',
-      '#title' => t('Ban !user?', array('!user' => check_plain($object->name))),
+      '#title' => t('Ban !user?', array('!user' => check_plain($object->account->name))),
       '#collapsible' => TRUE,
       '#collapsed' => TRUE,
       '#attributes' => array(
-        'class' => 'abuse-report-ban',
+        'class' => array(
+          'abuse-report-ban',
+        ),
       ),
     );
     $form['ban']['confirmation_message'] = array(
       '#type' => 'item',
-      '#value' => t('Are you sure you want to ban "@name"?', array('@name' => $object->name)),
+      '#value' => t('Are you sure you want to ban "@name"?', array('@name' => $object->account->name)),
       '#attributes' => array(
-        'class' => 'confirm',
+        'class' => array(
+          'confirm',
+        ),
       ),
     );
     $form['ban']['ban'] = array(
@@ -784,6 +804,7 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
       '#value' => t('ban'),
     );
   }
+
   return $form;
 }
 
@@ -792,7 +813,6 @@ function abuse_admin_moderate_content($form, &$form_state, $type = NULL, $oid =
  * @see http://drupal.org/node/1354
  */
 function abuse_admin_moderate_content_validate($form, &$form_state) {
-  global $user;
   $values = $form_state['values'];
   $op = $form_state['clicked_button']['#value'];
   if (t('ban') === $op && ($values['object_uid'] || $values['object_uid'] <= 1)) {
@@ -805,7 +825,6 @@ function abuse_admin_moderate_content_validate($form, &$form_state) {
  * @see http://drupal.org/node/1354
  */
 function abuse_admin_moderate_content_submit($form, &$form_state) {
-  global $user;
   $values = $form_state['values'];
   $op = $form_state['clicked_button']['#value'];
   if ($values['redirect']) {
@@ -821,7 +840,6 @@ function abuse_admin_moderate_content_submit($form, &$form_state) {
  * @see http://drupal.org/node/1354
  */
 function abuse_admin_moderate_content_js() {
-  global $user;
   $values = $_POST;
   $op = $values['op'];
   $message = _abuse_admin_moderate_content_shared($values, $op);
@@ -1026,40 +1044,3 @@ function abuse_mail($key, &$message, $params) {
   $message['subject'] .= str_replace(array("\r", "\n"), '', $subject);
   $message['body'][] = htmlspecialchars($body, ENT_NOQUOTES);
 }
-
-/**
- *
- * @param type $variables
- */
-function template_preprocess_abuse_page(&$variables) {
-  drupal_add_js('misc/jquery.form.js');
-  drupal_add_js("Drupal.base_url = '" . url('') . "';", array('type' => 'inline', 'scope' => JS_DEFAULT));
-  drupal_add_js(drupal_get_path('module', 'abuse') . '/abuse.js');
-}
-
-
-/**
- *
- * @staticvar int $counter
- * @param type $variables
- */
-function template_preprocess_abuse_report(&$variables) {
-  static $counter;
-  if (!isset($counter)) {
-    $counter = 1;
-  }
-  $object = $variables['object'];
-
-  $user = user_load($object->uid);
-  $variables['account'] = $user;
-
-  $variables['offences'] = number_format(_abuse_get_offence_count($object->uid));
-  $variables['warnings'] = number_format(_abuse_get_warning_count($object->uid));
-  $variables['nodeType'] = ($object->type == 'comment') ? "Comment" : node_type_get_name($object->oid);
-
-  // @TODO check counter
-  //$moderate = drupal_get_form('abuse_admin_moderate_content', $object->type, $object->oid, TRUE);
-  //$moderate = drupal_get_form('abuse_admin_moderate_content' . $counter++, $object->type, $object->oid, TRUE);
-  //$variables['moderate'] = $moderate;
-  $moderate = "@TODO add moderate";
-}
diff --git a/abuse.module b/abuse.module
index 1fb5844..26452b5 100644
--- a/abuse.module
+++ b/abuse.module
@@ -12,7 +12,7 @@ define('ABUSE_REMOVED', 3);
 define('ABUSE_SUPERADMIN', 4);
 
 // Set of content allowed for abuse flagging.
-define('ABUSE_CONTENT_NODE_TYPE',    'abuse_content_node_type_');
+define('ABUSE_ENTITY_TYPE',    'abuse_entity_type_');
 define('ABUSE_CONTENT_COMMENTS', 'abuse_content_comments');
 define('ABUSE_CONTENT_USERS', 'abuse_content_users');
 
@@ -122,18 +122,13 @@ function abuse_help($section) {
  * Implements hook_menu().
  */
 function abuse_menu() {
-  //Initial setup work
-  $flagger = array(REPORT_ABUSE, DIRECT_FLAG);
-  $admin = array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS);
-  $superadmin = array(ADMINISTER_ALL_ABUSE_REPORTS);
-  $configure = array(CONFIGURE_ABUSE_SETTINGS);
   // Regular flagging
   $items['abuse/report/%/%'] = array(
     'title' => 'Flag',
     'page callback' => 'abuse_report',
     'page arguments' => array(2, 3),
     'access callback' => 'abuse_node_access',
-    'access arguments' => $flagger,
+    'access arguments' => array(REPORT_ABUSE, DIRECT_FLAG),
     'type' => MENU_CALLBACK,
   );
   // Abuse system settings.
@@ -143,7 +138,7 @@ function abuse_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('abuse_admin_settings'),
     'access callback' => 'abuse_node_access',
-    'access arguments' => $configure,
+    'access arguments' => array(CONFIGURE_ABUSE_SETTINGS),
     'file' => 'abuse.admin.inc',
   );
   $items['admin/config/people/abuse/settings'] = array(
@@ -157,7 +152,7 @@ function abuse_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('abuse_admin_reason_settings'),
     'access callback' => 'user_access',
-    'access arguments' => $configure,
+    'access arguments' => array(CONFIGURE_ABUSE_SETTINGS),
     'file' => 'abuse.admin.inc',
     'type' => MENU_LOCAL_TASK,
   );
@@ -167,7 +162,7 @@ function abuse_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('abuse_admin_edit_reason', 5),
     'access callback' => 'user_access',
-    'access arguments' => $configure,
+    'access arguments' => array(CONFIGURE_ABUSE_SETTINGS),
     'file' => 'abuse.admin.inc',
     'type' => MENU_CALLBACK,
   );
@@ -177,14 +172,14 @@ function abuse_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('abuse_admin_moderate_content', 4, 5),
     'access callback' => 'abuse_node_access',
-    'access arguments' => $admin,
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'type' => MENU_CALLBACK,
   );
   $items['admin/abuse/moderate/content/js'] = array(
     'page callback' => 'abuse_admin_moderate_content_js',
     'access callback' => 'abuse_node_access',
-    'access arguments' => $admin,
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'type' => MENU_CALLBACK,
   );
@@ -193,7 +188,7 @@ function abuse_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('abuse_admin_ban', 3),
     'access callback' => 'abuse_node_access',
-    'access arguments' => $admin,
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'type' => MENU_CALLBACK,
   );
@@ -214,7 +209,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_moderate',
     'page arguments' => array(array(ABUSE_PENDING)),
     'access callback' => 'abuse_moderation_system_access',
-    'access arguments' => array($admin, TRUE),
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'weight' => 0,
     'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -225,7 +220,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_moderate',
     'page arguments' => array(array(ABUSE_HIDDEN)),
     'access callback' => 'abuse_moderation_system_access',
-    'access arguments' => array($admin, TRUE),
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'weight' => 1,
     'type' => MENU_LOCAL_TASK,
@@ -236,7 +231,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_moderate',
     'page arguments' => array(array(ABUSE_REMOVED)),
     'access callback' => 'abuse_moderation_system_access',
-    'access arguments' => array($admin, TRUE),
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'weight' => 2,
     'type' => MENU_LOCAL_TASK,
@@ -248,7 +243,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_moderate',
     'page arguments' => array(array(ABUSE_PENDING, ABUSE_HIDDEN), TRUE),
     'access callback' => 'abuse_moderation_system_access',
-    'access arguments' => array($admin, FALSE),
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'weight' => 0,
     'type' => MENU_DEFAULT_LOCAL_TASK,
@@ -259,7 +254,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_moderate',
     'page arguments' => array(array(ABUSE_PENDING, ABUSE_HIDDEN)),
     'access callback' => 'abuse_moderation_system_access',
-    'access arguments' => array($superadmin, FALSE),
+    'access arguments' => array(ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
     'weight' => 1,
     'type' => MENU_LOCAL_TASK,
@@ -269,7 +264,7 @@ function abuse_menu() {
     'description' => 'Manage items that were either flagged by the system or by other users',
     'page callback' => 'abuse_admin_default_callback',
     'access callback' => 'abuse_node_access',
-    'access arguments' => $admin,
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
   );
   $items['admin/abuse/status/%/%'] = array(
@@ -278,7 +273,7 @@ function abuse_menu() {
     'page callback' => 'abuse_admin_status',
     'page arguments' => array(3, 4),
     'access callback' => 'abuse_node_access',
-    'access arguments' => $admin,
+    'access arguments' => array(ADMINISTER_ABUSE_REPORTS, ADMINISTER_ALL_ABUSE_REPORTS),
     'file' => 'abuse.admin.inc',
   );
   return $items;
@@ -292,14 +287,13 @@ function abuse_theme() {
   $theme = array();
   $theme['abuse_page'] = array(
     'template' => 'abuse-page',
-    'file' => 'abuse.admin.inc',
     'variables' => array(
       'reports' => NULL,
+      'limit' => NULL,
     ),
   );
   $theme['abuse_report'] = array(
     'template' => 'abuse-report',
-    'file' => 'abuse.admin.inc',
     'variables' => array(
       'object' => NULL,
     ),
@@ -307,6 +301,37 @@ function abuse_theme() {
   return $theme;
 }
 
+/**
+ *
+ * @param type $variables
+ */
+function template_preprocess_abuse_page(&$variables) {
+  drupal_add_js('misc/jquery.form.js');
+  drupal_add_js("Drupal.base_url = '" . url('') . "';", array('type' => 'inline', 'scope' => JS_DEFAULT));
+  drupal_add_js(drupal_get_path('module', 'abuse') . '/abuse.js');
+}
+
+/**
+ *
+ * @staticvar int $counter
+ * @param type $variables
+ */
+function template_preprocess_abuse_report(&$variables) {
+  // TODO: What's the counter for?
+  static $counter;
+  if (!isset($counter)) {
+    $counter = 1;
+  }
+  $object = $variables['object'];
+
+  $variables['offences'] = number_format(_abuse_get_offence_count($object->uid));
+  $variables['warnings'] = number_format(_abuse_get_warning_count($object->uid));
+  $variables['nodeType'] = ($object->entity_type == 'comment') ? "Comment" : node_type_get_name($object->oid);
+
+  // @TODO check counter
+  //$moderate = drupal_get_form('abuse_admin_moderate_content' . $counter++, $object, TRUE);
+  $variables['moderate'] = drupal_get_form('abuse_admin_moderate_content', $object, TRUE);
+}
 
 /**
  * Implements hook_cron().
@@ -332,128 +357,36 @@ function abuse_cron() {
 
 
 /**
- * Implements hook_link().
+ * Implements hook_node_view().
  */
-function abuse_node_view($node, $view_mode, $langcode) {
+function abuse_entity_view($entity, $type, $view_mode, $langcode) {
   global $user;
   $links = array();
-  $object = $node;
-  if ($object && $user && $user->uid == $object->uid) {
+  if ($entity && $user && $user->uid == $entity->uid) {
     // Don't want user to flag their own content
     return $links;
   }
-  $type = $object->type;
-  if (isset($object->nid) && $object->content['body']['#view_mode'] != 'teaser') {
-    if (user_access(ADMINISTER_ABUSE_REPORTS) && variable_get(ABUSE_CONTENT_NODE_TYPE . $object->type, 0)) {
-      $links['abuse_node_history'] = array(
-        'title' => t('View abuse history'),
-        'href' => 'admin/abuse/status/node/' . $object->nid,
-        'attributes' => array('class' => 'node-history'),
-      );
-    }
-    if (variable_get(ABUSE_CONTENT_NODE_TYPE . $object->type, 0) && (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
-      if (user_is_logged_in() && ($user->uid != $object->uid)) {
-        // @TODO Convert to similar: has_rows = (bool) db_query_range('SELECT 1 FROM {mytable}', 0, 1)->fetchField();
-        $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(':type' => $type, ':oid' => $object->nid, ':uid' => $user->uid))->fetchField();
-        if (! $already_reported_check > 0) {
-          $links['abuse_flag_node'] = array(
-            'title' => t('Flag as offensive'),
-            'href' => 'abuse/report/node/' . $object->nid,
-            'attributes' => array(
-              'class' => 'flag-content',
-              'title' => t('Notify administrators of problematic content'),
-            ),
-          );
-        }
-      }
-      else {
-        $links['abuse_flag_node'] = array(
-          'title' => t('Flag as offensive'),
-          'href' => 'abuse/report/node/' . $object->nid,
-          'attributes' => array(
-            'class' => 'flag-content',
-            'title' => t('Notify administrators of problematic content'),
-          ),
-        );
-      }
-    }
-  }
-  elseif ($type == 'comment' &&
-    variable_get(ABUSE_CONTENT_COMMENTS, 0) &&
-    (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
-    // Commented out as a temporary solution to ticket 178:
-    // https://office.zincroe.com/zimmertwins/ticket/178
-    //
-//    if (user_access(ADMINISTER_ABUSE_REPORTS)) {
-//      $links['abuse_comment_history'] = array(
-//        'title' => t('View abuse history'),
-//        'href' => 'admin/abuse/status/comment/'. $object->cid,
-//        'attributes' => array('class' => 'node-history'),
-//      );
-//    }
-    if ($user->uid && ($user->uid != $object->uid)) {
-      // @TODO Convert to similar: has_rows = (bool) db_query_range('SELECT 1 FROM {mytable}', 0, 1)->fetchField();
-      $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(':type' => $type, ':oid' => $object->cid, ':uid' => $user->uid))->fetchField();
-      if ($already_reported_check > 0) {
-//        $links['abuse_already_flagged'] = array(
-//          'title' => t('This comment is currently under review'),
-//        );
-      }
-      else {
-        $links['abuse_flag_comment'] = array(
-          'title' => t('Flag as offensive'),
-          'href' => 'abuse/report/comment/' . $object->cid,
-          'attributes' => array(
-            'class' => 'flag-content',
-            'title' => t('Notify administrators of problematic comment'),
-          ),
-        );
-      }
-    }
-    else {
-      $links['abuse_flag_comment'] = array(
-        'title' => t('Flag as offensive'),
-        'href' => 'abuse/report/comment/' . $object->cid,
-        'attributes' => array(
-          'class' => 'flag-content',
-          'title' => t('Notify administrators of problematic comment'),
-          ),
-        );
-      }
-    }
-    $node->content['links']['blog'] = array(
-      '#theme' => 'links__node__blog',
-      '#links' => $links,
-      '#attributes' => array('class' => array('links', 'inline')),
-    );
-  }
 
-/**
- * Implements hook_link().
- */
-function abuse_link($type, $object, $teaser = FALSE) {
-  global $user;
-  $links = array();
-  if ($object && $user && $user->uid == $object->uid) {
-    // Don't want user to flag their own content
-    return $links;
-  }
-  if ($type == 'node' && !$teaser) {
-    if (user_access(ADMINISTER_ABUSE_REPORTS) && variable_get(ABUSE_CONTENT_NODE_TYPE . $object->type, 0)) {
+  if (isset($entity->nid) && $view_mode != 'teaser' && $type != 'comment') {
+    if (user_access(ADMINISTER_ABUSE_REPORTS) && variable_get(ABUSE_ENTITY_TYPE . $entity->type, 0)) {
       $links['abuse_node_history'] = array(
         'title' => t('View abuse history'),
-        'href' => 'admin/abuse/status/node/' . $object->nid,
+        'href' => 'admin/abuse/status/node/' . $entity->nid,
         'attributes' => array('class' => 'node-history'),
       );
     }
-    if (variable_get(ABUSE_CONTENT_NODE_TYPE . $object->type, 0) && (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
-      if (user_is_logged_in() && ($user->uid != $object->uid)) {
+    if (variable_get(ABUSE_ENTITY_TYPE . $entity->type, 0) && (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
+      if (user_is_logged_in() && ($user->uid != $entity->uid)) {
         // @TODO Convert to similar: has_rows = (bool) db_query_range('SELECT 1 FROM {mytable}', 0, 1)->fetchField();
-        $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(':type' => $type, ':oid' => $object->nid, ':uid' => $user->uid))->fetchField();
-        if (! $already_reported_check > 0) {
+        $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(
+            ':type' => $type,
+            ':oid' => $entity->nid,
+            ':uid' => $user->uid
+          ))->fetchField();
+        if (!$already_reported_check > 0) {
           $links['abuse_flag_node'] = array(
             'title' => t('Flag as offensive'),
-            'href' => 'abuse/report/node/' . $object->nid,
+            'href' => 'abuse/report/node/' . $entity->nid,
             'attributes' => array(
               'class' => 'flag-content',
               'title' => t('Notify administrators of problematic content'),
@@ -464,7 +397,7 @@ function abuse_link($type, $object, $teaser = FALSE) {
       else {
         $links['abuse_flag_node'] = array(
           'title' => t('Flag as offensive'),
-          'href' => 'abuse/report/node/' . $object->nid,
+          'href' => 'abuse/report/node/' . $entity->nid,
           'attributes' => array(
             'class' => 'flag-content',
             'title' => t('Notify administrators of problematic content'),
@@ -475,7 +408,8 @@ function abuse_link($type, $object, $teaser = FALSE) {
   }
   elseif ($type == 'comment' &&
     variable_get(ABUSE_CONTENT_COMMENTS, 0) &&
-    (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))) {
+    (user_access(REPORT_ABUSE) || user_access(DIRECT_FLAG))
+  ) {
     // Commented out as a temporary solution to ticket 178:
     // https://office.zincroe.com/zimmertwins/ticket/178
     //
@@ -486,10 +420,13 @@ function abuse_link($type, $object, $teaser = FALSE) {
 //        'attributes' => array('class' => 'node-history'),
 //      );
 //    }
-    if ($user->uid && ($user->uid != $object->uid)) {
+    if ($user->uid && ($user->uid != $entity->uid)) {
       // @TODO Convert to similar: has_rows = (bool) db_query_range('SELECT 1 FROM {mytable}', 0, 1)->fetchField();
-      // Make this a function, used elsewhere
-      $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(':type' => $type, ':oid' => $object->cid, ':uid' => $user->uid))->fetchField();
+      $already_reported_check = db_query("SELECT COUNT(*) FROM {abuse} WHERE type = :type AND oid = :oid AND uid = :uid", array(
+          ':type' => $type,
+          ':oid' => $entity->cid,
+          ':uid' => $user->uid
+        ))->fetchField();
       if ($already_reported_check > 0) {
 //        $links['abuse_already_flagged'] = array(
 //          'title' => t('This comment is currently under review'),
@@ -498,7 +435,7 @@ function abuse_link($type, $object, $teaser = FALSE) {
       else {
         $links['abuse_flag_comment'] = array(
           'title' => t('Flag as offensive'),
-          'href' => 'abuse/report/comment/' . $object->cid,
+          'href' => 'abuse/report/comment/' . $entity->cid,
           'attributes' => array(
             'class' => 'flag-content',
             'title' => t('Notify administrators of problematic comment'),
@@ -509,7 +446,7 @@ function abuse_link($type, $object, $teaser = FALSE) {
     else {
       $links['abuse_flag_comment'] = array(
         'title' => t('Flag as offensive'),
-        'href' => 'abuse/report/comment/' . $object->cid,
+        'href' => 'abuse/report/comment/' . $entity->cid,
         'attributes' => array(
           'class' => 'flag-content',
           'title' => t('Notify administrators of problematic comment'),
@@ -517,10 +454,15 @@ function abuse_link($type, $object, $teaser = FALSE) {
       );
     }
   }
-  return $links;
-}
 
 
+  $entity->content['links']['abuse'] = array(
+    '#theme' => 'links__node__abuse',
+    '#links' => $links,
+    '#attributes' => array('class' => array('links', 'inline')),
+  );
+}
+
 /**
  * Implements hook_node_load().
  */
@@ -553,12 +495,12 @@ function abuse_node_delete($node) {
 /**
  * Implements hook_comment_view().
  */
-function abuse_comment_view($comment) {
+/*function abuse_comment_view($comment) {
   if (user_access(ADMINISTER_ABUSE_REPORTS) || user_access(ADMINISTER_ALL_ABUSE_REPORTS)) {
     $comment->abuse_status = intval(_abuse_get_object_status('comment', $comment->cid));
   }
   return $comment;
-}
+}*/
 
 
 /**
@@ -757,26 +699,28 @@ function abuse_report($type, $oid) {
  */
 function abuse_report_form($form, &$form_state, $object, $user) {
   $form = array();
+
   $form['object_type'] = array(
-    '#type' => 'value',
-    '#value' => $object->type,
+    '#type' => 'hidden',
+    '#value' => $object->entity_type,
   );
+
   $form['object_oid'] = array(
-    '#type' => 'value',
+    '#type' => 'hidden',
     '#value' => $object->oid,
   );
   if ($user->uid) {
     $form['user'] = array(
       '#type' => 'item',
       '#title' => t('from'),
-      '#value' => check_plain($user->name),
+      '#markup' => check_plain($user->name),
     );
     $form['name'] = array(
-      '#type' => 'value',
+      '#type' => 'hidden',
       '#value' => check_plain($user->name),
     );
     $form['mail'] = array(
-      '#type' => 'value',
+      '#type' => 'hidden',
       '#value' => $user->mail,
     );
   }
@@ -799,13 +743,14 @@ function abuse_report_form($form, &$form_state, $object, $user) {
   $form['about'] = array(
     '#type' => 'item',
     '#title' => t('about'),
-    '#value' => ($object->type == 'node') ? check_plain($object->title) : $object->title,
+    '#markup' => check_plain($object->title),
   );
+
   $reason_objects = _abuse_reasons();
-  $reasons = array(0 => '');
   foreach ($reason_objects as $reason) {
     $reasons[$reason->arid] = t($reason->reason);
   }
+
   $form['reason'] = array(
     '#type' => 'select',
     '#title' => t('reason'),
@@ -875,12 +820,12 @@ function abuse_report_form_submit($form, &$form_state) {
   $oid = $form_values['object_oid'];
   $type = $form_values['object_type'];
   $object = _abuse_load($type, $oid);
-  $reason = db_query("SELECT reason FROM {abuse_reasons} WHERE arid = :arid", array(':arid' => $form_values['reason']))->fetchField();
+  //$reason = db_query("SELECT reason FROM {abuse_reasons} WHERE arid = :arid", array(':arid' => $form_values['reason']))->fetchField();
   if (!$object) {
     drupal_not_found();
   }
   // Object was found - system is alright from this point
-  $form_state['redirect'] = array($object->path['URL'], $object->path['QUERY'], $object->path['BREADCRUMB']);
+  $form_state['redirect'] = $object->link;
   $errors = ($form_values['op'] == t('cancel')) ? TRUE : FALSE;
   if ($user->uid) {
     // @TODO Convert to similar: has_rows = (bool) db_query_range('SELECT 1 FROM {mytable}', 0, 1)->fetchField();
@@ -927,98 +872,79 @@ function abuse_report_form_submit($form, &$form_state) {
  */
 
 /**
+ * @param string $entity_type
+ *   Type of entity. *
+ * @param int $entity_id
+ *  Entity ID.
  *
- * @param <type> $obj = entity type (and nid)
- * @param <type> $second_value = nid
  * @return <type>
  */
-function _abuse_load($obj, $second_value = NULL) {
-  // @TODO is this next line correct?
-  $object = node_load($obj);
-  if ($second_value !== NULL) {
-    $type = $obj;
-    $object->type = $type;
-    $object->oid = $oid = $second_value;
-  }
-  else {
-    $object->type = $type = $obj->type;
-    $object->oid = $oid = $obj->oid;
-    $object->abuse_status_number = $obj->status;
-    $object->abuse_status_string = _abuse_retrieve_status($object->abuse_status_number);
-    $object->abuse_assigned_to_uid = $obj->assigned_to_uid;
-    $object->abuse_assigned_to_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $object->abuse_assigned_to_uid))->fetchField();
-    if (!$object->abuse_assigned_to_name) {
-      $object->abuse_assigned_to_name = 'N/A';
-    }
+function _abuse_load($entity_type, $entity_id) {
+  $entity = entity_load_single($entity_type, $entity_id);
+  $wrapper = entity_metadata_wrapper($entity_type, $entity);
+  $account = user_load($entity->uid);
+
+  $object = $entity;
+  $object->account = $account;
+  $object->oid = $entity_id;
+  $object->uid = $entity->uid;
+  $object->entity_type = $entity_type;
+  $object->content_type = (isset($entity->type)) ? $entity->type : $entity_type;
+  $object->abuse_status_number = intval(_abuse_get_object_status($entity_id));
+  $object->abuse_status_string = _abuse_retrieve_status($object->abuse_status_number);
+  $object->abuse_assigned_to_uid = $entity->uid;
+  $object->abuse_assigned_to_name = db_query("SELECT name FROM {users} WHERE uid = :uid", array(':uid' => $object->abuse_assigned_to_uid))->fetchField();
+  if (!$object->abuse_assigned_to_name) {
+    $object->abuse_assigned_to_name = t('N/A');
   }
-  switch ($type) {
+
+  switch ($entity_type) {
     case 'node':
-      $node = node_load($object->nid);
-      if (!$node->nid) {
-        return FALSE;
-      }
-      $object->title = $node->title;
-      $object->uid = $node->uid;
-      $object->name = check_plain($node->name);
-      $object->description = $node->body;
-      $object->content_type = $node->type;
-      if (function_exists($node->type . '_replacement_content')) {
-        $function = $node->type . '_replacement_content';
-        $object->content = filter_xss_admin($function($node));
+      $object->name = check_plain($account->name);
+      $object->description = $wrapper->body->value();;
+
+      if (function_exists($entity->type . '_replacement_content')) {
+        $function = $entity->type . '_replacement_content';
+        $entity->content = filter_xss_admin($function($entity));
       }
       else {
-        // @TODO get lang param $object->content = check_markup($node->body, $node->format, $langcode = '' /* TODO Set this variable. */, FALSE);
-        $object->content = check_markup($node->body['und']['0']['value'], $node->body['und']['0']['format']);
-        //check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)
+        $object->content = $wrapper->body->value();
       }
-      $object->status = $node->status;
-      $object->path = array(
-        'URL' => 'node/' . $node->nid,
+      $entity->path = array(
+        'URL' => 'node/' . $entity->nid,
         'QUERY' => NULL,
         'BREADCRUMB' => NULL,
       );
-      $object->link = 'node/' . $node->nid;
+      $entity->link = 'node/' . $entity->nid;
       break;
     case 'comment':
-      $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :c.cid', array(':c.cid' => $oid));
-      $comment = db_fetch_object($result);
-      $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
-      $comment = drupal_unpack($comment);
-      if (!$comment->cid) {
-        return FALSE;
-      }
-      $object->title = check_plain($comment->subject);
-      $object->name = check_plain($comment->name);
-      $object->uid = $comment->uid;
-      $object->content_type = 'comment';
-      $object->description = check_markup($comment->comment, $comment->format, $langcode = '' /* TODO Set this variable. */, FALSE);
-      $object->status = ( $comment->status == 0);
+      $comment_body = $wrapper->comment_body->value();
+      $object->content = $comment_body['value'];
+      $object->title = check_plain($entity->subject);
+      $object->name = check_plain($account->name);
+
+      //$object->description = check_markup($comment->comment, $comment->format, $langcode = '' /* TODO Set this variable. */, FALSE);
       $object->path = array(
-        'URL' => 'node/' . $comment->nid,
+        'URL' => 'node/' . $entity->nid,
         'QUERY' => NULL,
-        'BREADCRUMB' => 'comment-' . $comment->cid,
+        'BREADCRUMB' => 'comment-' . $entity->cid,
       );
-      $object->link = 'node/' . $comment->nid . '#comment-' . $comment->cid;
+      $object->link = 'node/' . $entity->nid . '#comment-' . $entity->cid;
       break;
     case 'user':
-      $account = user_load($oid);
       user_build_content($account);
       $object->title = check_plain($account->name);
-      $object->uid = $oid;
-      $object->content_type = 'user';
-      $object->description = theme('user_profile', $account);
-      $object->status = $user->status;
       $object->path = array(
-        'URL' => 'user/' . $oid,
+        'URL' => 'user/' . $entity_id,
         'QUERY' => NULL,
         'BREADCRUMB' => NULL,
       );
-      $object->link = 'user/' . $oid;
+      $object->link = 'user/' . $entity_id;
       break;
   }
-  $object->reports = _abuse_load_reports($object->type, $object->oid);
-  $object->history = _abuse_load_history($object->type, $object->oid);
-  $object->warnings = _abuse_load_warnings($object->type, $object->oid);
+  $object->reports = _abuse_load_reports($object->content_type, $entity_id);
+  $object->history = _abuse_load_history($object->content_type, $entity_id);
+  $object->warnings = _abuse_load_warnings($object->content_type, $entity_id);
   return $object;
 }
 
@@ -1300,8 +1226,8 @@ function _abuse_get_tallied_count($status = array(ABUSE_LIVE)) {
  * @param <type> $oid
  * @return <type>
  */
-function _abuse_get_object_status($type, $oid) {
-  $res = db_query("SELECT status FROM {abuse_status} WHERE type = :type AND oid = :oid", array(':type' => $type, ':oid' => $oid))->fetchField();
+function _abuse_get_object_status($oid) {
+  $res = db_query("SELECT status FROM {abuse_status} WHERE oid = :oid", array(':oid' => $oid))->fetchField();
   return (empty($res)) ? 0 : $res;
 }
 
@@ -1353,40 +1279,47 @@ function _abuse_set_status($type, $oid, $status) {
   if (user_access('administer abuse reports')) {
     $assigned_to_uid = (ABUSE_SUPERADMIN == $status) ? 0 : $user->uid;
     // TODO Please convert this statement to the D7 database API syntax.
-    db_query("INSERT IGNORE INTO {abuse_status_log} (oid, type, uid, status, timestamp) " . "VALUES (:oid, :type, :uid, :status, :timestamp)", array(':oid' => $oid, ':type' => $type, ':uid' => $user->uid, ':status' => $status, ':timestamp' => REQUEST_TIME));
+    db_query(
+      "INSERT IGNORE INTO {abuse_status_log} (oid, type, uid, status, timestamp) VALUES (:oid, :type, :uid, :status, :timestamp)",
+      array(
+        ':oid' => $oid,
+        ':type' => $type,
+        ':uid' => $user->uid,
+        ':status' => $status,
+        ':timestamp' => REQUEST_TIME
+      )
+    );
   }
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("DELETE FROM {abuse_status} WHERE type='%s' AND oid=%d", $type, $oid) */
+
+  // Remove current active status.
   $query = db_delete('abuse_status')
     ->condition('type', $type)
-    ->condition('oid', $oid);
-  var_dump($query);
-  $result = $query->execute();
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("INSERT INTO {abuse_status} (type, oid, changed, status, assigned_to_uid) VALUES ('%s', %d, %d, %d, %d)", $type, $oid, REQUEST_TIME, $status, $assigned_to_uid) */
+    ->condition('oid', $oid)
+    ->execute();
+
+  // Insert fresh status.
   $query = db_insert('abuse_status')
-  ->fields(array(
-    'type' => $type,
-    'oid' => $oid,
-    'changed' => REQUEST_TIME,
-    'status' => $status,
-    'assigned_to_uid' => $assigned_to_uid,
-    ))->execute();
-  var_dump($query);
-  $id = $query->execute();
+    ->fields(array(
+      'type' => $type,
+      'oid' => $oid,
+      'changed' => REQUEST_TIME,
+      'status' => $status,
+      'assigned_to_uid' => $assigned_to_uid,
+      ))
+    ->execute();
+
+  // Comments need to update the node the belong to.
+  $nid = 0;
   if ('comment' == $type) {
-    $nid = db_query("SELECT nid FROM {comments} where cid=%d", $oid)->fetchField();
+    $nid = db_query("SELECT nid FROM {comments} where cid=:cid", array(':cid', $oid))->fetchField();
   }
   if ($nid) {
-    // TODO Please review the conversion of this statement to the D7 database API syntax.
-    /* db_query("UPDATE {node} SET changed=%d WHERE nid=%d", REQUEST_TIME, $nid) */
     $query = db_update('node')
-  ->fields(array(
-    'changed' => REQUEST_TIME,
-  ))
-  ->condition('nid', $nid);
-    var_dump($query);
-    $id = $query->execute();
+      ->fields(array(
+        'changed' => REQUEST_TIME,
+      ))
+      ->condition('nid', $nid)
+      ->execute();
   }
 }
 
@@ -1399,8 +1332,7 @@ function _abuse_set_status($type, $oid, $status) {
  */
 function _abuse_allow($type, $oid) {
   $object = _abuse_load($type, $oid);
-  $account = array_shift(user_load_multiple(array($object->uid), array('status' => 1)));
-  if ($account->uid) {
+  if ($object->uid) {
     // Re-Save the node so it can get indexed if not already done so and any other important functionality is carried out by being published
     switch ($type) {
       case 'node':
@@ -1411,33 +1343,32 @@ function _abuse_allow($type, $oid) {
         // Update the status just in case
         // TODO Please review the conversion of this statement to the D7 database API syntax.
         /* db_query("UPDATE {node} SET status=1 WHERE nid=%d", $oid) */
-        db_update('node')
-  ->fields(array(
-    'status' => 1,
-  ))
-  ->condition('nid', $oid)
-  ->execute();
+        /*db_update('node')
+          ->fields(array(
+            'status' => 1,
+          ))
+          ->condition('nid', $oid)
+          ->execute();*/
         break;
+
       case 'comment':
-        // TODO Please review the conversion of this statement to the D7 database API syntax.
-        /* db_query("UPDATE {comments} SET status=0 WHERE cid=%d", $object->oid) */
         db_update('comments')
-  ->fields(array(
-    'status' => 0,
-  ))
-  ->condition('cid', $object->oid)
-  ->execute();
+          ->fields(array(
+            'status' => 0,
+          ))
+          ->condition('cid', $object->oid)
+          ->execute();
         break;
     }
-    // TODO Please review the conversion of this statement to the D7 database API syntax.
-    /* db_query("UPDATE {abuse} SET valid=-1 WHERE type='%s' AND oid=%d", $type, $oid) */
+
+    // TODO: Changed from -1 to 0.
     db_update('abuse')
-  ->fields(array(
-    'valid' => -1,
-  ))
-  ->condition('type', $type)
-  ->condition('oid', $oid)
-  ->execute();
+      ->fields(array(
+        'valid' => 0,
+      ))
+      ->condition('type', $type)
+      ->condition('oid', $oid)
+      ->execute();
 
     _abuse_set_status($type, $oid, ABUSE_LIVE);
     _abuse_clear_oid_cache($oid);
@@ -1456,37 +1387,34 @@ function _abuse_allow($type, $oid) {
  * @param <type> $oid
  */
 function _abuse_remove($type, $oid) {
-  // TODO Please review the conversion of this statement to the D7 database API syntax.
-  /* db_query("UPDATE {abuse} SET valid=1 WHERE type='%s' AND oid=%d", $type, $oid) */
   db_update('abuse')
-  ->fields(array(
-    'valid' => 1,
-  ))
-  ->condition('type', $type)
-  ->condition('oid', $oid)
-  ->execute();
+    ->fields(array(
+      'valid' => 1,
+    ))
+    ->condition('type', $type)
+    ->condition('oid', $oid)
+    ->execute();
+
   switch ($type) {
     case 'node':
-      // TODO Please review the conversion of this statement to the D7 database API syntax.
-      /* db_query("UPDATE {node} SET status=-1 WHERE nid=%d", $oid) */
       db_update('node')
-  ->fields(array(
-    'status' => -1,
-  ))
-  ->condition('nid', $oid)
-  ->execute();
+        ->fields(array(
+          'status' => -1,
+        ))
+        ->condition('nid', $oid)
+        ->execute();
       break;
+
     case 'comment':
-      // TODO Please review the conversion of this statement to the D7 database API syntax.
-      /* db_query("UPDATE {comments} SET status=1 WHERE cid=%d", $oid) */
-      db_update('comments')
-  ->fields(array(
-    'status' => 1,
-  ))
-  ->condition('cid', $oid)
-  ->execute();
+      db_update('comment')
+        ->fields(array(
+          'status' => 1,
+        ))
+        ->condition('cid', $oid)
+        ->execute();
       break;
   }
+
   _abuse_clear_oid_cache($oid);
   _abuse_set_status($type, $oid, ABUSE_REMOVED);
 }
@@ -1510,34 +1438,42 @@ function _abuse_assign_superadmin($type, $oid) {
  * @return <type>
  */
 function _abuse_disable($type, $oid) {
-  $count = db_query("SELECT count(*) FROM {abuse} WHERE type = :type AND oid = :oid AND valid >= :valid", array(':type' => $type, ':oid' => $oid, ':valid' => 0))->fetchField();
+  $count = db_query(
+    'SELECT count(*) FROM {abuse} WHERE type = :type AND oid = :oid AND valid >= :valid',
+    array(
+      ':type' => $type,
+      ':oid' => $oid,
+      ':valid' => 0
+    )
+  )->fetchField();
+
   if (user_access('direct flag') || $count >= variable_get('abuse_threshold', 3)) {
     switch ($type) {
       case 'node':
-        // TODO Please review the conversion of this statement to the D7 database API syntax.
-        /* db_query("UPDATE {node} SET status=-1 WHERE nid=%d", $oid) */
+        // TODO: -1 is bad.
         db_update('node')
-  ->fields(array(
-    'status' => -1,
-  ))
-  ->condition('nid', $oid)
-  ->execute();
+          ->fields(array(
+            'status' => -1,
+          ))
+          ->condition('nid', $oid)
+          ->execute();
         break;
+
       case 'comment':
-        // TODO Please review the conversion of this statement to the D7 database API syntax.
-        /* db_query("UPDATE {comments} SET status=1 WHERE cid=%d", $oid) */
         db_update('comments')
-  ->fields(array(
-    'status' => 1,
-  ))
-  ->condition('cid', $oid)
-  ->execute();
+          ->fields(array(
+            'status' => 1,
+          ))
+          ->condition('cid', $oid)
+          ->execute();
         break;
     }
+
     _abuse_set_status($type, $oid, ABUSE_HIDDEN);
     _abuse_clear_oid_cache($oid);
     return TRUE;
   }
+
   return FALSE;
 }
 
