079e3060551474af5b1e9d7247be957f1df15f35
[atutor.git] / mods / wiki / plugins / interwiki / metadb.php
1 <?php
2 /*
3    This plugin provides utility and access code for NearLinks, SisterPages
4    and other InterWiki plugins. It depends upon the MetaWikiDatabase file
5    being available (not distributed with ewiki, but cron can download it).
6    You need to have it inside of the EWIKI_VAR directory with a filename
7    of "metadb" (maybe .gz compressed).
8 */
9
10
11 define("EWIKI_METADB_FN", "metadb");
12
13
14 #-- utility code class (static)
15 class ewiki_metadb {
16
17
18    #-- read-in metadb file
19    function LOAD() {
20       global $ewiki_metadb;
21       $ewiki_metadb = array();
22
23       if (file_exists($fn = EWIKI_VAR."/".EWIKI_METADB_FN)
24       or (file_exists($fn .= ".gz"))) {
25
26          $f = gzopen($fn, "r");
27          $line = gzread($f, 1<<24);
28          gzclose($f);
29
30          foreach (explode("\n", $line) as $line) {
31             $real = strtok($line, " ");
32             $ci = strtok(" ");
33             $where = strtok(" \n\r");
34
35             $ewiki_metadb[$ci] = array($real, $where);
36          }
37       }
38       return(count($ewiki_metadb));
39    }
40    function UNLOAD() {
41       global $ewiki_metadb;
42       $ewiki_metadb = array();
43    }
44    
45    #-- search for listed page names in InterWiki namespace
46    function FIND($list) {
47       global $ewiki_metadb, $ewiki_config;
48       $r = array();
49       
50       foreach ($list as $id) {
51          $ci = strtolower($id);
52          if ($uu = $ewiki_metadb[$ci]) {
53             $real = $uu[0];
54             $r[$id] = array();
55             foreach (explode("|", trim($uu[1], "|")) as $iw) {
56                if ($ewiki_config["interwiki"][$iw]) {
57                   $r[$id][] = "$iw:$real";
58                }
59             }
60          }
61          else {
62             $r[$id] = 0;
63          }
64       }
65       
66       return($r);
67    }
68
69 }
70
71
72
73 ?>