Add dynamic code for youtube code and a automatic reloader
authorymh <ymh.work@gmail.com>
Thu, 20 Sep 2018 15:10:28 +0200
changeset 1439 df4c992749ea
parent 1438 34d6ae9d2541
child 1440 4a97b38b8b80
Add dynamic code for youtube code and a automatic reloader
web/client.php
web/marathon-serpentine-2018/config.php
web/marathon-serpentine-2018/reloader.php
--- a/web/client.php	Thu Sep 20 13:23:31 2018 +0200
+++ b/web/client.php	Thu Sep 20 15:10:28 2018 +0200
@@ -46,7 +46,9 @@
 }
 
 $embed = (isset($_REQUEST['embed']) && $_REQUEST['embed']);
-$embed_video = isset($_REQUEST['embed_video']) ? boolval($_REQUEST['embed_video']) : true;
+$embed_video = isset($_REQUEST['embed_video']) ? 
+    boolval($_REQUEST['embed_video']) :
+    (isset($config['islive_embed']) && $config['islive_embed']) || (isset($config['islive']) && $config['islive']);
 $videoWidth = ( $embed ? 412 : 480 );
 $videoHeight = ( $embed ? 280 : 320 );
 if ($embed && !isset($_SESSION['TWITTER_ACCESS_TOKEN']) && (isset($_REQUEST['auth_redirect']) || isset($_SERVER['HTTP_REFERER']))) {
@@ -94,6 +96,11 @@
     <script type="text/javascript" src="<?php echo(registry_url('underscore','js'))?>"></script>
     <script type="text/javascript" src="<?php echo(registry_url('raphael','js'))?>"></script>
     <script type="text/javascript" src="<?php echo(registry_url('fancybox','js'))?>"></script>
+    <?php if( isset($config['additional_js']) && !empty($config['additional_js'])) { 
+        foreach ($config['additional_js'] as $jsUrl) {?>
+    <script type="text/javascript" src="<?php echo($jsUrl)?>"></script>
+        <?php }
+    } ?>
 
     <style>
     video {
@@ -344,7 +351,7 @@
 <?php
     if (isset($config['islive']) && $config['islive']) {
         $videofile = $translate->_('config__video_file');
-        if ($videofile == 'config__video_file') $videofile = "https://media.iri.centrepompidou.fr/dash/livestream.mpd";
+        if ($videofile === 'config__video_file') $videofile = "https://media.iri.centrepompidou.fr/dash/livestream.mpd";
 ?>
 
                     <script type="text/javascript" src="<?php echo(registry_url('dashjs','js'))?>"></script>
--- a/web/marathon-serpentine-2018/config.php	Thu Sep 20 13:23:31 2018 +0200
+++ b/web/marathon-serpentine-2018/config.php	Thu Sep 20 15:10:28 2018 +0200
@@ -1,4 +1,28 @@
 <?php
+
+$youtube_code_list = [
+    // [new DateTime('2018-09-20T12:43:00Z'),new DateTime('2018-09-20T13:10:00Z'), 'eqB0gIALuUs'],
+    [new DateTime('2018-09-22T08:30:00Z'),new DateTime('2018-09-22T12:15:00Z'), 'eqB0gIALuUs'],
+    // [new DateTime('2018-09-22T12:15:00Z'),new DateTime('2018-09-22T20:30:00Z'), ''],
+    [new DateTime('2018-09-23T07:30:00Z'),new DateTime('2018-09-23T16:00:00Z'), 'iHygIOIkZ0A'],
+];
+
+$youtube_code = null;
+$current_time = new DateTime();
+
+foreach ($youtube_code_list as $time_entry) {
+    if($current_time >= $time_entry[0] &&  $current_time <= $time_entry[1]) {
+        $youtube_code = $time_entry[2];
+        break;
+    }
+}
+$islive_embed = null;
+if(!is_null($youtube_code)) {
+    $islive_embed = "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/${youtube_code}?autoplay=1\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" modestbranding=1 allowfullscreen></iframe>";
+}
+
+
+
 $config = array(
     'rep' => basename(__DIR__),
     'title' => "Work Marathon 2018",
@@ -107,7 +131,7 @@
 *Denotes pre-recorded and video
 contribution<br/></br>
 
-<b><small>September 23</small> - 10AM - 4PM<br/>
+<b><small>September 23</small> - 9AM - 4PM<br/>
 WRITING WORKSHOP<br/>
 DRAFT FOR A NEGANTHROPOCENE MANIFESTO</b>
 <br/><br/>
@@ -123,9 +147,8 @@
 
     'link' 		 => '',
     'islive'     => false,
-    // 'islive_embed' => '<iframe width="560" height="315" src="https://www.youtube.com/embed/RtU_mdL2vBM" frameborder="0" allow="autoplay; encrypted-media" modestbranding=1 allowfullscreen></iframe>',
+    'islive_embed' => $islive_embed,
     'keywords'   => 'Work Marathon, Neganthropocene, Neganthropy, Samrt Cities, Economy of Contribution, Contributive research, Internation, Building Information Modeling, Disruption',
-    'annotation_protocol_version' => "2",
 
     'partenaires'=> "<a href='http://www.serpentinegalleries.org/'
 class='footerLink' target='_blank'> Serpentine Galleries </a><a href='http://www.iri.centrepompidou.fr/' class='footerLink' target='_blank'> IRI </a>",
@@ -141,6 +164,7 @@
     'archive_title' => "Work Marathon 2018",
     'archive_description' => "from <a href=\"http://www.iri.centrepompidou.fr/\" target=\"_blank\">IRI</a> at Serpentine Galleries and Goethe-Institut<br/> September 22nd | 10am - 10pm and September 23rd | 9am - 4pm",
     'annotation_protocol_version' => '3',
+    'additional_js' => ['reloader.php',],
 
     // After the event
     // 'metadata'		=> "fc62350e-69d9-11e1-9089-00145ea4a2be",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/marathon-serpentine-2018/reloader.php	Thu Sep 20 15:10:28 2018 +0200
@@ -0,0 +1,28 @@
+<?php
+include_once('./config.php');
+header("Content-type: application/x-javascript");
+?>
+var startYoutubeCode = "<?php echo($youtube_code ? $youtube_code : '') ?>";
+
+function getCurrentYoutubeCode() {
+    var resCode = null;
+    var youtubeCodeList = [
+    <?php foreach ($youtube_code_list as $time_entry): ?>
+        [<?php echo($time_entry[0]->getTimestamp() * 1000); ?>, <?php echo($time_entry[1]->getTimestamp() * 1000); ?>, "<?php echo($time_entry[2]);?>"]
+    <?php endforeach; ?>
+    ];
+    var currentTime = Date.now();
+    youtubeCodeList.some(function(timeEntry) {
+        if(currentTime >= timeEntry[0] && currentTime <= timeEntry[1]) {
+            resCode = timeEntry[2];
+            return true;
+        }
+    });
+    return resCode ? resCode : '';
+}
+
+setInterval(function() {
+    if(getCurrentYoutubeCode() !== startYoutubeCode) {
+        window.location.reload(true);
+    }
+}, 5000);