# HG changeset patch # User Christophe Lincoln # Date 1487918741 -3600 # Node ID 801f52294fa90a143520524cdfc7802f565b69c7 # Parent a82f38aff5baf54a69dcb5a2b4ee4a861012db34 blog: speed up things a little diff -r a82f38aff5ba -r 801f52294fa9 plugins/blog/blog.cgi --- a/plugins/blog/blog.cgi Thu Feb 23 18:54:37 2017 +0000 +++ b/plugins/blog/blog.cgi Fri Feb 24 07:45:41 2017 +0100 @@ -2,7 +2,6 @@ # # TinyCM Plugin - Blog # -. /usr/lib/slitaz/httphelper blog="$tiny/$content/blog" @@ -133,29 +132,29 @@ # Handle GET requests # -if [ "$(GET blog)" ]; then - case " $(GET blog) " in - *\ edit\ *) - d="Editing: $(GET p)" - p="$(GET p)" - header - html_header - user_box - if ! check_auth && admin_user; then - gettext "You must be admin to create a new Blog post" - html_footer && exit 0 - fi - blog_tools - # New post - if [ "$p" == "new" ]; then - last=$(ls $blog | sort -r -n | head -n 1) - p=$(($last + 1)) - AUTHOR="$user" - DATE=$(date '+%Y-%m-%d') - else - . ${blog}/${p}/post.conf - fi - cat << EOT + +case " $(GET blog) " in + *\ edit\ *) + d="Editing: $(GET p)" + p="$(GET p)" + header + html_header + user_box + if ! check_auth && admin_user; then + gettext "You must be admin to create a new Blog post" + html_footer && exit 0 + fi + blog_tools + # New post + if [ "$p" == "new" ]; then + last=$(ls $blog | sort -r -n | head -n 1) + p=$(($last + 1)) + AUTHOR="$user" + DATE=$(date '+%Y-%m-%d') + else + . ${blog}/${p}/post.conf + fi + cat << EOT

$(gettext "Blog post"): $p

@@ -179,78 +178,80 @@
EOT - html_footer && exit 0 ;; - - *\ save\ *) - p="$(GET p)" - if check_auth && admin_user; then - [ -d "$blog/$p" ] || mkdir -p ${blog}/${p} - # New post ? - if [ ! -f "${blog}/${p}/post.txt" ]; then - echo "New Blog post: Read it!" \ - | log_activity - fi - # Write config file - cat > ${blog}/${p}/post.conf << EOT + html_footer && exit 0 ;; + + *\ save\ *) + p="$(GET p)" + if check_auth && admin_user; then + [ -d "$blog/$p" ] || mkdir -p ${blog}/${p} + # New post ? + if [ ! -f "${blog}/${p}/post.txt" ]; then + echo "New Blog post: Read it!" \ + | log_activity + fi + # Write config file + cat > ${blog}/${p}/post.conf << EOT # TinyCM Blog post configuration AUTHOR="$(GET author)" DATE="$(GET date)" TITLE="$(GET title)" EOT - # Write content to file - sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT + # Write content to file + sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT $(GET content) EOT - fi - [ -f "${blog}/${p}/post.xml" ] || gen_rss - header "Location: $script?blog&p=$p" ;; + fi + [ -f "${blog}/${p}/post.xml" ] || gen_rss + header "Location: $script?blog&p=$p" ;; + + *\ rm\ *) + if check_auth && admin_user; then + rm -rf ${blog}/"$(GET p)" + fi + header "Location: $script?blog" ;; + + *\ archives\ *) + # List all posts with title only + d="Blog archives" + header + html_header + user_box + blog_tools + echo "

Blog archives

" + echo "
"
+		for p in $(ls $blog | sort -nr)
+		do
+			. ${blog}/${p}/post.conf
+			echo "\
+$DATE : $TITLE"
+		done 
+		echo "
" + html_footer && exit 0 ;; - *\ rm\ *) - if check_auth && admin_user; then - rm -rf ${blog}/"$(GET p)" - fi - header "Location: $script?blog" ;; - - *\ archives\ *) - # List all posts with title only - d="Blog archives" - header - html_header - user_box - blog_tools - echo "

Blog archives

" - echo "
"
-			for p in $(ls $blog | sort -nr)
-			do
-				. ${blog}/${p}/post.conf
-				echo "\
-$DATE : $TITLE"
-			done 
-			echo "
" ;; - - *) - if [ "$(GET blog)" == "rss" ]; then - rss && exit 0 - fi - d="Blog posts" - count="20" - header - html_header - user_box - blog_tools - # Exit if plugin is disabled - if [ ! -d "$blog" ]; then - echo "

" - gettext "Blog plugin is not yet active."; echo "

" - html_footer && exit 0 - fi - # Single post - if [ "$(GET p)" ]; then - show_post "$(GET p)" - else - show_posts ${count} - echo "

$(gettext "Blog archives")

" - fi ;; - esac - html_footer && exit 0 -fi + *) + if [ "$(GET blog)" == "rss" ]; then + rss && exit 0 + fi + d="Blog posts" + count="10" + header + html_header + user_box + blog_tools + # Exit if plugin is disabled + if [ ! -d "$blog" ]; then + echo "

" + gettext "Blog plugin is not yet active."; echo "

" + html_footer && exit 0 + fi + # Single post + if [ "$(GET p)" ]; then + show_post "$(GET p)" + else + show_posts ${count} + echo "

$(gettext "Blog archives")

" + fi + html_footer && exit 0 ;; +esac + +