From 701fff2145cc8fff038aed419b613377f158f79c Mon Sep 17 00:00:00 2001 From: stronk7 Date: Tue, 11 May 2004 19:59:17 +0000 Subject: [PATCH] Now, concept and aliases are not linked when viewing entry itself. This will close bugs 1145 and 1295. Thanks to Petr Skoda and his patch! --- mod/glossary/lib.php | 64 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 83c6e316d4..2f9dab2420 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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('//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('//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,"$entry->concept",$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 "$alias->alias: "; - $definition = str_ireplace($alias->alias,"$alias->alias",$definition); - echo "" . format_text($definition,2) . ""; - echo "
"; - } + + //Put doNolinks (concept + aliases) enclosed by tag + $definition= preg_replace($doNolinks,'$1',$definition); + + //Restore tags + if ( $tags ) { + $definition = str_replace(array_keys($tags),$tags,$definition); } -*/ $text = format_text($definition, $entry->format); if (!empty($entry->highlight)) { -- 2.39.5