]> git.mjollnir.org Git - moodle.git/commitdiff
- Implementing output text filters for glossary entries
authorwillcast <willcast>
Mon, 29 Sep 2003 17:45:42 +0000 (17:45 +0000)
committerwillcast <willcast>
Mon, 29 Sep 2003 17:45:42 +0000 (17:45 +0000)
    dynalink.php::glossary_dynamic_link($courseid, $text, $glossaryid = NULL)

mod/glossary/dynalink.php [new file with mode: 0644]
mod/glossary/showentry.php [new file with mode: 0644]
mod/glossary/view.php

diff --git a/mod/glossary/dynalink.php b/mod/glossary/dynalink.php
new file mode 100644 (file)
index 0000000..e2ac283
--- /dev/null
@@ -0,0 +1,66 @@
+<?PHP
+
+    function glossary_dynamic_link($courseid, $text,$glossaryid = NULL) {
+    global $CFG;
+    static $entries;
+        if ( !$glossaryid ) {
+            $glossary = get_record("glossary","course",$courseid,"mainglossary",1);
+        } else {
+            $glossary = get_record("glossary","course",$courseid,"id",$glossaryid);
+        }
+        if ( $glossary ) {
+            if ( !$entries ) {
+                $entries = get_records("glossary_entries","glossaryid",$glossary->id,"concept ASC");
+            }
+            if ( $entries ) {
+                foreach ( $entries as $entry ) {
+
+                    $href_tag_begin = "<a target=\"entry\" title=\"" . strip_tags("$glossary->name: $entry->concept") ."\" href=\"$CFG->wwwroot/mod/glossary/showentry.php?courseid=$courseid&eid=$entry->id\" ".
+                         "onClick=\"return openpopup('/mod/glossary/showentry.php?courseid=$courseid&eid=$entry->id', 'entry', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">";
+
+                    $concept = trim(strip_tags($entry->concept));
+                    
+                    $text = glossary_link_concepts($text,$concept,$href_tag_begin);
+                }
+            }
+        }
+        
+        return $text;
+    }
+    
+    function glossary_link_concepts($text,$concept,$href_tag_begin,$href_tag_end = "</a>") {
+        $list_of_words = eregi_replace("[^-a-zA-Z0-9&']", " ", $concept);
+        $list_array = explode(" ", $list_of_words);
+        for ($i=0; $i<sizeof($list_array); $i++) {
+            if (strlen($list_array[$i]) == 1) {
+                $list_array[$i] = "";
+            }
+        }
+        $list_of_words = implode(" ", $list_array);
+        $list_of_words_cp = $list_of_words;
+
+        $final = array();
+        preg_match_all('/<(.+?)>/is',$text,$list_of_words);
+
+        foreach (array_unique($list_of_words[0]) as $key=>$value) {
+            $final['<|'.$key.'|>'] = $value;
+        }
+
+        $text = str_replace($final,array_keys($final),$text);
+        $list_of_words_cp = eregi_replace(" +", "|", $list_of_words_cp);
+
+        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).")";
+
+        $text = eregi_replace("$list_of_words_cp", "$href_tag_begin"."\\1"."$href_tag_end", $text);
+
+        $text = str_replace(array_keys($final),$final,$text);
+
+        return stripslashes($text);
+    }
+?>
diff --git a/mod/glossary/showentry.php b/mod/glossary/showentry.php
new file mode 100644 (file)
index 0000000..5735c30
--- /dev/null
@@ -0,0 +1,38 @@
+<?PHP
+    require_once("../../config.php");
+    require_once("lib.php");
+
+    require_variable($courseid);
+    require_variable($eid);  // entry id
+
+    $entry = get_record("glossary_entries","id",$eid);
+
+    print_header();
+    
+    glossary_show_entry($courseid, $entry);
+    
+    close_window_button();
+
+    function glossary_show_entry($courseid, $entry) {
+        global $THEME, $USER;
+
+        $colour = $THEME->cellheading2;
+
+        echo "\n<center><table width=95% border=0><TR>";
+        echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
+        if ($entry->attachment) {
+            $entry->course = $courseid;
+            echo "<table border=0 align=right><tr><td>";
+            echo glossary_print_attachments($entry,"html");
+            echo "</td></tr></table>";
+        }
+        echo "<b>$entry->concept</b>: ";
+        echo format_text($entry->definition, $entry->format);
+        echo "</td>";
+        echo "</TR></table></center>";
+    }
+
+?>
+</body>
+</html>
+
index 72e45d1ff6ea3e88248b41f53a4688d355ac1128..dde2c4d85200f254269b809e18f139bd8ca39be9 100644 (file)
@@ -4,6 +4,7 @@
 
     require_once("../../config.php");
     require_once("lib.php");
+    require_once("dynalink.php");
 
     require_variable($id);    // Course Module ID, or
 
                         }
                  }
                  if ($search) {
-                       $entry->concept = highlight($search,$concept);
-                       $entry->definition = highlight($search,$definition);
+                     $entry->concept = highlight($search,$concept);
+                     $entry->definition = highlight($search,$definition);
                  }
+                 if ( !glossary->mainglossary ) {
+                     $entry->definition = glossary_dynamic_link($course->id,$definition);
+                 }
+                 
                     glossary_print_entry($course, $cm, $glossary, $entry,$currentview,$cat);
 
                  if ( $glossary->displayformat != 0 ) {