tinycm rev 62
blog: use a config file, add archives and bunch of improvments
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Feb 05 22:05:10 2014 +0100 (2014-02-05) |
parents | ea608c745b41 |
children | 1293a00e2a72 |
files | plugins/blog/blog.cgi style.css |
line diff
1.1 --- a/plugins/blog/blog.cgi Sat Feb 01 17:29:04 2014 +0000 1.2 +++ b/plugins/blog/blog.cgi Wed Feb 05 22:05:10 2014 +0100 1.3 @@ -6,43 +6,91 @@ 1.4 1.5 blog="$tiny/$content/blog" 1.6 1.7 -# Blog tools 1.8 +# # Blog tools for admin users only 1.9 blog_tools() { 1.10 - cat << EOT 1.11 + if check_auth && admin_user; then 1.12 + cat << EOT 1.13 <div id="tools"> 1.14 - <a href="$script?blog=edit&d=new">$(gettext "New post")</a> 1.15 + <a href="$script?blog">$(gettext "Blog")</a> 1.16 + <a href="$script?blog=edit&p=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 + fi 1.23 } 1.24 1.25 # Post tools 1.26 post_tools() { 1.27 cat << EOT 1.28 - - <a href="$script?blogedit&d=${d}">$(gettext "Edit it!")</a> 1.29 + - <a href="$script?blog=edit&p=${p}">$(gettext "Edit it!")</a> 1.30 + || <a href="$script?blog=rm&p=${p}">$(gettext "Remove")</a> 1.31 EOT 1.32 -#<a href="$script?blogrm=${d}">$(gettext "Remove")</a> 1.33 +} 1.34 + 1.35 +# Create a XML feed for a new post 1.36 +gen_rss() { 1.37 + pubdate=$(date "+%a, %d %b %Y %X") 1.38 + desc="$(cat ${blog}/${p}/post.txt | grep ^[A-Za-z] | head -n 4)" 1.39 + . ${blog}/${p}/post.conf 1.40 + cat > ${blog}/${p}/post.xml << EOT 1.41 + <item> 1.42 + <title>$TITLE</title> 1.43 + <link>http://${SERVER_NAME}?blog&p=$p</link> 1.44 + <guid>blog-$p</guid> 1.45 + <pubDate>$pubdate</pubDate> 1.46 + <description>$desc</description> 1.47 + </item> 1.48 +EOT 1.49 +} 1.50 + 1.51 +# RSS Feed 1.52 +rss() { 1.53 +pubdate=$(date "+%a, %d %b %Y %X") 1.54 + cat << EOT 1.55 +Content-Type: text/xml 1.56 + 1.57 +<?xml version="1.0" encoding="utf-8" ?> 1.58 +<rss version="2.0"> 1.59 +<channel> 1.60 + <title>TinyCM RSS</title> 1.61 + <description>The Blog feed</description> 1.62 + <link>http://${SERVER_NAME}</link> 1.63 + <lastBuildDate>$pubdate GMT</lastBuildDate> 1.64 + <pubDate>$pubdate GMT</pubDate> 1.65 +EOT 1.66 + for p in $(ls $blog | sort -r -n | head -n 8) 1.67 + do 1.68 + cat $blog/$p/post.xml 1.69 + done 1.70 + cat << EOT 1.71 +</channel> 1.72 +</rss> 1.73 +EOT 1.74 } 1.75 1.76 # Display blog post: show_posts nb 1.77 show_post() { 1.78 - d=${1%.txt} 1.79 - date=$(fgrep 'DATE=' ${blog}/${d}.txt | cut -d '"' -f 2) 1.80 - # Get post author 1.81 - author=$(fgrep 'AUTHOR=' ${blog}/${d}.txt | cut -d '"' -f 2) 1.82 - if [ -f "${PEOPLE}/${author}/account.conf" ]; then 1.83 - . ${PEOPLE}/${author}/account.conf 1.84 + [ -f "$blog/$1/post.conf" ] || return 1 1.85 + p="$1" 1.86 + . ${blog}/${p}/post.conf 1.87 + d="$TITLE" 1.88 + 1.89 + # Author info 1.90 + if [ -f "${PEOPLE}/${AUTHOR}/account.conf" ]; then 1.91 + . ${PEOPLE}/${AUTHOR}/account.conf 1.92 else 1.93 - echo "ERROR: ${PEOPLE}/${author}/account.conf" 1.94 + echo "ERROR: ${PEOPLE}/${AUTHOR}/account.conf" 1.95 fi 1.96 - echo "<div class=\"blogpost\">" 1.97 - cat ${blog}/${d}.txt | sed -e '/AUTHOR=/'d -e '/DATE=/'d | wiki_parser 1.98 + 1.99 + echo "<h2>$TITLE</h2>" 1.100 + echo "<div class='blogpost'>" 1.101 + cat ${blog}/${p}/post.txt | wiki_parser 1.102 cat << EOT 1.103 <div class="post-tools"> 1.104 <a href="$script?user=$USER">$(get_gravatar $MAIL 24)</a> 1.105 - <span class="date">$date</span> 1.106 + <span class="date">$DATE</span> 1.107 EOT 1.108 # Post tools for admin users 1.109 if check_auth && admin_user; then 1.110 @@ -87,7 +135,8 @@ 1.111 if [ "$(GET blog)" ]; then 1.112 case " $(GET blog) " in 1.113 *\ edit\ *) 1.114 - d="$(GET d)" 1.115 + d="Editing: $(GET p)" 1.116 + p="$(GET p)" 1.117 header 1.118 html_header 1.119 user_box 1.120 @@ -95,56 +144,98 @@ 1.121 gettext "You must be admin to create a new Blog post" 1.122 html_footer && exit 0 1.123 fi 1.124 + blog_tools 1.125 # New post 1.126 - if [ "$d" == "new" ]; then 1.127 - date=$(date '+%Y-%m-%d') 1.128 + if [ "$p" == "new" ]; then 1.129 last=$(ls $blog | sort -r -n | head -n 1) 1.130 - nb=${last%.txt} 1.131 - d=$(($nb + 1)) 1.132 - conf=$(echo -e "\n\nAUTHOR=\"$user\"\nDATE=\"$date\"\n\n====Title====") 1.133 + p=$(($last + 1)) 1.134 + AUTHOR="$user" 1.135 + DATE=$(date '+%Y-%m-%d') 1.136 + else 1.137 + . ${blog}/${p}/post.conf 1.138 fi 1.139 cat << EOT 1.140 -<h2>$(gettext "Blog post"): $d</h2> 1.141 +<h2>$(gettext "Blog post"): $p</h2> 1.142 1.143 <div id="edit"> 1.144 <form method="get" action="$script?" name="editor"> 1.145 + <input type="text" name="title" value="$TITLE" placeholder="Title" /> 1.146 <input type="hidden" name="blog" value="save" /> 1.147 - <input type="hidden" name="d" value="$d" /> 1.148 - <textarea name="content">${conf}$(cat "$blog/$d.txt")</textarea> 1.149 - <input type="submit" value="$(gettext "Post content")" /> 1.150 + <input type="hidden" name="p" value="$p" /> 1.151 + <textarea name="content">$(cat "$blog/$p/post.txt")</textarea> 1.152 + <div> 1.153 + <input type="submit" value="$(gettext "Post content")" /> 1.154 + <input style="width: 20%;" type="text" 1.155 + name="author" value="$AUTHOR" /> 1.156 + <input style="width: 20%; display: inline;" type="text" 1.157 + name="date" value="$DATE" /> 1.158 + </div> 1.159 + 1.160 + <p> 1.161 $(gettext "Code Helper:") 1.162 $(cat lib/jseditor.html) 1.163 + </p> 1.164 </form> 1.165 </div> 1.166 EOT 1.167 html_footer && exit 0 ;; 1.168 1.169 *\ save\ *) 1.170 - d="$(GET d)" 1.171 + p="$(GET p)" 1.172 if check_auth && admin_user; then 1.173 - [ -d "$blog" ] || mkdir -p ${blog} 1.174 + [ -d "$blog/$p" ] || mkdir -p ${blog}/${p} 1.175 # New post ? 1.176 - if [ ! -f "${blog}/${d}.txt" ]; then 1.177 - echo "New Blog post: <a href='$script?blog=$d'>Read it!</a>" \ 1.178 + if [ ! -f "${blog}/${p}/post.txt" ]; then 1.179 + cat > ${blog}/${p}/post.conf << EOT 1.180 +# TinyCM Blog post configuration 1.181 +AUTHOR="$(GET author)" 1.182 +DATE="$(GET date)" 1.183 +TITLE="$(GET title)" 1.184 +EOT 1.185 + echo "New Blog post: <a href='$script?blog=$p'>Read it!</a>" \ 1.186 | log_activity 1.187 fi 1.188 # Write content to file 1.189 - sed "s/$(echo -en '\r') /\n/g" > ${blog}/${d}.txt << EOT 1.190 + sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT 1.191 $(GET content) 1.192 EOT 1.193 - fi 1.194 + fi 1.195 + [ -f "${blog}/${p}/post.xml" ] || gen_rss 1.196 + header "Location: $script?blog&p=$p" ;; 1.197 + 1.198 + *\ rm\ *) 1.199 + if check_auth && admin_user; then 1.200 + rm -rf ${blog}/"$(GET p)" 1.201 + fi 1.202 header "Location: $script?blog" ;; 1.203 + 1.204 + *\ archives\ *) 1.205 + # List all post with title only 1.206 + d="Blog archives" 1.207 + header 1.208 + html_header 1.209 + user_box 1.210 + blog_tools 1.211 + echo "<h2>Blog archives</h2>" 1.212 + echo "<pre>" 1.213 + for p in $(ls $blog) 1.214 + do 1.215 + . ${blog}/${p}/post.conf 1.216 + echo "\ 1.217 +<span class='date'>$DATE :</span> <a href='$script?blog&p=$p'>$TITLE</a>" 1.218 + done 1.219 + echo "</pre>" ;; 1.220 1.221 *) 1.222 + if [ "$(GET blog)" == "rss" ]; then 1.223 + rss && exit 0 1.224 + fi 1.225 d="Blog posts" 1.226 count="20" 1.227 header 1.228 html_header 1.229 user_box 1.230 - # Blog tools for admin users 1.231 - if check_auth && admin_user; then 1.232 - blog_tools 1.233 - fi 1.234 + blog_tools 1.235 # Exit if plugin is disabled 1.236 if [ ! -d "$blog" ]; then 1.237 echo "<p class='error box'>" 1.238 @@ -152,10 +243,11 @@ 1.239 html_footer && exit 0 1.240 fi 1.241 # Single post 1.242 - if [ "$(GET blog)" != "blog" ]; then 1.243 - show_post "$(GET blog)" 1.244 + if [ "$(GET p)" ]; then 1.245 + show_post "$(GET p)" 1.246 else 1.247 show_posts ${count} 1.248 + echo "<p><a href='$script?blog=archives'>$(gettext "Blog archives")</a></p>" 1.249 fi ;; 1.250 esac 1.251 html_footer && exit 0
2.1 --- a/style.css Sat Feb 01 17:29:04 2014 +0000 2.2 +++ b/style.css Wed Feb 05 22:05:10 2014 +0100 2.3 @@ -188,7 +188,7 @@ 2.4 2.5 input[type="text"], input[type="password"] { 2.6 background: #fefefe; border: 2px solid #ccc; 2.7 - width: 460px; } 2.8 + width: 100%; } 2.9 /*input[type="file"] { border: 2px solid #ddd; }*/ 2.10 /*input[type="checkbox"] { background: #fefefe; }*/ 2.11