4 Beware, this is a fun plugin! It is supposed to work, but not
5 recommended for seriously big installations. This database backend
6 stores all your pages in a ZIP file, it requires the standard util
7 "zip" ('pkzip.exe' may not work).
9 You must set EWIKI_DB_ZIP and EWIKI_TMP to writable locations (the
10 directory in which the single ZIP file resides must be world-
12 This database plugin is _CASE_INSENSITIVE always, hit counting isn't
13 done. Eventually you even have to create an empty ZIP file yourself.
14 And this will only run in UNIX environments!
17 define("EWIKI_DB_ZIP", "/tmp/database.zip");
18 define("EWIKI_CASE_INSENSITIVE", "always");
21 $ewiki_plugins["database"][0] = "ewiki_db_zip";
28 var $util_un = "unzip ";
29 var $util_get = "unzip -q -C -p ";
30 var $util_add = "zip -j -q -u ";
31 var $zip = EWIKI_DB_ZIP;
32 var $QUIET = "2>/dev/null";
35 function ewiki_db_zip() {
39 function GET($id, $version=false) {
42 $version = 0 + trim(`$this->util_get $this->zip $fn $this->QUIET`);
46 $r = `$this->util_get $this->zip $fn `;
53 function WRITE($hash, $overwrite=0) {
54 $fn = "$this->tmp/" . $this->FN($hash["id"]);
55 $fn2 = "$fn." . $hash["version"];
56 if ($f = fopen($fn2, "w")) {
57 fwrite($f, serialize($hash)); // unsafe, to say mildly
59 if ($f = fopen($fn, "w")) {
60 fwrite($f, $hash["version"]);
63 $r = `$this->util_add $this->zip $fn2 $fn $this->QUIET`;
78 function FIND($list) {
80 foreach ($list as $id) if ($id) {
83 if ($ver = `$this->util_get $this->zip $fn $this->QUIET`) {
91 function GETALL($fields, $mask=0, $filter=0) {
92 $r = new ewiki_dbquery_result($fields);
93 foreach (explode("\n", `$this->util_un -l $this->zip | cut -b 29-290`) as $id) {
94 if (!strpos($id, ".") || !preg_match('/\.\d+$/', $id)) {
95 $r->entries[] = rawurldecode($id);
102 function SEARCH($field, $content, $ci="i", $regex=0, $mask=0, $filter=0) {
103 $r = new ewiki_dbquery_result($args);
104 if ($ci && !$regex) {
105 $content = strtolower($content);
107 $ALL = $this->GETALL(array($field), $mask, $filter);
108 while ($row = $ALL->get()) {
110 $match = preg_match("\007$content\007$ci", $row["field"]);
113 $match = strpos(strtolower($row[$field]), $content) !== false;
116 $match = strpos($row[$field], $content) !== false;
126 # function DELETE($id, $version) {
131 if (!file_exists($this->zip) || !filesize($this->zip)) {
132 $f = fopen($this->zip, "wb");
133 fwrite($f, "PK\005\006".str_repeat("\000", 18));
136 if (!is_writeable($this->zip)) {
137 echo "error db_zip: $this->zip is not writeable!\n";
143 $id = ewiki_lowercase($id);
144 return(rawurlencode($id));