tinycm view plugins/community/community.cgi @ rev 88
Small fix to commnity plugin
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Feb 12 01:23:48 2017 +0100 (2017-02-12) |
parents | d6f01c5019bb |
children | 12c983066e52 |
line source
1 #!/bin/sh
2 #
3 # TinyCM/TazBug Plugin - Community Tools
4 #
6 case " $(GET) " in
7 *\ wall\ *)
8 d="Community Wall"
9 wall="$tiny/$content/wall"
10 date=$(date '+%Y-%m-%d %H:%M')
11 header
12 html_header
13 user_box
15 # Wall is only for logged users
16 if ! check_auth; then
17 gettext "You must be logged to read the wall"
18 html_footer && exit 0
19 fi
21 # Save any new message first
22 if [ "$(GET message)" ] && check_auth; then
23 # Prevent more than one message by minute peer user
24 file="$(date '+%Y-%m-%d_%H:%M')_$user.txt"
25 [ -d "$wall" ] || mkdir -p ${wall}
26 # Write content to file
27 sed "s/$(echo -en '\r') /\n/g" > ${wall}/${file} << EOT
28 $(GET message)
29 EOT
30 fi
32 # Delete message if requested
33 if [ "$(GET delmsg)" ] && check_auth; then
34 m=$(GET delmsg)
35 author=$(echo ${m} | cut -d "_" -f 3)
36 if [ "$user" == "${author%.txt}" ] || admin_user; then
37 rm -f ${wall}/${m}
38 fi
39 fi
41 # Message form
42 cat << EOT
43 <h2>$d</h2>
45 <form method="get" action="$script" id="wall-form" name ="wall" onsubmit="return checkWall();">
46 <input type="hidden" name="wall" />
47 <textarea name="message" maxlength="${MESSAGE_LENGTH}"></textarea>
48 <div>
49 <input type="submit" value="$(gettext 'Send message')" />
50 $(eval_gettext "Date: $date - Max char:") ${MESSAGE_LENGTH} -
51 $(gettext "Wiki syntax is supported:")
52 <a href="?d=en/help">$(gettext "Help page")</a>
53 </div>
54 </form>
56 <h2>$(gettext "Latest Messages")</h2>
57 EOT
58 # Display messages &nb=40
59 msg_nb=40
60 if [ "$(GET nb)" ]; then
61 msg_nb=$(GET nb)
62 fi
63 for m in $(ls -r $wall | head -n ${msg_nb})
64 do
65 author=$(echo ${m} | cut -d "_" -f 3)
66 pubdate=$(echo ${m} | cut -d "_" -f 1-2 | sed s"/_/ /")
67 cat << EOT
68 <div class="wall-message">
69 <div>By <a href='?user=${author%.txt}'>${author%.txt}</a>
70 - <span class="date">${pubdate}</span>
71 EOT
72 if [ "$user" == "${author%.txt}" ] || admin_user; then
73 echo " - <span class='del'><a href='?wall&delmsg=$m'>Delete</a></span>"
74 fi
75 echo "</div><p>"
76 cat ${wall}/${m} | wiki_parser
77 echo "</p></div>"
78 done
79 cat << EOT
80 <div id="tools">
81 <a href="$script?community">$(gettext "Community Tools")</a>
82 </div>
83 EOT
84 html_footer && exit 0 ;;
86 *\ community\ *)
87 d="Community Tools"
88 header
89 html_header
90 user_box
91 cat << EOT
92 <h2>$d</h2>
93 <p>$SHORT_DESC</p>
94 <div id="tools">
95 <a href="$script?wall">Community Wall</a>
96 </div>
97 EOT
99 html_footer && exit 0 ;;
100 esac