Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding <span class="nolink"> filter. It doesn't break in editor.

  • Loading branch information...
commit d00ffdf949cc080ebef075cc79e9179a6c693af8 1 parent 14d6c23
authored

Showing 1 changed file with 21 additions and 6 deletions. Show diff stats Hide diff stats

  1. 27  mod/glossary/filter.php
27  mod/glossary/filter.php
@@ -16,7 +16,7 @@ function glossary_filter($courseid, $text) {
16 16
             case 'mysql':
17 17
                 $as = '';
18 18
                 break;
19  
-        }    
  19
+        }
20 20
 
21 21
         $glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or globalglossary != 0)","globalglossary, id");
22 22
         if ( $glossarieslist ) {
@@ -25,7 +25,7 @@ function glossary_filter($courseid, $text) {
25 25
                 $glossaries .= "$glossary->id,";
26 26
             }
27 27
             $glossaries=substr($glossaries,0,-1);
28  
-///         sorting by the lenght of the concept in order to assure that large concepts 
  28
+///         sorting by the lenght of the concept in order to assure that large concepts
29 29
 ///            could be linked first, if they exist in the text to parse
30 30
             switch ($CFG->dbtype) {
31 31
                 case "postgres7":
@@ -38,7 +38,7 @@ function glossary_filter($courseid, $text) {
38 38
                     $cbylenght = "";
39 39
                 break;
40 40
             }
41  
-            
  41
+
42 42
             $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink != 0 and approved != 0 and concept != ''","$ebylenght glossaryid","id,glossaryid, concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY $as category,fullmatch");
43 43
             $categories  = get_records_select("glossary_categories", "glossaryid IN ($glossaries) AND usedynalink != 0", "$cbylenght glossaryid","id,glossaryid, name $as concept, 1 $as casesensitive,$GLOSSARY_CONCEPT_IS_CATEGORY $as category, 1 $as fullmatch");
44 44
             if ( $entries and $categories ) {
@@ -52,7 +52,7 @@ function glossary_filter($courseid, $text) {
52 52
 
53 53
             if ( isset($concepts) ) {
54 54
                 $lastglossary = 0;
55  
-                $lastcategory = 0;                
  55
+                $lastcategory = 0;
56 56
                 $cm = '';
57 57
                 foreach ( $concepts as $concept ) {
58 58
                     if ( $concept->category ) {
@@ -111,7 +111,7 @@ function glossary_filter($courseid, $text) {
111 111
 
112 112
         return $text;
113 113
     }
114  
-    
  114
+
115 115
     function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "</a>",$casesensitive,$fullmatch) {
116 116
 
117 117
         $list_of_words_cp = strip_tags($concept);
@@ -155,6 +155,18 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
155 155
             $text = str_replace($excludes,array_keys($excludes),$text);
156 156
         }
157 157
 
  158
+        //Now avoid searching inside the <span class="nolink">tag
  159
+        // This style doesn't break in editor. See bug #2428
  160
+        $nolinkspan = array();
  161
+        preg_match_all('/<span class=\"nolink\">(.+?)<\/span>/is',$text,$list_of_span);
  162
+        foreach (array_unique($list_of_span[0]) as $key=>$value) {
  163
+            $nolinkspan['<%'.$key.'%>'] = $value;
  164
+        }
  165
+
  166
+        if (!empty($nolinkspan)) {
  167
+            $text = str_replace($nolinkspan,array_keys($nolinkspan),$text);
  168
+        }
  169
+
158 170
         //Now avoid searching inside links
159 171
         $links = array();
160 172
         preg_match_all('/<a[\s](.+?)>(.+?)<\/A>/is',$text,$list_of_links);
@@ -192,12 +204,15 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
192 204
         if (!empty( $excludes)) {
193 205
             $text = str_replace(array_keys($excludes),$excludes,$text);
194 206
         }
  207
+        if (!empty( $nolinkspan)) {
  208
+            $text = str_replace(array_keys($nolinkspan),$nolinkspan,$text);
  209
+        }
195 210
         if ($fullmatch and !empty($words)) {
196 211
             $text = str_replace(array_keys($words),$words,$text);
197 212
         }
198 213
         return $text;
199 214
     }
200  
-    
  215
+
201 216
     function glossary_sort_entries_by_length ( $entry0, $entry1 ) {
202 217
         if ( strlen(trim($entry0->concept)) < strlen(trim($entry1->concept)) ) {
203 218
             return 1;

0 notes on commit d00ffdf

Please sign in to comment.
Something went wrong with that request. Please try again.