X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=page_channel.sh;h=111b6f95241b1a1151845bf8410b9b3c57836be5;hb=b2a1e39b85a0c5d3e650094ec47e0a52434c6ca1;hp=bc05b15919fef30dd305de83b8ef7d853f685f79;hpb=e82750023ec5907d4a373f7fe377c79cde41fd04;p=rawnet diff --git a/page_channel.sh b/page_channel.sh index bc05b15..111b6f9 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -1,267 +1,138 @@ #!/bin/sh -chan_db="$_DATA/channels.db" +["$includepage_channel" ] && return 0 +includepage_channel="$0" -channel='' video='' action='' -path_info="$PATH_INFO" -path_info="${path_info#/channel/}" -if [ "$(checkid "${path_info%%/*}")" ]; then - channel="${path_info%%/*}" - path_info="${path_info#*/}" -fi -if [ "$(checkid "${path_info%%/*}")" ]; then - video="${path_info%%/*}" - path_info="${path_info#*/}" -fi -action="${path_info}" -unset path_info - -# Channel -# ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE - -if [ "$channel" -a -f "$chan_db" -a -r "$chan_db" ]; then - read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \ - CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \ - CHANNEL_FUTUREUSE <<-EOF - $(grep "^${channel} " "${chan_db}") - EOF - if [ "$CHANNEL_ID" ]; then - CHANNEL_NAME="$(UNSTRING "${CHANNEL_NAME}")" - CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")" - CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")" - CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")" - vid_db="${_DATA}/${CHANNEL_ID}/videos.db" - else - channel='' - fi -fi +. "$_EXEC/db_channel.sh" +. "$_EXEC/widgets.sh" -update_channel(){ - local id="${1}" name description logo theme authors descr_cache futureuse - local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE - local arg - - for arg in "$@"; do case $arg in - name=*) name="${arg#*=}";; - description=*) description="${arg#*=}";; - logo=*) logo="${arg#*=}";; - theme=*) theme="${arg#*=}";; - authors=*) authors="${arg#*=}";; - esac; done - - if LOCK "$chan_db"; then - while read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; do - if [ "$id" = "$ID" ]; then - printf '%s %s %s %s %s %s %s %s\n' \ - "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \ - "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \ - "${logo:-${logo-${LOGO}}${logo+\\}}" \ - "${theme:-${theme-${THEME}}${theme+\\}}" \ - "$(STRING "${authors-$(UNSTRING "${AUTHORS}")}")" \ - "$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \ - "${FUTUREUSE:-\\}" - else - printf '%s %s %s %s %s %s %s %s\n' \ - "$ID" "$NAME" "$DESCRIPTION" "$LOGO" "$THEME" "$AUTHORS" \ - "$DESCR_CACHE" "$FUTUREUSE" - fi - done <"$chan_db" >"${chan_db}.$$" - mv -- "${chan_db}.$$" "${chan_db}" - RELEASE "$chan_db" - else - return 1 - fi -} - -AUTHOR(){ - if [ "$CHANNEL_ID" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then - return 0 - else - return 1 - fi -} - -# Video -# ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS +read_channel "$channel" [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in newchannel) channel="$(POST channel |checkid)" if [ ! "$USER_ID" ]; then REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED" - elif LOCK "$chan_db"; then - if grep -q '^${channel} ' "$chan_db"; then - RELEASE "$chan_db" - REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_EXISTS" - else - printf '%s \\ \\ \\ \\ %s \\ \\\n' \ - "$channel" "$(STRING "$USER_ID")" \ - >>"$chan_db" - RELEASE "$chan_db" - REDIRECT "${_BASE}/channel/${channel}/edit" - fi + elif new_channel "$channel"; then + REDIRECT "${_BASE}/channel/$channel/edit" else REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK" fi ;; update_channel) - if [ ! "$channel" ]; then + authors="${USER_ID}" + n="$(POST_COUNT author)" + while [ $n -gt 0 ]; do + newauthor="$(POST author $n |checkid)" + user_idmap "$newauthor" && authors="${authors}${BR}${newauthor}" >&- + n=$((n - 1)) + done + n="$(POST_COUNT newauthor)" + while [ $n -gt 0 ]; do + newauthor="$(POST newauthor $n)" + newauthor="$(user_idof "$newauthor")" \ + && authors="${authors}${BR}${newauthor}" + n=$((n - 1)) + done + + if [ ! "$CHANNEL_ID" ]; then REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" - elif update_channel "$channel" "name=$(POST name)" \ + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED" + elif update_channel "$CHANNEL_ID" "name=$(POST name)" \ "description=$(POST description)" \ - "authors=$USER_ID"; then - REDIRECT "${_BASE}/channel/${channel}/" + "authors=${authors}"; then + REDIRECT "${_BASE}/channel/$CHANNEL_ID/" else - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOLOCK" fi ;; update_channel_cancel) - REDIRECT "${_BASE}/channel/${channel}/" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/" ;; newvideo) + . "$_EXEC/db_video.sh" video="$(POST video |checkid)" AUTHOR \ - && mkdir -p -- "${_DATA}/${channel}/" + && mkdir -p -- "${_DATA}/$CHANNEL_ID/" if [ ! "$video" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID" - elif [ ! "$channel" ]; then + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_INVALID_ID" + elif [ ! "$CHANNEL_ID" ]; then REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN" elif ! AUTHOR; then - REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" - elif LOCK "$vid_db"; then - if grep -q "^${video} " "$vid_db"; then - RELEASE "$vid_db" - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_EXISTS" - else - # ID NAME DESC RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE - printf '%s \\ \\ \\ \\ \\ \\ void %s \\ \\\n' \ - "$video" "$(STRING "$USER_ID")" \ - >>"$vid_db" - RELEASE "$vid_db" - REDIRECT "${_BASE}/channel/${channel}/${video}/edit" - fi + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED" + elif new_video "$video"; then + REDIRECT "${_BASE}/channel/$CHANNEL_ID/$video/" else - REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK" + REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NEWVIDEO_NOLOCK" fi ;; esac -w_video(){ - local thumb - local VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \ - VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \ - VIDEO_DESCR_CACHE VIDEO_FUTUREUSE - - if read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \ - VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \ - VIDEO_DESCR_CACHE VIDEO_FUTUREUSE; then - VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")" - VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")" - VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")" - - [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0 - - thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg" - [ "$NAME" = \\ ] && NAME="(Unnamed Video)" - printf '[div .video .thumb - [a href="%s/channel/%s/%s/" - [h3 . %s] - [figure [img src="%s" alt=""]] - [span .duration . %i:%02i] - [div .description . %s] - ] - ]' "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \ - "$(HTML "${VIDEO_NAME:-(Unnamed Video)}")" \ - "$thumb" \ - "$((${VIDEO_LENGTH%.*} / 60))" "$((${VIDEO_LENGTH%.*} % 60))" \ - "$(UNSTRING "$DESCR_CACHE")" - else - return 1 - fi -} - -w_channel(){ - local vid_db - local CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \ - CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE - - if read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \ - CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \ - CHANNEL_FUTUREUSE; then - CHANNEL_NAME="$(UNSTRING "$CHANNEL_NAME")" - CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")" - CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")" - CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")" - - vid_db="${_DATA}/${CHANNEL_ID}/videos.db" - cat <<-EOF - [div .channel - [div .description - [h2 [a href="${_BASE}/channel/${CHANNEL_ID}/" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]] - ${CHANNEL_DESCR_CACHE} - ]$( - [ -f "$vid_db" -a -r "$vid_db" ] \ - && while w_video; do :; done <"$vid_db" - ) - ] - EOF - else - return 1 - fi -} - -w_channel_list(){ - if [ $USER_ID ]; then - printf ' - [form .channel .newchannel method=POST - [hidden "channel" "%s"] - [submit "action" "newchannel" New Channel] - ]' "$(timeid)" - fi - [ -f "$chan_db" -a -r "$chan_db" ] \ - && while w_channel; do :; done <"$chan_db" -} - -if [ "$channel" -a "$video" ]; then - . ${_EXEC}/page_video.sh -elif [ "$channel" -a "$action" = edit ]; then - AUTHOR || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED" +if [ "$CHANNEL_ID" -a "$action" = edit ]; then + AUTHOR || REDIRECT "${_BASE}/$CHANNEL_ID/#ERROR_EDIT_NOTALLOWED" yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF + [datalist #list_authors + $(user_idmap |cut -f2 |UNSTRING |while read name; do + printf '[option value="%s"]' "$(HTML "$name")" + done) + ] [form .channel .edit method=POST - [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"] + [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name" autocomplete=off] [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")] + [div .authors [h3 Authors:] + $(for each in $CHANNEL_AUTHORS; do + printf '[checkbox "author" "%s" id="author_%s" %s %s][label for="author_%s" . %s]\n' \ + "$each" "$each" "checked=checked" "$([ "$each" = "$USER_ID" ] && printf 'disabled=disabled')" \ + "$each" "$(user_idmap "$each" |UNSTRING |HTML)" + done + for n in 0 1 2 3 4 5 6 7 8 9; do + printf '[checkbox "" "" #newauthor%i][label for=newauthor%i . +] + [input name=newauthor value="" placeholder="Author" list=list_authors]' \ + $n $n + done) + ] [submit "action" "update_channel" . Update] [submit "action" "update_channel_cancel" . Cancel] ] EOF -elif [ "$channel" ]; then +elif [ "$CHANNEL_ID" ]; then yield_page "$CHANNEL_NAME" "channel" <<-EOF - [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - $(AUTHOR && printf ' - [a href="edit" edit]') - ] + [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]] [h1 .name $(HTML "$CHANNEL_NAME")] [div .description . ${CHANNEL_DESCR_CACHE}] + [div .authors [h3 Authors:] + $(for each in $CHANNEL_AUTHORS; do + printf '[span .author . %s]\n' "$(user_idmap "$each" |UNSTRING |HTML)" + done |sort) + ] + $(AUTHOR && printf '[a .button href="edit" edit]') [h1 .videos Videos] [div .videos . $( AUTHOR && printf ' - [form .video .newvideo method=POST - [hidden "video" "%s"] - [submit "action" "newvideo" New Video] - ]' "$(timeid)" - [ -f "$vid_db" -a -r "$vid_db" ] \ - && while w_video "$ID"; do :; done <"$vid_db" + [form .video .newvideo method=POST + [hidden "video" "%s"] + [submit "action" "newvideo" New Video] + ]' "$(timeid)" + list_videos |while w_video; do :; done )] EOF else yield_page "Channels" "channels" <<-EOF - $(w_channel_list) + $([ "$USER_ID" ] && printf ' + [form .channel .newchannel method=POST + [hidden "channel" "%s"] + [submit "action" "newchannel" New Channel] + ]' "$(timeid)" + ) + $([ -f "$chan_db" -a -r "$chan_db" ] \ + && while w_channel; do :; done <"$chan_db" + ) EOF fi