# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /Users/OMerida/vhosts/dcunited2.com/html/sites/all/modules/glossify
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: glossify.module
--- glossify.module Base (BASE)
+++ glossify.module Locally Modified (Based On LOCAL)
@@ -316,6 +316,8 @@
  * Implementation of hook_filter().
  */
 function glossify_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
+  static $configurations;
+
   switch ($op) {
     case 'list':
       return array(0 => t('Glossify filter'));
@@ -327,26 +329,37 @@
       return $text;
 
     case 'process':
+      // TODO: option should be to only do this on a node page
+      // or have a list of paths where this filter will not be invoked
       if (($node = menu_get_object()) == NULL) {
         $q = db_query("SELECT nid FROM {node_revisions} WHERE '%s'=CONCAT(format, ':', MD5(body))", $cache_id);
         $r = db_fetch_object($q);
+        if ($r->nid) {
         $node = node_load($r->nid);
+        } else {
+          return;
       }
+      }
+      
+      if (!isset($configurations)) {
       $configurations = variable_get('glossify_configurations', array());
+      }      
+
       $html_body = str_get_html($text);
       foreach ($configurations as $config_name => $configuration) {
-        if (in_array($node->type, $configuration['from'])) {
+        if (isset($configuration['from'][$node->type])) {
+          $enabled_styles = array_filter($configuration['style']);          
           foreach (_fetch_possible_keywords($configuration, $node->nid) as $term_title => $target_url) {
-            foreach ($configuration['style'] as $style => $enabled) {
-              if ($enabled) {
+            $replaced = 0;
+            foreach ($enabled_styles as $style => $enabled) {
+              if ($enabled && false !== strpos($html_body, $term_title)) {
                 if (isset($old_body) && $old_body !== $html_body->innertext) {
                   $html_body = str_get_html($html_body->innertext);
                 }
                 
                 $replacement = _fetch_replacement($style, $term_title, $target_url);
-                $old_body = $html_body->innertext;
-                $replaced = 0;
                 _glossify_replace($configuration, $html_body, $term_title, $replacement, $replaced);
+                $old_body = $html_body->innertext;
               }
             }
           }
@@ -371,7 +384,8 @@
   }
   else {
     if (isset($html->tag) && $html->tag !== 'root') {
-      if ($configuration['only_first'] && $replaced == 0) {
\ No newline at end of file
+      if (0 == $replaced) {
+        $temp_replaced = 0;
\ No newline at end of file
         if ($configuration['break']) {
           $html->innertext = preg_replace('/\b'.$term_title.'\b/', $replacement, $html->innertext, ($configuration['only_first'] ? 1 : -1), $temp_replaced);
         }
