tinycm annotate plugins/blog/blog.cgi @ rev 64
Tiny edits
author | Paul Issott <paul@slitaz.org> |
---|---|
date | Thu Feb 06 19:35:03 2014 +0000 (2014-02-06) |
parents | 03338ebb4d86 |
children | 007a950f9808 |
rev | line source |
---|---|
pankso@27 | 1 #!/bin/sh |
pankso@27 | 2 # |
pankso@27 | 3 # TinyCM Plugin - Blog |
pankso@27 | 4 # |
pankso@27 | 5 . /usr/lib/slitaz/httphelper |
pankso@27 | 6 |
pankso@27 | 7 blog="$tiny/$content/blog" |
pankso@27 | 8 |
pankso@62 | 9 # # Blog tools for admin users only |
pankso@27 | 10 blog_tools() { |
pankso@62 | 11 if check_auth && admin_user; then |
pankso@62 | 12 cat << EOT |
pankso@27 | 13 <div id="tools"> |
pankso@62 | 14 <a href="$script?blog">$(gettext "Blog")</a> |
pankso@62 | 15 <a href="$script?blog=edit&p=new">$(gettext "New post")</a> |
pankso@27 | 16 <a href="$script?dashboard">Dashboard</a> |
pankso@27 | 17 $([ "$index" == "blog" ] && echo "<a href='$script?d=index'>Index</a>") |
pankso@27 | 18 $([ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>") |
pankso@27 | 19 </div> |
pankso@27 | 20 EOT |
pankso@62 | 21 fi |
pankso@27 | 22 } |
pankso@27 | 23 |
pankso@27 | 24 # Post tools |
pankso@27 | 25 post_tools() { |
pankso@27 | 26 cat << EOT |
pankso@62 | 27 - <a href="$script?blog=edit&p=${p}">$(gettext "Edit it!")</a> |
pankso@62 | 28 || <a href="$script?blog=rm&p=${p}">$(gettext "Remove")</a> |
pankso@27 | 29 EOT |
pankso@62 | 30 } |
pankso@62 | 31 |
pankso@62 | 32 # Create a XML feed for a new post |
pankso@62 | 33 gen_rss() { |
pankso@62 | 34 pubdate=$(date "+%a, %d %b %Y %X") |
pankso@62 | 35 desc="$(cat ${blog}/${p}/post.txt | grep ^[A-Za-z] | head -n 4)" |
pankso@62 | 36 . ${blog}/${p}/post.conf |
pankso@62 | 37 cat > ${blog}/${p}/post.xml << EOT |
pankso@62 | 38 <item> |
pankso@62 | 39 <title>$TITLE</title> |
pankso@62 | 40 <link>http://${SERVER_NAME}?blog&p=$p</link> |
pankso@62 | 41 <guid>blog-$p</guid> |
pankso@62 | 42 <pubDate>$pubdate</pubDate> |
pankso@62 | 43 <description>$desc</description> |
pankso@62 | 44 </item> |
pankso@62 | 45 EOT |
pankso@62 | 46 } |
pankso@62 | 47 |
pankso@62 | 48 # RSS Feed |
pankso@62 | 49 rss() { |
pankso@62 | 50 pubdate=$(date "+%a, %d %b %Y %X") |
pankso@62 | 51 cat << EOT |
pankso@62 | 52 Content-Type: text/xml |
pankso@62 | 53 |
pankso@62 | 54 <?xml version="1.0" encoding="utf-8" ?> |
pankso@62 | 55 <rss version="2.0"> |
pankso@62 | 56 <channel> |
pankso@62 | 57 <title>TinyCM RSS</title> |
pankso@62 | 58 <description>The Blog feed</description> |
pankso@62 | 59 <link>http://${SERVER_NAME}</link> |
pankso@62 | 60 <lastBuildDate>$pubdate GMT</lastBuildDate> |
pankso@62 | 61 <pubDate>$pubdate GMT</pubDate> |
pankso@62 | 62 EOT |
pankso@62 | 63 for p in $(ls $blog | sort -r -n | head -n 8) |
pankso@62 | 64 do |
pankso@62 | 65 cat $blog/$p/post.xml |
pankso@62 | 66 done |
pankso@62 | 67 cat << EOT |
pankso@62 | 68 </channel> |
pankso@62 | 69 </rss> |
pankso@62 | 70 EOT |
pankso@27 | 71 } |
pankso@27 | 72 |
pankso@27 | 73 # Display blog post: show_posts nb |
pankso@28 | 74 show_post() { |
pankso@62 | 75 [ -f "$blog/$1/post.conf" ] || return 1 |
pankso@62 | 76 p="$1" |
pankso@62 | 77 . ${blog}/${p}/post.conf |
pankso@62 | 78 d="$TITLE" |
pankso@62 | 79 |
pankso@62 | 80 # Author info |
pankso@62 | 81 if [ -f "${PEOPLE}/${AUTHOR}/account.conf" ]; then |
pankso@62 | 82 . ${PEOPLE}/${AUTHOR}/account.conf |
pankso@28 | 83 else |
pankso@62 | 84 echo "ERROR: ${PEOPLE}/${AUTHOR}/account.conf" |
pankso@28 | 85 fi |
pankso@62 | 86 |
pankso@62 | 87 echo "<h2>$TITLE</h2>" |
pankso@62 | 88 echo "<div class='blogpost'>" |
pankso@62 | 89 cat ${blog}/${p}/post.txt | wiki_parser |
pankso@28 | 90 cat << EOT |
pankso@28 | 91 <div class="post-tools"> |
pankso@28 | 92 <a href="$script?user=$USER">$(get_gravatar $MAIL 24)</a> |
pankso@62 | 93 <span class="date">$DATE</span> |
pankso@28 | 94 EOT |
pankso@48 | 95 # Post tools for admin users |
pankso@48 | 96 if check_auth && admin_user; then |
pankso@28 | 97 post_tools |
pankso@28 | 98 echo "</div>" |
pankso@28 | 99 else |
pankso@28 | 100 echo "</div>" |
pankso@28 | 101 fi |
pankso@28 | 102 echo "</div>" |
pankso@28 | 103 } |
pankso@28 | 104 |
pankso@28 | 105 # Display blog post: show_posts count |
pankso@27 | 106 show_posts() { |
pankso@49 | 107 for p in $(ls $blog | sort -r -n | head -n $1) |
pankso@27 | 108 do |
pankso@28 | 109 show_post ${p} |
pankso@27 | 110 done |
pankso@27 | 111 } |
pankso@27 | 112 |
pankso@27 | 113 # |
paul@64 | 114 # Index main page can display the latest Blog posts |
pankso@27 | 115 # |
pankso@27 | 116 if fgrep -q '[BLOG]' $tiny/$wiki/index.txt && [ ! "$(GET)" ]; then |
pankso@28 | 117 d="Blog posts" |
pankso@27 | 118 index="blog" |
pankso@27 | 119 header |
pankso@27 | 120 html_header |
pankso@27 | 121 user_box |
pankso@27 | 122 # Post tools for auth users |
pankso@30 | 123 if admin_user; then |
pankso@27 | 124 blog_tools |
pankso@27 | 125 fi |
pankso@27 | 126 show_posts 5 |
pankso@27 | 127 echo "<p><a href='$script?blog'>$(gettext "More blog posts")</a></p>" |
pankso@27 | 128 html_footer && exit 0 |
pankso@27 | 129 fi |
pankso@27 | 130 |
pankso@60 | 131 # |
pankso@60 | 132 # Handle GET requests |
pankso@60 | 133 # |
pankso@60 | 134 |
pankso@60 | 135 if [ "$(GET blog)" ]; then |
pankso@60 | 136 case " $(GET blog) " in |
pankso@60 | 137 *\ edit\ *) |
pankso@62 | 138 d="Editing: $(GET p)" |
pankso@62 | 139 p="$(GET p)" |
pankso@60 | 140 header |
pankso@60 | 141 html_header |
pankso@60 | 142 user_box |
pankso@60 | 143 if ! check_auth && admin_user; then |
pankso@60 | 144 gettext "You must be admin to create a new Blog post" |
pankso@60 | 145 html_footer && exit 0 |
pankso@60 | 146 fi |
pankso@62 | 147 blog_tools |
pankso@60 | 148 # New post |
pankso@62 | 149 if [ "$p" == "new" ]; then |
pankso@60 | 150 last=$(ls $blog | sort -r -n | head -n 1) |
pankso@62 | 151 p=$(($last + 1)) |
pankso@62 | 152 AUTHOR="$user" |
pankso@62 | 153 DATE=$(date '+%Y-%m-%d') |
pankso@62 | 154 else |
pankso@62 | 155 . ${blog}/${p}/post.conf |
pankso@60 | 156 fi |
pankso@60 | 157 cat << EOT |
pankso@62 | 158 <h2>$(gettext "Blog post"): $p</h2> |
pankso@27 | 159 |
pankso@27 | 160 <div id="edit"> |
pankso@60 | 161 <form method="get" action="$script?" name="editor"> |
pankso@62 | 162 <input type="text" name="title" value="$TITLE" placeholder="Title" /> |
pankso@60 | 163 <input type="hidden" name="blog" value="save" /> |
pankso@62 | 164 <input type="hidden" name="p" value="$p" /> |
pankso@62 | 165 <textarea name="content">$(cat "$blog/$p/post.txt")</textarea> |
pankso@62 | 166 <div> |
pankso@62 | 167 <input type="submit" value="$(gettext "Post content")" /> |
pankso@62 | 168 <input style="width: 20%;" type="text" |
pankso@62 | 169 name="author" value="$AUTHOR" /> |
pankso@62 | 170 <input style="width: 20%; display: inline;" type="text" |
pankso@62 | 171 name="date" value="$DATE" /> |
pankso@62 | 172 </div> |
pankso@62 | 173 |
pankso@62 | 174 <p> |
pankso@27 | 175 $(gettext "Code Helper:") |
pankso@27 | 176 $(cat lib/jseditor.html) |
pankso@62 | 177 </p> |
pankso@27 | 178 </form> |
pankso@27 | 179 </div> |
pankso@27 | 180 EOT |
pankso@60 | 181 html_footer && exit 0 ;; |
pankso@60 | 182 |
pankso@60 | 183 *\ save\ *) |
pankso@62 | 184 p="$(GET p)" |
pankso@60 | 185 if check_auth && admin_user; then |
pankso@62 | 186 [ -d "$blog/$p" ] || mkdir -p ${blog}/${p} |
pankso@60 | 187 # New post ? |
pankso@62 | 188 if [ ! -f "${blog}/${p}/post.txt" ]; then |
pankso@62 | 189 cat > ${blog}/${p}/post.conf << EOT |
pankso@62 | 190 # TinyCM Blog post configuration |
pankso@62 | 191 AUTHOR="$(GET author)" |
pankso@62 | 192 DATE="$(GET date)" |
pankso@62 | 193 TITLE="$(GET title)" |
pankso@62 | 194 EOT |
pankso@62 | 195 echo "New Blog post: <a href='$script?blog=$p'>Read it!</a>" \ |
pankso@60 | 196 | log_activity |
pankso@60 | 197 fi |
pankso@60 | 198 # Write content to file |
pankso@62 | 199 sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT |
pankso@27 | 200 $(GET content) |
pankso@27 | 201 EOT |
pankso@62 | 202 fi |
pankso@62 | 203 [ -f "${blog}/${p}/post.xml" ] || gen_rss |
pankso@62 | 204 header "Location: $script?blog&p=$p" ;; |
pankso@62 | 205 |
pankso@62 | 206 *\ rm\ *) |
pankso@62 | 207 if check_auth && admin_user; then |
pankso@62 | 208 rm -rf ${blog}/"$(GET p)" |
pankso@62 | 209 fi |
pankso@60 | 210 header "Location: $script?blog" ;; |
pankso@62 | 211 |
pankso@62 | 212 *\ archives\ *) |
paul@64 | 213 # List all posts with title only |
pankso@62 | 214 d="Blog archives" |
pankso@62 | 215 header |
pankso@62 | 216 html_header |
pankso@62 | 217 user_box |
pankso@62 | 218 blog_tools |
pankso@62 | 219 echo "<h2>Blog archives</h2>" |
pankso@62 | 220 echo "<pre>" |
pankso@62 | 221 for p in $(ls $blog) |
pankso@62 | 222 do |
pankso@62 | 223 . ${blog}/${p}/post.conf |
pankso@62 | 224 echo "\ |
pankso@62 | 225 <span class='date'>$DATE :</span> <a href='$script?blog&p=$p'>$TITLE</a>" |
pankso@62 | 226 done |
pankso@62 | 227 echo "</pre>" ;; |
pankso@60 | 228 |
pankso@60 | 229 *) |
pankso@62 | 230 if [ "$(GET blog)" == "rss" ]; then |
pankso@62 | 231 rss && exit 0 |
pankso@62 | 232 fi |
pankso@60 | 233 d="Blog posts" |
pankso@60 | 234 count="20" |
pankso@60 | 235 header |
pankso@60 | 236 html_header |
pankso@60 | 237 user_box |
pankso@62 | 238 blog_tools |
pankso@60 | 239 # Exit if plugin is disabled |
pankso@60 | 240 if [ ! -d "$blog" ]; then |
pankso@60 | 241 echo "<p class='error box'>" |
pankso@60 | 242 gettext "Blog plugin is not yet active."; echo "</p>" |
pankso@60 | 243 html_footer && exit 0 |
pankso@60 | 244 fi |
pankso@60 | 245 # Single post |
pankso@62 | 246 if [ "$(GET p)" ]; then |
pankso@62 | 247 show_post "$(GET p)" |
pankso@60 | 248 else |
pankso@60 | 249 show_posts ${count} |
pankso@62 | 250 echo "<p><a href='$script?blog=archives'>$(gettext "Blog archives")</a></p>" |
pankso@60 | 251 fi ;; |
pankso@60 | 252 esac |
pankso@60 | 253 html_footer && exit 0 |
pankso@60 | 254 fi |