--- /home/hy0kl/www/diff/linkchecker/linkchecker.module	2008-04-10 04:38:33.000000000 +0800
+++ /home/hy0kl/www/diff/patch/linkchecker.module	2008-10-07 14:17:20.000005000 +0800
@@ -6,7 +6,7 @@
  * This module periodically check html links referenced by drupal nodes
  * Developed and maintained by Marek Tichy, marek@ecn.cz
  */
-
+define('LINKCHECKER_PAGE_SIZE', 50); //page size
 /**
  * Implementation of hook_help().
  */
@@ -34,7 +34,7 @@ function linkchecker_menu($may_cache) {
     'type' => MENU_NORMAL_ITEM, // optional
    );
   $items[] = array(
-      'path' => 'linkchecker/report'. $path,
+      'path' => 'admin/linkchecker/report'. $path, /* reset the menu*/
       'title' => t('Broken links report'),
       'callback' => 'linkchecker_report',
       'callback arguments' => array('node', $path),
@@ -49,9 +49,20 @@ function linkchecker_menu($may_cache) {
      'access' => user_access('administer linkchecker'),
      'type' => MENU_NORMAL_ITEM
   );
+  $items[] = array(
+     'path' => 'admin/linkchecker/test'. $path,
+     'title' => t('test'),
+     'callback' => 'linkchecker_get_field',
+     'callback arguments' => array('node', $path),
+     'access' => user_access('administer linkchecker'),
+     'type' => MENU_NORMAL_ITEM
+  );
   return $items;
 }
 
+/**
+ * set global variables by system form.
+ */
 function linkchecker_admin_settings() {
 
  $instruction_text = '<div>Configure Link checker core parameters.</div>';
@@ -59,28 +70,28 @@ function linkchecker_admin_settings() {
  $form['instructions'] = array('#type' => 'markup', '#value' => $instruction_text);
 
  $form['linkchecker_rebuild'] = array(
-   '#default_value' => variable_get( 'linkchecker_rebuild', 1 ),
+   '#default_value' => variable_get('linkchecker_rebuild', 1),
    '#type' => 'select',
    '#title' => t('Delete all existing reports and scheduled tasks and start linkchecker from scratch'),
    '#description' =>  t("Choose how often should linkchecker inspect all existing nodes again. Menwhile, the linkchecker operates in an incremental mode, when only newly added and updated nodes are being checked."),
    '#options'=> array("0" => t("Never"),
                       "1" => t("Next cron run"),
                  "604800" => t("Weekly"),
-                "2419200" => t("Monthly"))
+                "2419200" => t("Monthly")),
  );
 
  $form['linkchecker_fqdn_only'] = array(
-   '#default_value' => variable_get( 'linkchecker_fqdn_only', 1 ),
+   '#default_value' => variable_get('linkchecker_fqdn_only', 1),
    '#type' => 'checkbox',
    '#title' => t('Consider only fully qualified URLs ( not local links )'),
-   '#description' =>  ""
+   '#description' =>  "",
  );
 
  $form['linkchecker_ignore_responses'] = array(
-   '#default_value' => variable_get( 'linkchecker_ignore_responses', "401\n403" ),
+   '#default_value' => variable_get('linkchecker_ignore_responses', "401\n403"),
    '#type' => 'textarea',
    '#title' => t("Don't treat those response codes as errors"),
-   '#description' =>  "One per line, HTTP code only (e.g. 403) or full response string (e.g. 402 Payment Required)"
+   '#description' =>  t("One per line, HTTP code only (e.g. 403) or full response string (e.g. 402 Payment Required))"),
  );
 
  $form['linkchecker_maxtime'] = array(
@@ -89,7 +100,7 @@ function linkchecker_admin_settings() {
    '#title' => t('Maximum runtime'),
    '#size' => 50,
    '#maxlength' => 100,
-   '#description' => t('Maximum allowed time (in seconds) that can be spent on link checking every cron job run. The default value is 30 seconds. ')
+   '#description' => t('Maximum allowed time (in seconds) that can be spent on link checking every cron job run. The default value is 30 seconds.'),
  );
 
  $form['linkchecker_socket_timeout'] = array(
@@ -98,7 +109,7 @@ function linkchecker_admin_settings() {
    '#title' => t('Socket timeout (seconds)'),
    '#size' => 50,
    '#maxlength' => 100,
-   '#description' => t('If the linkchecker does not get at least some response from a remote site within the socket timeout, the link is considered broken.')
+   '#description' => t('If the linkchecker does not get at least some response from a remote site within the socket timeout, the link is considered broken.'),
  );
 
   $form['linkchecker_max_links_per_node'] = array(
@@ -107,7 +118,7 @@ function linkchecker_admin_settings() {
    '#title' => t('Max links per node'),
    '#size' => 50,
    '#maxlength' => 100,
-   '#description' => t('Set this limit if you have nodes with many links for which the link checking often takes longer than maximum runtime (you will see messages in the log files). 0 means no limit (default).')
+   '#description' => t('Set this limit if you have nodes with many links for which the link checking often takes longer than maximum runtime (you will see messages in the log files). 0 means no limit (default).'),
  );
 
  $form['linkchecker_remove_after'] = array(
@@ -116,7 +127,7 @@ function linkchecker_admin_settings() {
    '#title' => t('Days to keep reports'),
    '#size' => 50,
    '#maxlength' => 100,
-   '#description' => t('If the node is not fixed within this number of days, we remove it.')
+   '#description' => t('If the node is not fixed within this number of days, we remove it.'),
  );
 
  $form['linkchecker_give_up'] = array(
@@ -125,15 +136,59 @@ function linkchecker_admin_settings() {
    '#title' => t('Max attempts'),
    '#size' => 50,
    '#maxlength' => 100,
-   '#description' => t('If the linkchecker keeps timing out on a node, give up on it after this number of attempts.')
+   '#description' => t('If the linkchecker keeps timing out on a node, give up on it after this number of attempts.'),
  );
 
-
+  /** merge modules record*/
+  //Create the settings form
+  $form['linkchecker_batch_quantity'] = array (
+    '#type' => 'select',
+    '#title' => t('Max links to check per link field'),
+    '#description' => t('Determines the maximum number of links that will be checked for each link field per cron run. 
+						 A high number will cause cron to run slowly whereas a low number will require cron to be ran more often. 
+						'),
+    '#options' => array(1=>1, 2=>2, 5=>5, 10=>10),
+    '#default_value' => variable_get('linkchecker_batch_quantity', NULL),
+	);
+  $form['linkchecker_unpublish'] = array(
+	'#type' => 'checkbox',
+	'#title' => t('Unpublish nodes with bad links?'),
+	'#description' => t('If set to yes and node is found to have one or more links that returns a 404 error 
+		the node will be automatically unpublished'),
+	'#default_value' => variable_get('linkchecker_unpublish', NULL),
+	);
+  //check for which nodes have link fields
+  $types = array();
+  if (module_exists('content') && module_exists('link') ) {
+    $node_types = node_get_types();
+    //print_r($node_types);
+    foreach ($node_types as $type => $name) {
+      //print_r($type);
+      $fields = content_fields(NULL, $type);
+      //print_r($fields);
+      foreach ($fields as $field) {
+        if ($field['type'] === 'link') {
+          //found a node type with a link field 
+          $types[$type] = $name->name;
+        }
+      }
+    }
+    //print_r($types);
+    if (!empty($types)) {
+      $form['linkchecker_node_types'] = array(
+        '#type' => 'select',
+        '#title' => t('Select the node types to check'),
+        '#description' => t('Unselected items will not be checked for 404 errors'),
+        '#options' => $types,
+        '#default_value' => variable_get('linkchecker_node_types', NULL),
+        '#multiple' => true,
+      );
+    }
+  }
   return system_settings_form($form);
 }
 
-
-
 /**
  * Implementation of hook_perm().
  */
@@ -145,26 +200,28 @@ function linkchecker_perm() {
  * menu callback for reporting
  */
 function linkchecker_report( ) {
-
   $header = array(
-                  array('data' => t('Node'), 'field' => 'nodeid', 'sort' => 'desc'),
-                  array('data' => t('URL'), 'field' => 'url', 'sort' => 'desc'),
-                  array('data' => t('Error'), 'field' => 'response')
-                  );
+              array('data' => t('Node'), 'field' => 'nodeid', 'sort' => 'desc'),
+              array('data' => t('URL'), 'field' => 'url', 'sort' => 'desc'),
+              array('data' => t('Error'), 'field' => 'response'),
+              t('Field name'),
+            );
 
-  $result = pager_query('SELECT * FROM `linkchecker_tasks` INNER JOIN linkchecker_results ON linkchecker_tasks.taskid = linkchecker_results.taskid  '. tablesort_sql($header), 3000, 0, 'SELECT COUNT(*) `linkchecker_tasks`;');
+  $result = pager_query('SELECT lt.*, lr.*, lc.field_name FROM {linkchecker_tasks} lt INNER JOIN linkchecker_results lr ON lt.taskid = lr.taskid LEFT JOIN {linkchecker_cck} lc ON lc.tid = lt.taskid '. tablesort_sql($header), LINKCHECKER_PAGE_SIZE, 0, 'SELECT COUNT(*) FROM  {linkchecker_tasks}');
   while ($foo = db_fetch_object($result)) {
-    $rows[] = array('<a href="/node/'. $foo->nodeid .'">'. $foo->nodeid .'</a>',
+    $rows[] = array(l($foo->nodeid, 'node/'.$foo->nodeid),
                     $foo->url,
-                    $foo->response
-                    );
+                    $foo->response,
+                    $foo->field_name ? $foo->field_name : t('No match data'),
+              );
+  }
+  if (empty($rows)) {
+    $rows = linkchecker_empty_table(4);
   }
-
   drupal_set_title(check_plain($node->title));
   $output = theme('table', $header, $rows);
   $output .= theme('pager', NULL, 3000, 0);
-  print theme('page', $output, FALSE);
-
+  echo theme('page', $output, FALSE);
 }
 
 function linkchecker_debug_run() {
@@ -180,15 +237,15 @@ function linkchecker_debug_run() {
  */
 
 function linkchecker_cron() {
-  $res = db_query("SELECT * FROM `linkchecker_tasks` WHERE `taskid` = 0;");
+  $res = db_query("SELECT * FROM {linkchecker_tasks} WHERE `taskid` = 0");
   $foo = db_fetch_array($res);
   $finish = false;
-  $debug_report="Linkchecker run";
-  $lastrun = $foo["update"]?strtotime ($foo["update"]):0;
+  $debug_report = "Linkchecker run";
+  $lastrun = $foo["update"] ? strtotime($foo["update"]) : 0;
   d_("Lastrun: $lastrun");
   // Check if linkchecking process has not exceeded it's maximum run time
   $maxtime = variable_get('linkchecker_maxtime', 30);
-  if ( lc_CheckRuntime($maxtime) == false ) {
+  if (lc_CheckRuntime($maxtime) == false) {
      d_("Finishing early");
      $finish = true;
   }
@@ -197,10 +254,10 @@ function linkchecker_cron() {
    $rebuildnow = false;
    $rebuild = variable_get('linkchecker_rebuild', 1);
    if ( $rebuild ) {
-     $res = db_query("SELECT * FROM `linkchecker_tasks` WHERE taskid=0;");
+     $res = db_query("SELECT * FROM {linkchecker_tasks} WHERE taskid = 0");
      $foo = db_fetch_array($res);
      if ( empty ($foo) ) {  // the 0 record is missing, add it
-       $sql = "INSERT INTO `linkchecker_tasks` VALUES (0,".  lc_now_to_int() .",0,NOW());";
+       $sql = "INSERT INTO {linkchecker_tasks} (taskid, nodeid, status, update) VALUES (0,".  lc_now_to_int() .",0,NOW())";
        db_query($sql);
        d_("Cannot find time record, adding it: $sql.");
        $foo["status"] = 0;
@@ -216,12 +273,16 @@ function linkchecker_cron() {
        }
      }
    }
-   if ( $rebuildnow ) {
+   if ($rebuildnow) {
       d_("Completely rebuilding the table");
       watchdog( "linkchecker", t("Rebuilding the entire linkchecker database from scratch") );
-      db_query("TRUNCATE TABLE linkchecker_tasks;"); //would be nice to find a slightly less destructive way
-      db_query("TRUNCATE TABLE linkchecker_results;");
-      db_query("INSERT INTO `linkchecker_tasks` VALUES (0,".  lc_now_to_int() .",0,NOW());");
+      db_query("TRUNCATE TABLE {linkchecker_tasks}"); //would be nice to find a slightly less destructive way
+      db_query("TRUNCATE TABLE {linkchecker_results}");
+
+      /* merge module*/
+      db_query('TRUNCATE TABLE {linkchecker_cck}');
+
+      db_query("INSERT INTO {linkchecker_tasks} (taskid, nodeid, status, update) VALUES (0,".  lc_now_to_int() .",0,NOW())");
       $lastrun = 0;
       if ($rebuild == 1) { // next cron run then never
         variable_set('linkchecker_rebuild', 0);
@@ -230,17 +291,17 @@ function linkchecker_cron() {
 
  // Tasks table maintenance
  // - garbage collect
-   $maxage = time() - 24*60*60*variable_get('linkchecker_remove_after', 30);
-   d_("SELECT * FROM `linkchecker_tasks` WHERE `update` < FROM_UNIXTIME($maxage)");
-   $res = db_query("SELECT * FROM `linkchecker_tasks` WHERE `update` < FROM_UNIXTIME($maxage)");
+   $maxage = time() - 24 * 60 * 60 * variable_get('linkchecker_remove_after', 30);
+   d_("SELECT * FROM {linkchecker_tasks} WHERE `update` < FROM_UNIXTIME($maxage)");
+   $res = db_query("SELECT * FROM {linkchecker_tasks} WHERE `update` < FROM_UNIXTIME($maxage)");
    while ( $task = db_fetch_array($res) ) {
      d_("Remove aged task: $task[taskid]");
      lc_RemoveTask($task);
    }
  // Find and delete orphaned reports
-   $res = db_query("SELECT DISTINCT taskid FROM `linkchecker_results`;");
+   $res = db_query("SELECT DISTINCT taskid FROM {linkchecker_results}");
    while ( $task = db_fetch_array($res) ) {
-     $res2 = db_query("SELECT * FROM `linkchecker_tasks` WHERE `taskid` = ". $task["taskid"] .";");
+     $res2 = db_query("SELECT * FROM {linkchecker_tasks} WHERE `taskid` = ". $task["taskid"] .";");
      if ( ! db_result($res2) ) {
        d_("Remove orphaned report for task : ". $task["taskid"]);
        lc_RemoveTask($task);
@@ -248,7 +309,7 @@ function linkchecker_cron() {
    }
 
  //  - add new tasks
-    $res = db_query("SELECT * FROM `node` WHERE `changed` > '$lastrun'");
+    $res = db_query("SELECT * FROM {node} WHERE `changed` > '$lastrun'");
     $i=0;
     while ( $foo = db_fetch_array($res) ) {
       $task= array("nodeid" => $foo["nid"]);
@@ -258,7 +319,7 @@ function linkchecker_cron() {
     }
     $debug_report .= ", loaded $i new or updated nodes";
  //  - load tasks one by one and process them
-    $res = db_query("SELECT * FROM `linkchecker_tasks` WHERE `nodeid` > 0 AND `status` < 999 ORDER BY status ASC;");
+    $res = db_query("SELECT * FROM {linkchecker_tasks} WHERE `nodeid` > 0 AND `status` < 999 ORDER BY status ASC");
     $i=0;
     $j=0;
     while ( $task = db_fetch_array($res) ) {
@@ -271,6 +332,10 @@ function linkchecker_cron() {
         }
         else {
           lc_AddReport($task, $report);
+          /* merge link_checker*/
+          $task['status'] = variable_get('linkchecker_unpublish', NULL) ? 1 : 0;
+          _linkchecker_record($task);
+
           $j++;
         }
       }
@@ -282,7 +347,7 @@ function linkchecker_cron() {
           watchdog("linkchecker", "Linkchecker was unable to check node $task[nodeid] for $max_attempts times, giving up on it for good." );
         }
         else {
-          db_query("UPDATE `linkchecker_tasks` SET `status` = ". ($task["status"]+1) .", `update` = NOW() WHERE taskid = ". $task["taskid"] .";");
+          db_query("UPDATE {linkchecker_tasks} SET `status` = ". ($task["status"]+1) .", `update` = NOW() WHERE taskid = ". $task["taskid"] .";");
           watchdog("linkchecker", "Linkchecker was unable to check node ". $task["nodeid"] ." within the given maximum runtime.");
         }
         d_("Finishing early");
@@ -292,7 +357,7 @@ function linkchecker_cron() {
         break;
       }
     }
-    db_query("UPDATE `linkchecker_tasks` SET `status` = 0, `update` = NOW() WHERE taskid=0;");
+    db_query("UPDATE {linkchecker_tasks} SET `status` = 0, `update` = NOW() WHERE taskid=0");
     if (!$finish) {
       d_("Finishing properly");
       $debug_report .= ", processed $i";
@@ -330,7 +395,7 @@ function lc_DoLinkChecks($task, $maxtime
   }
   unset ($node);
   unset ($nodecontent);
- return true;
+  return true;
 }
 
 // Convert task to node ID
@@ -343,8 +408,8 @@ function lc_RemoveTask($task) {
    $tid = $task["taskid"];
    d_("Removing task $tid");
    if ( is_numeric ( $tid ) ) {
-     db_query( "DELETE FROM `linkchecker_tasks` WHERE `taskid` = $tid;" );
-     db_query( "DELETE FROM `linkchecker_results` WHERE `taskid` = $tid;" );
+     db_query("DELETE FROM {linkchecker_tasks} WHERE `taskid` = $tid");
+     db_query("DELETE FROM {linkchecker_results} WHERE `taskid` = $tid");
    }
    else {
      // Error: invalid task id
@@ -353,11 +418,11 @@ function lc_RemoveTask($task) {
 
 // Add task to the table
 function lc_PushTask($task) {
-    $res = db_query("SELECT max( taskid ) AS maxid FROM `linkchecker_tasks`");
+    $res = db_query("SELECT max( taskid ) AS maxid FROM {linkchecker_tasks}");
     $foo = db_fetch_array($res);
     $newid = $foo["maxid"]?$foo["maxid"]+1:1;
     // Have we seen and processed this node ? If yes, delete it first
-    $res = db_query("SELECT * FROM `linkchecker_tasks` where `status` = 999 AND `nodeid` = $task[nodeid]");
+    $res = db_query("SELECT * FROM {linkchecker_tasks} where `status` = 999 AND `nodeid` = $task[nodeid]");
     $foo = db_fetch_array($res);
     $taskid =  $foo["taskid"];
     if ( $taskid ) {
@@ -365,16 +430,16 @@ function lc_PushTask($task) {
       d_("Removing task $taskid and it's reports since node $task[nodeid] has been updated");
     }
     // Push task into a queue for (re)checking
-    db_query( "INSERT INTO `linkchecker_tasks` ( `taskid` , `nodeid` , `status` , `update` )
-                VALUES ($newid, $task[nodeid], '0', NOW( ));");
+    db_query( "INSERT INTO {linkchecker_tasks} (`taskid` , `nodeid` , `status` , `update`)
+                VALUES ($newid, $task[nodeid], '0', NOW( ))");
 }
 
 function lc_AddReport($task, $report) {
-   db_query("DELETE FROM `linkchecker_results` WHERE `taskid` = ". $task["taskid"] .";");
+   db_query("DELETE FROM {linkchecker_results} WHERE `taskid` = ". $task["taskid"]);
    foreach ($report as $r) {
-      db_query("INSERT INTO `linkchecker_results` VALUES ('". $task["taskid"] ."','". $r["url"] ."','". $r["response"] ."');");
+      db_query("INSERT INTO {linkchecker_results} VALUES ('". $task["taskid"] ."','". $r["url"] ."','". $r["response"] ."')");
    }
-   db_query("UPDATE `linkchecker_tasks` SET `status` = 999, `update` = NOW() WHERE taskid = ". $task["taskid"] .";");
+   db_query("UPDATE {linkchecker_tasks} SET `status` = 999, `update` = NOW() WHERE taskid = ". $task["taskid"]);
 }
 
 // Checks how long we have been running, if runtime is 0 (not running) it starts counting and returns true, if we have exceeded maxtime it stops counting and returns false
@@ -387,17 +452,17 @@ function lc_CheckRuntime($maxtime) {
      status  - 1 - running, 0 - not running
      update  - timestamp of the last start
    */
-   $res = db_query("SELECT * FROM `linkchecker_tasks` WHERE taskid=0;");
+   $res = db_query("SELECT * FROM {linkchecker_tasks} WHERE taskid=0");
    $foo = db_fetch_array($res);
    if ( empty ($foo) ) {  // the 0 record is missing, add it
-      $sql = "INSERT INTO `linkchecker_tasks` VALUES (0,".  lc_now_to_int() .",0,NOW());";
+      $sql = "INSERT INTO {linkchecker_tasks} VALUES (0,".  lc_now_to_int() .",0,NOW())";
       db_query($sql);
       d_("Cannot find time record, adding it: $sql.");
       $foo["status"] = 0;
    }
    if ( ( $foo["status"] ) == 0 ) { // not running yet
       d_("Setting the process state to 1 (running)");
-      db_query("UPDATE `linkchecker_tasks` SET `status` = 1, `update` = NOW() WHERE taskid=0;");
+      db_query("UPDATE {linkchecker_tasks} SET `status` = 1, `update` = NOW() WHERE taskid=0");
       $time = 0;
    }
    else { // has been running for a while, check time
@@ -411,7 +476,7 @@ function lc_CheckRuntime($maxtime) {
    }
    else {
       d_("No time left, switching to state 0 (not running)");
-      db_query("UPDATE `linkchecker_tasks` SET `status` = 0, `update` = NOW() WHERE taskid=0;");
+      db_query("UPDATE {linkchecker_tasks} SET `status` = 0, `update` = NOW() WHERE taskid=0");
       $ret = false;
    }
    return $ret;
@@ -433,12 +498,12 @@ function lc_GetUrls( $html ) {
   @iex", $html, $matches);
   $links = array();
   $ret = $matches[5];
-  for ($i=0;isset($ret[$i]);$i++) {
+  for ($i=0; isset($ret[$i]); $i++) {
      if (preg_match("|^http://(.*)|i", $ret[$i])) {
       $links[] = $ret[$i];
      }
      elseif (preg_match("|^/(.*)|i", $ret[$i])) {
-      if ( variable_get( 'linkchecker_fqdn_only', 1 ) == 0 )
+      if (variable_get('linkchecker_fqdn_only', 1) == 0)
         $links[] = "http://". $_SERVER["SERVER_NAME"] ."". $ret[$i];
      }
   }
@@ -475,15 +540,15 @@ function lc_GetHeaders($url) {
 
   // Opens socket
 
-  $fp    = @fsockopen( $info["host"], 80, $errno, $errstr, variable_get('linkchecker_socket_timeout', 3) );
+  $fp = @fsockopen( $info["host"], 80, $errno, $errstr, variable_get('linkchecker_socket_timeout', 3));
   // Makes sure the socket is open or returns false
-  if ( !$fp ) {
+  if (!$fp) {
      return false;
   }
   else {
 
      // Checks the path is not empty
-     if ( empty( $info["path"] ) ) {
+     if (empty( $info["path"])) {
 
         // If it is empty it fills it
         $info["path"] = "/";
@@ -491,7 +556,7 @@ function lc_GetHeaders($url) {
      $query = "";
 
      // Checks if there is a query string in the url
-     if ( isset( $info["query"] ) ) {
+     if (isset($info["query"])) {
 
           // If there is a query string it adds a ? to the front of it
           $query = "?". $info["query"] ."";
@@ -557,7 +622,9 @@ function lc_GetResponse($url) {
 function lc_RandReduce($urls) {
    $maxtime = variable_get('linkchecker_maxtime', 30);
    $timeout = variable_get('linkchecker_socket_timeout', 3);
-   if ( $timeout < 1 ) $timeout = 1;
+   if ($timeout < 1) {
+      $timeout = 1;
+   }
    $maxlinks = variable_get('linkchecker_max_links_per_node', 0);
    $newurls = array();
    srand((double) microtime() * 10000000);
@@ -596,10 +663,121 @@ function lc_int_to_age($when) {
 
 function lc_ignore_response ($response, $code) {
   $ignored = split ("\n",variable_get('linkchecker_ignore_responses', ""));
-  var_dump($ignored);
+  //var_dump($ignored);
   foreach ($ignored as $i)  {
     if ($code == trim($i)) return true;
     if ($response == trim($i)) return true;
   }
   return false;
 }
+
+/*------------------functions from link_checker--------------------------------*/
+/** merge*/
+// get field name by nid
+function linkchecker_get_field($nid) {
+  //$nid = 21;
+  if (module_exists('content') && module_exists('link')) {
+    //$node_types  = variable_get('linkchecker_node_types', NULL);
+    //print_r($node_types);
+    $node = node_load($nid);
+    //foreach ($node_types as $node) {
+    $fields = content_fields(NULL, $node->type/*$type*/);
+    //print_r($fields);
+    foreach ($fields as $field) {
+      //print_r($field);
+      if ($field['type'] == 'link') {
+          //We're at the link field type if its multiple we'll query the link table directly 
+          //otherwise we'll query the node type table directly
+          if ($field['multiple'] == 1) {
+            $table_name = "content_". $field['field_name'];
+            $field_name = $field['field_name']. "_url";
+            $max = variable_get('linkchecker_batch_quantity', 10);
+            $sql = "SELECT c.nid, c.vid, c.delta, c.$field_name as link
+              FROM {$table_name} c 
+              LEFT JOIN {linkchecker_cck} lc ON c.nid = lc.nid && c.vid = lc.vid && c.delta = lc.delta  
+              WHERE c.nid = %d
+          ";
+          $links = db_query($sql, $nid);
+          while ($link = db_fetch_object($links)) {
+            //send over to _link_checker_check_status to update the status in the DB
+            $link->field_name = $field_name;
+            //print_r($link);
+            return $link;
+          }
+        }
+        else {
+          //It is a field on the node type table
+          $table_name = "content_type_". $node->type;
+          $field_name = $field['field_name']. "_url";
+          $max = variable_get('linkchecker_batch_quantity', NULL);
+          $sql = "SELECT c.nid, c.vid
+            FROM {$table_name} c 
+            LEFT JOIN {linkchecker_cck} lc ON c.nid = lc.nid && c.vid = lc.vid
+            WHERE c.nid = %d
+          ";
+          $links = db_query($sql, $nid);
+          while ($link = db_fetch_object($links)) {
+            //send over to _link_checker_check_status to update the status in the DB
+            $link->field_name = $field_name;
+            //print_r($link);
+            return $link;
+          }
+          return false;
+        }
+      }	//if field['type']
+    } //foreach fields as field	
+    //} //foreach node_types as node
+  }else {
+    return false;
+  }
+}
+
+/*
+ * Checks the link for a status
+*/
+function linkchecker_check_record($link, $status = 0) {
+  // tell the db what we have discovered...
+  //First we need to check if there is an existing row 
+  $sql = "SELECT lc.nid, lc.delta, lc.vid 
+		  FROM {linkchecker_cck} lc
+		  WHERE lc.nid = %d && lc.vid = %d && lc.delta = %d && lc.field_name = '%s' LIMIT 1";
+		
+  if (db_num_rows(db_query($sql, $link->nid, $link->vid, $link->delta, $link->field_name)) > 0) {
+   //row exist so we'll update it.  
+   $sql = "UPDATE {linkchecker_cck} lc
+			SET status = '%s', last_checked = NOW(), tid = %d
+			WHERE lc.nid = %d && lc.vid = %d && lc.delta = %d && lc.field_name = '%s'
+		   ";
+	db_query($sql, $status, $link->tid, $link->nid, $link->vid, $link->delta, $link->field_name);
+  }
+  else {
+	//row doesn't exist so we'll add it in
+	$sql = "INSERT INTO {linkchecker_cck} (nid, vid, delta, last_checked, status, field_name, tid) 
+	        VALUES (%d, %d, %d, NOW(), '%s', '%s', %d) ";
+	db_query($sql, $link->nid, $link->vid, $link->delta, $status, $link->field_name, $link->tid);
+  }
+
+  // unpublish and force the node into the moderation queue 
+  if ((int)$status) {
+	//The user would like all errors above 300 unpublished.. ok we'll do that. 
+    db_query("UPDATE {node} SET status = 0, moderate = 1 WHERE nid = %d", $link->nid);
+  }
+}
+
+function _linkchecker_record($task) {
+  $nid = lc_Task2Nid($task);
+  $link = linkchecker_get_field($nid);
+  if ($link) {
+    $link->tid = $task['taskid'];
+    linkchecker_check_record($link, $task['status']);
+  }
+}
+
+/*
+ * when the table rows is empty, set the default data.
+ */
+function linkchecker_empty_table($colspan = 4, $message = 'No match data!') {
+  $rows = array();
+  $rows[] = array(array('data' => t($message), 'colspan' => $colspan, 'align' => 'center'));
+  return $rows;
+}
\ No newline at end of file
