diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/helper.php | 174 | ||||
-rw-r--r-- | lib/program.php | 168 |
2 files changed, 0 insertions, 342 deletions
diff --git a/lib/helper.php b/lib/helper.php index 640651b..7423a9c 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -1,46 +1,5 @@ <?php -require_once('program.php'); - -function link_player($room, $format = 'video', $translated = false) -{ - $defaultformat = room_has_hd($room) ? 'hd' : 'sd'; - - return rawurlencode($room).'/'.(($defaultformat == $format || 'video' == $format) ? '' : rawurlencode($format).'/').($translated ? 'translated/' : ''); -} - -function link_stream($protocol, $room, $format, $translated = false) -{ - $language = $translated ? 'translated' : 'native'; - - switch ($protocol) { - case 'rtmp': - return 'rtmp://cdn.c3voc.de/stream/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'_'.rawurlencode($language).'_'.rawurlencode($format); - - case 'hls': - return 'http://cdn.c3voc.de/hls/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'_'.rawurlencode($language).($format == 'auto' ? '' : '_'.rawurlencode($format)).'.m3u8'; - - case 'webm': - return 'http://cdn.c3voc.de/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'_'.rawurlencode($language).'_'.rawurlencode($format).'.webm'; - - case 'music': - return 'http://cdn.c3voc.de/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'.'.rawurlencode($format); - - case 'audio': - return 'http://cdn.c3voc.de/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'_'.rawurlencode($language).'.'.rawurlencode($format); - - case 'slide': - return 'http://cdn.c3voc.de/slides/'.rawurlencode(get("ROOMS.$room.STREAM", $room)).'/current.png'; - } - - return '#'; -} - -function link_vod($id) -{ - return 'relive/'.rawurlencode($id).'/'; -} - function baseurl() { if(isset($GLOBALS['CONFIG']['baseurl'])) @@ -62,12 +21,6 @@ function forceslash($url) return $url; } -function strtoduration($str) -{ - $parts = explode(':', $str); - return ((int)$parts[0] * 60 + (int)$parts[1]) * 60; -} - function has($keychain) { return _has($GLOBALS['CONFIG'], $keychain); @@ -106,134 +59,7 @@ function _get($array, $keychain, $default) return _get($array[$key], array_slice($keychain, 1), $default); } - - -function room_has_hd($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('rtmp-hd', 'hls-hd', 'webm-hd'), $formats)) > 0; -} - -function room_has_sd($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('rtmp-sd', 'hls-sd', 'webm-sd'), $formats)) > 0; -} - -function room_has_video($room) -{ - return room_has_hd($room) || room_has_sd($room); -} - -function room_has_audio($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('audio-mp3', 'audio-opus', 'audio-ogg'), $formats)) > 0; -} - -function room_has_music($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('music-mp3', 'music-opus', 'music-ogg'), $formats)) > 0; -} - -function room_has_slides($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('slides'), $formats)) > 0; -} - -function room_get_possible_selections($room) -{ - $selections = array(); - - if(room_has_hd($room)) $selections[] = 'hd'; - if(room_has_sd($room)) $selections[] = 'sd'; - if(room_has_audio($room)) $selections[] = 'audio'; - if(room_has_music($room)) $selections[] = 'music'; - if(room_has_slides($room)) $selections[] = 'slides'; - - return $selections; -} - -function room_has_rtmp($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('rtmp-hd', 'rtmp-sd'), $formats)) > 0; -} - -function room_has_webm($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('webm-hd', 'webm-sd'), $formats)) > 0; -} - -function room_has_hls($room) -{ - $formats = get("ROOMS.$room.FORMATS"); - return count(array_intersect(array('hls-hd', 'hls-sd'), $formats)) > 0; -} - -function room_has_irc($room) -{ - return get("ROOMS.$room.IRC") && has("IRC"); -} - -function room_has_twitter($room) -{ - return get("ROOMS.$room.TWITTER") && has("TWITTER"); -} - -function room_has_chat($room) -{ - return room_has_irc($room) || room_has_twitter($room); -} - -function room_get_irc_url($room) -{ - $cfg = get("ROOMS.$room.IRC_CONFIG", get("IRC")); - return sprintf($cfg['URL'], rawurlencode($room)); -} - -function room_get_irc_display($room) -{ - $cfg = get("ROOMS.$room.IRC_CONFIG", get("IRC")); - return sprintf($cfg['DISPLAY'], $room); -} - -function room_get_twitter_hashtag($room) -{ - $cfg = get("ROOMS.$room.TWITTER_CONFIG", get("TWITTER")); - return sprintf($cfg['TEXT'], $room); -} - -function room_get_twitter_display($room) -{ - $cfg = get("ROOMS.$room.TWITTER_CONFIG", get("TWITTER")); - return sprintf($cfg['DISPLAY'], $room); -} - function startswith($needle, $haystack) { return substr($haystack, 0, strlen($needle)) == $needle; } - -function relive_talks() -{ - $talks = @file_get_contents(get('OVERVIEW.RELIVE_JSON')); - $talks = utf8_decode($talks); - $talks = (array)json_decode($talks, true); - - usort($talks, function($a, $b) { - $sort = array('live', 'recorded', 'released'); - return array_search($a['status'], $sort) > array_search($b['status'], $sort); - }); - - $talks_by_id = array(); - foreach ($talks as $value) - { - $talks_by_id[$value['id']] = $value; - } - - return $talks_by_id; -} diff --git a/lib/program.php b/lib/program.php deleted file mode 100644 index 79ce91d..0000000 --- a/lib/program.php +++ /dev/null @@ -1,168 +0,0 @@ -<?php - -function program() -{ - if(!has('SCHEDULE')) - return; - - if(has('SCHEDULE.CACHE') && function_exists('apc_fetch')) - { - $program = apc_fetch('SCHEDULE.CACHE'); - if($program) return $program; - } - - - $program = array(); - $opts = array( - 'http' => array( - 'timeout' => 2, - 'user_agent' => 'C3Voc Universal Streaming-Website Backend @ '.$_SERVER['HTTP_HOST'], - ) - ); - $context = stream_context_create($opts); - $schedule = file_get_contents(get('SCHEDULE.URL'), false, $context); - - // failed, give up - if(!$schedule) - return array(); - - $schedule = simplexml_load_string($schedule); - - // re-calculate day-ends - // some schedules have long gaps before the first talk or talks that expand beyond the dayend - // (fiffkon, i look at you) - // so to be on the safer side we calculate our own daystart/end here - foreach($schedule->day as $day) - { - $daystart = PHP_INT_MAX; - $dayend = 0; - - foreach($day->room as $room) - { - foreach($room->event as $event) - { - $start = strtotime((string)$event->date); - $duration = strtoduration((string)$event->duration); - $end = $start + $duration; - - $daystart = min($daystart, $start); - $dayend = max($dayend, $end); - } - } - - $day['start'] = $daystart; - $day['end'] = $dayend; - } - - $dayidx = 0; - foreach($schedule->day as $day) - { - $dayidx++; - $daystart = (int)$day['start']; - $dayend = (int)$day['end']; - - $roomidx = 0; - foreach($day->room as $room) - { - $roomidx++; - $lastend = false; - $name = (string)$room['name']; - if(isset($GLOBALS['CONFIG']['FAHRPLAN_ROOM_MAPPING'][$name])) - $name = $GLOBALS['CONFIG']['FAHRPLAN_ROOM_MAPPING'][$name]; - - foreach($room->event as $event) - { - $start = strtotime((string)$event->date); - $duration = strtoduration((string)$event->duration); - $end = $start + $duration; - - if($lastend && $lastend < $start) - { - // synthesize pause event - $pauseduration = $start - $lastend; - $program[$name][] = array( - 'special' => 'pause', - 'title' => round($pauseduration / 60).' minutes pause', - - 'fstart' => date('c', $lastend), - 'fend' => date('c', $start), - - 'start' => $lastend, - 'end' => $start, - 'duration' => $pauseduration, - ); - } - else if(!$lastend && $daystart < $start) - { - $program[$name][] = array( - 'special' => 'gap', - - 'fstart' => date('c', $daystart), - 'fend' => date('c', $start), - - 'start' => $daystart, - 'end' => $start, - 'duration' => $start - $daystart, - ); - } - - $personnames = array(); - foreach($event->persons->person as $person) - $personnames[] = (string)$person; - - $program[$name][] = array( - 'title' => (string)$event->title, - 'speaker' => implode(', ', $personnames), - - 'fstart' => date('c', $start), - 'fend' => date('c', $end), - - 'start' => $start, - 'end' => $end, - 'duration' => $duration, - ); - - $lastend = $end; - } - - // synthesize daychange event - if(!$lastend) $lastend = $daystart; - if($lastend < $dayend) - { - $program[$name][] = array( - 'special' => 'gap', - - 'fstart' => date('c', $lastend), - 'fend' => date('c', $dayend), - - 'start' => $lastend, - 'end' => $dayend, - 'duration' => $dayend - $lastend, - ); - } - - if($dayidx < count($schedule->day)) - { - $program[$name][] = array( - 'special' => 'daychange', - 'title' => 'Daychange from Day '.$dayidx.' to '.($dayidx+1), - - 'start' => $dayend, - 'end' => (int)$schedule->day[$dayidx]['start'], - 'duration' => 60*60, - ); - } - } - } - - if(has('SCHEDULE.CACHE') && function_exists('apc_store')) - { - apc_store( - 'SCHEDULE.CACHE', - $program, - get('SCHEDULE.CACHE') - ); - } - - return $program; -} |