# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- ckeditor_link.module
+++ ckeditor_link.module
@@ -21,7 +21,7 @@
  * Implementation of hook_perm().
  */
 function ckeditor_link_perm() {
-  return array('access ckeditor link');
+  return array('access ckeditor link', 'administer ckeditor link');
 }
 
 /**
@@ -33,6 +33,13 @@
     'access arguments' => array('access ckeditor link'),
     'type' => MENU_CALLBACK,
   );
+  $items['admin/settings/ckeditor_link'] = array(
+    'title' => 'CKEditor link',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('ckeditor_link_settings_form'),
+    'access arguments' => array('administer ckeditor link'),
+    'type' => MENU_NORMAL_ITEM,
+  );
   return $items;
 }
 
@@ -40,8 +47,17 @@
   $matches = array();
 
   if ($string !== '') {
-    $sql = db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.title LIKE '%%%s%%' ORDER BY n.title, n.type");
-    $result = db_query_range($sql, array($string), 0, 10);
+    $where = "n.title LIKE '%%%s%%'";
+    $args = array($string);
+    
+    $node_types = array_keys(array_filter(variable_get('ckeditor_link_exclude_ct', array())));
+    if($node_types) {
+      $where .= ' AND n.type NOT IN(' . db_placeholders($node_types, 'text') . ')';
+      $args = array_merge($args, $node_types);
+    }
+    
+    $sql = db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE $where ORDER BY n.title, n.type");
+    $result = db_query_range($sql, $args, 0, 10);
     while ($node = db_fetch_object($result)) {
       $matches[$node->title .' (node/'. $node->nid. ')'] = '<div class="reference-autocomplete">'. check_plain($node->title) .'</div>';
     }
@@ -50,6 +66,21 @@
   drupal_json($matches);
 }
 
+function ckeditor_link_settings_form(&$form_state) {
+  $form = array();
+
+  $node_types = node_get_types('names');
+
+  $form['ckeditor_link_exclude_ct'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Exclude these node types from autocomplete widget'),
+      '#options' => $node_types,
+      '#default_value' => variable_get('ckeditor_link_exclude_ct', array())
+  );
+
+  return system_settings_form($form);
+}
+
 /**
  * Implementation of hook_form_alter().
  */
