tinycm rev 83
Add forum plugin (old code, needs work, for testing)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Feb 11 17:34:44 2017 +0100 (2017-02-11) |
parents | 4418f0315c8e |
children | d6f01c5019bb |
files | plugins/forum/forum.cgi plugins/forum/forum.conf plugins/users/users.cgi tinycm |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/plugins/forum/forum.cgi Sat Feb 11 17:34:44 2017 +0100 1.3 @@ -0,0 +1,317 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TinyCM/TazBug Plugin - Support/discussion forum using #hashtags 1.7 +# 1.8 +# Display a topic: ?forum&topic=NB 1.9 +# d= is used by html_header to set page title 1.10 +# t= is used to set the topic number 1.11 +# 1.12 +. /usr/lib/slitaz/httphelper 1.13 + 1.14 +forum="$tiny/$content/forum" 1.15 + 1.16 +# Forum tools 1.17 +forum_tools() { 1.18 + cat << EOT 1.19 +<div id="tools"> 1.20 + <a href="$script?forum=edit&t=new">$(gettext "New post")</a> 1.21 + $([ "$(GET t)" ] && echo "<a href='$script?forum'>Forum</a>") 1.22 + $([ "$index" == "forum" ] && echo "<a href='$script?d=index'>Index</a>") 1.23 + $([ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>") 1.24 +</div> 1.25 +EOT 1.26 +} 1.27 + 1.28 +# Topic tools for admin and author 1.29 +topic_tools() { 1.30 + cat << EOT 1.31 + - <a href="?forum=edit&t=${t}">$(gettext "Edit it!")</a> 1.32 + || <a href="$script?forum=rm&t=${t}">$(gettext "Remove")</a> 1.33 +EOT 1.34 +} 1.35 + 1.36 +# Create a XML feed for a new topic 1.37 +gen_rss() { 1.38 + pubdate=$(date "+%a, %d %b %Y %X") 1.39 + title="Forum: $(fgrep '====' ${forum}/${t}/topic.txt | sed s'/====//'g)" 1.40 + cat > ${forum}/${t}/topic.xml << EOT 1.41 + <item> 1.42 + <title>$title</title> 1.43 + <link>http://${SERVER_NAME}?forum=topic&t=$t</link> 1.44 + <guid>topic-$t</guid> 1.45 + <pubDate>$pubdate</pubDate> 1.46 + <description>$hashtags</description> 1.47 + </item> 1.48 +EOT 1.49 +} 1.50 + 1.51 +new_msg() { 1.52 + if check_auth; then 1.53 + cat << EOT 1.54 +<div id="edit"> 1.55 + <h3>$(gettext "New message")</h3> 1.56 + <form method="get" action="$script" name="editor"> 1.57 + <textarea name="message"></textarea> 1.58 + <input type="hidden" name="forum" value="msg" /> 1.59 + <input type="hidden" name="t" value="$t" /> 1.60 + <input type="submit" value="$(gettext 'Send message')" /> 1.61 + $(gettext "Wiki syntax is supported") - 1.62 + <a href="?d=en/help">$(gettext "Help page")</a> 1.63 + </form> 1.64 +</div> 1.65 +EOT 1.66 + fi 1.67 +} 1.68 + 1.69 +# Display a forum topic with messages: show_topic NB 1.70 +show_topic() { 1.71 + t=${1%.txt} 1.72 + . ${forum}/${t}/topic.conf 1.73 + 1.74 + if [ -f "${PEOPLE}/${AUTHOR}/account.conf" ]; then 1.75 + . ${PEOPLE}/${AUTHOR}/account.conf 1.76 + else 1.77 + echo "ERROR: ${PEOPLE}/${AUTHOR}/account.conf" 1.78 + fi 1.79 + 1.80 + echo "<div class='blogpost'>" 1.81 + cat ${forum}/${t}/topic.txt | wiki_parser 1.82 + cat << EOT 1.83 +<div class="post-tools"> 1.84 + <a href="$script?user=$USER">$(get_gravatar $MAIL 24)</a> 1.85 + <span class="date">$DATE</span> 1.86 +EOT 1.87 + 1.88 + # Topic tools for admin users (edit, remove) 1.89 + if check_auth && admin_user; then 1.90 + topic_tools 1.91 + echo "</div>" 1.92 + else 1.93 + echo "</div>" 1.94 + fi 1.95 + echo "</div>" 1.96 + 1.97 + # Hashtags 1.98 + if [ -f "${forum}/${t}/hashtags.txt" ]; then 1.99 + echo "<h3>Hashtags</h3>" 1.100 + echo "<div id='hashtags'>" 1.101 + link_hashtags 1.102 + echo "</div>" 1.103 + fi 1.104 +} 1.105 + 1.106 +# Display blog post: show_posts count 1.107 +show_topics() { 1.108 + for t in $(ls $forum | sort -r -n | head -n $1) 1.109 + do 1.110 + . ${forum}/${t}/topic.conf 1.111 + . ${PEOPLE}/${AUTHOR}/account.conf 1.112 + title="$(fgrep '====' ${forum}/${t}/topic.txt | sed s'/====//'g)" 1.113 + cat << EOT 1.114 +<div class="box topic"> 1.115 + <a href="?user=${AUTHOR}">$(get_gravatar $MAIL 24)</a> 1.116 + <span class="date">$DATE</span> : <a href="?forum=topic&t=${t}">$title</a> 1.117 + <span> 1.118 +EOT 1.119 + link_hashtags 1.120 + echo "</span></div>" 1.121 + done 1.122 +} 1.123 + 1.124 +show_messages() { 1.125 + msgs=$(ls -1 $forum/$t/msg.*.txt | wc -l) 1.126 + echo "<h3>$(gettext 'Messages'): $msgs</h3>" 1.127 + [ "$msgs" == 0 ] && echo "<p>$(gettext 'Be the first to post a message!')<p/>" 1.128 + for msg in $(ls -1tr $forum/$t/msg.*.conf) 1.129 + do 1.130 + . ${msg} 1.131 + rm="" 1.132 + # User can delete his post. 1.133 + if [ "$user" == "$AUTHOR" ]; then 1.134 + rm="- <a href=\"?forum=msgrm&t=$t&msg=$ID\">$(gettext 'Remove')</a>" 1.135 + fi 1.136 + # Display user gravatar, date and message 1.137 + cat << EOT 1.138 +<p> 1.139 + <a href="?user=$AUTHOR">$(get_gravatar $MAIL 24)</a> 1.140 + <span class="date">$DATE</span> $rm 1.141 +</p> 1.142 +<div class="forum-msg"> 1.143 +$(cat ${msg%.conf}.txt | wiki_parser) 1.144 +</div> 1.145 +EOT 1.146 + unset NAME DATE 1.147 + done 1.148 +} 1.149 + 1.150 +# Create HTML link for a topic #hashtags 1.151 +link_hashtags() { 1.152 + for h in $(cat ${forum}/${t}/hashtags.txt) 1.153 + do 1.154 + echo "<a href='?forum=hashtag&h=${h#\#}'>${h}</a>" 1.155 + done 1.156 +} 1.157 + 1.158 +# 1.159 +# Handle GET requests 1.160 +# 1.161 +if [ "$(GET forum)" ]; then 1.162 + case " $(GET forum) " in 1.163 + *\ edit\ *) 1.164 + t="$(GET t)" 1.165 + d="Edit: $(fgrep '====' ${forum}/${t}/topic.txt | sed s'/====//'g)" 1.166 + header 1.167 + html_header 1.168 + user_box 1.169 + if ! check_auth; then 1.170 + gettext "You must be logged to create a new Forum post" 1.171 + html_footer && exit 0 1.172 + fi 1.173 + # New post 1.174 + if [ "$t" == "new" ]; then 1.175 + date=$(date '+%Y-%m-%d %H:%M') 1.176 + last=$(ls -r $forum | head -n 1) 1.177 + nb=${last%.txt} 1.178 + t=$(($nb + 1)) 1.179 + conf=$(echo "====Title====") 1.180 + else 1.181 + hashtags="$(cat $forum/$t/hashtags.txt)" 1.182 + fi 1.183 + cat << EOT 1.184 +<h2>$(gettext "Forum topic"): $t</h2> 1.185 + 1.186 +<div id="edit"> 1.187 + <form method="get" action="$script" name="editor"> 1.188 + <input type="hidden" name="forum" value="save" /> 1.189 + <input type="hidden" name="t" value="$t" /> 1.190 + <textarea name="content">${conf}$(cat "$forum/$t/topic.txt")</textarea> 1.191 + <div> 1.192 + <b>#HashTags : </b> 1.193 + <input type="text" name="hashtags" value="$hashtags" /> 1.194 + </div> 1.195 + <input type="submit" value="$(gettext "Post topic")" /> 1.196 + $(gettext "Code Helper:") 1.197 + $(cat lib/jseditor.html) 1.198 + </form> 1.199 +</div> 1.200 +EOT 1.201 + html_footer && exit 0 ;; 1.202 + 1.203 + *\ save\ *) 1.204 + t="$(GET t)" 1.205 + hashtags="$(GET hashtags)" 1.206 + if check_auth; then 1.207 + [ -d "${forum}/${t}" ] || mkdir -p ${forum}/${t} 1.208 + # New topic ? 1.209 + if [ ! -f "${forum}/${t}/topic.txt" ]; then 1.210 + echo "New Forum topic: <a href='$script?forum=topic&t=$t'>Read it!</a>" \ 1.211 + | log_activity 1.212 + cat > ${forum}/${t}/topic.conf << EOT 1.213 +# TinyCM Forum topic config file 1.214 +AUTHOR="$user" 1.215 +DATE="$(date '+%Y-%m-%d %H:%M')" 1.216 +STATUS="open" 1.217 +EOT 1.218 + gen_rss 1.219 + fi 1.220 + # Write content and #hashtags to file 1.221 + sed "s/$(echo -en '\r') /\n/g" > ${forum}/${t}/topic.txt << EOT 1.222 +$(GET content) 1.223 +EOT 1.224 + echo "${hashtags}" > ${forum}/${t}/hashtags.txt 1.225 + fi 1.226 + header "Location: $script?forum=topic&t=$t" ;; 1.227 + 1.228 + *\ msgrm\ *) 1.229 + # Remove a message 1.230 + t="$(GET t)" 1.231 + if check_auth; then 1.232 + rm -f ${forum}/${t}/msg."$(GET msg)".* 1.233 + fi 1.234 + header "Location: $script?forum=topic&t=$t" ;; 1.235 + 1.236 + *\ msg\ *) 1.237 + t="$(GET t)" 1.238 + if check_auth; then 1.239 + date=$(date "+%Y-%m-%d %H:%M") 1.240 + msgs=$(ls -1 $forum/$t/msg.*.txt | wc -l) 1.241 + count=$(($msgs + 1)) 1.242 + # Write config file 1.243 + cat > ${forum}/${t}/msg.${count}.conf << EOT 1.244 +# TinyCM Forum message config file 1.245 +AUTHOR="$user" 1.246 +DATE="$(date '+%Y-%m-%d %H:%M')" 1.247 +ID="$count" 1.248 +EOT 1.249 + # Write message to file 1.250 + sed "s/$(echo -en '\r') /\n/g" > ${forum}/${t}/msg.${count}.txt << EOT 1.251 +$(GET message) 1.252 +EOT 1.253 + fi 1.254 + header "Location: $script?forum=topic&t=$t" ;; 1.255 + 1.256 + *\ rm\ *) 1.257 + # Remove a forum topic 1.258 + t="$(GET t)" 1.259 + if [ -d "${forum}/${t}" ]; then 1.260 + rm -rf ${forum}/${t} 1.261 + fi 1.262 + header "Location: $script?forum" ;; 1.263 + 1.264 + *\ hashtag\ *) 1.265 + # Display an hashtag 1.266 + hashtag="$(GET h)" 1.267 + header 1.268 + html_header 1.269 + user_box 1.270 + echo "<h2>Forum Hashtag #$hashtag</h2>" 1.271 + for h in $(fgrep -l "#$hashtag" ${forum}/*/hashtags.txt) 1.272 + do 1.273 + path=$(dirname ${h}) 1.274 + t=$(basename $path) 1.275 + . ${path}/topic.conf 1.276 + title="$(fgrep '====' $(dirname ${h})/topic.txt | sed s'/====//'g)" 1.277 + cat << EOT 1.278 +<div class='box topic'> 1.279 + <span class='date'>$DATE</span> - <a href='?forum=topic&t=$t'>$title</a> 1.280 +</div> 1.281 +EOT 1.282 + done 1.283 + html_footer && exit 0 ;; 1.284 + 1.285 + *\ topic\ *) 1.286 + # Single post: get title from topic content before html_header 1.287 + t="$(GET t)" 1.288 + d="Forum: $(fgrep '====' ${forum}/${t}/topic.txt | sed s'/====//'g)" 1.289 + header 1.290 + html_header 1.291 + user_box 1.292 + # Forum tools for auth users 1.293 + [ check_auth ] && forum_tools 1.294 + show_topic "$t" 1.295 + show_messages 1.296 + new_msg 1.297 + html_footer && exit 0 ;; 1.298 + 1.299 + *) 1.300 + d="$(gettext 'Forum Topics')" 1.301 + count="20" 1.302 + header 1.303 + html_header 1.304 + user_box 1.305 + # Exit if plugin is disabled 1.306 + if [ ! -d "$forum" ]; then 1.307 + echo "<pre class='error box'>" 1.308 + gettext "Forum plugin is not yet active."; echo 1.309 + echo "Command: install -m 0777 -d $forum</pre>" 1.310 + html_footer && exit 0 1.311 + fi 1.312 + echo $(GET topic) 1.313 + # Forum tools for auth users 1.314 + [ check_auth ] && forum_tools 1.315 + echo "<h2>$d</h2>" 1.316 + show_topics ${count} ;; 1.317 + esac 1.318 + html_footer && exit 0 1.319 +fi 1.320 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/plugins/forum/forum.conf Sat Feb 11 17:34:44 2017 +0100 2.3 @@ -0,0 +1,7 @@ 2.4 +# TinyCM Plugin configuration 2.5 + 2.6 +PLUGIN="Hashtags Forum" 2.7 +SHORT_DESC="Support/discussion forum using #hashtags" 2.8 +MAINTAINER="devel@slitaz.org" 2.9 + 2.10 +# Configurable variables used in plugin.cgi
3.1 --- a/plugins/users/users.cgi Sat Feb 11 17:04:56 2017 +0100 3.2 +++ b/plugins/users/users.cgi Sat Feb 11 17:34:44 2017 +0100 3.3 @@ -50,6 +50,7 @@ 3.4 </div> 3.5 <pre> 3.6 User accounts : $(ls -1 $PEOPLE | wc -l) 3.7 +Logged users : $(ls $sessions | wc -l) 3.8 People DB : $PEOPLE 3.9 Auth file : $AUTH_FILE 3.10 EOT 3.11 @@ -105,8 +106,9 @@ 3.12 gettext "You must be logged in to view online users" 3.13 exit 0 3.14 fi 3.15 + logged="$(ls $sessions | wc -l)" 3.16 cat << EOT 3.17 -<h2>Logged users</h2> 3.18 +<h2>Logged users: $logged</h2> 3.19 <div id="tools"> 3.20 <a href="$script?dashboard">Dashboard</a> 3.21 <a href="$script?users">Users admin</a>
4.1 --- a/tinycm Sat Feb 11 17:04:56 2017 +0100 4.2 +++ b/tinycm Sat Feb 11 17:34:44 2017 +0100 4.3 @@ -4,7 +4,7 @@ 4.4 # Linux/BSD distribution providing a web server with CGI SHell support 4.5 # such as LightTPD. 4.6 # 4.7 -# Copyright (C) 2014 SliTaz GNU/Linux - BSD License 4.8 +# Copyright (C) 2014-2017 SliTaz GNU/Linux - BSD License 4.9 # 4.10 4.11 list="tinycm.list" 4.12 @@ -69,6 +69,7 @@ 4.13 mkdir -p $path 4.14 for file in index.cgi style.css images lib plugins 4.15 do 4.16 + echo "* Installing: $file" 4.17 cp -a $file $path 4.18 done 4.19 if [ $(id) == 0 ]; then