]> git.mjollnir.org Git - moodle.git/commitdiff
Now, concept and aliases are not linked when
authorstronk7 <stronk7>
Tue, 11 May 2004 19:59:17 +0000 (19:59 +0000)
committerstronk7 <stronk7>
Tue, 11 May 2004 19:59:17 +0000 (19:59 +0000)
viewing entry itself. This will close bugs 1145 and 1295.
Thanks to Petr Skoda and his patch!

mod/glossary/lib.php

index 83c6e316d421b2671ffd78438068217375a0b07f..2f9dab242099325ff04b97b3ee5bd323629d9892 100644 (file)
@@ -468,51 +468,45 @@ function  glossary_print_entry_concept($entry) {
 }
 
 function glossary_print_entry_definition($entry) {
+
     $definition = $entry->definition;
 
-    //getting ride of A tags
-    $links = array();
-    preg_match_all('/<img (.+?)>/is',$definition,$list_of_links);
+    $tags = array();
 
-    foreach (array_unique($list_of_links[0]) as $key=>$value) {
-        $links['<@'.$key.'@>'] = $value;
-    }
-    if ( $links ) {
-        $definition = str_replace($links,array_keys($links),$definition);
+    //Calculate all the strings to be no-linked
+    //First, the concept
+    $term = preg_quote(trim($entry->concept));
+    $pat = '/('.$term.')/is';
+    $doNolinks[] = $pat;
+    //Now the aliases
+    if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) {
+        foreach ($aliases as $alias) {
+            $term = preg_quote(trim($alias->alias));
+            $pat = '/('.$term.')/is';
+            $doNolinks[] = $pat;
+        }
     }
 
-    //getting ride of IMG tags
-    $images = array();
-    preg_match_all('/<A (.+?)>/is',$definition,$list_of_images);
+    //Extract all tags from definition
+    preg_match_all('/(<.*?>)/is',$definition,$list_of_tags);
 
-    foreach (array_unique($list_of_images[0]) as $key=>$value) {
-        $images['<@'.$key.'@>'] = $value;
-    }
-    if ( $images ) {
-        $definition = str_replace($images,array_keys($images),$definition);
+    //Save them into tags array to use them later
+    foreach (array_unique($list_of_tags[0]) as $key=>$value) {
+        $tags['<@'.$key.'@>'] = $value;
     }
-        
-    $definition = str_ireplace($entry->concept,"<nolink>$entry->concept</nolink>",$definition);
 
-    //restoring A tags
-    if ( $links ) {
-        $definition = str_replace(array_keys($links),$links,$definition);
+    //Take off every tag from definition
+    if ( $tags ) {
+        $definition = str_replace($tags,array_keys($tags),$definition);
     }
-
-    //restoring IMG tags
-    if ( $images ) {
-        $definition = str_replace(array_keys($images),$images,$definition);
-    }
-
-/*    if ( $aliases = get_records("glossary_alias","entryid",$entry->id) ) {
-        foreach ($aliases as $alias) {
-        echo "<small><font color=red>$alias->alias: ";
-            $definition = str_ireplace($alias->alias,"<nolink>$alias->alias</nolink>",$definition);
-            echo "<b>" . format_text($definition,2) . "</b>";
-        echo "</font></small><br>";
-        }
+    
+    //Put doNolinks (concept + aliases) enclosed by <nolink> tag
+    $definition= preg_replace($doNolinks,'<nolink>$1</nolink>',$definition);
+        
+    //Restore tags
+    if ( $tags ) {
+        $definition = str_replace(array_keys($tags),$tags,$definition);
     }
-*/
 
     $text = format_text($definition, $entry->format);
     if (!empty($entry->highlight)) {