diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-11-22 00:13:58 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-11-22 00:13:58 +0100 |
commit | ee9ea17367518b4589ee988526d17dc09686e4eb (patch) | |
tree | f0389c020413967abd46550941102d189c99accf /prog/skovikanje/komentar.sh | |
parent | DN04 (diff) | |
download | r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar.gz r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar.bz2 r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar.lz r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar.xz r-ee9ea17367518b4589ee988526d17dc09686e4eb.tar.zst r-ee9ea17367518b4589ee988526d17dc09686e4eb.zip |
Diffstat (limited to '')
-rwxr-xr-x | prog/skovikanje/komentar.sh | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/prog/skovikanje/komentar.sh b/prog/skovikanje/komentar.sh new file mode 100755 index 0000000..a007822 --- /dev/null +++ b/prog/skovikanje/komentar.sh @@ -0,0 +1,113 @@ +#!/bin/bash +set -xeuo pipefail +function besedilo () { # <tip -- html> <datoteka> <zaupanje - 0 za html escaping, 1 brez html escapinga> <nesting level> + seznam=1 + echo "<div class=besedilo>" + tail -n+2 $2 | while read -r l + do + navadno=1 + if grep ^!http <<<"$l" > /dev/null && grep -v \' <<<"$l" > /dev/null + then + echo "<img style=max-width:100% src='`sed -e s/!// <<<"$l"`' />" + navadno=0 + fi + seznam=$(($seznam-1)) + if grep '^*' <<<"$l" > /dev/null + then + [ $seznam -eq 0 ] && echo "<ul>" + seznam=2 + navadno=0 + fi + zelena=0 + if grep '^>' <<<"$l" > /dev/null + then + echo "<span style=color:green>" + zelena=1 + fi + [ $seznam -eq 1 ] && echo "</ul>" + if [ $navadno -eq 1 ] + then + if [ $3 -eq 0 ] + then + tekst=`sed -e 's/</</g' <<<"$l"` + else + tekst=$l + fi + if [ $seznam -eq 2 ] + then + tekst=`sed 's/^*/<li>/' <<<"$tekst"` + fi + if [ $4 -gt 0 ] + then + for you in `grep -Eo ">>[A-Za-z0-9+-]{8}" <<<"$l"` + do + stil="border:1px solid green" + if [ $(($4%2)) -eq 0 ] + then + stil="border:1px solid red" + fi + koment=`komentar $1 $(cut -d\> -f3 <<<$you) $(($4-1))` + echo "<details class=komentar style='$stil'><summary>`head -n1 <<<$koment`</summary>`tail -n+2 <<<$koment`</details>" + + done + fi + sed -e 's,\(http[s]*://[A-Za-z0-9._~:/?#@!$&()*+,;=-]*\),<a href="\1">\1</a>,g' <<<"$tekst" + echo "<br>" + fi + if [ $zelena -eq 1 ] + then + echo "</span>" + fi + done + echo "</div>" +} +function komentar () { # tip id nesting-level + stat komentarji/$2 > /dev/null || { echo komentar ne $3 ne obstaja.; return; } + echo -n "<a onclick=citiraj('$2')><code>$2</code></a> <b class=avtor>$(head -n1 komentarji/$2 | cut -f2 | cut -d@ -f1 | sed -e 's/</</g')</b> " + echo "dne <span class=datum>`date --date @$(stat --format %W komentarji/$2)`</span> <a href=//z.4a.si/skovikanje/komentar.php?koga=$2 target=_blank>uredi</a> <a href=/skovikanje/skovik/$(head -n1 komentarji/$2 | cut -f1).html>na</a>" + besedilo $1 komentarji/$2 0 $3 +} +if [ $1 = komentar ] +then + komentar $2 $3 5 +fi +if [ $1 = objava ] +then + echo "<meta name=referrer content=unsafe-url />" + if [ $4 -eq 1 ] + then + echo "<title>`head -n1 objave/$3 | cut -f1`</title>" + echo "<h2><a href=..><<< nazaj</a></h2>" + fi + echo "<script>function citiraj(slug) {odgovor.hidden=false;besedilo.value+='>>'+slug+'\n';} </script>" + echo "<h1 class=naslov>`head -n1 objave/$3 | cut -f1`</h1>" + echo "<p>spisal <span class=spisal>`head -n1 objave/$3 | cut -f2`</span>" + if [ ! `head -n1 objave/$3 | cut -f2` = `date --iso-8601 --date @$(stat --format %Y objave/$3)` ] + then + echo "| nazadnje spremenil <span class=spremenil>`date --iso-8601 --date @$(stat --format %Y objave/$3)`</span>" + fi + echo "</p>" + if [ $4 -eq 1 ] + then + besedilo $2 objave/$3 1 5 + echo "<hr><h2>komentarji</h2>" + komentiraj="<input id=komentiraj hidden type=button onclick='document.getElementById("odgovor").hidden=false' value=komentiraj />" + echo $komentiraj + for file in `ls --reverse --sort=time --time=birth komentarji` + do + + grep "^$3 " komentarji/$file > /dev/null && { echo "<div class=komentar style='border:1px solid red'>"; komentar $1 $file 5; echo "</div>"; } + done + echo "<div id=odgovor>`curl --fail-with-body http://z.4a.si/skovikanje/komentar.php?action=//z.4a.si./skovikanje/komentar.php%3Fna=$3%26tip=objava%26ref=REPLACEME | sed s/REPLACEME/HTTP_REFERER/`</div>" + echo $komentiraj + echo "<script>odgovor.style='background:gray;position:fixed;right:0;bottom:0';odgovor.hidden=true;komentiraj.hidden=false;</script>" + else + besedilo $2 <(head -n4 objave/$3) 1 5 + komentarjev=0 + for file in `ls --reverse --sort=time --time=birth komentarji` + do + grep "^$3 " komentarji/$file > /dev/null && komentarjev=$(($komentarjev+1)) + done + echo "<h4><a href=skovik/$3.html>Klikni sem za ogled celotnega besedila, komentiranje in branje komentarjev ($komentarjev).</a></h4>" + fi +fi |