]> git.plutz.net Git - rawnet/blob - page_channel.sh
For progress frame use chunked encoding instead of long poll
[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     authors="${USER_ID}"
24     n="$(POST_COUNT author)"
25     while [ $n -gt 0 ]; do
26       newauthor="$(POST author $n |checkid)"
27       user_idmap "$newauthor" && authors="${authors}${BR}${newauthor}" >&-
28       n=$((n - 1))
29     done
30     n="$(POST_COUNT newauthor)"
31     while [ $n -gt 0 ]; do
32       newauthor="$(POST newauthor $n)"
33       newauthor="$(user_idof "$newauthor")" \
34       && authors="${authors}${BR}${newauthor}"
35       n=$((n - 1))
36     done
37
38     if [ ! "$CHANNEL_ID" ]; then
39       REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
40     elif [ ! "$USER_ID" ]; then
41       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
42     elif ! AUTHOR; then
43       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
44     elif update_channel "$CHANNEL_ID" "name=$(POST name)" \
45                         "description=$(POST description)" \
46                         "authors=${authors}"; then
47       REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
48     else
49       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOLOCK"
50     fi
51     ;;
52   update_channel_cancel)
53     REDIRECT "${_BASE}/channel/$CHANNEL_ID/"
54     ;;
55   newvideo)
56     . "$_EXEC/db_video.sh"
57     video="$(POST video |checkid)"
58
59     AUTHOR \
60     && mkdir -p -- "${_DATA}/$CHANNEL_ID/"
61
62     if [ ! "$video" ]; then
63       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_INVALID_ID"
64     elif [ ! "$CHANNEL_ID" ]; then
65       REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
66     elif [ ! "$USER_ID" ]; then
67       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NOTLOGGEDIN"
68     elif ! AUTHOR; then
69       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_UPDATE_NOTALLOWED"
70     elif new_video "$video"; then
71       REDIRECT "${_BASE}/channel/$CHANNEL_ID/$video/"
72     else
73       REDIRECT "${_BASE}/channel/$CHANNEL_ID/#ERROR_NEWVIDEO_NOLOCK"
74     fi
75     ;;
76 esac
77
78 if [ "$CHANNEL_ID" -a "$action" = edit ]; then
79   AUTHOR || REDIRECT "${_BASE}/$CHANNEL_ID/#ERROR_EDIT_NOTALLOWED"
80   yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
81         [datalist #list_authors
82         $(user_idmap |cut -f2 |UNSTRING |while read name; do
83           printf '[option value="%s"]' "$(HTML "$name")"
84         done)
85         ]
86         [form .channel .edit method=POST
87           [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name" autocomplete=off]
88           [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")]
89           [div .authors [h3 Authors:]
90             $(for each in $CHANNEL_AUTHORS; do
91               printf '[checkbox "author" "%s" id="author_%s" %s %s][label for="author_%s" . %s]\n' \
92                      "$each" "$each" "checked=checked" "$([ "$each" = "$USER_ID" ] && printf 'disabled=disabled')" \
93                      "$each" "$(user_idmap "$each" |UNSTRING |HTML)"
94             done
95             for n in 0 1 2 3 4 5 6 7 8 9; do
96               printf '[checkbox "" "" #newauthor%i][label for=newauthor%i . +]
97                       [input name=newauthor value="" placeholder="Author" list=list_authors]' \
98                       $n $n
99             done)
100           ]
101           [submit "action" "update_channel" . Update]
102           [submit "action" "update_channel_cancel" . Cancel]
103         ]
104         EOF
105 elif [ "$CHANNEL_ID" ]; then
106   yield_page "$CHANNEL_NAME" "channel" <<-EOF
107         [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]]
108         [h1 .name $(HTML "$CHANNEL_NAME")]
109         [div .description . ${CHANNEL_DESCR_CACHE}]
110         [div .authors [h3 Authors:]
111           $(for each in $CHANNEL_AUTHORS; do
112             printf '[span .author . %s]\n' "$(user_idmap "$each" |UNSTRING |HTML)"
113           done |sort)
114         ]
115         $(AUTHOR && printf '[a .button href="edit" edit]')
116         [h1 .videos Videos]
117         [div .videos . $(
118           AUTHOR && printf '
119              [form .video .newvideo method=POST
120                [hidden "video" "%s"]
121                [submit "action" "newvideo" New Video]
122              ]' "$(timeid)"
123           list_videos |while w_video; do :; done
124         )]
125         EOF
126 else
127   yield_page "Channels" "channels" <<-EOF
128         $([ "$USER_ID" ] && printf '
129           [form .channel .newchannel method=POST
130             [hidden "channel" "%s"]
131             [submit "action" "newchannel" New Channel]
132           ]' "$(timeid)"
133         )
134         $([ -f "$chan_db" -a -r "$chan_db" ] \
135           && while w_channel; do :; done <"$chan_db"
136         )
137         EOF
138 fi