-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiddlers.php
50 lines (38 loc) · 1.7 KB
/
tiddlers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
if (isset($_GET['user'])) {
$user = $_GET['user'];
} else {
$user = "na";
}
$db = new SQLite3('tiddlywiki.sqlite', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
$doc = new DOMDocument;
$statement = $db->prepare('SELECT phpuuid FROM tiddlers WHERE status = "ACTIVE" AND (user LIKE "%' . $user . '%" OR user IS NULL);');
$activeTiddlers = $statement->execute();
while ($tiddler = $activeTiddlers->fetchArray()) {
// Create tiddler
$node = $doc->createElement("div");
$node->setAttribute("phpuuid", $tiddler["phpuuid"]);
// Add text
$tiddlerText = $db->querySingle('SELECT text FROM tiddlertext WHERE phpuuid="'.$tiddler["phpuuid"].'" AND status = "ACTIVE" LIMIT 1');
$txt = $doc->createElement("pre", htmlspecialchars($tiddlerText));
$node->appendChild($txt);
// Add fields
$statement = $db->prepare('SELECT * FROM fields WHERE phpuuid="'.$tiddler["phpuuid"].'" AND status = "ACTIVE";');
$activeFields = $statement->execute();
while ($field = $activeFields->fetchArray()){
$node->setAttribute($field["fieldname"], $field["fieldvalue"]);
}
$doc->appendChild($node);
}
// Add tiddler with url arguments
foreach($_GET as $urlvar => $urlvalue){
$node = $doc->createElement("div");
$tidtit = "$:/url/" . $urlvar;
$node->setAttribute("title", htmlspecialchars($tidtit));
$node->setAttribute("sqlsave", "no");
$txt = $doc->createElement("pre", htmlspecialchars($urlvalue));
$node->appendChild($txt);
$doc->appendChild($node);
}
echo $doc->saveHTML();
?>