tinycm rev 27
Add small blog plugin
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Jan 05 23:20:19 2014 +0000 (2014-01-05) |
parents | fd29a41905a3 |
children | 09f5185ff6e0 |
files | plugins/blog/blog.cgi plugins/blog/blog.conf plugins/blog/help.txt |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/plugins/blog/blog.cgi Sun Jan 05 23:20:19 2014 +0000 1.3 @@ -0,0 +1,126 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TinyCM Plugin - Blog 1.7 +# 1.8 +. /usr/lib/slitaz/httphelper 1.9 + 1.10 +blog="$tiny/$content/blog" 1.11 + 1.12 +# Blog tools 1.13 +blog_tools() { 1.14 + cat << EOT 1.15 +<div id="tools"> 1.16 + <a href="$script?blogedit&d=new">$(gettext "New post")</a> 1.17 + <a href="$script?dashboard">Dashboard</a> 1.18 + $([ "$index" == "blog" ] && echo "<a href='$script?d=index'>Index</a>") 1.19 + $([ "$HG" == "yes" ] && echo "<a href='$script?hg'>Hg Log</a>") 1.20 +</div> 1.21 +EOT 1.22 +} 1.23 + 1.24 +# Post tools 1.25 +post_tools() { 1.26 + cat << EOT 1.27 +<div class="post-tools"> 1.28 + ${d}: <a href="$script?blogedit&d=${d}">$(gettext "Edit post")</a> 1.29 +</div> 1.30 +EOT 1.31 +} 1.32 + 1.33 +# Display blog post: show_posts nb 1.34 +show_posts() { 1.35 + for p in $(find $blog -type f | head -n $1) 1.36 + do 1.37 + name=$(basename $p) 1.38 + d=${name%.txt} 1.39 + echo "<div class=\"blogpost\">" 1.40 + cat ${blog}/${d}.txt | wiki_parser 1.41 + echo "</div>" 1.42 + # Post tools for auth users 1.43 + if check_auth; then 1.44 + post_tools 1.45 + fi 1.46 + done 1.47 +} 1.48 + 1.49 +# 1.50 +# Index main page can display the lastest Blog posts 1.51 +# 1.52 +if fgrep -q '[BLOG]' $tiny/$wiki/index.txt && [ ! "$(GET)" ]; then 1.53 + d="Blog" 1.54 + index="blog" 1.55 + header 1.56 + html_header 1.57 + user_box 1.58 + echo "<h2>$(gettext "Latest blog posts")</h2>" 1.59 + # Post tools for auth users 1.60 + if check_auth; then 1.61 + blog_tools 1.62 + fi 1.63 + show_posts 5 1.64 + echo "<p><a href='$script?blog'>$(gettext "More blog posts")</a></p>" 1.65 + html_footer && exit 0 1.66 +fi 1.67 + 1.68 +case " $(GET) " in 1.69 + *\ blogedit\ *) 1.70 + d="$(GET d)" 1.71 + header 1.72 + html_header 1.73 + user_box 1.74 + # Blog tools for auth users 1.75 + if ! check_auth; then 1.76 + gettext "You must be logged in to create a new Blog post" 1.77 + html_footer && exit 0 1.78 + fi 1.79 + # New post 1.80 + if [ "$d" == "new" ]; then 1.81 + d=$(date '+%Y%m%d') 1.82 + [ -f "$blog/$d.txt" ] && d=$(date '+%Y%m%d-%H%M') 1.83 + fi 1.84 + cat << EOT 1.85 +<h2>$(gettext "Blog post"): $d</h2> 1.86 + 1.87 +<div id="edit"> 1.88 + <form method="get" action="$script" name="editor"> 1.89 + <input type="hidden" name="blogsave" value="$d" /> 1.90 + <textarea name="content">$(cat "$blog/$d.txt")</textarea> 1.91 + <input type="submit" value="$(gettext "Post content")" /> 1.92 + $(gettext "Code Helper:") 1.93 + $(cat lib/jseditor.html) 1.94 + </form> 1.95 +</div> 1.96 +EOT 1.97 + html_footer && exit 0 ;; 1.98 + 1.99 + *\ blogsave\ *) 1.100 + d="$(GET blogsave)" 1.101 + if check_auth; then 1.102 + [ -d "$blog" ] || mkdir -p ${blog} 1.103 + sed "s/$(echo -en '\r') /\n/g" > ${blog}/${d}.txt << EOT 1.104 +$(GET content) 1.105 +EOT 1.106 + fi 1.107 + header "Location: $script?blog" ;; 1.108 + 1.109 + *\ blog\ *) 1.110 + d="Latest blog posts" 1.111 + nb="20" 1.112 + header 1.113 + html_header 1.114 + user_box 1.115 + echo "<h2>$(gettext "Latest blog posts")</h2>" 1.116 + # Blog tools for auth users 1.117 + if check_auth; then 1.118 + blog_tools 1.119 + fi 1.120 + # Exit if plugin is disabled 1.121 + if [ ! -d "$blog" ]; then 1.122 + echo "<p class='error box'>" 1.123 + gettext "Blog plugin is not yet active."; echo "</p>" 1.124 + html_footer && exit 0 1.125 + fi 1.126 + show_posts ${nb} 1.127 + html_footer 1.128 + exit 0 ;; 1.129 +esac
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/plugins/blog/blog.conf Sun Jan 05 23:20:19 2014 +0000 2.3 @@ -0,0 +1,7 @@ 2.4 +# TinyCM Plugin configuration 2.5 + 2.6 +PLUGIN="Blog Post" 2.7 +SHORT_DESC="A tiny Blog plugin for TinyCM" 2.8 +MAINTAINER="devel@slitaz.org" 2.9 + 2.10 +# Configurable variables used in plugin.cgi
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/plugins/blog/help.txt Sun Jan 05 23:20:19 2014 +0000 3.3 @@ -0,0 +1,4 @@ 3.4 + 3.5 +The blog plugin use the Wiki syntax for formating text and store all 3.6 +posts in $content/blog. It can replace the default index to have a 3.7 +dynamic website home page.