From 37450b7423b778817c24521e60c6719335d62d26 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 2 Aug 2015 20:07:28 +0000 Subject: [PATCH] introduced page size cookie; globalised some input validation svn path=/trunk/; revision=72 --- actions/preferences.sh | 12 +++++++----- actions/watch.sh | 1 - constants.sh | 11 ++++++++++- pages/common.sh | 16 +++++++-------- pages/list.sh | 1 - templates/common.css.sh | 20 +++++++++++++------ templates/list.html.sh | 4 ++-- templates/preferences.html.sh | 37 +++++++++++++++++++++-------------- 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/actions/preferences.sh b/actions/preferences.sh index 1552d75..e754044 100755 --- a/actions/preferences.sh +++ b/actions/preferences.sh @@ -1,16 +1,18 @@ #!/bin/zsh cgi_post -cgi_cookie -fakemp4="$(printf %s "${_POST[fakemp4]}" |sed -rn '/^yes$/{p;q};ano' )" -watch="$(printf %s "${_POST[watch]}" |sed -rn '/^(240p|480p|download|raspi|player|server)$/{p;q};aplayer' )" +fakemp4=$(validate "${_POST[fakemp4]}" yes no) +watch=$(validate "${_POST[watch]}" '(240p|480p|download|raspi|player|server)' player) +pagesize=$(validate "${_POST[pagesize]}" '[1-9][0-9]+' 1) debug '== Setting Preferences ==' -debug "fakemp4 = $fakemp4" -debug "watch = $watch" +debug "fakemp4 = $fakemp4" +debug "watch = $watch" +debug "pagesize = $pagesize" set_cookie '+ 1 month' "fakemp4=${fakemp4}" HttpOnly set_cookie '+ 1 month' "watch=${watch}" HttpOnly +set_cookie '+ 1 month' "pagesize=${pagesize}" HttpOnly redirect "$HTTP_REFERER" diff --git a/actions/watch.sh b/actions/watch.sh index 46fc795..39ca7e0 100755 --- a/actions/watch.sh +++ b/actions/watch.sh @@ -1,7 +1,6 @@ #!/bin/zsh cgi_refdata -cgi_cookie info="${_GET[i]}" order="${_REF[o]}" search="${_REF[s]}" diff --git a/constants.sh b/constants.sh index 89236b1..8dcccd5 100755 --- a/constants.sh +++ b/constants.sh @@ -19,7 +19,16 @@ alias _wiki="stx2any --no-template --link-abbrevs --quote -T html" [ -z "${_GET[p]}" ] && _GET[p]=list -pagesize=100 file_pattern='^.*(mov|ts|mpg|mpeg|mp4|m4v|avi|mkv|flv|sfv|wmv|ogm|webm|iso|rmvb)$' data_dirs cache meta mp4 videos thumbs trash by_length transcoded + +cgi_cookie +validate(){ printf '%s\n' "$1" |sed -rn '2q;/^'"$2"'$/{p;q};a'"$3"; } + +_GET[o]=$( validate "${_GET[o]}" '(Name|Date|Length)' Name) +_GET[pn]=$(validate "${_GET[pn]}" '[1-9][0-9]*' 1) + +_COOKIE[pagesize]=$(validate "${_COOKIE[pagesize]}" '[1-9][0-9]*' 50) + + diff --git a/pages/common.sh b/pages/common.sh index efb61fd..9926bad 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -19,17 +19,17 @@ filter="${_GET[f]}" search="${_GET[s]}" -order=$(echo -E "${_GET[o]}" |egrep '^(Name|Date|Length)$') -page=$(echo -E "${_GET[pn]}" |egrep '^[0-9]+$') -[ -z "$page" ] && page=0 +order="${_GET[o]}" #validated +page="${_GET[pn]}" #validated +pagesize="${_COOKIE[pagesize]}" #validated page_link='' [ -n "$info" ] && page_link="i=$(urlsave "$info")&" [ -n "$order" ] && page_link="${page_link}o=${order}&" [ -n "$search" ] && page_link="${page_link}s=${search}&" [ -n "$filter" ] && page_link="${page_link}f=${filter}&" -page_prev="${page_link}pn=$([ "$page" = 0 ] && echo 0 || echo $(($page - 1)) )" -page_next="${page_link}pn=$(($page + 1))" +page_prev="${page_link}pn=$([ "$page" -le "$pagesize" ] && echo 1 || echo $(($page - $pagesize)) )" +page_next="${page_link}pn=$(($page + $pagesize))" page_this="${page_link}pn=$page" taglist=$( @@ -85,12 +85,12 @@ genlist(){ case "$order" in Date) ls -c ${_DATA}/videos/ |egrep -i "$file_pattern";; Length) sed -sn 1p "${_DATA}/meta/"*.meta |sort -n |sed -r 's;^[0-9\t]+\t;;';; - *) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';; + Name) printf '%s\n' "${_DATA}/meta/"*meta |sed -r 's;^.*/;;;s;\.meta$;;';; esac } thumblist() { - cache="${_DATA}/cache/?o=${order}&s=${search}&f=${filter}&pn=${page}" + cache="${_DATA}/cache/${pagesize}?o=${order}&s=${search}&f=${filter}&pn=${page}" if [ "$cache" -nt ${_DATA}/videos -a "$cache" -nt ${_DATA}/meta ]; then cat "$cache" else @@ -112,7 +112,7 @@ thumblist() { else cat fi \ - | sed -n "$(($page * $pagesize + 1)),$(($page * $pagesize + $pagesize))p" \ + | sed -n "$page,$(($page + $pagesize - 1))p" \ | tee "$cache" fi \ | while read line; do diff --git a/pages/list.sh b/pages/list.sh index 32b4b94..a86f04c 100755 --- a/pages/list.sh +++ b/pages/list.sh @@ -17,7 +17,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Serve0. If not, see . -cgi_cookie . $_EXEC/pages/common.sh filters="$(printf %s "${_GET[f]}" |sed -r 's;^!*\^*;;; s;\^*!*$;;; s;!+;!;g; s;\^+;^;g')" diff --git a/templates/common.css.sh b/templates/common.css.sh index 0747d08..da390b5 100755 --- a/templates/common.css.sh +++ b/templates/common.css.sh @@ -29,7 +29,7 @@ body { color: #DDD; } a { color: #EEE; } -label, .label { font-weight: bold; } +legend, label, .label { font-weight: bold; } input.tabhandle { display: none; } .tabcontent { display: none; } @@ -97,7 +97,8 @@ a.clearsearch, a.show, .pagination_nav { #advfilter .quicklinks, #advfilter .filter, #tagger .newtag, -#tagger input[type=submit] { +#tagger input[type=submit], +#preferences > * { display: inline-block; vertical-align: top; margin-top: 1em; @@ -186,21 +187,28 @@ a.clearsearch, a.show, .pagination_nav { margin: .75em .5em; } -#preferences { display: none; } -#preferences:target { display: block; z-index: 1; } - #tagger { display: none; } #tagger:target { display: block; z-index: 1; } - #tagger .newtag select, #tagger .newtag .label{ display: block; width: 10em; } +#preferences { display: none; } +#preferences:target { + display: block; + z-index: 1; +} +#preferences > fieldset { + border: solid 1px; + border-radius: .25em; +} +#preferences > input { display: block; } + #videoview a.panel { position: absolute; right: 1em; diff --git a/templates/list.html.sh b/templates/list.html.sh index dd35173..a03c4da 100755 --- a/templates/list.html.sh +++ b/templates/list.html.sh @@ -34,7 +34,7 @@ cat < << - $(($page + 1)) + $(($page / $pagesize + 1)) >> @@ -53,7 +53,7 @@ cat < << - $(($page + 1)) + $(($page / $pagesize + 1)) >> diff --git a/templates/preferences.html.sh b/templates/preferences.html.sh index ee0e8be..49e6c7f 100755 --- a/templates/preferences.html.sh +++ b/templates/preferences.html.sh @@ -18,23 +18,30 @@ cat < +
+ Watch videos: + +
+ +
+ +
+ +
+ +
+ +
- - + + +
-

Watch videos:

- -
- -
- -
- -
- -
- -
+
+ Display: + + +
-- 2.39.2