aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaZderMind2015-03-31 23:17:01 +0200
committerMaZderMind2015-03-31 23:17:01 +0200
commit024d632396def58c335944cae24371a10a3306b9 (patch)
tree579b4cdf2b4bb00a4329e186e19d2b2f9b1e519d
parent5b3788456f9e5b290eb2148af50b3f0a981a8923 (diff)
Implement Relive based on the MVT Pattern
Diffstat (limited to '')
-rw-r--r--config.php7
-rw-r--r--index.php7
-rw-r--r--model/Relive.php66
-rw-r--r--template/relive.phtml5
-rw-r--r--view/relive-player.php8
-rw-r--r--view/relive.php6
6 files changed, 80 insertions, 19 deletions
diff --git a/config.php b/config.php
index af427d7..7acfe4d 100644
--- a/config.php
+++ b/config.php
@@ -82,6 +82,13 @@ $GLOBALS['CONFIG']['CONFERENCE'] = array(
* Wird beides auskommentiert, wird der Link nicht angezeigt
*/
'RELIVE_JSON' => 'http://vod.c3voc.de/index.json',
+
+ /**
+ * APCU-Cache-Zeit in Sekunden
+ * Wird diese Zeile auskommentiert, werden die apc_*-Methoden nicht verwendet und
+ * das Relive-Json bei jedem Request von der Quelle geladen und geparst
+ */
+ 'RELIVE_JSON_CACHE' => 30*60,
);
/**
diff --git a/index.php b/index.php
index 5292f82..0e5117f 100644
--- a/index.php
+++ b/index.php
@@ -15,6 +15,7 @@ require_once('model/Room.php');
require_once('model/RoomTab.php');
require_once('model/RoomSelection.php');
require_once('model/Stream.php');
+require_once('model/Relive.php');
$route = @$_GET['route'];
$route = rtrim($route, '/');
@@ -61,9 +62,6 @@ try {
else if(preg_match('@^relive/([0-9]+)$@', $route, $m))
{
- if(!has('OVERVIEW.RELIVE_JSON'))
- return require('view/404.php');
-
$_GET = array(
'id' => $m[1],
);
@@ -72,9 +70,6 @@ try {
else if(preg_match('@^relive$@', $route, $m))
{
- if(!has('OVERVIEW.RELIVE_JSON'))
- return require('view/404.php');
-
require('view/relive.php');
}
diff --git a/model/Relive.php b/model/Relive.php
index 3ffdc1b..a76761c 100644
--- a/model/Relive.php
+++ b/model/Relive.php
@@ -2,9 +2,18 @@
class Relive extends ModelBase
{
- function relive_talks()
+ public function isEnabled()
{
- $talks = @file_get_contents(get('OVERVIEW.RELIVE_JSON'));
+ // having CONFERENCE.RELIVE is not enough!
+ return $this->has('CONFERENCE.RELIVE_JSON');
+ }
+
+ public function getTalks()
+ {
+ if($talks_by_id = $this->getCached())
+ return $talks_by_id;
+
+ $talks = file_get_contents($this->get('CONFERENCE.RELIVE_JSON'));
$talks = utf8_decode($talks);
$talks = (array)json_decode($talks, true);
@@ -14,11 +23,58 @@ class Relive extends ModelBase
});
$talks_by_id = array();
- foreach ($talks as $value)
+ foreach ($talks as $talk)
{
- $talks_by_id[$value['id']] = $value;
+ if($talk['status'] == 'released')
+ $talk['url'] = $talk['release_url'];
+ else
+ $talk['url'] = 'relive/'.rawurlencode($talk['id']).'/';
+
+ $talks_by_id[$talk['id']] = $talk;
}
- return $talks_by_id;
+ return $this->doCache($talks_by_id);
+ }
+
+ public function getTalk($id)
+ {
+ $talks = $this->getTalks();
+ if(!isset($talks[$id]))
+ throw new NotFoundException('Relive-Talk id '.$id);
+
+ return $talks[$id];
+ }
+
+ private function isCacheEnabled()
+ {
+ return $this->has('CONFERENCE.RELIVE_JSON_CACHE') && function_exists('apc_fetch') && function_exists('apc_store');
+ }
+
+ private function getCacheDuration()
+ {
+ return $this->get('CONFERENCE.RELIVE_JSON_CACHE', 60*10 /* 10 minutes */);
+ }
+
+ private $localCache = null;
+ private function getCached()
+ {
+ if($this->localCache)
+ return $this->localCache;
+
+ if(!$this->isCacheEnabled())
+ return null;
+
+ return apc_fetch('RELIVE.CACHE');
+ }
+
+ private function doCache($value)
+ {
+ $this->localCache = $value;
+
+ if(!$this->isCacheEnabled())
+ return $value;
+
+ apc_store('RELIVE.CACHE', $value, $this->getCacheDuration());
+ return $value;
}
}
diff --git a/template/relive.phtml b/template/relive.phtml
index b26dd20..94e4acf 100644
--- a/template/relive.phtml
+++ b/template/relive.phtml
@@ -21,20 +21,19 @@
</div>
<? else: ?>
<? foreach ($talks as $talk): ?>
- <? $url = ($talk['status'] == 'released') ? $talk['release_url'] : link_vod($talk['id']) ?>
<div class="col-xs-12 recording">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
- <a href="<?=h($url)?>">
+ <a href="<?=h($talk['url'])?>">
<?=h($talk['title'])?>
</a>
</h3>
</div>
<div class="panel-body">
- <a href="<?=h($url)?>">
+ <a href="<?=h($talk['url'])?>">
<img class="preview" alt="<?=h($talk['title'])?>" class="video-thumbnail" src="<?=h($talk['thumbnail'])?>" width="213" height="120" />
</a>
diff --git a/view/relive-player.php b/view/relive-player.php
index bc8bb57..587286b 100644
--- a/view/relive-player.php
+++ b/view/relive-player.php
@@ -1,10 +1,10 @@
<?php
-$talks_by_id = relive_talks();
-$talk = @$talks_by_id[intval($_GET['id'])];
+$relive = new Relive();
+if(!$relive->isEnabled())
+ throw new NotFoundException('Internal Relive is disabled');
-if(!$talk)
- return require('page/404.php');
+$talk = $relive->getTalk(intval($_GET['id']));
echo $tpl->render(array(
'page' => 'relive-player',
diff --git a/view/relive.php b/view/relive.php
index 0608423..686d61e 100644
--- a/view/relive.php
+++ b/view/relive.php
@@ -1,7 +1,11 @@
<?php
+$relive = new Relive();
+if(!$relive->isEnabled())
+ throw new NotFoundException('Internal Relive is disabled');
+
echo $tpl->render(array(
'page' => 'relive',
'title' => 'Relive!',
- 'talks' => relive_talks(),
+ 'talks' => $relive->getTalks(),
));