tinycm view plugins/community/community.cgi @ rev 94
Clean-up keygen plugin
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Feb 17 13:39:44 2017 +0100 (2017-02-17) |
parents | 97dca04ea0fa |
children | a7f76c79d13f |
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&delmsg=$m'>Delete</a></span>"
76 fi
77 echo "</div><p>"
78 cat ${wall}/${m} | wiki_parser
79 echo "</p></div>"
80 done
81 if check_auth; then
82 cat << EOT
83 <div id="tools">
84 <a href="$script?community">$(gettext "Community Tools")</a>
85 </div>
86 EOT
87 fi
88 html_footer && exit 0 ;;
90 *\ community\ *)
91 d="Community Tools"
92 header
93 html_header
94 user_box
95 echo '<div id="tools">'
96 if check_auth; then
97 echo "<a href='$script?dashboard'>Dashboard</a>"
98 fi
99 cat << EOT
100 <a href="$script?wall">Community Wall</a>
101 </div>
102 <h2>$d</h2>
103 <p>$SHORT_DESC</p>
104 EOT
105 if admin_user; then
106 cat << EOT
107 <h3>Plugin config</h3>
108 <pre>
109 Wall mode : $WALL_MODE
110 Messages length : $WALL_MESSAGES_LENGTH
111 </pre>
112 EOT
113 fi
114 html_footer && exit 0 ;;
115 esac