tazweb diff data/bookmarks.cgi @ rev 149

Fix user bookmarks on first run
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 13 02:30:09 2014 +0200 (2014-04-13)
parents c2ec2ff2e813
children e40064ab71b4
line diff
     1.1 --- a/data/bookmarks.cgi	Sat Apr 05 20:15:13 2014 +0100
     1.2 +++ b/data/bookmarks.cgi	Sun Apr 13 02:30:09 2014 +0200
     1.3 @@ -31,6 +31,7 @@
     1.4  		a { text-decoration: none; } a:hover { text-decoration: underline; }
     1.5  		li { list-style-type: none; color: #666; line-height: 1.4em; padding: 0; }
     1.6  		footer { font-size: 80%; border-top: 2px solid #666; padding: 5px 0; }
     1.7 +		textarea { width: 100%; height: 240px; font-size: 98%; }
     1.8  	</style>
     1.9  </head>
    1.10  <body>
    1.11 @@ -46,8 +47,9 @@
    1.12  </section>
    1.13  
    1.14  <footer>
    1.15 -	<a href="$script?home=$home">Bookmarks</a> -
    1.16 -	<a href="$script?raw&amp;home=$home">bookmarks.txt</a>
    1.17 +	<a href="$script?home=$home">Bookmarks</a>
    1.18 +	- <a href="$script?raw&amp;home=$home">Raw</a>
    1.19 +	- <a href="$script?edit&amp;home=$home">Edit</a>
    1.20  </footer>
    1.21  
    1.22  </body>
    1.23 @@ -58,21 +60,49 @@
    1.24  # Handle GET actions: continue or exit
    1.25  
    1.26  case " $(GET) " in
    1.27 +	
    1.28 +	*\ edit\ *)
    1.29 +		header
    1.30 +		html_header
    1.31 +		cat << EOT
    1.32 +<h1>Bookmarks Edit</h1>
    1.33 +<form method="get" action="$script" name="edit">
    1.34 +	<input type="hidden" name="save" />
    1.35 +	<input type="hidden" name="home" value="$home" />
    1.36 +	<textarea name="content">$(cat "$bookmarks")</textarea>
    1.37 +	<p><input type="submit" value="$(gettext "Save bookmarks")" /></p>
    1.38 +</form>
    1.39 +EOT
    1.40 +		html_footer && exit 0 ;;
    1.41 +	
    1.42 +	*\ save\ *)
    1.43 +		sed "s/$(echo -en '\r') /\n/g" > ${bookmarks} << EOT
    1.44 +$(GET content)
    1.45 +EOT
    1.46 +		;;
    1.47 +	
    1.48  	*\ raw\ *)
    1.49  		# View bookmarks file
    1.50  		header
    1.51  		html_header
    1.52 -		echo "<h1>TazWeb: bookmarks.txt</h1>"
    1.53 -		echo "<pre>" 
    1.54 -		cat ${bookmarks}
    1.55 +		echo '<h1>Raw Bookmarks</h1>'
    1.56 +		echo "<pre>"
    1.57 +		IFS="|"
    1.58 +		cat ${bookmarks} | cat ${bookmarks} | while read title url null
    1.59 +		do
    1.60 +			echo "$title | <a href='$url'>$url</a>"
    1.61 +		done
    1.62 +		unset IFS
    1.63  		echo "</pre>"
    1.64  		html_footer && exit 0 ;;
    1.65 +	
    1.66  	*\ rm\ *)
    1.67  		# Remove a bookmark item and continue
    1.68  		url=$(GET rm)
    1.69  		[ "$url" ] || continue
    1.70  		sed -i s"#.*${url}.*##" ${bookmarks}
    1.71  		sed -i "/^$/"d ${bookmarks} ;;
    1.72 +	
    1.73  esac
    1.74  
    1.75  # Show all bookmarks