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="${2}" description="${3}" logo="${4}" theme="${5}" \
41 authors="${6}" descr_cache="${7}" futureuse="${8}"
43 if LOCK "$chan_db"; then
44 while read -r ID INFO; do
45 if [ "$id" = "$ID" ]; then
46 printf '%s %s %s %s %s %s %s %s\n' \
47 "$id" "$(STRING "$name")" "$(STRING "$description")" \
48 "${logo:-\\}" "${theme:-\\}" "$(STRING "$authors")" \
49 "$(printf %s "$description" |markdown |STRING)" \
52 printf '%s %s\n' "$ID" "$INFO"
54 done <"$chan_db" >"${chan_db}.$$"
55 mv -- "${chan_db}.$$" "${chan_db}"
63 if [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
71 # ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS
73 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
75 channel="$(POST channel |checkid)"
76 if [ ! "$USER_ID" ]; then
77 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED"
78 elif LOCK "$chan_db"; then
79 if grep -q '^${channel} ' "$chan_db"; then
81 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_EXISTS"
83 printf '%s \\ \\ \\ \\ %s \\ \\\n' \
84 "$channel" "$(STRING "$USER_ID")" \
87 REDIRECT "${_BASE}/channel/${channel}/edit"
90 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK"
94 if [ ! "$channel" ]; then
95 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
96 elif [ ! "$USER_ID" ]; then
97 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
99 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
100 elif update_channel "$channel" "$(POST name)" "$(POST description)" \
101 "" "" "$USER_ID" "" ""; then
102 REDIRECT "${_BASE}/channel/${channel}/"
104 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK"
107 update_channel_cancel)
108 REDIRECT "${_BASE}/channel/${channel}/"
111 video="$(POST video |checkid)"
114 && mkdir -p -- "${_DATA}/${channel}/"
116 if [ ! "$video" ]; then
117 REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID"
118 elif [ ! "$channel" ]; then
119 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
120 elif [ ! "$USER_ID" ]; then
121 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
123 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
124 elif LOCK "$vid_db"; then
125 if grep -q '^${video} ' "$vid_db"; then
127 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_EXISTS"
129 # ID NAME DESC RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE
130 printf '%s \\ \\ \\ \\ \\ \\ private %s \\ \\\n' \
131 "$video" "$(STRING "$USER_ID")" \
134 REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
137 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK"
144 local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE
145 if read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE; then
146 thumb="${_BASE}/${CID}/thumb_${ID}.jpg"
147 [ "$NAME" = \\ ] && NAME="(Unnamed Video)"
148 printf '[div .video .thumb
149 [h3 [a href="%s/channel/%s/%s/" . %s]]
150 [figure [img src="%s" alt=""]]
151 [div .description . %s]
152 ]' "$_BASE" "$CID" "$ID" "$(UNSTRING "$NAME" |HTML)" "$thumb" "$(UNSTRING "$DESCR_CACHE")"
160 local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE
161 if read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; then
162 vid_db="${_DATA}/${ID}/videos.db"
163 [ "$NAME" = \\ ] && NAME="(UNNAMED CHANNEL)"
167 [h2 [a href="${_BASE}/channel/${ID}/" $(UNSTRING "${NAME}" |HTML)]]
168 $(UNSTRING "$DESCR_CACHE")
170 [ -f "$vid_db" -a -r "$vid_db" ] \
171 && while w_video "$ID"; do :; done <"$vid_db"
181 if [ $USER_ID ]; then
183 [form .channel .newchannel method=POST
184 [hidden "channel" "%s"]
185 [submit "action" "newchannel" New Channel]
188 [ -f "$chan_db" -a -r "$chan_db" ] \
189 && while w_channel; do :; done <"$chan_db"
192 if [ "$channel" -a "$video" ]; then
193 . ${_EXEC}/page_video.sh
194 elif [ "$channel" -a "$action" = edit ]; then
195 AUTHOR || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED"
196 yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
197 [form .channel .edit method=POST
198 [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"]
199 [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")]
200 [submit "action" "update_channel" . Update]
201 [submit "action" "update_channel_cancel" . Cancel]
204 elif [ "$channel" ]; then
205 yield_page "$CHANNEL_NAME" "channel" <<-EOF
206 [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]
207 $(AUTHOR && printf ' - [a href="edit" edit]')
209 [h1 .name $(HTML "$CHANNEL_NAME")]
210 [div .description . ${CHANNEL_DESCR_CACHE}]
214 [form .video .newvideo method=POST
215 [hidden "video" "%s"]
216 [submit "action" "newvideo" New Video]
218 [ -f "$vid_db" -a -r "$vid_db" ] \
219 && while w_video "$ID"; do :; done <"$vid_db"
223 yield_page "Channels" "channels" <<-EOF