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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ phlogmap | 16 +++++++------ phlogrss | 22 ++++++++--------- phlogthis | 20 ++++++++-------- search.php | 43 +++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 29 deletions(-) create mode 100755 guestbook.php create mode 100644 search.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"; + } + } +} + +?> + + + + + + + + diff --git a/phlogmap b/phlogmap index 872d5ef..c43b38e 100755 --- a/phlogmap +++ b/phlogmap @@ -1,10 +1,11 @@ #!/usr/bin/env bash # build the phlog gophermap -cd "$HOME/src/gopher/phlog" +year=$(date +%Y) +cd "$HOME/src/gopher/phlog/$year" echo "+-----------------------------------+" > gophermap -echo "| Phils Phlog |" >> gophermap +echo "| Phils Phlog $year |" >> gophermap echo "+-----------------------------------+" >> gophermap echo "" >> gophermap echo "0Subscribe to rss feed /phlog/rss.xml spike.nagatha.fr 70" >> gophermap @@ -13,11 +14,12 @@ echo "" >> gophermap echo "+----------------------------------------------------------+" >> gophermap echo "" >> gophermap -dirs=($(ls -dr */)) -for dir in "${dirs[@]}"; do - dt=$(echo "$dir" | cut -c 1-10) - title="$(head -n 1 "$dir/gophermap")" - echo -e "1$dt $title\t/phlog/$dir\tspike.nagatha.fr\t70" >> gophermap +files=$(ls -r *.txt) +for file in $files; do + dt=$(echo "$file" | cut -c 1-10) + title="$(head -n 1 "$file")" + echo -e "0$dt $title\t/phlog/$year/$file\tspike.nagatha.fr\t70" >> gophermap done + exit 0 diff --git a/phlogrss b/phlogrss index f90d4df..fb88419 100755 --- a/phlogrss +++ b/phlogrss @@ -1,9 +1,9 @@ #!/usr/bin/env bash # create a gopher rss feed - -root="$HOME/src/gopher/phlog" -phloglink="gopher://spike.nagatha.fr/1/phlog" +year="$(date +%Y)" +root="$HOME/src/gopher/phlog/$year" +phloglink="gopher://spike.nagatha.fr/0/phlog/$year" description="Phil's Phlog" rsslink="gopher://spike.nagatha.fr/0/phlog/rss.xml" filename="$HOME/src/gopher/phlog/rss.xml" @@ -60,18 +60,16 @@ if [[ -f $filename ]]; then fi touch "$filename" -mapfile -t dir_array < <(ls -dr */) postNum=0 -for dir in "${dir_array[@]}"; do +files=$(ls -r *.txt) +for file in $files; do ((postNum+=1)) - post=$dir - post="${dir//\//}" - title=$(head -n1 "$post/gophermap") - postdate=$(cat "$post/gophermap" | sed -n '2p') - linkadd="$phloglink/$post" - description="$(cat "$post/gophermap" | sed -n "/^$/,/^$/p" | head -n 3 )..." - build_item "$post" + title=$(head -n1 "$file") + postdate=$(cat "$file" | sed -n '2p') + linkadd="$phloglink/$file" + description="$(cat "$file" | sed -n "/^$/,/^$/p" | head -n 3 )..." + build_item "$file" done # put it all together diff --git a/phlogthis b/phlogthis index e218b3c..8de9302 100755 --- a/phlogthis +++ b/phlogthis @@ -5,10 +5,12 @@ # see https://git.wittamore.com/par/tree # config -root="$HOME/src/gopher/phlog" +root="$HOME/src/gopher/phlog/" remoteroot="/srv/gopher/phlog" editor="micro +1:1" -mkremotedir="ssh spike mkdir" +mkremotedir="ssh spike mkdir -p" +mkdir -p "$root/$(date +%Y)" +eval "$mkremotedir $remoteroot/$(date +%Y)" # save location pushd "$(pwd)" || exit @@ -18,15 +20,15 @@ cd "$HOME/.tmp" || exit editfile="phlogtmp.txt" articledate="$(date -R)" filedate="$(date +%Y-%m-%d-%H-%I)" -article="/tmp/gophermap.tmp" +article="$HOME/.tmp/article.tmp" read -rp "Enter title: " title filetitle=$(echo "$title" | sed "s/ /-/g" | sed "s/[^A-Za-z0-9._-]//g") -dirname="$filedate-$filetitle" +articlename="$filedate-$filetitle.txt" # make local dir -mkdir "$root/$dirname" +#mkdir "$root/$dirname" # edit text eval "$editor $editfile" @@ -38,9 +40,9 @@ cat "$editfile" | par -jw67 > $article || cat "$editfile" > $article header="$title\n$articledate\n+$(printf "%*s" 65 | tr " " "-")+\n\n" sed -i "1s/^/$header/" $article -dest="$root/$dirname/gophermap" +dest="$root/$(date +%Y)/$articlename" mv "$article" "$dest" -echo "\n\n␌" >> "$dest" +echo -e "\n\n␌" >> "$dest" rm $editfile clear @@ -57,11 +59,9 @@ fi echo "Article saved as $dest" echo "--------------------------" -read -rp "Make remote folder, run phlogmap & phlogrss & gosend? ; " choix2 +read -rp "run phlogmap & phlogrss & gosend? ; " choix2 if [ "$choix2" != "n" ] ; then - echo "creating remote directory..." - eval "$mkremotedir $remoteroot/$dirname" phlogmap; phlogrss ; gosend fi diff --git a/search.php b/search.php new file mode 100644 index 0000000..dc09366 --- /dev/null +++ b/search.php @@ -0,0 +1,43 @@ +setFlags(RecursiveDirectoryIterator::SKIP_DOTS); + $iter = new RecursiveIteratorIterator($dir); + + $i=0; + + echo "+".str_repeat("-", 65)."+\n\n"; + foreach ($iter as $phlogdir) { + $path=$phlogdir->getPathname(); + if (str_contains($path, "/gophermap") || + ($path=="/srv/gopher/phlog/rss.xml") || + ($path=="/srv/gopher/phlog/search.php")) + continue; + $content = strtolower(file_get_contents($path)); + $path=str_replace("/srv/gopher", "", $path); + if (strpos($content, $string) !== false) { + $i++; + $title = preg_split('#\r?\n#', $content, 2)[0]; + $dt=substr($path, 12, 10); + echo "0".$dt." ".ucfirst($title)."\t".$path."\t"."spike.nagatha.fr\t70\n"; + } + } + + if ($i == 0) echo "No match"; +}else{ + echo "Empty search string\n\n"; + echo "1Return to Phlo\t/phlog\tspike.nagatha.fr\t70\n"; +} + +?> + -- cgit v1.2.3