3 chan_db="$_DATA/channels.db"
5 channel='' video='' action=''
7 path_info="${path_info#/channel/}"
8 if [ "$(checkid "${path_info%%/*}")" ]; then
9 channel="${path_info%%/*}"
10 path_info="${path_info#*/}"
12 if [ "$(checkid "${path_info%%/*}")" ]; then
13 video="${path_info%%/*}"
14 path_info="${path_info#*/}"
20 # ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE
22 if [ "$channel" -a -f "$chan_db" -a -r "$chan_db" ]; then
23 read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
24 CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \
25 CHANNEL_FUTUREUSE <<-EOF
26 $(grep "^${channel} " "${chan_db}")
28 if [ "$CHANNEL_ID" ]; then
29 CHANNEL_NAME="$(UNSTRING "${CHANNEL_NAME}")"
30 CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")"
31 CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")"
32 CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")"
33 vid_db="${_DATA}/${CHANNEL_ID}/videos.db"
40 local id="${1}" name description logo theme authors descr_cache futureuse
41 local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE
44 for arg in "$@"; do case $arg in
45 name=*) name="${arg#*=}";;
46 description=*) description="${arg#*=}";;
47 logo=*) logo="${arg#*=}";;
48 theme=*) theme="${arg#*=}";;
49 authors=*) authors="${arg#*=}";;
52 if LOCK "$chan_db"; then
53 while read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; do
54 if [ "$id" = "$ID" ]; then
55 printf '%s %s %s %s %s %s %s %s\n' \
56 "$id" "$(STRING "${name-$(UNSTRING "$NAME")}")" \
57 "$(STRING "${description-$(UNSTRING "$DESCRIPTION")}")" \
58 "${logo:-${logo-${LOGO}}${logo+\\}}" \
59 "${theme:-${theme-${THEME}}${theme+\\}}" \
60 "$(STRING "${authors-$(UNSTRING "${AUTHORS}")}")" \
61 "$(printf %s "${description-$(UNSTRING "$DESCRIPTION")}" |markdown |STRING)" \
64 printf '%s %s %s %s %s %s %s %s\n' \
65 "$ID" "$NAME" "$DESCRIPTION" "$LOGO" "$THEME" "$AUTHORS" \
66 "$DESCR_CACHE" "$FUTUREUSE"
68 done <"$chan_db" >"${chan_db}.$$"
69 mv -- "${chan_db}.$$" "${chan_db}"
77 if [ "$CHANNEL_ID" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
85 # ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS
87 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
89 channel="$(POST channel |checkid)"
90 if [ ! "$USER_ID" ]; then
91 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED"
92 elif LOCK "$chan_db"; then
93 if grep -q '^${channel} ' "$chan_db"; then
95 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_EXISTS"
97 printf '%s \\ \\ \\ \\ %s \\ \\\n' \
98 "$channel" "$(STRING "$USER_ID")" \
101 REDIRECT "${_BASE}/channel/${channel}/edit"
104 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK"
108 if [ ! "$channel" ]; then
109 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
110 elif [ ! "$USER_ID" ]; then
111 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
113 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
114 elif update_channel "$channel" "name=$(POST name)" \
115 "description=$(POST description)" \
116 "authors=$USER_ID"; then
117 REDIRECT "${_BASE}/channel/${channel}/"
119 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK"
122 update_channel_cancel)
123 REDIRECT "${_BASE}/channel/${channel}/"
126 video="$(POST video |checkid)"
129 && mkdir -p -- "${_DATA}/${channel}/"
131 if [ ! "$video" ]; then
132 REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID"
133 elif [ ! "$channel" ]; then
134 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
135 elif [ ! "$USER_ID" ]; then
136 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
138 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
139 elif LOCK "$vid_db"; then
140 if grep -q '^${video} ' "$vid_db"; then
142 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_EXISTS"
144 # ID NAME DESC RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE
145 printf '%s \\ \\ \\ \\ \\ \\ void %s \\ \\\n' \
146 "$video" "$(STRING "$USER_ID")" \
149 REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
152 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK"
159 local VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \
160 VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \
161 VIDEO_DESCR_CACHE VIDEO_FUTUREUSE
163 if read -r VIDEO_ID VIDEO_NAME VIDEO_DESCRIPTION VIDEO_RESX VIDEO_RESY \
164 VIDEO_LENGTH VIDEO_COVER VIDEO_STATUS VIDEO_UPLOADER VIDEO_HITS \
165 VIDEO_DESCR_CACHE VIDEO_FUTUREUSE; then
166 VIDEO_NAME="$(UNSTRING "$VIDEO_NAME")"
167 VIDEO_DESCRIPTION="$(UNSTRING "$VIDEO_DESCRIPTION")"
168 VIDEO_DESCR_CACHE="$(UNSTRING "$VIDEO_DESCR_CACHE")"
170 [ "${VIDEO_STATUS}" = public ] || AUTHOR || return 0
172 thumb="${_BASE}/video/${CHANNEL_ID}/${VIDEO_ID}_thumb.jpg"
173 [ "$NAME" = \\ ] && NAME="(Unnamed Video)"
174 printf '[div .video .thumb
175 [h3 [a href="%s/channel/%s/%s/" . %s]]
176 [figure [img src="%s" alt=""]]
177 [span .duration . %i:%02i]
178 [div .description . %s]
179 ]' "$_BASE" "$CHANNEL_ID" "$VIDEO_ID" \
180 "$(HTML "${VIDEO_NAME:-(Unnamed Video)}")" \
182 "$((${VIDEO_LENGTH%.*} / 60))" "$((${VIDEO_LENGTH%.*} % 60))" \
183 "$(UNSTRING "$DESCR_CACHE")"
191 local CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
192 CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE CHANNEL_FUTUREUSE
194 if read -r CHANNEL_ID CHANNEL_NAME CHANNEL_DESCRIPTION CHANNEL_LOGO \
195 CHANNEL_THEME CHANNEL_AUTHORS CHANNEL_DESCR_CACHE \
196 CHANNEL_FUTUREUSE; then
197 CHANNEL_NAME="$(UNSTRING "$CHANNEL_NAME")"
198 CHANNEL_DESCRIPTION="$(UNSTRING "$CHANNEL_DESCRIPTION")"
199 CHANNEL_AUTHORS="$(UNSTRING "$CHANNEL_AUTHORS")"
200 CHANNEL_DESCR_CACHE="$(UNSTRING "$CHANNEL_DESCR_CACHE")"
202 vid_db="${_DATA}/${CHANNEL_ID}/videos.db"
206 [h2 [a href="${_BASE}/channel/${CHANNEL_ID}/" $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]]
207 ${CHANNEL_DESCR_CACHE}
209 [ -f "$vid_db" -a -r "$vid_db" ] \
210 && while w_video; do :; done <"$vid_db"
220 if [ $USER_ID ]; then
222 [form .channel .newchannel method=POST
223 [hidden "channel" "%s"]
224 [submit "action" "newchannel" New Channel]
227 [ -f "$chan_db" -a -r "$chan_db" ] \
228 && while w_channel; do :; done <"$chan_db"
231 if [ "$channel" -a "$video" ]; then
232 . ${_EXEC}/page_video.sh
233 elif [ "$channel" -a "$action" = edit ]; then
234 AUTHOR || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED"
235 yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
236 [form .channel .edit method=POST
237 [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"]
238 [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")]
239 [submit "action" "update_channel" . Update]
240 [submit "action" "update_channel_cancel" . Cancel]
243 elif [ "$channel" ]; then
244 yield_page "$CHANNEL_NAME" "channel" <<-EOF
245 [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]
246 $(AUTHOR && printf ' - [a href="edit" edit]')
248 [h1 .name $(HTML "$CHANNEL_NAME")]
249 [div .description . ${CHANNEL_DESCR_CACHE}]
253 [form .video .newvideo method=POST
254 [hidden "video" "%s"]
255 [submit "action" "newvideo" New Video]
257 [ -f "$vid_db" -a -r "$vid_db" ] \
258 && while w_video "$ID"; do :; done <"$vid_db"
262 yield_page "Channels" "channels" <<-EOF