summaryrefslogtreecommitdiff
path: root/tears.cgi
diff options
context:
space:
mode:
authorbie <bie@blekksprut.net>2016-11-10 18:49:36 +0100
committerbie <bie@blekksprut.net>2016-11-10 18:49:36 +0100
commit61d54a847fe5dd79c945820bba5d42b8e357b4d3 (patch)
tree4893b18a516526356c62bd8bc39203ddd482fc90 /tears.cgi
parente5a20e6113a0a1e303cffa54945d120de3ce31b2 (diff)
downloadtears-61d54a847fe5dd79c945820bba5d42b8e357b4d3.tar.xz
THESE TEARS ARE MADE FOR CAULKIN'
Diffstat (limited to 'tears.cgi')
-rwxr-xr-xtears.cgi121
1 files changed, 77 insertions, 44 deletions
diff --git a/tears.cgi b/tears.cgi
index 6698f07..ebf246f 100755
--- a/tears.cgi
+++ b/tears.cgi
@@ -1,10 +1,10 @@
-#!/usr/local/bin/haserl --shell=/bin/bash
+#!/usr/bin/haserl --shell=/bin/bash
<%
-VERSION=0.1
-BASE="/~bie/tears"
-HOST="low.radionova.no"
+VERSION=0.4
+BASE="/tears"
+HOST="zanthia.radionova.no"
path=$(pdecode <<<"${PATH_INFO#/}")
@@ -15,11 +15,11 @@ error() {
}
irc() {
- teatime -c '#radionova' "$1"
+ /opt/bin/birk -c radionova "$1"
}
byline() {
- echo # noe som fungerer både på lunix og bsd her
+ echo "skrevet av $(ls -ld $1 | awk '{print $3}')"
}
info() {
@@ -27,43 +27,70 @@ info() {
}
link() {
- [ "$BASE/$2" = $REQUEST_URI ] && echo "$1" || echo "<a href='$BASE/$2'>$1</a>"
+ local raw=${REQUEST_URI%\?*}
+ local clean="/${raw%/}"
+ local rawt="$BASE/$2"
+ local cleant="/${rawt%/}"
+ [ $cleant = $clean ] && echo "$1" || echo "<a href='$BASE/$2'>$1</a>"
}
qlink() {
text="$1" && url="$BASE/$2" && shift 2
- IFS=\& && echo -n "<a href='$url?$*'>$text</a>"
+ local IFS=\& && echo -ne "<a href='$url?$*'>$text</a>\n"
}
redirect() {
- echo "Content-Type: text/html"
+ echo -e "Content-Type: text/html; charset=utf-8"
echo -e "Location: https://$HOST$1\n"
echo "٩(͡๏̯͡๏)۶>"
}
+stikkordsøk() {
+ [ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return
+ echo "<form method=get>"
+ echo "<p><b>stikkordsøk</b>"
+ echo "<br><input type=text size=10 name=stikkord value='$GET_stikkord'>"
+ echo "<input type=hidden name=dato value='$GET_dato'>"
+ echo "</form>"
+}
+
kalender() {
[ "$action" = index.html -o "$action" = ditt -o "$action" = gruppe ] || return
echo "<p><b>for mye? reis i tid…</b>"
IFS=- read y m d <<<"$GET_dato"
+ n=0
+ [ -n "$GET_stikkord" ] && n=1
if [ -z "$y" ]; then
- for directory in $(cut -d / -f 2 | sort | uniq); do
+ for directory in $(cut -d / -f $((n + 2)) | sort | uniq); do
year=$(basename $directory)
- echo "<a href='?dato=$year'>$year</a>"
+ qlink "$year" "$action/$path" "dato=$year" "stikkord=$GET_stikkord"
done
elif [ -z "$m" ]; then
- echo "<b><a href='?'>$y</a></del></b><br>"
- for directory in $(cut -d / -f 3 | sort | uniq); do
+ echo "<b>"
+ qlink "$y" "$action/$path" "stikkord=$GET_stikkord"
+ echo "</b><br>"
+ for directory in $(cut -d / -f $((n + 3)) | sort | uniq); do
month=$(basename $directory)
- echo "<a href='?dato=$y-$month'>$month</a>"
+ qlink "$month" "$action/$path" "dato=$y-$month" "stikkord=$GET_stikkord"
done
elif [ -z "$d" ]; then
- echo "<b><a href='?'>$y</a>/<a href='?dato=$y'>$m</a></b><br>"
- for directory in $(cut -d / -f 4 | sort | uniq); do
+ echo "<b>"
+ qlink "$y" "$action/$path" "stikkord=$GET_stikkord"
+ echo "/"
+ qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord"
+ echo "</b><br>"
+ for directory in $(cut -d / -f $((n + 4)) | sort | uniq); do
day=$(basename $directory)
- echo "<a href='?dato=$y-$m-$day'>$day</a>"
+ qlink "$day" "$action/$path" "dato=$y-$m-$day" "stikkord=$GET_stikkord"
done
else
- echo "<b><a href='?'>$y</a>/<a href='?dato=$y'>$m</a>/<a href='?dato=$y-$m'>$d</a></b>"
+ echo "<b>"
+ qlink "$y" "$action/$path" "stikkord=$GET_stikkord"
+ echo "/"
+ qlink "$m" "$action/$path" "dato=$y" "stikkord=$GET_stikkord"
+ echo "/"
+ qlink "$d" "$action/$path" "dato=$y-$m" "stikkord=$GET_stikkord"
+ echo "</b><br>"
fi
}
@@ -83,6 +110,7 @@ meny() {
link "$group" "gruppe/$group"
done
kalender
+ stikkordsøk
echo "<p><b>kos deg! ٩(͡๏̯͡๏)۶</b>"
echo "<p class=footer><b>tears $VERSION</b><br>"
link 'todo' 'todo' && echo '|' && link 'teatime' 'teatime'
@@ -101,21 +129,22 @@ liste() {
qlink "eldre artikler…" "$action/$path" "dato=$GET_dato" "n=$n"
}
-tags() {
- find -L tags -samefile "$1" -execdir dirname {} + | while read file; do
- echo -n "${file##*/} "
+stikkord() {
+ find -L stikkord -samefile "$1" | while read file; do
+ local imp=${file#stikkord/}
+ local ord=${imp%%/*}
+ [ -z "$first" ] || echo -n " "
+ echo -n "$ord"
+ first=1
done
-
- # tag "$1" "$POST_tags"
}
-tag() {
- echo "<p>"
- for tag in $2; do
- echo "-- sjekke om tag $tag er ok --"
- echo "<br>"
- echo ln -s "$1" "tags/$tag/$(tr / - <<<$1)"
- echo "<br>"
+stikk() {
+ find -L stikkord -samefile "$1" -delete
+ for ord in $2; do
+ local path="stikkord/$ord/${1#artikler/}"
+ mkdir -p "$(dirname $path)"
+ ln -s "../../../../../$1" "$path"
done
}
@@ -124,9 +153,8 @@ skjema() {
[ ! -w "$1" ] && echo "<p>du har ikke skrivetilgang" && exit
echo "<form method='post' action='$BASE/oppdater/$1'>"
lupin -f <$1
- echo "<p><label>Magiske ord:</label>"
- echo "<input type='text' name='tags' value='$(tags $1)'>"
- tag "$1" "ok test haha"
+ echo "<p><label>Stikkord:</label>"
+ echo "<input type='text' name='stikkord' value='$(stikkord $1)'>"
echo "<p><input type='submit' value='Lagre'>"
echo "</form>"
echo "<p><b>$(info $1)</b>"
@@ -155,6 +183,8 @@ oppdater() {
[ ! -f "$1" ] && error "finner ikke $1"
[ ! -w "$1" ] && error "ikke skrivetilgang til $1"
[ -z "$POST_title" ] && error "ingen overskrift"
+ [ -z "$POST_stikkord" ] && error "ingen stikkord"
+ stikk "$1" "$POST_stikkord"
lupin -l -e >$1
irc "$(whoami) redigerte $POST_title"
redirect "$BASE/rediger/$path"
@@ -162,13 +192,11 @@ oppdater() {
kort() {
IFS=/. read -r type y m d hhmm slug ext <<< "$1"
- (
- read -r tittel
- echo "<h2>$tittel</h2>" "<p class='x'>$(byline $1), $y/$m/$d"
- [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1")
- [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1")
- [ -z "$2" ] && head -1 | marxup - || marxup -
- ) < $1
+ lupin -t -h <$1
+ echo "<p class='x'>$(byline $1), $y/$m/$d"
+ [ -r "$1" ] && echo "·" && link "vis" $(pencode / <<<"vis/$1")
+ [ -w "$1" ] && echo "·" && link "rediger" $(pencode / <<<"rediger/$1")
+ lupin -s -h <$1
}
forbered() {
@@ -202,8 +230,13 @@ umask 0022
groups=$(groups | tr " " "\n" | sort)
available=$(comm -12 - <(ls redaksjoner | sort) <<<"$groups")
action=$(basename $SCRIPT_FILENAME)
-kilde="artikler/$(sed 's|-|/|g' <<<$GET_dato)"
-finder="find $kilde -type f"
+if [[ "$action" == rediger && $path == stikkord/* ]]; then
+ redirect "$BASE/rediger/artikler/${path#stikkord/*/}"
+fi
+mappe="artikler"
+[ -n "$GET_stikkord" ] && mappe="stikkord/$GET_stikkord"
+kilde="$mappe/$(sed 's|-|/|g' <<<$GET_dato)"
+finder="find -L $kilde -type f"
[ "$action" = gruppe ] && finder="$finder -group $path"
[ "$action" = ditt ] && finder="$finder -user $REMOTE_USER"
[ "$REQUEST_METHOD" = GET ] && $finder | meny
@@ -214,8 +247,8 @@ case $action in
vis) vis $path;;
lagre) lagre;;
oppdater) oppdater $path;;
- teatime) irc "$(whoami) <3 teatime"; echo "<p><img src='http://atei.st/src/1352063360909860.jpg'><br>";;
- spökvåningen) echo "<p>spök";;
+ teatime) irc "$(whoami) <3 teatime"; echo "<p><img src='http://kyber.io/orz/src/1352063360909860.jpg'><br>";;
+ spökvåningen) echo "<p><img src='http://kyber.io/orz/src/1360086359591352.jpg'>";;
todo) echo "<pre>$(cat TODO)</pre>";;
esac
%>