--- freelinking.module.old	2007-12-27 23:03:30.000000000 +0100
+++ freelinking.module	2007-12-27 23:03:19.827555611 +0100
@@ -51,10 +51,10 @@ function freelinking_page($thetitle = NU
         $rows[$i][] = '<a class="freelink" href="' . $freelink->path . '">' . $flpair->path . '</a>';
       }
       else { // a freelink
-        $fltargetnid = _freelinking_exists($freelink->phrase);
+        $fltargetnpath = _freelinking_exists($freelink->phrase);
         $freelink = _freelinking_make_link($freelink->phrase);
         if ($fltargetnid) {
-          $link = l(t('see this content'), drupal_get_path_alias('node/' . $fltargetnid));
+          $link = l(t('see this content'), $fltargetnpath);
         }
         else { // content not found, show link to create
           $link = '<a href=' . url($freelink['path'], $freelink['args']) . '>' . t('create this content') . '</a>';
@@ -327,16 +327,33 @@ function _freelinking_exists($thetitle) 
   while ($node = db_fetch_object($result)) { // only one, I hope... what if there's more than one?
     $nid = $node->nid;
   }
-  return (empty($nid) ? 0 : $nid);
+  if (!empty($nid)) {
+    return drupal_get_path_alias('node/' . $nid);
+  }
+
+  $query = "SELECT dst FROM {url_alias} WHERE dst = '%s'";
+  $noderestrict = variable_get('freelinking_restriction', 'none');
+//    if ($noderestrict != 'none') { // need to add the where clause
+//      $query .= " AND type = '%s'";
+//      $result = db_query($query, $title, $noderestrict);
+//    }
+//    else { // no restriction. query is fine but db_query doesn't need the extra argument
+    $result = db_query($query, $title);
+//    }
+// FIXME ***
+    while ($node = db_fetch_object($result)) { // only one, I hope... what if there's more than one?
+      $dst = $node->dst;
+    }
+  return (empty($dst) ? 0 : $dst);
 }
 
 
 function _freelinking_make_link($thetitle) { // helper function for freelinking_page
   global $user;
   // Returns a link to a node named $thetitle if found, or a link to new content otherwise.
-  $nid = _freelinking_exists($thetitle); 
-  if ($nid) { // the node exists, set the path to go there
-    $freelink['path'] = 'node/' . $nid;
+  $npath = _freelinking_exists($thetitle); 
+  if ($npath) { // the node exists, set the path to go there
+    $freelink['path'] = $npath;
   }
   else { // node doesn't exist, set path to create it
     switch (variable_get('freelinking_notfound', 'no access search')) {
