aboutsummaryrefslogtreecommitdiff
path: root/guestbook.php
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-11-08 17:52:58 +0100
committerPhilip Wittamore <philip@wittamore.com>2025-11-08 17:52:58 +0100
commit5637b6bc9e9ca99779fd6483318f33a6fe38152d (patch)
treee7c7f5556be89e8f11ded44ca167a473032bcdfe /guestbook.php
parent301c765535e2dc4e51a3b756e2b830dbe51293aa (diff)
downloadscripts-5637b6bc9e9ca99779fd6483318f33a6fe38152d.tar.gz
scripts-5637b6bc9e9ca99779fd6483318f33a6fe38152d.tar.bz2
scripts-5637b6bc9e9ca99779fd6483318f33a6fe38152d.zip
Diffstat (limited to 'guestbook.php')
-rwxr-xr-xguestbook.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/guestbook.php b/guestbook.php
new file mode 100755
index 0000000..33ed46e
--- /dev/null
+++ b/guestbook.php
@@ -0,0 +1,76 @@
+<?php
+
+// Guestbook for Gopher
+session_start();
+$db = new PDO("sqlite:db/guestbook.db");
+$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$stm="CREATE TABLE IF NOT EXISTS log (
+ id integer primary key autoincrement,
+ sessionid TEXT,
+ msg TEXT,
+ date TEXT
+);";
+$db -> exec($stm);
+
+$i="";
+
+if (getenv("SEARCHREQUEST") !== false) {
+ $msg=htmlentities(getenv("SEARCHREQUEST"));
+
+ $sessionid = $_SERVER["SESSION_ID"];
+ date_default_timezone_set('Europe/Paris');
+ $d = new DateTime();
+ $date = $d->format('r');
+
+ if ((isset($msg)) && (!empty($msg))) {
+ $i="i";
+ try {
+ $stm = $db->prepare("INSERT INTO log (sessionid,msg,date) VALUES (:sessionid,:msg,:date)");
+ $stm -> execute([ 'sessionid' => $sessionid, 'msg' => $msg, 'date' => $date ]);
+ } catch(Exception $e) {
+ $db->rollback();
+ throw $e;
+ }
+ }
+}
+
+// print out guestbook comments
+
+$stm = $db->query("SELECT `sessionid`, `msg`,`date` FROM `log` ORDER BY id DESC");
+
+while ($row = $stm->fetch()) {
+ $sessionid=$row['sessionid'];
+ $date=$row['date'];
+ $msg=$row['msg'];
+
+ if (!empty($msg)) {
+
+ // prepend "i" to each line if gophermap
+ echo $i."+".str_repeat("-", 65)."+\n";
+ echo $i."[".$sessionid."] ".date("H:i, l jS F Y", strtotime($date))."\n";
+ echo $i."+".str_repeat("-", 65)."+\n";
+
+ // get a clean string for passing to the shell
+ $msg = escapeshellarg(html_entity_decode($msg));
+ // format string newline on words
+ $msg = shell_exec("echo $msg | par w67");
+
+ // split lines to array
+ $ma = explode(PHP_EOL, $msg);
+
+ foreach ($ma as $msgline) {
+ $msgline = stripslashes(trim($msgline,'\'"'));
+ echo $i.$msgline."\n";
+ }
+ }
+}
+
+?>
+
+
+
+
+
+
+
+