Permalink
Browse files

Case sensitive match

Whole words match
No match at all (a bit rude (you have to get down to the HTML code), no GUI so far either)
Categories are now linked too (I forced to be a case sensitive match)
You can automatically link one or several glossaries at once no matter if it is a main one or not.
  • Loading branch information...
1 parent 09c3588 commit dc36351d8ba7eb55a64ebd3cecd304555e94dd6a willcast committed Oct 16, 2003
View
@@ -12,6 +12,7 @@
$string['areyousuredeletecomment'] = "Are you sure you want to delete this comment?";
$string['attachment'] = "Attachment";
$string['back'] = "Back";
+$string['casesensitive'] = "This entry is<br>case sensitive";
$string['categories'] = "Categories";
$string['categoryview'] = "Browse by category";
$string['category'] = "Category";
@@ -41,12 +42,14 @@
$string['entry'] = "Entry";
$string['entryalreadyexist'] = "Entry already exists";
$string['entrydeleted'] = "Entry deleted";
+$string['entryusedynalink'] = "This entry should be<br>automatically linked";
$string['entryexported'] = "Entry succesfully exported";
$string['explainspecial'] = "Shows entries that do not begin with a letter";
$string['explainalphabet'] = "Browse the glossary using this index";
$string['explainall'] = "Shows ALL entries on one page";
$string['exportedentry'] = "Exported entry";
$string['exporttomainglossary'] = "Export to main glossary";
+$string['fullmatch'] = "Match whole words only<br><small>(when automatically linked)</small>";
$string['glossarytype'] = "Glossary Type";
$string['mainglossary'] = "Main glossary";
$string['modulename'] = "Glossary";
@@ -66,6 +69,7 @@
$string['special'] = "Special";
$string['standardview'] = "Browse by alphabet";
$string['studentcanpost'] = "Students can add entries";
+$string['usedynalink'] = "Link this glossary with other modules automatically";
$string['warningstudentcapost'] = "(Applies only if the glossary is not the main one)";
$string['writtenby'] = "by";
$string['youarenottheauthor'] = "You are not the author of this comment, therefore, you are not allowed to edit it.";
@@ -0,0 +1,5 @@
+<P ALIGN=CENTER><B>Case sensitive matching</B></P>
+
+<P>This setting specify if an entry should be found with the exact case as it is in order to be automatically linked.
+<p>Note that this flag does not limit that a concept could be contained insidee another: Use the Whole Words Matching flag instead.
+
@@ -0,0 +1,5 @@
+<P ALIGN=CENTER><B>Whole words matching</B></P>
+
+<P>If you stablish that an entry could be automatically linked from other resources, then,
+if you set this flag also, only those concepts which words match completelly with this entry, will be linked.
+<p>Note that this flag does not force the match of the case. Use the Case Sensitive flag instead.
@@ -0,0 +1,6 @@
+<P ALIGN=CENTER><B>Linking glossaries' entries with other modules automatically</B></P>
+
+<P>If you stablish that a glossary or an entry should be automatically linked, the entries affected will be automatically linked whenever they are found in other resources (forums, comments, etc).
+<p>If you do not want a specific entry to be linked, you should insert it between the &lt;nolink> and &lt;/nolink> tags in the source of the HTML.
+<p>Also, if a category is found, it will also be linked. Note that category linking is case sensitive.
+
View
@@ -91,6 +91,19 @@ function glossary_upgrade($oldversion) {
execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete comment', 'glossary', 'name') ");
}
+ if ( $oldversion < 2003101600 ) {
+ execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` " .
+ "ADD `usedynalink` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `allowcomments` " );
+
+ execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
+ "ADD `usedynalink` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `sourceglossaryid`, ".
+ "ADD `casesensitive` TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `usedynalink` ");
+ }
+
+ if ( $oldversion < 2003101601 ) {
+ execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
+ "ADD `fullmatch` TINYINT(2) UNSIGNED NOT NULL DEFAULT '1' AFTER `casesensitive` ");
+ }
return true;
}
@@ -21,6 +21,7 @@ CREATE TABLE prefix_glossary (
showalphabet tinyint(2) unsigned NOT NULL default '1',
showall tinyint(2) unsigned NOT NULL default '1',
allowcomments tinyint(2) unsigned NOT NULL default '0',
+ usedynalink tinyint(2) unsigned NOT NULL default '1',
timecreated int(10) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id)
@@ -42,6 +43,9 @@ CREATE TABLE prefix_glossary_entries (
timemodified int(10) unsigned NOT NULL default '0',
teacherentry tinyint(2) unsigned NOT NULL default '0',
sourceglossaryid int(10) unsigned NOT NULL default '0',
+ usedynalink tinyint(2) unsigned NOT NULL default '1',
+ casesensitive tinyint(2) unsigned NOT NULL default '0',
+ fullmatch tinyint(2) unsigned NOT NULL default '1',
PRIMARY KEY (id)
) TYPE=MyISAM COMMENT='all glossary entries';
@@ -21,6 +21,7 @@ CREATE TABLE prefix_glossary (
showalphabet int2 NOT NULL default '1',
showall int2 NOT NULL default '1',
allowcomments int2 NOT NULL default '0',
+ usedynalink int2 NOT NULL default '1',
timecreated int4 NOT NULL default '0',
timemodified int4 NOT NULL default '0',
PRIMARY KEY (id)
@@ -42,6 +43,9 @@ CREATE TABLE prefix_glossary_entries (
timemodified int4 NOT NULL default '0',
teacherentry int2 NOT NULL default '0',
sourceglossaryid int4 NOT NULL default '0',
+ usedynalink int2 NOT NULL default '1',
+ casesensitive int2 NOT NULL default '0',
+ fullmatch tinyint(2) NOT NULL default '1',
PRIMARY KEY(id)
);
View
@@ -1,92 +1,114 @@
<?PHP // $Id$
+ define("GLOSSARY_CONCEPT_IS_ENTRY", "0");
+ define("GLOSSARY_CONCEPT_IS_CATEGORY", "1");
+
$textfilter_function = 'glossary_dynamic_link';
if (function_exists($textfilter_function)) {
return;
}
- function glossary_dynamic_link($courseid, $text,$glossaryid = NULL) {
+ function glossary_dynamic_link($courseid, $text) {
global $CFG;
- static $entries; // to avoid repeated calls to database
- static $glossary; // even when dealing with the same glossary
-
- if ( !$glossary and !$glossaryid ) {
- $permissiongranted = 1; // if it is the first call and no glossary was specify
- } elseif ( $glossaryid ) {
- if ( $glossary ) { // if it is not the first call
- if ( $glossary->id != $glossaryid ) { // ...and the specified glossary is different from the previous call
- $permissiongranted = 1;
- }
- } else {
- $permissiongranted = 1; // if it is the first call and a glossary was specify
+
+ $glossarieslist = get_records_select("glossary", "usedynalink = 1 and course = $courseid","id");
+ if ( $glossarieslist ) {
+ $glossaries = "";
+ foreach ( $glossarieslist as $glossary ) {
+ $glossaries .= "$glossary->id,";
}
- }
- if ( $permissiongranted ) {
- if ( !$glossaryid ) { // If no glossary was specify, fetch the main glossary of the course
- $glossary = get_record("glossary","course",$courseid,"mainglossary",1);
- } else { // if a glossary as specify, fetch this one
- $glossary = get_record("glossary","course",$courseid,"id",$glossaryid);
+ $glossaries=substr($glossaries,0,-1);
+
+ $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink = 1","glossaryid","id,glossaryid,concept,casesensitive,".GLOSSARY_CONCEPT_IS_ENTRY." category,fullmatch");
+ $categories = get_records_select("glossary_categories", "glossaryid IN ($glossaries)", "glossaryid,id","id,glossaryid,name concept, 1 casesensitive,".GLOSSARY_CONCEPT_IS_CATEGORY." category, 1 fullmatch");
+ if ( $entries and $categories ) {
+ $concepts = array_merge($entries, $categories);
+ } elseif ( $categories ) {
+ $concepts = $categories;
+ } elseif ( $entries ) {
+ $concepts = $entries;
}
- }
- if ( $glossary ) {
- if ( !$entries ) {
- // char_lenght is compatible with PostgreSQL and MySQL. Other DBMS must be implemented
-
- /* I'm ordering the cursor by the lenght of the concept trying to avoid the bug that occurs
- when a concept in contained in other entry's concept (i.e. HOUSE is in DOLL HOUSE).
- However, I haven't find a solution yet.
- Will (Sept. 30, 2003)
- */
- if ($CFG->dbtype == "postgres7" or $CFG->dbtype == "mysql") {
- $ORDER_BY = "CHAR_LENGTH(concept) DESC";
- } else {
- $ORDER_BY = "concept ASC";
- }
- $ownentries = get_records("glossary_entries", "glossaryid", $glossary->id,$ORDER_BY);
- $importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id,$ORDER_BY);
+ if ( $concepts ) {
+ $lastglossary = 0;
+ $lastcategory = 0;
+ foreach ( $concepts as $concept ) {
+ if ( $lastglossary != $concept->glossaryid ) {
+ $glossary = get_record("glossary","id",$concept->glossaryid);
+ $lastglossary = $glossary->id;
+ }
- if ( $ownentries and $importedentries ) {
- $entries = array_merge($ownentries, $importedentries);
- usort($entries, glossary_sort_entries_by_lenght);
- } elseif ( $importedentries ) {
- $entries = $importedentries;
- } elseif ( $ownentries ) {
- $entries = $ownentries;
- }
- }
- if ( $entries ) {
- foreach ( $entries as $entry ) {
- $title = strip_tags("$glossary->name: $entry->concept");
- $href_tag_begin = "<a target=\"entry\" class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&concept=$entry->concept\" ".
- "onClick=\"return openpopup('/mod/glossary/showentry.php?courseid=$courseid\&concept=$entry->concept', 'entry', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">";
+ if ( $concept->category ) {
+ if ( $lastcategory != $concept->id ) {
+ $category = get_record("glossary_categories","id",$concept->id);
+ $lastcategory = $concept->id;
+ }
- $concept = trim(strip_tags($entry->concept));
+ $title = strip_tags("$glossary->name: " . get_string("category","glossary"). " $category->name");
+ $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/view.php?id=182&currentview=categories&cat=$concept->id\">";
+ } else {
+ $title = strip_tags("$glossary->name: $concept->concept");
+ $href_tag_begin = "<a target=\"entry\" class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&concept=$concept->concept\" ".
+ "onClick=\"return openpopup('/mod/glossary/showentry.php?courseid=$courseid\&concept=$concept->concept', 'entry', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">";
+ }
- $text = glossary_link_concepts($text,$concept,$href_tag_begin, "</a>");
+ $currentconcept = trim(strip_tags($concept->concept));
+ $text = glossary_link_concepts($text,$currentconcept,$href_tag_begin, "</a>",$concept->casesensitive,$concept->fullmatch);
}
}
}
-
return $text;
}
- function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "</a>") {
+ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "</a>",$casesensitive,$fullmatch) {
$list_of_words_cp = $concept;
- // getting ride of "A" tags
- $final = array();
+ if ($list_of_words_cp{0}=="|") {
+ $list_of_words_cp{0} = "";
+ }
+ if ($list_of_words_cp{strlen($list_of_words_cp)-1}=="|") {
+ $list_of_words_cp{strlen($list_of_words_cp)-1}="";
+ }
+ $list_of_words_cp = trim($list_of_words_cp);
+ if ($fullmatch) {
+ $invalidprefixs = "([a-zA-Z0-9])";
+ $invalidsufixs = "([a-zA-Z0-9])";
+ // getting ride of words or phrases that containg the pivot concept on it
+ $words = array();
+ $regexp = '/' . $invalidprefixs . "(" . $list_of_words_cp . ")" . "|" . "(" . $list_of_words_cp . ")". $invalidsufixs . '/is';
+ preg_match_all($regexp,$text,$list_of_words);
+
+ foreach (array_unique($list_of_words[0]) as $key=>$value) {
+ $words['<*'.$key.'*>'] = $value;
+ }
+ if ( $words ) {
+ $text = str_replace($words,array_keys($words),$text);
+ }
+ }
+
+ // getting ride of "nolink" tags
+ $excludes = array();
+ preg_match_all('/<nolink>(.+?)<\/nolink>/is',$text,$list_of_excludes);
+ foreach (array_unique($list_of_excludes[0]) as $key=>$value) {
+ $excludes['<+'.$key.'+>'] = $value;
+ }
+ if ( $excludes ) {
+ $text = str_replace($excludes,array_keys($excludes),$text);
+ }
+
+ // getting ride of "A" tags
+ $links = array();
preg_match_all('/<A (.+?)>(.+?)<\/A>/is',$text,$list_of_links);
foreach (array_unique($list_of_links[0]) as $key=>$value) {
- $links['<|*'.$key.'*|>'] = $value;
+ $links['<@'.$key.'@>'] = $value;
}
- if ( $links ) {
+ if ( $links ) {
$text = str_replace($links,array_keys($links),$text);
}
- // getting ride of all other tahs
+ // getting ride of all other tags
$final = array();
preg_match_all('/<(.+?)>/is',$text,$list_of_words);
@@ -96,19 +118,22 @@ function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "
$text = str_replace($final,array_keys($final),$text);
- if ($list_of_words_cp{0}=="|") {
- $list_of_words_cp{0} = "";
- }
- if ($list_of_words_cp{strlen($list_of_words_cp)-1}=="|") {
- $list_of_words_cp{strlen($list_of_words_cp)-1}="";
+ $list_of_words_cp = "(".$list_of_words_cp."$nocharsend)";
+ if ( $casesensitive ) {
+ $text = ereg_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text);
+ } else {
+ $text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text);
}
- $list_of_words_cp = "(".trim($list_of_words_cp).")";
-
- $text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text);
$text = str_replace(array_keys($final),$final,$text);
- if ( $links ) {
+ if ( $links ) {
$text = str_replace(array_keys($links),$links,$text);
}
+ if ( $excludes ) {
+ $text = str_replace(array_keys($excludes),$excludes,$text);
+ }
+ if ( $words and $fullmatch ) {
+ $text = str_replace(array_keys($words),$words,$text);
+ }
return stripslashes($text);
}
View
@@ -17,7 +17,7 @@
<?php
$categories = get_records("glossary_categories","glossaryid",$glossary->id);
echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
- echo "<option value=\"0\">" . get_string("nocategorized","glossary") . "</optioon>";
+ echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</optioon>";
if ( $categories ) {
foreach ( $categories as $category ) {
@@ -33,6 +33,63 @@
</select>
</td>
</tr>
+<tr valign=top>
+ <td align=right><p><b><?php echo get_string("entryusedynalink","glossary") ?>:</b></p></td>
+ <td>
+ <select size="1" name="usedynalink">
+ <option value="1" <?php
+ if ( $form->usedynalink ) {
+ echo "selected";
+ }
+ ?>
+ ><?php echo get_string("yes") ?></option>
+ <option value="0" <?php
+ if ( !$form->usedynalink ) {
+ echo "selected";
+ }
+ ?>><?php echo get_string("no") ?>
+ </option>
+ </select> <?php helpbutton("usedynalink", get_string("usedynalink", "glossary"), "glossary") ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><p><b><?php echo get_string("casesensitive","glossary") ?>:</b></p></td>
+ <td>
+ <select size="1" name="casesensitive">
+ <option value="1" <?php
+ if ( $form->casesensitive ) {
+ echo "selected";
+ }
+ ?>
+ ><?php echo get_string("yes") ?></option>
+ <option value="0" <?php
+ if ( !$form->casesensitive ) {
+ echo "selected";
+ }
+ ?>><?php echo get_string("no") ?>
+ </option>
+ </select> <?php helpbutton("casesensitive", get_string("casesensitive", "glossary"), "glossary") ?>
+ </td>
+</tr>
+<tr valign=top>
+ <td align=right><p><b><?php echo get_string("fullmatch","glossary") ?>:</b></p></td>
+ <td>
+ <select size="1" name="fullmatch">
+ <option value="1" <?php
+ if ( $form->fullmatch ) {
+ echo "selected";
+ }
+ ?>
+ ><?php echo get_string("yes") ?></option>
+ <option value="0" <?php
+ if ( !$form->fullmatch ) {
+ echo "selected";
+ }
+ ?>><?php echo get_string("no") ?>
+ </option>
+ </select> <?php helpbutton("fullmatch", get_string("fullmatch", "glossary"), "glossary") ?>
+ </td>
+</tr>
<tr valign=top>
<td align=right><p><b><?php echo get_string("definition","glossary") ?>:</b></p>
<font size="1">
@@ -99,7 +156,7 @@
<?PHP
if ($usehtmleditor) {
- print_richedit_javascript("theform", "text", "no");
+ print_richedit_javascript("theform", "text", "yes");
}
?>
Oops, something went wrong.

0 comments on commit dc36351

Please sign in to comment.