From 5637b6bc9e9ca99779fd6483318f33a6fe38152d Mon Sep 17 00:00:00 2001 From: Philip Wittamore Date: Sat, 8 Nov 2025 17:52:58 +0100 Subject: update --- guestbook.php | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 guestbook.php (limited to 'guestbook.php') diff --git a/guestbook.php b/guestbook.php new file mode 100755 index 0000000..33ed46e --- /dev/null +++ b/guestbook.php @@ -0,0 +1,76 @@ + 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"; + } + } +} + +?> + + + + + + + + -- cgit v1.2.3