Skip to content

Commit

Permalink
MDL-17164: Glossary autolinking doesn't work for entries similar to c…
Browse files Browse the repository at this point in the history
…urrent entry
  • Loading branch information
sam_marshall committed Nov 12, 2008
1 parent 6995ba7 commit 2232f4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 86 deletions.
11 changes: 11 additions & 0 deletions mod/glossary/filter.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ function glossary_filter($courseid, $text) {


$conceptlist = filter_remove_duplicates($conceptlist); $conceptlist = filter_remove_duplicates($conceptlist);
} }

global $GLOSSARY_EXCLUDECONCEPTS;
if(!empty($GLOSSARY_EXCLUDECONCEPTS)) {
$reducedconceptlist=array();
foreach($conceptlist as $concept) {
if(!in_array($concept->phrase,$GLOSSARY_EXCLUDECONCEPTS)) {
$reducedconceptlist[]=$concept;
}
}
return filter_phrases($text, $reducedconceptlist);
}


return filter_phrases($text, $conceptlist); // Actually search for concepts! return filter_phrases($text, $conceptlist); // Actually search for concepts!
} }
Expand Down
93 changes: 7 additions & 86 deletions mod/glossary/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -699,101 +699,18 @@ function glossary_print_entry_definition($entry) {
$ttpresent = false; $ttpresent = false;
} }


$links = array(); global $GLOSSARY_EXCLUDECONCEPTS;
$tags = array();
$urls = array();
$addrs = array();


//Calculate all the strings to be no-linked //Calculate all the strings to be no-linked
//First, the concept //First, the concept
$term = preg_quote(trim($entry->concept),'/'); $GLOSSARY_EXCLUDECONCEPTS=array($entry->concept);
$pat = '/('.$term.')/is';
$doNolinks[] = $pat;
//Now the aliases //Now the aliases
if ( $aliases = get_records('glossary_alias','entryid',$entry->id) ) { if ( $aliases = get_records('glossary_alias','entryid',$entry->id) ) {
foreach ($aliases as $alias) { foreach ($aliases as $alias) {
$term = preg_quote(trim($alias->alias),'/'); $GLOSSARY_EXCLUDECONCEPTS[]=trim($alias->alias);
$pat = '/('.$term.')/is';
$doNolinks[] = $pat;
} }
} }



//Extract <a>..><a> tags from definition
preg_match_all('/<a\s[^>]+?>(.*?)<\/a>/is',$definition,$list_of_a);

//Save them into links array to use them later
foreach (array_unique($list_of_a[0]) as $key=>$value) {
$links['<#'.$key.'#>'] = $value;
}
//Take off every link from definition
if ( $links ) {
$definition = str_replace($links,array_keys($links),$definition);
}


//Extract all tags from definition
preg_match_all('/(<.*?>)/is',$definition,$list_of_tags);

//Save them into tags array to use them later
foreach (array_unique($list_of_tags[0]) as $key=>$value) {
$tags['<@'.$key.'@>'] = $value;
}
//Take off every tag from definition
if ( $tags ) {
$definition = str_replace($tags,array_keys($tags),$definition);
}


//Extract all URLS with protocol (http://domain.com) from definition
preg_match_all('/([[:space:]]|^|\(|\[)([[:alnum:]]+):\/\/([^[:space:]]*)([[:alnum:]#?\/&=])/is',$definition,$list_of_urls);

//Save them into urls array to use them later
foreach (array_unique($list_of_urls[0]) as $key=>$value) {
$urls['<*'.$key.'*>'] = $value;
}
//Take off every url from definition
if ( $urls ) {
$definition = str_replace($urls,array_keys($urls),$definition);
}


//Extract all WEB ADDRESSES (www.domain.com) from definition
preg_match_all('/([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?\/&=])/is',$definition,$list_of_addresses);

//Save them into addrs array to use them later
foreach (array_unique($list_of_addresses[0]) as $key=>$value) {
$addrs['<+'.$key.'+>'] = $value;
}
//Take off every addr from definition
if ( $addrs ) {
$definition = str_replace($addrs,array_keys($addrs),$definition);
}


//Put doNolinks (concept + aliases) enclosed by <nolink> tag
$definition= preg_replace($doNolinks,'<span class="nolink">$1</span>',$definition);

//Restore addrs
if ( $addrs ) {
$definition = str_replace(array_keys($addrs),$addrs,$definition);
}

//Restore urls
if ( $urls ) {
$definition = str_replace(array_keys($urls),$urls,$definition);
}

//Restore tags
if ( $tags ) {
$definition = str_replace(array_keys($tags),$tags,$definition);
}

//Restore links
if ( $links ) {
$definition = str_replace(array_keys($links),$links,$definition);
}

$options = new object(); $options = new object();
$options->para = false; $options->para = false;
$options->trusttext = true; $options->trusttext = true;
Expand All @@ -806,6 +723,10 @@ function glossary_print_entry_definition($entry) {
} }


$text = format_text($definition, $entry->format, $options); $text = format_text($definition, $entry->format, $options);

// Stop excluding concepts from autolinking
unset($GLOSSARY_EXCLUDECONCEPTS);

if (!empty($entry->highlight)) { if (!empty($entry->highlight)) {
$text = highlight($entry->highlight, $text); $text = highlight($entry->highlight, $text);
} }
Expand Down

0 comments on commit 2232f4f

Please sign in to comment.