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

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 12:26:25 2019 +0100 (2019-02-26)
parents 95673a3de4e4
children
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 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 *\ twitter\ *)
91 d="Tweets by @${TWITTER_USER}"
92 header
93 html_header
94 user_box
95 cat << EOT
96 <a class="twitter-timeline"
97 href="https://twitter.com/${TWITTER_USER}">Tweets by ${TWITTER_USER}</a>
98 <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
99 EOT
100 html_footer && exit 0 ;;
102 *\ facebook\ *)
103 d="Facebook @${FACEBOOK_PAGE}"
104 header
105 html_header
106 user_box
107 cat << EOT
108 <div id="fb-root"></div>
109 <script>(function(d, s, id) {
110 var js, fjs = d.getElementsByTagName(s)[0];
111 if (d.getElementById(id)) return;
112 js = d.createElement(s); js.id = id;
113 js.src = "//connect.facebook.net/fr_FR/sdk.js#xfbml=1&version=v2.8";
114 fjs.parentNode.insertBefore(js, fjs);
115 }(document, 'script', 'facebook-jssdk'));</script>
117 <div style="text-align: center;">
118 <div class="fb-page"
119 data-href="https://www.facebook.com/${FACEBOOK_PAGE}"
120 data-tabs="timeline"
121 data-width="500"
122 data-height="500"
123 data-small-header="true"
124 data-adapt-container-width="false"
125 data-hide-cover="true"
126 data-show-facepile="false">
127 <blockquote cite="https://www.facebook.com/${FACEBOOK_PAGE}" class="fb-xfbml-parse-ignore">
128 <a href="https://www.facebook.com/${FACEBOOK_PAGE}">${FACEBOOK_PAGE}</a>
129 </blockquote>
130 </div>
131 </div>
132 EOT
133 html_footer && exit 0 ;;
135 *\ community\ *)
136 d="Community Tools"
137 header
138 html_header
139 user_box
140 echo '<div id="tools">'
141 if check_auth; then
142 echo "<a href='$script?dashboard'>Dashboard</a>"
143 fi
144 cat << EOT
145 <a href="$script?wall">Community Wall</a>
146 <a href="$script?twitter">Twitter Timeline</a>
147 <a href="$script?facebook">Facebook Page</a>
148 </div>
149 <h2>$d</h2>
150 <p>$SHORT_DESC</p>
151 EOT
152 if admin_user; then
153 cat << EOT
154 <h3>Plugin config</h3>
155 <pre>
156 Wall mode : $WALL_MODE
157 Messages length : $WALL_MESSAGES_LENGTH
158 Twitter user : $TWITTER_USER
159 </pre>
160 EOT
161 fi
162 html_footer && exit 0 ;;
163 esac