$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";
$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";
$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.";
--- /dev/null
+<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.
+
--- /dev/null
+<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.
\ No newline at end of file
--- /dev/null
+<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 <nolink> and </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.
+
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;
}
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)
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';
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)
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)
);
<?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¤tview=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);
$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);
}
<?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 ) {
</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">
<?PHP
if ($usehtmleditor) {
- print_richedit_javascript("theform", "text", "no");
+ print_richedit_javascript("theform", "text", "yes");
}
?>
$newentry->concept = $form->concept;
$newentry->definition = $form->text;
$newentry->format = $form->format;
+ $newentry->usedynalink = $form->usedynalink;
+ $newentry->casesensitive = $form->casesensitive;
+ $newentry->fullmatch = $form->fullmatch;
$newentry->timemodified = time();
$newentry->teacherentry = isteacher($course->id,$USER->id);
$permissiongranted = 1;
if ( !$glossary->allowduplicatedentries ) {
- $dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept));
- if ($dupentries) {
+ $dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept));
+ if ($dupentries) {
foreach ($dupentries as $curentry) {
if ( $glossary->id == $curentry->glossaryid ) {
if ( $curentry->id != $entry ) {
}
}
}
- }
+ }
}
if ( $permissiongranted ) {
$newentry->attachment = $_FILES["attachment"];
$newentry->definition = $form->text;
$newentry->format = $form->format;
$newentry->timecreated = time();
+ $newentry->usedynalink = $form->usedynalink;
+ $newentry->casesensitive = $form->casesensitive;
+ $newentry->fullmatch = $form->fullmatch;
$newentry->timemodified = time();
$newentry->teacherentry = isteacher($course->id,$USER->id);
$newentry->sourceglossaryid = 0;
$entry->format = $defaultformat;
}
-print_header("$course->shortname: $glossary->name", "$course->fullname",
+print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->
<A HREF=\"index.php?id=$course->id\">$strglossaries</A> ->
<A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "theform.text",
$isteacher = isteacher($course->id);
$ismainglossary = $glossary->mainglossary;
- echo "<table width=100% border=0><tr>";
-
- if ( $glossary->allowcomments ) {
- echo "<td>";
- $count = count_records("glossary_comments","entryid",$entry->id);
+ echo "<table width=100% border=0>";
+ echo "<tr><td>";
+ $count = count_records("glossary_comments","entryid",$entry->id);
+ if ( $count ) {
echo "<a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count " . get_string("comments","glossary") . "</a>";
- echo "</td><td align=\"right\">";
+ }
+ echo "</td><td align=\"right\">";
+
+ echo "<td align=\"right\">";
+ if ( $glossary->allowcomments ) {
echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
- } else {
- echo "<td align=\"right\">";
}
-
+
if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
// only teachers can export entries so check it out
</select> <?php helpbutton("allowcomments", get_string("allowcomments", "glossary"), "glossary") ?>
</TD>
</TR>
+<TR valign=top>
+ <TD align=right><P><B><?php echo get_string("usedynalink", "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 colspan=2><hr>
</tr>
echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
if ( $entries ) {
foreach ( $entries as $entry ) {
- if( $ConceptIsPrinted ) {
- echo "<hr>";
+
+ if (! $glossary = get_record("glossary", "id", $entry->glossaryid)) {
+ error("Glossary ID was incorrect or no longer exists");
}
- if ( !$ConceptIsPrinted ) {
- echo "<b>" . $entry->concept . "</b>:<br>";
- $ConceptIsPrinted = 1;
+ if (! $course = get_record("course", "id", $glossary->course)) {
+ error("Glossary is misconfigured - don't know what course it's from");
}
-
- if ($entry->attachment) {
- $entry->course = $courseid;
- echo "<table border=0 align=right><tr><td>";
- echo glossary_print_attachments($entry,"html");
- echo "</td></tr></table>";
+ if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) {
+ error("Glossary is misconfigured - don't know what course module it is ");
}
- echo format_text($entry->definition, $entry->format);
+
+ glossary_print_entry($course, $cm, $glossary, $entry);
}
}
echo "</td>";
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003101501; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2003101601; // The current module version (Date: YYYYMMDDXX)
$module->cron = 0; // Period for cron to check this module (secs)
$release = "0.5 development"; // User-friendly version number