From cb48ba9b7068302414b18435505a041d22bd9e4b Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 8 Mar 2015 13:42:58 +0100 Subject: Introduce Models abstracting the Config away from Views & Templates --- index.php | 205 ++++++++++++++++++++++++++---------------------- lib/Exceptions.php | 3 + lib/helper.php | 10 --- model/Overview.php | 52 ++++++++++++ model/Room.php | 49 ++++++++++++ model/Stream.php | 5 ++ model/StreamList.php | 28 +++++++ template/overview.phtml | 67 +++++++++------- view/overview.php | 2 + 9 files changed, 290 insertions(+), 131 deletions(-) create mode 100644 lib/Exceptions.php create mode 100644 model/Overview.php create mode 100644 model/Room.php create mode 100644 model/Stream.php create mode 100644 model/StreamList.php diff --git a/index.php b/index.php index 1802af4..80bf348 100644 --- a/index.php +++ b/index.php @@ -1,115 +1,132 @@ set(array( +$tpl = new PhpTemplate('template/page.phtml'); +$tpl->set(array( 'baseurl' => baseurl(), 'assemblies' => './template/assemblies/', )); -if($route == '') -{ - include('view/overview.php'); -} - -else if(preg_match('@^about$@', $route, $m)) -{ - include('view/about.php'); -} - -else if(preg_match('@^program.json$@', $route, $m)) -{ - if(!has('SCHEDULE')) - return include('view/404.php'); - - include('view/program-json.php'); -} - -else if(preg_match('@^feedback$@', $route, $m)) -{ - if(!has('FEEDBACK')) - return include('view/404.php'); - - include('view/feedback.php'); -} - -else if(preg_match('@^feedback/read$@', $route, $m)) -{ - if(!has('FEEDBACK')) - return include('view/404.php'); - - include('view/feedback-read.php'); -} - -else if(preg_match('@^relive/([0-9]+)$@', $route, $m)) -{ - if(!has('OVERVIEW.RELIVE_JSON')) - return include('view/404.php'); - - $_GET = array( - 'id' => $m[1], - ); - include('view/relive-player.php'); -} - -else if(preg_match('@^relive$@', $route, $m)) -{ - if(!has('OVERVIEW.RELIVE_JSON')) - return include('view/404.php'); +try { + + if($route == '') + { + include('view/overview.php'); + } + + else if(preg_match('@^about$@', $route, $m)) + { + include('view/about.php'); + } + + else if(preg_match('@^program.json$@', $route, $m)) + { + if(!has('SCHEDULE')) + return include('view/404.php'); + + include('view/program-json.php'); + } + + else if(preg_match('@^feedback$@', $route, $m)) + { + if(!has('FEEDBACK')) + return include('view/404.php'); + + include('view/feedback.php'); + } + + else if(preg_match('@^feedback/read$@', $route, $m)) + { + if(!has('FEEDBACK')) + return include('view/404.php'); + + include('view/feedback-read.php'); + } + + else if(preg_match('@^relive/([0-9]+)$@', $route, $m)) + { + if(!has('OVERVIEW.RELIVE_JSON')) + return include('view/404.php'); + + $_GET = array( + 'id' => $m[1], + ); + include('view/relive-player.php'); + } + + else if(preg_match('@^relive$@', $route, $m)) + { + if(!has('OVERVIEW.RELIVE_JSON')) + return include('view/404.php'); + + include('view/relive.php'); + } + + else if(preg_match('@^([^/]+)$@', $route, $m)) + { + $_GET = array( + 'room' => $m[1], + 'selection' => '', + 'language' => 'native', + ); + include('view/room.php'); + } + + else if(preg_match('@^([^/]+)/translated$@', $route, $m)) + { + $_GET = array( + 'room' => $m[1], + 'selection' => '', + 'language' => 'translated', + ); + include('view/room.php'); + } + + else if(preg_match('@^([^/]+)/(sd|audio|slides)$@', $route, $m)) + { + $_GET = array( + 'room' => $m[1], + 'selection' => $m[2], + 'language' => 'native', + ); + include('view/room.php'); + } + + else if(preg_match('@^([^/]+)/(sd|audio|slides)/translated$@', $route, $m)) + { + $_GET = array( + 'room' => $m[1], + 'selection' => $m[2], + 'language' => 'translated', + ); + include('view/room.php'); + } + + else + { + throw new NotFoundException(); + } - include('view/relive.php'); } - -else if(preg_match('@^([^/]+)$@', $route, $m)) -{ - $_GET = array( - 'room' => $m[1], - 'selection' => '', - 'language' => 'native', - ); - include('view/room.php'); -} - -else if(preg_match('@^([^/]+)/translated$@', $route, $m)) +catch(NotFoundException $e) { - $_GET = array( - 'room' => $m[1], - 'selection' => '', - 'language' => 'translated', - ); - include('view/room.php'); -} - -else if(preg_match('@^([^/]+)/(sd|audio|slides)$@', $route, $m)) -{ - $_GET = array( - 'room' => $m[1], - 'selection' => $m[2], - 'language' => 'native', - ); - include('view/room.php'); -} - -else if(preg_match('@^([^/]+)/(sd|audio|slides)/translated$@', $route, $m)) -{ - $_GET = array( - 'room' => $m[1], - 'selection' => $m[2], - 'language' => 'translated', - ); - include('view/room.php'); + include('view/404.php'); } - -else +catch(Exception $e) { - include('view/404.php'); + header("HTTP/1.1 500 Internal Server Error"); + die($e); } diff --git a/lib/Exceptions.php b/lib/Exceptions.php new file mode 100644 index 0000000..d5a4600 --- /dev/null +++ b/lib/Exceptions.php @@ -0,0 +1,3 @@ + $rooms) + { + foreach($rooms as $room) + { + try { + $groups[$group][] = Room::get($room); + } + catch(NotFountException $e) + { + // just ignore unknown rooms + continue; + } + } + } + + return $groups; + } + + public function getReleasesUrl() { + return get('OVERVIEW.RELEASES'); + } + + public function getReliveUrl() { + if(has('OVERVIEW.RELIVE')) + return get('OVERVIEW.RELIVE'); + + elseif(has('OVERVIEW.RELIVE_JSON')) + return 'relive/'; + + else + return null; + } + + + + public function hasRelive() { + return has('OVERVIEW.RELIVE') || has('OVERVIEW.RELIVE_JSON'); + } + + public function hasReleases() { + return has('OVERVIEW.RELEASES'); + } +} diff --git a/model/Room.php b/model/Room.php new file mode 100644 index 0000000..7394870 --- /dev/null +++ b/model/Room.php @@ -0,0 +1,49 @@ +slug = $slug; + } + + + public function getSlug() { + return $this->slug; + } + + public function getThumb() { + return 'thumbs/'.$this->getStream().'.png'; + } + + public function getLink() { + return rawurlencode($this->getSlug()).'/'; + } + + public function getStream() { + return get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); + } + + public function getDisplay() { + return get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); + } + + + + public function hasPreview() { + return get('ROOMS.'.$this->getSlug().'.PREVIEW'); + } + + public function hasSchedule() { + return get('ROOMS.'.$this->getSlug().'.SCHEDULE') && has('SCHEDULE'); + } +} diff --git a/model/Stream.php b/model/Stream.php new file mode 100644 index 0000000..a60284a --- /dev/null +++ b/model/Stream.php @@ -0,0 +1,5 @@ +streams); + } + + + public function hasTranslation() { + } + + public function hasRTMP() { + } + + public function hasHLS() { + } + + public function hasWebM() { + } + + public function hasHD() { + } + + public function hasSD() { + } +} diff --git a/template/overview.phtml b/template/overview.phtml index 37fb154..7916cdb 100644 --- a/template/overview.phtml +++ b/template/overview.phtml @@ -7,7 +7,7 @@ - $rooms): ?> + getGroups() as $group => $rooms): ?>

@@ -16,49 +16,60 @@ $room): ?>
+ narrow + hasPreview() && $room->hasSchedule()): ?> col-md-6 col-sm-6 - narrow - + hasPreview()): ?> has-preview - + hasSchedule()): ?> has-schedule "> +
- - - .png" alt="" width="213" height="120" /> + hasPreview()): ?> + + + <?=h($room->getDisplay())?> + - - + + getDisplay())?> - + hasSchedule()): ?>
Now: @@ -78,18 +89,25 @@
- - + hasReleases() || $overview->hasRelive()): ?> + hasReleases() && $overview->hasRelive()) ? + // both enabled + 'col-sm-6 col-xs-12' : + + // only one of both enabled + 'col-xs-12'; + ?>

Recordings

- + hasReleases()): ?>
@@ -97,16 +115,11 @@
- + hasRelive()): ?>
diff --git a/view/overview.php b/view/overview.php index 6305940..3b52e8f 100644 --- a/view/overview.php +++ b/view/overview.php @@ -3,4 +3,6 @@ echo $tpl->render(array( 'page' => 'overview', 'title' => 'Live-Streams', + + 'overview' => new Overview(), )); -- cgit v1.2.3