]> git.plutz.net Git - rawnet/blob - page_channel.sh
list_videos function including sorting
[rawnet] / page_channel.sh
1 #!/bin/sh
2
3 ["$includepage_channel" ] && return 0
4 includepage_channel="$0"
5
6 . "$_EXEC/db_channel.sh"
7 . "$_EXEC/widgets.sh"
8
9 read_channel "$channel"
10
11 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
12   newchannel)
13     channel="$(POST channel |checkid)"
14     if [ ! "$USER_ID" ]; then
15       REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED"
16     elif new_channel "$channel"; then
17       REDIRECT "${_BASE}/channel/$channel/edit"
18     else
19       REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK"
20     fi
21     ;;
22   update_channel)
23     if [ ! "$CHANNEL_ID" ]; then
24       REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
25     elif [ ! "$USER_ID" ]; then
26       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
27     elif ! AUTHOR; then
28       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
29     elif update_channel "$CHANNEL_ID" "name=$(POST name)" \
30                         "description=$(POST description)" \
31                         "authors=$USER_ID"; then
32       REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
33     else
34       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOLOCK"
35     fi
36     ;;
37   update_channel_cancel)
38     REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
39     ;;
40   newvideo)
41     . "$_EXEC/db_video.sh"
42     video="$(POST video |checkid)"
43
44     AUTHOR \
45     && mkdir -p -- "${_DATA}/$CHANNEL_ID/"
46
47     if [ ! "$video" ]; then
48       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_INVALID_ID"
49     elif [ ! "$CHANNEL_ID" ]; then
50       REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
51     elif [ ! "$USER_ID" ]; then
52       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
53     elif ! AUTHOR; then
54       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
55     elif new_video "$video"; then
56       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$video/"
57     else
58       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NEWVIDEO_NOLOCK"
59     fi
60     ;;
61 esac
62
63 if [ "$CHANNEL_ID" -a "$action" = edit ]; then
64   AUTHOR || REDIRECT "${_BASE}/$CHANNEL_ID/#ERROR_EDIT_NOTALLOWED"
65   yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
66         [form .channel .edit method=POST
67           [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name" autocomplete=off]
68           [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")]
69           [submit "action" "update_channel" . Update]
70           [submit "action" "update_channel_cancel" . Cancel]
71         ]
72         EOF
73 elif [ "$CHANNEL_ID" ]; then
74   yield_page "$CHANNEL_NAME" "channel" <<-EOF
75         [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]]
76         [h1 .name $(HTML "$CHANNEL_NAME")]
77         [div .description . ${CHANNEL_DESCR_CACHE}]
78         $(AUTHOR && printf '[a .button href="edit" edit]')
79         [h1 .videos Videos]
80         [div .videos . $(
81           AUTHOR && printf '
82              [form .video .newvideo method=POST
83                [hidden "video" "%s"]
84                [submit "action" "newvideo" New Video]
85              ]' "$(timeid)"
86           list_videos |while w_video; do :; done
87         )]
88         EOF
89 else
90   yield_page "Channels" "channels" <<-EOF
91         $([ "$USER_ID" ] && printf '
92           [form .channel .newchannel method=POST
93             [hidden "channel" "%s"]
94             [submit "action" "newchannel" New Channel]
95           ]' "$(timeid)"
96         )
97         $([ -f "$chan_db" -a -r "$chan_db" ] \
98           && while w_channel; do :; done <"$chan_db"
99         )
100         EOF
101 fi