#// preview.awk
#// Preview a post in the post edit interface
#// 25.04.2015
#//
#// Copyright (C) 2015 Balthasar SzczepaĆski
#//
#// This program is free software: you can redistribute it and/or modify
#// it under the terms of the GNU Affero General Public License as
#// published by the Free Software Foundation, either version 3 of the
#// License, or (at your option) any later version.
#//
#// This program is distributed in the hope that it will be useful,
#// but WITHOUT ANY WARRANTY; without even the implied warranty of
#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#// GNU Affero General Public License for more details.
#//
#// You should have received a copy of the GNU Affero General Public License
#// along with this program. If not, see .
BEGIN{
sentpath="/eizm/mem/t1i/mpost/sent/"
waitpath="/eizm/mem/t1i/mpost/"
HTML="
"
wrong="%s
\n"
subject=" \n"
username=" \n"
time="Y: M: D: H: \n"
message="\n"
# forcetime1=" \n"
# forcetime2="fTime: day: month: year: \n"
# img=" "
back="back to the Silent Chronotransponder "
disable_bbcode=" Disable BBcode \n"
disable_smilies=" Disable smilies \n"
disable_magic_url=" Do not automatically parse URLs \n"
attach_sig=" Attach a signature \n"
notify=" Notify me when a reply is posted \n"
silent=" Very silent \n"
forceID=" \n"
forcekey=" \n"
addquote=""
# print ""
close(argfile)
if(argtab["edit"] ~ /^wt[0-9]+_[0-9a-fA-F]+$/)
{
argtab["forceID"]=substr(argtab["edit"],3)
argfile= waitpath argtab["forceID"]
while((getline argline < argfile)>0)
{
gsub(/[\r\n]/,"",argline)
eq=index(argline,"=")
if(argline ~ /^key=/)
{
if(substr(argline,eq+1)!=key && argtab["addquote"]~/^wt/)
{
argtab["wrong"]="Invalid key."
break;
}
argtab["key"]=substr(argline,eq+1)
}
else if(argline ~ /^((username)|(subject))_h=/)
argtab[substr(argline,1,eq-3)]=substr(argline,eq+1)
else if(argline ~ /^BBHTML=/)
{
argtab["message"]=substr(argline,eq+1)
gsub(/ /,"\n",argtab["message"])
}
else if(argline ~ /^((BB)|(username)|(subject)|(message)|(HTML)|(debug))=/)
{}
else
argtab[substr(argline,1,eq-1)]=substr(argline,eq+1)
}
close(argfile)
}
else if(argtab["addquote"] ~ /^[sw]t[0-9]+_[0-9a-fA-F]+$/)
{
if(argtab["addquote"] ~ /^st[0-9]+_[0-9a-fA-F]+$/)
argfile= sentpath substr(argtab["addquote"],3)
if(argtab["addquote"] ~ /^wt[0-9]+_[0-9a-fA-F]+$/)
argfile= waitpath substr(argtab["addquote"],3)
#else
#argfile is not changed = quote self?
while((getline argline < argfile)>0)
{
gsub(/[\r\n]/,"",argline)
eq=index(argline,"=")
if(argline ~ /^key=/)
{
if(substr(argline,eq+1)!=key && argtab["addquote"]~/^wt/)
{
argtab["wrong"]="Invalid key."
break;
}
}
if(argline ~ /^BBHTML=/)
{
addquotehtml=substr(argline,eq+1)
gsub(/ /,"\n",addquotehtml)
}
if(argline ~ /^username_h=/)
addquotename=substr(argline,eq+1)
if(argline ~ /^subject_h/)
{
addquotesub=substr(argline,eq+1)
if(addquotesub ~ /^Re:/)
argtab["subject"]=addquotesub
else
argtab["subject"]="Re: "addquotesub
}
if(argline ~ /^y=/)
{
argtab["y"]=substr(argline,eq+1)
}
if(argline ~ /^d=/)
{
argtab["d"]=substr(argline,eq+1)
}
if(argline ~ /^m=/)
{
argtab["m"]=substr(argline,eq+1)
}
if(argline ~ /^h=/)
{
argtab["h"]=substr(argline,eq+1)
}
}
close(argfile)
if(addquotehtml!="")
addquote="[quote=""addquotename""]"addquotehtml"[/quote]"
}
};
{
if ($0 ~ /^###HTML/)
{
if((argtab["HTML"]!="")&&(argtab["wrong"]==""))
printf(HTML,argtab["subject"],argtab["HTML"])
}
else if ($0 ~ /^###wrong/)
{
if(argtab["wrong"]!="")
printf(wrong,argtab["wrong"])
}
else if ($0 ~ /^###subject/)
printf(subject,((argtab["subject"]=="")?"Wait for it.":argtab["subject"]))
else if ($0 ~ /^###username/)
printf(username,argtab["username"])
else if ($0 ~ /^###message/)
printf(message,argtab["message"],addquote)
else if ($0 ~ /^###time/)
printf(time,argtab["y"],argtab["m"],argtab["d"],argtab["h"])
else if ($0 ~ /^###future/)
{
###no longer supported
}
else if ($0 ~ /^###forceID/)
{
if(argtab["forceID"]!="")
printf(forceID,argtab["forceID"])
}
else if ($0 ~ /^###forcekey/)
{
if(argtab["key"]!="")
printf(forcekey,argtab["key"])
}
else if ($0 ~ /^###back/)
{
print back
}
else if ($0 ~ /^###debug/)
{
gsub(/###nl;/,"\n",argtab["debug"])
gsub(/-/," - ",argtab["debug"])
print ""
}
else if ($0 ~ /^###disable_bbcode/)
printf(disable_bbcode,(argtab["disable_bbcode"]=="on")?"checked=\"checked\"":"")
else if ($0 ~ /^###disable_smilies/)
printf(disable_smilies,(argtab["disable_smilies"]=="on")?"checked=\"checked\"":"")
else if ($0 ~ /^###disable_magic_url/)
printf(disable_magic_url,(argtab["disable_magic_url"]=="on")?"checked=\"checked\"":"")
else if ($0 ~ /^###attach_sig/)
printf(attach_sig,(argtab["attach_sig"]=="on")?"checked=\"checked\"":"")
else if ($0 ~ /^###notify/)
printf(notify,(argtab["notify"]=="on")?"checked=\"checked\"":"")
else if ($0 ~ /^###silent/)
printf(silent,(argtab["silent"]=="on")?"checked=\"checked\"":"")
else
print $0
};