diff options
Diffstat (limited to '')
-rw-r--r-- | model/Conference.php | 110 | ||||
-rw-r--r-- | model/Conferences.php | 73 | ||||
-rw-r--r-- | model/Feedback.php | 22 | ||||
-rw-r--r-- | model/GenericConference.php | 5 | ||||
-rw-r--r-- | model/ModelBase.php | 20 | ||||
-rw-r--r-- | model/Overview.php | 15 | ||||
-rw-r--r-- | model/Relive.php | 54 | ||||
-rw-r--r-- | model/Room.php | 85 | ||||
-rw-r--r-- | model/RoomSelection.php | 10 | ||||
-rw-r--r-- | model/RoomTab.php | 8 | ||||
-rw-r--r-- | model/Schedule.php | 58 | ||||
-rw-r--r-- | model/Subtitles.php | 21 |
12 files changed, 303 insertions, 178 deletions
diff --git a/model/Conference.php b/model/Conference.php index c6afa98..8d387a0 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -2,12 +2,24 @@ class Conference extends ModelBase { + private $slug; + + public function __construct($config, $slug) + { + parent::__construct($config); + $this->slug = $slug; + } + + public function getSlug() { + return $this->slug; + } + public function getTitle() { return $this->get('CONFERENCE.TITLE', 'C3VOC'); } public function isPreviewEnabled() { - if($GLOBALS['forceopen']) + if(@$GLOBALS['forceopen']) return true; if($this->has('PREVIEW_DOMAIN') && ($this->get('PREVIEW_DOMAIN') == $_SERVER['SERVER_NAME'])) @@ -20,6 +32,24 @@ class Conference extends ModelBase return !$this->hasBegun() || $this->hasEnded(); } + public function isOpen() { + return !$this->isClosed(); + } + + public function startsAt() { + if(!$this->has('CONFERENCE.STARTS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.STARTS_AT')); + } + + public function endsAt() { + if(!$this->has('CONFERENCE.ENDS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.ENDS_AT')); + } + public function hasBegun() { // on the preview-domain all conferences are always open if($this->isPreviewEnabled()) @@ -42,7 +72,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.STARTS_AT')) { - return time() >= $this->get('CONFERENCE.STARTS_AT'); + $now = new DateTime('now'); + return $now >= $this->startsAt(); } else { return true; } @@ -64,7 +95,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.ENDS_AT')) { - return time() >= $this->get('CONFERENCE.ENDS_AT'); + $now = new DateTime('now'); + return $now >= $this->endsAt(); } else { return false; } @@ -101,23 +133,37 @@ class Conference extends ModelBase } public function getLink() { - return url_params(); + return forceslash($this->getSlug()).url_params(); } public function getAboutLink() { - return 'about/'.url_params(); + return joinpath([$this->getSlug(), 'about']).url_params(); } public function hasRelive() { - return $this->has('CONFERENCE.RELIVE_JSON'); + return $this->getRelive()->isEnabled(); } public function getReliveUrl() { - if($this->has('CONFERENCE.RELIVE_JSON')) - return 'relive/'.url_params(); + if($this->getRelive()->isEnabled()) + return joinpath([$this->getSlug(), 'relive']).url_params(); else return null; } + public function hasFeedback() { + return $this->has('FEEDBACK'); + } + public function getFeedbackUrl() { + return joinpath([$this->getSlug(), 'feedback']).url_params(); + } + public function getFeedbackReadUrl() { + return joinpath([$this->getSlug(), 'feedback', 'read']).url_params(); + } + + public function getScheduleJsonUrl() { + return joinpath([$this->getSlug(), 'schedule.json']).url_params(); + } + public function hasBannerHtml() { return $this->has('CONFERENCE.BANNER_HTML'); } @@ -131,4 +177,52 @@ class Conference extends ModelBase public function getFooterHtml() { return $this->get('CONFERENCE.FOOTER_HTML'); } + + + public function getRooms() + { + $rooms = array(); + foreach($this->get('ROOMS') as $slug => $room) + $rooms[] = $this->getRoom($slug); + + return $rooms; + } + + public function getRoomIfExists($room) + { + if($this->hasRoom($room)) + return $this->getRoom($room); + + return null; + } + + public function hasRoom($slug) + { + return $this->has('ROOMS.'.$slug); + } + + public function getRoom($room) { + return new Room($this, $room); + } + + + public function getFeedback() { + return new Feedback($this); + } + public function getSchedule() { + return new Schedule($this); + } + public function getSubtitles() { + return new Subtitles($this); + } + public function getOverview() { + return new Overview($this); + } + public function getRelive() { + return new Relive($this); + } + + public function getExtraFiles() { + return $this->get('EXTRA_FILES', []); + } } diff --git a/model/Conferences.php b/model/Conferences.php index 461186f..f930e32 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -1,30 +1,41 @@ <?php -class Conferences extends ModelBase +class Conferences { const MANDATOR_DIR = 'configs/conferences/'; + public static function listConferences() { + $directories = scandir(forceslash(Conferences::MANDATOR_DIR)); + $conferences = array_filter($directories, function($dirname) { + return $dirname[0] != '.'; + }); + + return $conferences; + } + public static function getConferences() { $conferences = []; - foreach(scandir(forceslash(Conferences::MANDATOR_DIR)) as $el) + foreach(Conferences::listConferences() as $conference) { - if($el[0] == '.') - continue; - - $conferences[$el] = Conferences::getConferenceInformation($el); + try { + $conferences[$conference] = Conferences::getConference($conference); + } + catch(Exception $e) { + // ignore unloadable conferences + } } return $conferences; } public static function getConferencesCount() { - return count(Conferences::getConferences()); + return count(Conferences::listConferences()); } public static function getActiveConferences() { return array_values(array_filter( - Conferences::getConferences(), - function($info) { - return $info['active']; + Conferences::getConferencesSorted(), + function($conference) { + return !$conference->isClosed(); } )); } @@ -37,7 +48,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferences(); usort($sorted, function($a, $b) { - return @$b['CONFIG']['CONFERENCE']['STARTS_AT'] - @$a['CONFIG']['CONFERENCE']['STARTS_AT']; + return $b->startsAt() > $a->endsAt() ? 1 : -1; }); return $sorted; @@ -47,7 +58,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferencesSorted(); $finished = array_values(array_filter($sorted, function($c) { - return @$c['CONFIG']['CONFERENCE']['ENDS_AT'] < time(); + return $c->hasEnded(); })); return $finished; @@ -58,33 +69,22 @@ class Conferences extends ModelBase } public static function exists($mandator) { - return array_key_exists($mandator, Conferences::getConferences()); + return in_array($mandator, Conferences::listConferences()); } - public static function getConferenceInformation($mandator) { - if(isset($GLOBALS['CONFIG'])) - $saved_config = $GLOBALS['CONFIG']; - - Conferences::load($mandator); - $conf = new Conference(); - $info = [ - 'slug' => $mandator, - 'link' => forceslash($mandator).url_params(), - 'active' => !$conf->isClosed(), - 'title' => $conf->getTitle(), - 'description' => $conf->getDescription(), + public static function loadConferenceConfig($mandator) { + $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + $config = include($configfile); - 'relive' => $conf->hasRelive() ? forceslash($mandator).$conf->getReliveUrl() : null, - 'releases' => $conf->hasReleases() ? $conf->getReleasesUrl() : null, - - 'CONFIG' => $GLOBALS['CONFIG'], - ]; - unset($GLOBALS['CONFIG']); + if(!is_array($config)) { + throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); + } - if(isset($saved_config)) - $GLOBALS['CONFIG'] = $saved_config; + return $config; + } - return $info; + public static function getConference($mandator) { + return new Conference(Conferences::loadConferenceConfig($mandator), $mandator); } public static function hasCustomStyles($mandator) { @@ -96,9 +96,4 @@ class Conferences extends ModelBase public static function getCustomStylesDir($mandator) { return forceslash(Conferences::MANDATOR_DIR).forceslash($mandator); } - - public static function load($mandator) { - include(forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'); - return isset($GLOBALS['CONFIG']); - } } diff --git a/model/Feedback.php b/model/Feedback.php index 578650a..9475fe8 100644 --- a/model/Feedback.php +++ b/model/Feedback.php @@ -1,12 +1,16 @@ <?php -class Feedback extends ModelBase +class Feedback { - public function isEnabled() { - return $this->has('FEEDBACK'); + private $conference; + + public function __construct(Conference $conference) + { + $this->conference = $conference; } - public function getUrl() { - return 'feedback/'; + + public function getConference() { + return $this->conference; } public function validate($info) @@ -23,7 +27,7 @@ class Feedback extends ModelBase public function store($info) { - $db = new PDO($this->get('FEEDBACK.DSN')); + $db = new PDO($this->getConference()->get('FEEDBACK.DSN')); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stm = $db->prepare(' @@ -50,8 +54,8 @@ class Feedback extends ModelBase { return isset($_SERVER['PHP_AUTH_USER']) && - $_SERVER['PHP_AUTH_USER'] == $this->get('FEEDBACK.USERNAME') && - $_SERVER['PHP_AUTH_PW'] == $this->get('FEEDBACK.PASSWORD'); + $_SERVER['PHP_AUTH_USER'] == $this->getConference()->get('FEEDBACK.USERNAME') && + $_SERVER['PHP_AUTH_PW'] == $this->getConference()->get('FEEDBACK.PASSWORD'); } public function requestLogin() @@ -64,7 +68,7 @@ class Feedback extends ModelBase public function read($from, $to) { - $db = new PDO($this->get('FEEDBACK.DSN')); + $db = new PDO($this->getConference()->get('FEEDBACK.DSN')); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stm = $db->prepare(' diff --git a/model/GenericConference.php b/model/GenericConference.php index 5f134fc..63faf8f 100644 --- a/model/GenericConference.php +++ b/model/GenericConference.php @@ -2,6 +2,11 @@ class GenericConference extends Conference { + public function __construct() + { + $this->config = null; + } + public function hasBegun() { return true; } diff --git a/model/ModelBase.php b/model/ModelBase.php index 7b1370b..41f329b 100644 --- a/model/ModelBase.php +++ b/model/ModelBase.php @@ -2,14 +2,17 @@ class ModelBase { - protected function has($keychain) + protected $config; + public function __construct($config) { - return ModelBase::_has($GLOBALS['CONFIG'], $keychain); + $this->config = $config; } - protected static function staticHas($keychain) + + public function has($keychain) { - return ModelBase::_has($GLOBALS['CONFIG'], $keychain); + return ModelBase::_has($this->config, $keychain); } + private static function _has($array, $keychain) { if(!is_array($keychain)) @@ -25,14 +28,11 @@ class ModelBase return ModelBase::_has($array[$key], array_slice($keychain, 1)); } - protected function get($keychain, $default = null) + public function get($keychain, $default = null) { - return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default); - } - protected static function staticGet($keychain, $default = null) - { - return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default); + return ModelBase::_get($this->config, $keychain, $default); } + private static function _get($array, $keychain, $default) { if(!is_array($keychain)) diff --git a/model/Overview.php b/model/Overview.php index 03ef8b4..8a467bc 100644 --- a/model/Overview.php +++ b/model/Overview.php @@ -1,16 +1,25 @@ <?php -class Overview extends ModelBase +class Overview { + public function __construct(Conference $conference) + { + $this->conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function getGroups() { $groups = array(); - foreach($this->get('OVERVIEW.GROUPS') as $group => $rooms) + foreach($this->getConference()->get('OVERVIEW.GROUPS') as $group => $rooms) { foreach($rooms as $room) { try { - $groups[$group][] = new Room($room); + $groups[$group][] = $this->getConference()->getRoom($room); } catch(NotFoundException $e) { diff --git a/model/Relive.php b/model/Relive.php index d0e7522..542836d 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -1,21 +1,37 @@ <?php -class Relive extends ModelBase +class Relive { + private $conference; + + public function __construct($conference) + { + $this->conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { // having CONFERENCE.RELIVE is not enough! - return $this->has('CONFERENCE.RELIVE_JSON'); + return $this->getConference()->has('CONFERENCE.RELIVE_JSON'); } public function getJsonUrl() { - return $this->get('CONFERENCE.RELIVE_JSON'); + return $this->getConference()->get('CONFERENCE.RELIVE_JSON'); + } + + public function getJsonCache() + { + return sprintf('/tmp/relive-cache-%s.json', $this->getConference()->getSlug()); } public function getTalks() { - if(!file_exists($this->getJsonUrl())) + if(!file_exists($this->getJsonCache())) return array(); $talks = file_get_contents($this->getJsonUrl()); @@ -23,22 +39,22 @@ class Relive extends ModelBase $mapping = $this->getScheduleToRoomMapping(); - usort($talks, function($a, $b) { - // first, make sure that live talks are always on top - if($a['status'] == 'live' && $b['status'] != 'live') { - return -1; - } else if($a['status'] != 'live' && $b['status'] == 'live') { - return 1; - } else if($a['status'] == 'live' && $b['status'] == 'live') { - // sort live talks by room - - return strcmp($a['room'], $b['room']); - } - - // all other talks get sorted by their name + usort($talks, function($a, $b) { + // first, make sure that live talks are always on top + if($a['status'] == 'live' && $b['status'] != 'live') { + return -1; + } + else if($a['status'] != 'live' && $b['status'] == 'live') { + return 1; + } + else if($a['status'] == 'live' && $b['status'] == 'live') { + // sort live talks by room + return strcmp($a['room'], $b['room']); + } - return strcmp($a['title'], $b['title']); - }); + // all other talks get sorted by their name + return strcmp($a['title'], $b['title']); + }); $talks_by_id = array(); foreach ($talks as $talk) diff --git a/model/Room.php b/model/Room.php index 3baa0cf..9c9dadf 100644 --- a/model/Room.php +++ b/model/Room.php @@ -1,107 +1,92 @@ <?php -class Room extends ModelBase +class Room { private $slug; + private $conference; - public function __construct($slug) + public function __construct(Conference $conference, $slug) { + $this->conference = $conference; + if(preg_match('/[^a-z0-9_\-]/i', $slug)) throw new Exception('Room Slug contains invalid Characters: "'.$slug.'"'); - if(! $this->has('ROOMS.'.$slug)) + if(!$this->getConference()->hasRoom($slug)) throw new NotFoundException('Room '.$slug); $this->slug = $slug; } - public static function exists($slug) - { - return ModelBase::staticHas('ROOMS.'.$slug); - } - - public static function createIfExists($room) - { - if(Room::exists($room)) - return new Room($room); - - return null; - } - - public static function rooms() - { - $rooms = array(); - foreach(ModelBase::staticGet('ROOMS') as $slug => $room) - $rooms[] = new Room($slug); - return $rooms; + public function getConference() { + return $this->conference; } - public function getSlug() { return $this->slug; } public function getThumb() { - return '../thumbs/'.$this->getStream().'.png'; + return joinpath(['/', 'thumbs', $this->getStream().'.png']); } public function getLink() { - return rawurlencode($this->getSlug()).'/'.url_params(); + return joinpath([$this->getConference()->getSlug(), $this->getSlug()]).url_params(); } public function getStream() { - return $this->get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); } public function getScheduleName() { - return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getDisplay()); } public function getDisplay() { - return $this->get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); } public function hasStereo() { - return $this->get('ROOMS.'.$this->getSlug().'.STEREO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.STEREO'); } public function hasPreview() { - return $this->get('ROOMS.'.$this->getSlug().'.PREVIEW'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.PREVIEW'); } public function requestsWide() { - return $this->get('ROOMS.'.$this->getSlug().'.WIDE'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.WIDE'); } public function hasSchedule() { - return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->has('SCHEDULE'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->getConference()->has('SCHEDULE'); } public function hasSubtitles() { return - $this->get('ROOMS.'.$this->getSlug().'.SUBTITLES') && - $this->has('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID') && - $this->has('SUBTITLES'); + $this->getConference()->get('ROOMS.'.$this->getSlug().'.SUBTITLES') && + $this->getConference()->has('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID') && + $this->getConference()->has('SUBTITLES'); } public function getSubtitlesRoomId() { - return $this->get('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID'); } public function hasFeedback() { - return $this->get('ROOMS.'.$this->getSlug().'.FEEDBACK') && $this->has('FEEDBACK'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.FEEDBACK') && $this->getConference()->has('FEEDBACK'); } public function hasTwitter() { - return $this->get('ROOMS.'.$this->getSlug().'.TWITTER') && $this->has('TWITTER'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER') && $this->getConference()->has('TWITTER'); } public function getTwitterDisplay() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.DISPLAY', $this->get('TWITTER.DISPLAY')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.DISPLAY', $this->getConference()->get('TWITTER.DISPLAY')), $this->getSlug() ); } @@ -115,26 +100,26 @@ class Room extends ModelBase public function getTwitterText() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.TEXT', $this->get('TWITTER.TEXT')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.TEXT', $this->getConference()->get('TWITTER.TEXT')), $this->getSlug() ); } public function hasIrc() { - return $this->get('ROOMS.'.$this->getSlug().'.IRC') && $this->has('IRC'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC') && $this->getConference()->has('IRC'); } public function getIrcDisplay() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.DISPLAY', $this->get('IRC.DISPLAY')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.DISPLAY', $this->getConference()->get('IRC.DISPLAY')), $this->getSlug() ); } public function getIrcUrl() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.URL', $this->get('IRC.URL')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.URL', $this->getConference()->get('IRC.URL')), rawurlencode($this->getSlug()) ); } @@ -146,16 +131,16 @@ class Room extends ModelBase public function hasEmbed() { - return $this->get('ROOMS.'.$this->getSlug().'.EMBED') && $this->get('EMBED'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.EMBED') && $this->getConference()->get('EMBED'); } public function hasSdVideo() { - return $this->get('ROOMS.'.$this->getSlug().'.SD_VIDEO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SD_VIDEO'); } public function hasHdVideo() { - return $this->get('ROOMS.'.$this->getSlug().'.HD_VIDEO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.HD_VIDEO'); } public function hasVideo() { @@ -163,15 +148,15 @@ class Room extends ModelBase } public function hasAudio() { - return $this->get('ROOMS.'.$this->getSlug().'.AUDIO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.AUDIO'); } public function hasSlides() { - return $this->get('ROOMS.'.$this->getSlug().'.SLIDES'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SLIDES'); } public function hasMusic() { - return $this->get('ROOMS.'.$this->getSlug().'.MUSIC'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.MUSIC'); } public function hasDash() { @@ -179,7 +164,7 @@ class Room extends ModelBase } public function hasTranslation() { - return $this->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); } public function getSelectionNames() diff --git a/model/RoomSelection.php b/model/RoomSelection.php index 9f0b16d..9211c31 100644 --- a/model/RoomSelection.php +++ b/model/RoomSelection.php @@ -20,16 +20,18 @@ class RoomSelection public function getLink() { + $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; + $selection = $this->getRoom()->getSelectionNames(); - if($selection[0] == $this->getSelection()) - return rawurlencode($this->getRoom()->getSlug()).'/'; + if($selection[0] != $this->getSelection()) + $path[] = $this->getSelection(); - return rawurlencode($this->getRoom()->getSlug()).'/'.rawurlencode($this->getSelection()).'/'; + return joinpath($path).url_params(); } public function getTranslatedLink() { - return $this->getLink().'translated/'; + return joinpath([$this->getLink(), 'translated']); } public function getDisplay() diff --git a/model/RoomTab.php b/model/RoomTab.php index dfe6e84..b986602 100644 --- a/model/RoomTab.php +++ b/model/RoomTab.php @@ -20,11 +20,13 @@ class RoomTab public function getLink() { + $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; + $tabs = $this->getRoom()->getTabNames(); - if($tabs[0] == $this->getTab()) - return rawurlencode($this->getRoom()->getSlug()).'/'.url_params(); + if($tabs[0] != $this->getTab()) + $path[] = $this->getTab(); - return rawurlencode($this->getRoom()->getSlug()).'/'.rawurlencode($this->getTab()).'/'.url_params(); + return joinpath($path).url_params(); } public function getDisplay() diff --git a/model/Schedule.php b/model/Schedule.php index c0ff69b..b54709e 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -1,41 +1,45 @@ <?php -class Schedule extends ModelBase +class Schedule { + private $conference; + + public function __construct($conference) + { + $this->conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { - return $this->has('SCHEDULE'); + return $this->getConference()->has('SCHEDULE'); } private function isRoomFiltered($room) { - if(!$this->has('SCHEDULE.ROOMFILTER')) + if(!$this->getConference()->has('SCHEDULE.ROOMFILTER')) return false; - $rooms = $this->get('SCHEDULE.ROOMFILTER'); + $rooms = $this->getConference()->get('SCHEDULE.ROOMFILTER'); return !in_array($room, $rooms); } public function getSimulationOffset() { - return $this->get('SCHEDULE.SIMULATE_OFFSET', 0); + return $this->getConference()->get('SCHEDULE.SIMULATE_OFFSET', 0); } public function getScale() { - return floatval($this->get('SCHEDULE.SCALE', 7)); + return floatval($this->getConference()->get('SCHEDULE.SCALE', 7)); } private function fetchSchedule() { - $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($this->getScheduleUrl(), false, $context); + $schedule = file_get_contents($this->getScheduleCache()); if(!$schedule) - throw new ScheduleException("Error Downloading Schedule from ".$this->getScheduleUrl()); + throw new ScheduleException("Error Loading Schedule from ".$this->getScheduleCache()); return simplexml_load_string($schedule); } @@ -43,14 +47,7 @@ class Schedule extends ModelBase public function getSchedule() { // download schedule-xml - try - { - $schedule = $this->fetchSchedule(); - } - catch(Exception $e) - { - return array(); - } + $schedule = $this->fetchSchedule(); $mapping = $this->getScheduleToRoomSlugMapping(); $program = array(); @@ -220,10 +217,10 @@ class Schedule extends ModelBase } - if($this->has('SCHEDULE.ROOMFILTER')) + if($this->getConference()->has('SCHEDULE.ROOMFILTER')) { // sort by roomfilter - $roomfilter = $this->get('SCHEDULE.ROOMFILTER'); + $roomfilter = $this->getConference()->get('SCHEDULE.ROOMFILTER'); // map roomfilter-rooms to room-slugs $roomfilter = array_map(function($e) use ($mapping) { @@ -261,15 +258,20 @@ class Schedule extends ModelBase return ((int)$parts[0] * 60 + (int)$parts[1]) * 60; } - private function getScheduleUrl() + public function getScheduleUrl() + { + return $this->getConference()->get('SCHEDULE.URL'); + } + + public function getScheduleCache() { - return $this->get('SCHEDULE.URL'); + return sprintf('/tmp/schedule-cache-%s.xml', $this->getConference()->getSlug()); } public function getScheduleToRoomSlugMapping() { $mapping = array(); - foreach($this->get('ROOMS') as $slug => $room) + foreach($this->getConference()->get('ROOMS') as $slug => $room) { if(isset($room['SCHEDULE_NAME'])) $mapping[ $room['SCHEDULE_NAME'] ] = $slug; diff --git a/model/Subtitles.php b/model/Subtitles.php index e1878f2..1d401b8 100644 --- a/model/Subtitles.php +++ b/model/Subtitles.php @@ -1,14 +1,25 @@ <?php -class Subtitles extends ModelBase +class Subtitles { + private $conference; + + public function __construct(Conference $conference) + { + $this->conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { - return $this->has('SUBTITLES'); + return $this->getConference()->has('SUBTITLES'); } public function getEnabledRooms($slug) { $rooms = []; - foreach(Room::rooms() as $room) + foreach($this->getConference()->getOverview()->getRooms() as $room) { if($room->hasSubtitles()) $rooms[] = $room; @@ -18,9 +29,9 @@ class Subtitles extends ModelBase } public function getPrimusURL() { - return $this->get('SUBTITLES.PRIMUS_URL'); + return $this->getConference()->get('SUBTITLES.PRIMUS_URL'); } public function getFrontendURL() { - return $this->get('SUBTITLES.FRONTEND_URL'); + return $this->getConference()->get('SUBTITLES.FRONTEND_URL'); } } |