tinycm view plugins/community/community.cgi @ rev 92

Improve users and community plugin
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 17 12:44:05 2017 +0100 (2017-02-17)
parents 12c983066e52
children 97dca04ea0fa
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 [ "$WALL_MODE" == "private" ] && ! check_auth; then
17 gettext "Private Wall - You must be logged in 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 echo "<h2>$d</h2>"
43 if check_auth; then
44 cat << EOT
46 <form method="get" action="$script" id="wall-form" name ="wall" onsubmit="return checkWall();">
47 <input type="hidden" name="wall" />
48 <textarea name="message" maxlength="${WALL_MESSAGES_LENGTH}"></textarea>
49 <div>
50 <input type="submit" value="$(gettext 'Send message')" />
51 $(eval_gettext "Date: $date - Max char:") ${WALL_MESSAGES_LENGTH} -
52 $(gettext "Wiki syntax is supported:")
53 <a href="?d=en/help">$(gettext "Help page")</a>
54 </div>
55 </form>
57 <h2>$(gettext "Latest Messages")</h2>
58 EOT
59 fi
60 # Display messages &nb=40
61 msg_nb=40
62 if [ "$(GET nb)" ]; then
63 msg_nb=$(GET nb)
64 fi
65 for m in $(ls -r $wall | head -n ${msg_nb})
66 do
67 author=$(echo ${m} | cut -d "_" -f 3)
68 pubdate=$(echo ${m} | cut -d "_" -f 1-2 | sed s"/_/ /")
69 cat << EOT
70 <div class="wall-message">
71 <div>By <a href='?user=${author%.txt}'>${author%.txt}</a>
72 - <span class="date">${pubdate}</span>
73 EOT
74 if [ "$user" == "${author%.txt}" ] || admin_user; then
75 echo " - <span class='del'><a href='?wall&amp;delmsg=$m'>Delete</a></span>"
76 fi
77 echo "</div><p>"
78 cat ${wall}/${m} | wiki_parser
79 echo "</p></div>"
80 done
81 cat << EOT
82 <div id="tools">
83 <a href="$script?community">$(gettext "Community Tools")</a>
84 </div>
85 EOT
86 html_footer && exit 0 ;;
88 *\ community-config\ *)
89 d="Community plugin config"
90 header
91 html_header
92 user_box
93 cat << EOT
94 <div id="tools">
95 <a href="$script?dashboard">Dashboard</a>
96 <a href="$script?community">Community Tools</a>
97 </div>
99 <h2>$d</h2>
100 <pre>
101 Wall mode : $WALL_MODE
102 Messages length : $WALL_MESSAGES_LENGTH
103 </pre>
104 EOT
105 html_footer && exit 0 ;;
107 *\ community\ *)
108 d="Community Tools"
109 header
110 html_header
111 user_box
112 cat << EOT
113 <div id="tools">
114 <a href="$script?dashboard">Dashboard</a>
115 <a href="$script?wall">Community Wall</a>
116 <a href="$script?community-config">Plugin Config</a>
117 </div>
118 <h2>$d</h2>
119 <p>$SHORT_DESC</p>
120 EOT
122 html_footer && exit 0 ;;
123 esac