c2470fee480b9b7d693268ac4272814f06a680c7
[atutor.git] / mods / wiki / plugins / db / ext_subwiki.php
1 <?php
2
3 /*
4    This plugin encapsulates the database layer to fragment your database
5    into several pieces. All pages from then will be created in separate
6    namespaces. The global '$subwiki' variable makes the internal pagename
7    prefix and must be set by yoursite.php (the layout wrapper).
8
9    The initial pages are created as usual, but then exist multiple times
10    in the database ("WikiOne:EditThisPage" and "WikiTwo:EditThisPage").
11    You should preferrably use the colon as separator, as it perfectly
12    matches the InterWiki syntax; define the interwiki monikers and
13    wrappers at different URLs correctly to get a closed system.
14 */
15
16 define("SUBWIKI_SEPARATOR", ":");
17
18
19 $ewiki_plugins["init"][] = "ewiki_database_subwiki_init";
20 # initialization timing is difficult here, this breaks binary upload support
21
22
23 function ewiki_database_subwiki_init()
24 {
25    global $ewiki_plugins, $subwiki, $ewiki_db;
26
27    #-- only engage wrapper if subwiki filtering requested
28    if ($subwiki) {
29       $ewiki_db = & new ewiki_database_subwiki($ewiki_db);
30    }
31 }
32
33
34 #-- wrapper
35 class ewiki_database_subwiki {
36
37    var $db;
38    var $dot = SUBWIKI_SEPARATOR;
39    
40    function ewiki_database_subwiki(&$backend) {
41       $this->db = & $backend;
42    }
43
44
45    function GET($id, $version=false) {
46       global $subwiki;
47       $id = $subwiki . $this->dot . $id;
48       $r = $this->db->GET($id, $version);
49       if ($r) {
50          $r["id"] = substr($r["id"], strlen($subwiki) + 1);
51       }
52       return($r);
53    }
54
55
56    function HIT($id) {
57       $id = $GLOBALS["subwiki"] . $this->dot . $id;
58       return $this->db->HIT($id);
59    }
60
61
62    function DELETE($id, $version=false) {
63       $id = $GLOBALS["subwiki"] . $this->dot . $id;
64       return $this->db->DELETE($id, $version);
65    }
66
67
68    function WRITE($hash, $overburn=0) {
69       $hash["id"] = $GLOBALS["subwiki"] . $this->dot . $hash["id"];
70       return $this->db->WRITE($hash, $overburn);
71    }
72
73
74    function INIT() {
75       $this->db->INIT();
76    }
77
78       
79    function FIND($list) {
80       global $subwiki;
81       if ($subwiki) {
82          $n = strlen($subwiki);
83          foreach ($list as $i=>$s) {
84             $list[$i] = $subwiki . $dot . $s;
85          }
86          $e = $this->db->FIND($list);
87          $r = array();
88          foreach ($e as $s=>$x) {
89             $r[substr($s, $n+1)] = $x;
90          }
91          return($r);
92       }
93       return $this->db->FIND($list);
94    }
95
96
97    function SEARCH($field, $content, $ci=1, $regex=0, $mask=0, $filter=0) {
98       
99          $r = $dbf($func, $args, $f1, $f2);
100          foreach ($r->entries as $i=>$d) {
101             if (is_array($d) && (0==strncmp($d["id"], $subwiki, $n))) {
102                $r->entries[$i]["id"] = substr($d["id"], $n+1);
103             }
104             elseif (is_string($d) && (0==strncmp($d, $subwiki, $n))) {
105                $r->entries[$i] = substr($d, $n+1);
106             }
107             else {
108                unset($i);
109             }
110          }
111    }
112    
113    function GETALL($fields, $mask=0, $filter=0) {
114    }
115          
116
117
118 } // end of class
119
120
121 ?>