]> git.plutz.net Git - serve0/commitdiff
move urlsave function to cgi "lib"
authorpaul <paul@plutz.net>
Sat, 20 Dec 2014 01:34:45 +0000 (01:34 +0000)
committerpaul <paul@plutz.net>
Sat, 20 Dec 2014 01:34:45 +0000 (01:34 +0000)
svn path=/trunk/; revision=29

cgi.sh
pages/videoview.sh

diff --git a/cgi.sh b/cgi.sh
index 49e68b457f0bc88fc36281c3b0403f5c8d5f18d4..2c4d45d3f49a6fa4070ca8a503cfa2d52ad562a1 100755 (executable)
--- a/cgi.sh
+++ b/cgi.sh
@@ -52,3 +52,7 @@ cgi_refdata() { # Parse GET data from referer
     _REF["$key"]="$(echo -e "$(echo "$val" |sed 's:+: :g;s:%:\\x:g')")"
   done
 }
+
+urlsave(){
+  echo -E "$*" |sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s;!;\%21;g;s;\(;\%28;g;s;\);\%29;g;'
+}
index 738eeb10feddef01506dd860f0308453c19bb694..e90c951dceda6f961c297323db4d9dc61c2b398f 100755 (executable)
 info="$_GET[\"i\"]"
 filter="$_GET[\"f\"]"
 search="$_GET[\"s\"]"
-order=$(echo "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
-page=$(echo "$_GET[\"p\"]" |egrep '^[0-9]+$')
+order=$(echo -E "$_GET[\"o\"]" |egrep '^(Name|Date|Length)$')
+page=$(echo -E "$_GET[\"p\"]" |egrep '^[0-9]+$')
 [ -z "$page" ] && page=0
 
 page_link=''
-[ -n "$info" ]   && page_link="i=$(echo -n "$info" |sed -r 's:%:%25:g;s:\&:%26:g;')&"
+[ -n "$info" ]   && page_link="i=$(echo -En "$info" |sed -r 's:%:%25:g;s:\&:%26:g;')&"
 [ -n "$order" ]  && page_link="${page_link}o=${order}&"
 [ -n "$search" ] && page_link="${page_link}s=${search}&"
 [ -n "$filter" ] && page_link="${page_link}f=${filter}&"
@@ -69,8 +69,6 @@ view() {
   fi
 }
 
-alias urlsave="sed 's:%:\%25:g;s:\?:\%3F:g;s:&:\%26:g;s:'\'':\%27:g;s: :\%20:g;s;!;\%21;g;s;\(;\%28;g;s;\);\%29;g;'"
-
 _printVideo(){
   info="$1"
   cache="${_DATA}/cache/$info.cache"
@@ -92,15 +90,15 @@ _printVideo(){
     [ -r "$meta" ] || ". ${_EXEC}/helpers/genmeta.sh" "$video" "$meta"
     [ -r "$thumb" ] || ". ${_EXEC}/helpers/genthumb.sh" "$video" "$thumb"
     [ -L "$mpfake" ] || ln -s "../videos/$info" "$mpfake"
-    video="$(echo "videos/$info" |urlsave)"
-    thumb="$(echo "thumbs/$info.jpg" |urlsave)"
-    mpfake="$(echo "$info" |sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:mp4/\1.mp4:' |urlsave)"
+    video="$(urlsave "videos/$info")"
+    thumb="$(urlsave "thumbs/$info.jpg")"
+    mpfake="$(urlsave "$info" |sed -r 's:^(.*)\.[a-zA-Z0-9]{3,4}$:mp4/\1.mp4:')"
 
     [ "$(($length % 60))" -lt 10 ] &&\
       minutes="$(($length / 60)):0$(($length % 60))" ||\
       minutes="$(($length / 60)):$(($length % 60))"
 
-    linkinfo="$(echo -n "$info" |urlsave)"
+    linkinfo="$(urlsave "$info")"
     tee "$cache" <<VIDEOend
       <li class="thumb">
         <a class="watchlink" name="$linkinfo" href="?action=watch&i=$linkinfo">
@@ -112,7 +110,7 @@ _printVideo(){
         <input type="checkbox" name="tagsel" value="$info">
         <span class="info property">${minutes}min</span>
         <span class="info property">${width}x${height}</span>
-       $(echo "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
+       $(echo -E "$tags" |sed -r 's:\|*([^|]+)\|*:<span class="info tag">\1</span>:g')
       </div>
 VIDEOend
   fi
@@ -151,7 +149,7 @@ thumblist() {
       $genlist |sed -rn 's:^(.+)$:'"${_DATA}"'/meta/\1'.meta':p' |xargs -d\\n egrep -sil "$search" |sed -rn 's:^(.*/)+([^/]+)\.meta$:\2:p'
     elif [ "$filterex" != "q0" ]; then
       $genlist |while read video; do
-        [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && echo "$video"
+        [ -r "${_DATA}/meta/$video.meta" ] && sed -rn "2{$filterex;q1}" "${_DATA}/meta/$video.meta" && echo -E "$video"
       done
     else
       $genlist