tinycm rev 111

blog: speed up things a little
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 24 07:45:41 2017 +0100 (2017-02-24)
parents a82f38aff5ba
children 32ce2737ecfd
files plugins/blog/blog.cgi
line diff
     1.1 --- a/plugins/blog/blog.cgi	Thu Feb 23 18:54:37 2017 +0000
     1.2 +++ b/plugins/blog/blog.cgi	Fri Feb 24 07:45:41 2017 +0100
     1.3 @@ -2,7 +2,6 @@
     1.4  #
     1.5  # TinyCM Plugin - Blog
     1.6  #
     1.7 -. /usr/lib/slitaz/httphelper
     1.8  
     1.9  blog="$tiny/$content/blog"
    1.10  
    1.11 @@ -133,29 +132,29 @@
    1.12  # Handle GET requests
    1.13  #
    1.14  
    1.15 -if [ "$(GET blog)" ]; then
    1.16 -	case " $(GET blog) " in
    1.17 -		*\ edit\ *)
    1.18 -			d="Editing: $(GET p)"
    1.19 -			p="$(GET p)"
    1.20 -			header
    1.21 -			html_header
    1.22 -			user_box
    1.23 -			if ! check_auth && admin_user; then
    1.24 -				gettext "You must be admin to create a new Blog post"
    1.25 -				html_footer && exit 0
    1.26 -			fi
    1.27 -			blog_tools
    1.28 -			# New post
    1.29 -			if [ "$p" == "new" ]; then
    1.30 -				last=$(ls $blog | sort -r -n | head -n 1)
    1.31 -				p=$(($last + 1))
    1.32 -				AUTHOR="$user"
    1.33 -				DATE=$(date '+%Y-%m-%d')
    1.34 -			else
    1.35 -				. ${blog}/${p}/post.conf
    1.36 -			fi		
    1.37 -			cat << EOT
    1.38 +
    1.39 +case " $(GET blog) " in
    1.40 +	*\ edit\ *)
    1.41 +		d="Editing: $(GET p)"
    1.42 +		p="$(GET p)"
    1.43 +		header
    1.44 +		html_header
    1.45 +		user_box
    1.46 +		if ! check_auth && admin_user; then
    1.47 +			gettext "You must be admin to create a new Blog post"
    1.48 +			html_footer && exit 0
    1.49 +		fi
    1.50 +		blog_tools
    1.51 +		# New post
    1.52 +		if [ "$p" == "new" ]; then
    1.53 +			last=$(ls $blog | sort -r -n | head -n 1)
    1.54 +			p=$(($last + 1))
    1.55 +			AUTHOR="$user"
    1.56 +			DATE=$(date '+%Y-%m-%d')
    1.57 +		else
    1.58 +			. ${blog}/${p}/post.conf
    1.59 +		fi		
    1.60 +		cat << EOT
    1.61  <h2>$(gettext "Blog post"): $p</h2>
    1.62  
    1.63  <div id="edit">
    1.64 @@ -179,78 +178,80 @@
    1.65  	</form>
    1.66  </div>
    1.67  EOT
    1.68 -			html_footer && exit 0 ;;
    1.69 -	
    1.70 -		*\ save\ *)
    1.71 -			p="$(GET p)"
    1.72 -			if check_auth && admin_user; then
    1.73 -				[ -d "$blog/$p" ] || mkdir -p ${blog}/${p}
    1.74 -				# New post ?
    1.75 -				if [ ! -f "${blog}/${p}/post.txt" ]; then
    1.76 -					echo "New Blog post: <a href='$script?blog&amp;p=$p'>Read it!</a>" \
    1.77 -						| log_activity
    1.78 -				fi
    1.79 -				# Write config file
    1.80 -				cat > ${blog}/${p}/post.conf << EOT
    1.81 +		html_footer && exit 0 ;;
    1.82 +
    1.83 +	*\ save\ *)
    1.84 +		p="$(GET p)"
    1.85 +		if check_auth && admin_user; then
    1.86 +			[ -d "$blog/$p" ] || mkdir -p ${blog}/${p}
    1.87 +			# New post ?
    1.88 +			if [ ! -f "${blog}/${p}/post.txt" ]; then
    1.89 +				echo "New Blog post: <a href='$script?blog&amp;p=$p'>Read it!</a>" \
    1.90 +					| log_activity
    1.91 +			fi
    1.92 +			# Write config file
    1.93 +			cat > ${blog}/${p}/post.conf << EOT
    1.94  # TinyCM Blog post configuration
    1.95  AUTHOR="$(GET author)"
    1.96  DATE="$(GET date)"
    1.97  TITLE="$(GET title)"
    1.98  EOT
    1.99 -				# Write content to file
   1.100 -				sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT
   1.101 +			# Write content to file
   1.102 +			sed "s/$(echo -en '\r') /\n/g" > ${blog}/${p}/post.txt << EOT
   1.103  $(GET content)
   1.104  EOT
   1.105 -			fi
   1.106 -			[ -f "${blog}/${p}/post.xml" ] || gen_rss
   1.107 -			header "Location: $script?blog&p=$p" ;;
   1.108 +		fi
   1.109 +		[ -f "${blog}/${p}/post.xml" ] || gen_rss
   1.110 +		header "Location: $script?blog&p=$p" ;;
   1.111 +	
   1.112 +	*\ rm\ *)
   1.113 +		if check_auth && admin_user; then
   1.114 +			rm -rf ${blog}/"$(GET p)"
   1.115 +		fi
   1.116 +		header "Location: $script?blog" ;;
   1.117 +	
   1.118 +	*\ archives\ *)
   1.119 +		# List all posts with title only
   1.120 +		d="Blog archives"
   1.121 +		header
   1.122 +		html_header
   1.123 +		user_box
   1.124 +		blog_tools
   1.125 +		echo "<h2>Blog archives</h2>"
   1.126 +		echo "<pre>"
   1.127 +		for p in $(ls $blog | sort -nr)
   1.128 +		do
   1.129 +			. ${blog}/${p}/post.conf
   1.130 +			echo "\
   1.131 +<span class='date'>$DATE :</span> <a href='$script?blog&amp;p=$p'>$TITLE</a>"
   1.132 +		done 
   1.133 +		echo "</pre>" 
   1.134 +		html_footer && exit 0 ;;
   1.135  		
   1.136 -		*\ rm\ *)
   1.137 -			if check_auth && admin_user; then
   1.138 -				rm -rf ${blog}/"$(GET p)"
   1.139 -			fi
   1.140 -			header "Location: $script?blog" ;;
   1.141 -		
   1.142 -		*\ archives\ *)
   1.143 -			# List all posts with title only
   1.144 -			d="Blog archives"
   1.145 -			header
   1.146 -			html_header
   1.147 -			user_box
   1.148 -			blog_tools
   1.149 -			echo "<h2>Blog archives</h2>"
   1.150 -			echo "<pre>"
   1.151 -			for p in $(ls $blog | sort -nr)
   1.152 -			do
   1.153 -				. ${blog}/${p}/post.conf
   1.154 -				echo "\
   1.155 -<span class='date'>$DATE :</span> <a href='$script?blog&amp;p=$p'>$TITLE</a>"
   1.156 -			done 
   1.157 -			echo "</pre>" ;;
   1.158 -			
   1.159 -		*)
   1.160 -			if [ "$(GET blog)" == "rss" ]; then
   1.161 -				rss && exit 0
   1.162 -			fi
   1.163 -			d="Blog posts"
   1.164 -			count="20"
   1.165 -			header
   1.166 -			html_header
   1.167 -			user_box
   1.168 -			blog_tools
   1.169 -			# Exit if plugin is disabled
   1.170 -			if [ ! -d "$blog" ]; then
   1.171 -				echo "<p class='error box'>"
   1.172 -				gettext "Blog plugin is not yet active."; echo "</p>"
   1.173 -				html_footer && exit 0
   1.174 -			fi
   1.175 -			# Single post
   1.176 -			if [ "$(GET p)" ]; then
   1.177 -				show_post "$(GET p)"
   1.178 -			else
   1.179 -				show_posts ${count}
   1.180 -				echo "<p><a href='$script?blog=archives'>$(gettext "Blog archives")</a></p>"
   1.181 -			fi ;;
   1.182 -	esac
   1.183 -	html_footer && exit 0
   1.184 -fi
   1.185 +	*)
   1.186 +		if [ "$(GET blog)" == "rss" ]; then
   1.187 +			rss && exit 0
   1.188 +		fi
   1.189 +		d="Blog posts"
   1.190 +		count="10"
   1.191 +		header
   1.192 +		html_header
   1.193 +		user_box
   1.194 +		blog_tools
   1.195 +		# Exit if plugin is disabled
   1.196 +		if [ ! -d "$blog" ]; then
   1.197 +			echo "<p class='error box'>"
   1.198 +			gettext "Blog plugin is not yet active."; echo "</p>"
   1.199 +			html_footer && exit 0
   1.200 +		fi
   1.201 +		# Single post
   1.202 +		if [ "$(GET p)" ]; then
   1.203 +			show_post "$(GET p)"
   1.204 +		else
   1.205 +			show_posts ${count}
   1.206 +			echo "<p><a href='$script?blog=archives'>$(gettext "Blog archives")</a></p>"
   1.207 +		fi 
   1.208 +		html_footer && exit 0 ;;
   1.209 +esac
   1.210 +	
   1.211 +