--- ORIG/freelinking/freelinking.module 2007-02-17 06:47:39.000000000 -0600
+++ ./freelinking.module        2007-08-29 12:42:08.000000000 -0500
@@ -52,8 +52,8 @@
       }
       else { // a freelink
-        $fltargetnid = _freelinking_exists($freelink->phrase);
+        $fltargeturl = _freelinking_exists($freelink->phrase);
         $freelink = _freelinking_make_link($freelink->phrase);
-        if ($fltargetnid) {
-          $link = l(t('see this content'), drupal_get_path_alias('node/' . $fltargetnid));
+        if ($fltargeturl) {
+          $link = l(t('see this content'), drupal_get_path_alias( $fltargeturl));
         }
         else { // content not found, show link to create
@@ -150,7 +150,9 @@
     '#title' => t('Restrict free links to this content type'),
     '#type' => 'select',
-    '#options' => array_merge(array('none' => t('No restrictions')), node_get_types('names')),
+    '#multiple' => TRUE,
+    '#size' => 5,
+    '#options' => array_merge(array('none' => t('No restrictions'), 'VIEWS' => 'Views'), node_get_types('names')),
     '#default_value' => variable_get("freelinking_restriction", 'none'),
-    '#description' => t('If desired, you can restrict the freelinking title search to just content of this type. Note that if it is not the same as the "Default for new content," above, new freelinked content cannot be found.')
+    '#description' => t('If desired, you can restrict the freelinking title search to just content of this type. Note that if it does not include the same as the "Default for new content," above, new freelinked content cannot be found.')
   );
   $form["freelinking_camelcase"] = array(
@@ -315,18 +317,34 @@
   // looks through the db for nodes matching $title. Returns the nid if such a node exists, otherwise, returns 0
   $title = urldecode($thetitle);
-  $query = "SELECT nid FROM {node} WHERE title = '%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);
+  # AWG also view-titles
+  # titles can be in several places:
+  #     {node}.title, {view_view}.page_title
+  $query = "SELECT nid,null as url FROM {node} WHERE title = '%s'";
+  $noderestrict = variable_get('freelinking_restriction', array('[none]' => 'none'));
+
+  $query_args[] = $title;
+  $restriction_count = count($noderestrict);
+  if ($restriction_count > 0 && $noderestrict[0] != 'none') { // need to add the where clause
+    $in_list = rtrim( str_repeat("'%s',",$restriction_count), ','); # repeat '%s', but trim the trailing ','
+    $query .= " AND type in ($in_list)";
+    # may have extraneous 'VIEWS' in restrict list
+    $query_args = array_merge($query_args, $noderestrict);
   }
+  if ($restriction_count == 0 || $noderestrict[0] == 'none' || array_search('VIEWS',$noderestrict) !== FALSE) {
+    $query .= " UNION SELECT null as nid, url from {view_view} where page_title ='%s'";
+    $query_args[] = $title;
+    }
+  $result = db_query($query, $query_args);
 // FIXME ***
+  # this gets last object found
+  $url = '';
   while ($node = db_fetch_object($result)) { // only one, I hope... what if there's more than one?
-    $nid = $node->nid;
+    $url =
+        ($node->nid != null)
+        ? "node/".$node->nid
+        : $node->url;
   }
-  return (empty($nid) ? 0 : $nid);
+  # FIXME: use {url_alias} if possible
+  return $url;
 }

@@ -335,7 +353,7 @@
   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;
+  $url = _freelinking_exists($thetitle);
+  if ($url) { // the node exists, set the path to go there
+    $freelink['path'] = $url;
   }
   else { // node doesn't exist, set path to create it

