aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php205
-rw-r--r--lib/Exceptions.php3
-rw-r--r--lib/helper.php10
-rw-r--r--model/Overview.php52
-rw-r--r--model/Room.php49
-rw-r--r--model/Stream.php5
-rw-r--r--model/StreamList.php28
-rw-r--r--template/overview.phtml67
-rw-r--r--view/overview.php2
9 files changed, 290 insertions, 131 deletions
diff --git a/index.php b/index.php
index 1802af4..80bf348 100644
--- a/index.php
+++ b/index.php
@@ -1,115 +1,132 @@
<?php
require_once('config.php');
+
require_once('lib/PhpTemplate.php');
+require_once('lib/Exceptions.php');
require_once('lib/helper.php');
+require_once('model/Overview.php');
+require_once('model/Room.php');
+
$route = @$_GET['route'];
$route = rtrim($route, '/');
-$GLOBALS['ROUTE'] = $route;
-$GLOBALS['tpl'] = new PhpTemplate('template/page.phtml');
-$GLOBALS['tpl']->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 @@
+<?php
+
+class NotFoundException extends Exception {}
diff --git a/lib/helper.php b/lib/helper.php
index d23eb35..640651b 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -2,16 +2,6 @@
require_once('program.php');
-function link_index()
-{
- return '';
-}
-
-function link_room($room)
-{
- return rawurlencode($room).'/';
-}
-
function link_player($room, $format = 'video', $translated = false)
{
$defaultformat = room_has_hd($room) ? 'hd' : 'sd';
diff --git a/model/Overview.php b/model/Overview.php
new file mode 100644
index 0000000..005233f
--- /dev/null
+++ b/model/Overview.php
@@ -0,0 +1,52 @@
+<?php
+
+require_once('model/Room.php');
+
+class Overview
+{
+ public function getGroups() {
+ $groups = array();
+
+ foreach(get('OVERVIEW.GROUPS') as $group => $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 @@
+<?php
+
+class Room {
+ private $slug;
+
+ public static function get($slug)
+ {
+ return new Room($slug);
+ }
+
+ private function __construct($slug)
+ {
+ if(! has('ROOMS.'.$slug))
+ throw new NotFoundException('Room '.$slug);
+
+ $this->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 @@
+<?php
+
+class Room {
+
+}
diff --git a/model/StreamList.php b/model/StreamList.php
new file mode 100644
index 0000000..4fd035e
--- /dev/null
+++ b/model/StreamList.php
@@ -0,0 +1,28 @@
+<?php
+
+class StreamList implements AggregateIterator {
+ private $streams = array();
+
+ public function getIterator() {
+ return new ArrayIterator($this->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 @@
</div>
</div>
- <? foreach(get('OVERVIEW.GROUPS') as $group => $rooms): ?>
+ <? foreach($overview->getGroups() as $group => $rooms): ?>
<div class="row room-group">
<div class="col-xs-12">
<h2><?=h($group)?></h2>
@@ -16,49 +16,60 @@
<? $count = count($rooms); ?>
<? foreach($rooms as $idx => $room): ?>
<div class="
- room room-<?=h($room)?> clearfix
+ room
+ room-<?=h($room->getSlug())?>
+ clearfix
<? /* when the count is odd and this is the last item - make it full width */ ?>
- <? if($count % 2 == 1 && $idx == $count - 1): ?>
- col-xs-12 wide
+ <? if( ($count % 2 == 1) && ($idx == $count - 1) ): ?>
+ wide
+ col-xs-12
<? else: ?>
- <? if(get("ROOMS.$room.PREVIEW") && get("ROOMS.$room.SCHEDULE") && has("SCHEDULE")): ?>
+ narrow
+ <? if($room->hasPreview() && $room->hasSchedule()): ?>
col-md-6
<? else: ?>
col-sm-6
<? endif ?>
- narrow
<? endif ?>
- <? if(get("ROOMS.$room.PREVIEW")): ?>
+ <? if($room->hasPreview()): ?>
has-preview
<? endif ?>
- <? if(get("ROOMS.$room.SCHEDULE") && has("SCHEDULE")): ?>
+ <? if($room->hasSchedule()): ?>
has-schedule
<? endif ?>
">
+
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
- <a href="<?=h(link_room($room))?>">
- <?=h(get("ROOMS.$room.DISPLAY"))?>
+ <a href="<?=h($room->getLink())?>">
+ <?=h($room->getDisplay())?>
</a>
</div>
</div>
<div class="panel-body">
- <? if(get("ROOMS.$room.PREVIEW")): ?>
- <a href="<?=h(link_room($room))?>">
- <img class="preview" src="thumbs/<?=h(get("ROOMS.$room.STREAM"))?>.png" alt="" width="213" height="120" />
+ <? if($room->hasPreview()): ?>
+
+ <a href="<?=h($room->getLink())?>">
+ <img
+ class="preview"
+ src="<?=h($room->getThumb())?>"
+ alt="<?=h($room->getDisplay())?>"
+ width="213" height="120"
+ />
</a>
+
<? endif ?>
- <a href="<?=h(link_room($room))?>" class="title">
- <?=h(get("ROOMS.$room.DISPLAY"))?>
+ <a href="<?=h($room->getLink())?>" class="title">
+ <?=h($room->getDisplay())?>
</a>
- <? if(get("ROOMS.$room.SCHEDULE") && has("SCHEDULE")): ?>
+ <? if($room->hasSchedule()): ?>
<div class="program-schedule">
<div class="talk current-talk">
<strong>Now:</strong>
@@ -78,18 +89,25 @@
</div>
<? endforeach ?>
- <? if(has('OVERVIEW.RELEASES') || has('OVERVIEW.RELIVE') || has('OVERVIEW.RELIVE_JSON')): ?>
- <? $class = has('OVERVIEW.RELEASES') && (has('OVERVIEW.RELIVE') || has('OVERVIEW.RELIVE_JSON')) ? 'col-sm-6 col-xs-12' : 'col-xs-12' ?>
+ <? if($overview->hasReleases() || $overview->hasRelive()): ?>
+ <?
+ $class = ($overview->hasReleases() && $overview->hasRelive()) ?
+ // both enabled
+ 'col-sm-6 col-xs-12' :
+
+ // only one of both enabled
+ 'col-xs-12';
+ ?>
<div class="row recordings">
<div class="col-xs-12">
<h2>Recordings</h2>
</div>
- <? if(has('OVERVIEW.RELEASES')): ?>
+ <? if($overview->hasReleases()): ?>
<div class="<?=h($class)?>">
<div class="panel panel-primary">
<div class="panel-body">
- <a href="<?=h(get('OVERVIEW.RELEASES'))?>">
+ <a href="<?=h($overview->getReleasesUrl())?>">
<span class="fa fa-video-camera"></span> Releases
</a>
</div>
@@ -97,16 +115,11 @@
</div>
<? endif ?>
- <? if(has('OVERVIEW.RELIVE') || has('OVERVIEW.RELIVE_JSON')): ?>
+ <? if($overview->hasRelive()): ?>
<div class="<?=h($class)?>">
<div class="panel panel-primary">
<div class="panel-body">
- <? if(has('OVERVIEW.RELIVE')): ?>
- <a href="<?=h(get('OVERVIEW.RELIVE'))?>">
- <? else: ?>
- <a href="relive/">
- <? endif ?>
-
+ <a href="<?=h($overview->getReliveUrl())?>">
<span class="fa fa-play-circle"></span> ReLive
</a>
</div>
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(),
));