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 # ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS
65 [ "$REQUEST_METHOD" = POST ] && case "$(POST action)" in
67 channel="$(POST channel |checkid)"
68 if [ ! "$USER_ID" ]; then
69 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOTALLOWED"
70 elif LOCK "$chan_db"; then
71 if grep -q '^${channel} ' "$chan_db"; then
73 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_EXISTS"
75 printf '%s \\ \\ \\ \\ %s \\ \\\n' \
76 "$channel" "$(STRING "$USER_ID")" \
79 REDIRECT "${_BASE}/channel/${channel}/edit"
82 REDIRECT "${_BASE}/channel/#ERROR_NEWCHANNEL_NOLOCK"
86 if [ ! "$channel" ]; then
87 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
88 elif [ ! "$USER_ID" ]; then
89 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
90 elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
91 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
92 elif update_channel "$channel" "$(POST name)" "$(POST description)" \
93 "" "" "$USER_ID" "" ""; then
94 REDIRECT "${_BASE}/channel/${channel}/"
96 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOLOCK"
99 update_channel_cancel)
100 REDIRECT "${_BASE}/channel/${channel}/"
103 video="$(POST video |checkid)"
105 [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \
106 && mkdir -p -- "${_DATA}/${channel}/"
108 if [ ! "$video" ]; then
109 REDIRECT "${_BASE}/channel/${channel}/#ERROR_INVALID_ID"
110 elif [ ! "$channel" ]; then
111 REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL"
112 elif [ ! "$USER_ID" ]; then
113 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN"
114 elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then
115 REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED"
116 elif LOCK "$vid_db"; then
117 if grep -q '^${video} ' "$vid_db"; then
119 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_EXISTS"
121 # ID NAME DESC RESX RESY LENGTH COVER STATUS UPLOADER HITS FUTUREUSE
122 printf '%s \\ \\ \\ \\ \\ \\ private %s \\ \\\n' \
123 "$video" "$(STRING "$USER_ID")" \
126 REDIRECT "${_BASE}/channel/${channel}/${video}/edit"
129 REDIRECT "${_BASE}/channel/${channel}/#ERROR_NEWVIDEO_NOLOCK"
136 local ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE
137 if read -r ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS DESCR_CACHE FUTUREUSE; then
138 thumb="${_BASE}/${CID}/thumb_${ID}.jpg"
139 [ "$NAME" = \\ ] && NAME="(Unnamed Video)"
140 printf '[div .video .thumb
141 [h3 [a href="%s/" . %s]]
142 [figure [img src="%s" alt=""]]
143 [div .description . %s]
144 ]' "$ID" "$(UNSTRING "$NAME" |HTML)" "$thumb" "$(UNSTRING "$DESCR_CACHE")"
152 local ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE
153 if read -r ID NAME DESCRIPTION LOGO THEME AUTHORS DESCR_CACHE FUTUREUSE; then
154 vid_db="${_DATA}/${ID}/videos.db"
155 [ "$NAME" = \\ ] && NAME="(UNNAMED CHANNEL)"
159 [h2 [a href="${_BASE}/channel/${ID}/" $(UNSTRING "${NAME}" |HTML)]]
160 $(UNSTRING "$DESCR_CACHE")
162 [ -f "$vid_db" -a -r "$vid_db" ] \
163 && while w_video "$ID"; do :; done <"$vid_db"
173 if [ $USER_ID ]; then
175 [form .channel .newchannel method=POST
176 [hidden "channel" "%s"]
177 [submit "action" "newchannel" New Channel]
180 [ -f "$chan_db" -a -r "$chan_db" ] \
181 && while w_channel; do :; done <"$chan_db"
184 if [ "$channel" -a "$video" ]; then
185 . ${_EXEC}/page_video.sh
186 elif [ "$channel" -a "$action" = edit ]; then
187 [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \
188 || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED"
189 yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF
190 [form .channel .edit method=POST
191 [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"]
192 [textarea name="description" placeholder="Description" . $(HTML "$CHANNEL_DESCRIPTION")]
193 [submit "action" "update_channel" . Update]
194 [submit "action" "update_channel_cancel" . Cancel]
197 elif [ "$channel" ]; then
198 yield_page "$CHANNEL_NAME" "channel" <<-EOF
199 [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")]
200 $( [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \
201 && printf ' - [a href="edit" edit]'
204 [h1 .name $(HTML "$CHANNEL_NAME")]
205 [div .description . ${CHANNEL_DESCR_CACHE}]
208 [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \
210 [form .video .newvideo method=POST
211 [hidden "video" "%s"]
212 [submit "action" "newvideo" New Video]
214 [ -f "$vid_db" -a -r "$vid_db" ] \
215 && while w_video "$ID"; do :; done <"$vid_db"
219 yield_page "Channels" "channels" <<-EOF