From f6c0270d40f6730fe1e1820f2866b08792df1db6 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:22:34 +0100 Subject: rewrite data-model so that every configuration option is accessed through the conference --- index.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 9a5e304..19a174a 100644 --- a/index.php +++ b/index.php @@ -59,7 +59,8 @@ try { 'route' => $route, 'canonicalurl' => forceslash(baseurl()).forceslash($route), 'assemblies' => 'template/assemblies/', - 'assets' => 'assets/', + 'assets' => forceslash('assets'), + 'conference_assets' => '/', 'conference' => new GenericConference(), )); @@ -113,7 +114,7 @@ try { // redirect $clients = Conferences::getActiveConferences(); - header('Location: '.forceslash( baseurl() . $clients[0]['link'] )); + header('Location: '.joinpath([baseurl(), $clients[0]->getSlug()])); exit; } else @@ -132,8 +133,9 @@ try { require('view/404.php'); exit; } - - Conferences::load($mandator); + else { + // fallthrough through to the main mandator-based routes + } } catch(Exception $e) { @@ -144,20 +146,19 @@ catch(Exception $e) // PER-CONFERENCE CODE -$GLOBALS['MANDATOR'] = $mandator; -$conference = new Conference(); +$conference = Conferences::getConference($mandator); // update template information $tpl->set(array( 'baseurl' => forceslash(baseurl()), 'route' => $route, - 'canonicalurl' => forceslash(baseurl()).forceslash($route), - 'assets' => '../assets/', + 'canonicalurl' => joinpath([baseurl(), $mandator, $route]), + 'conference_assets' => forceslash($mandator), 'conference' => $conference, - 'feedback' => new Feedback(), - 'schedule' => new Schedule(), - 'subtitles' => new Subtitles(), + 'feedback' => $conference->getFeedback(), + 'schedule' => $conference->getSchedule(), + 'subtitles' => $conference->getSubtitles(), )); ob_start(); -- cgit v1.3.1 From d0a891dcc4f261300616883aab384bd93f9f487c Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:23:22 +0100 Subject: aways print a stack-trace --- index.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'index.php') diff --git a/index.php b/index.php index 19a174a..b27055e 100644 --- a/index.php +++ b/index.php @@ -140,7 +140,16 @@ try { catch(Exception $e) { ob_clean(); - require('view/500.php'); + try { + require('view/500.php'); + exit; + } + catch(Exception $e) { + header("HTTP/1.1 500 Internal Server Error"); + header("Content-Type: text/plain"); + print_r($e); + exit; + } } -- cgit v1.3.1 From 3de0b86d9c3c82428ed7d1f0e04cec9fa2d0d758 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:23:45 +0100 Subject: alwas allow access to the conference about-page --- index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index b27055e..414dede 100644 --- a/index.php +++ b/index.php @@ -214,6 +214,11 @@ try { require('view/multiview.php'); } + else if($route == 'about') + { + require('view/about.php'); + } + // HAS-NOT-BEGUN VIEW else if(!$conference->hasBegun()) { @@ -247,11 +252,6 @@ try { require('view/overview.php'); } - else if($route == 'about') - { - require('view/about.php'); - } - else if($route == 'feedback') { require('view/feedback.php'); -- cgit v1.3.1 From 738878b8b060b3cfcdde2d88a1a28d5ce83e4aa7 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 20:01:33 +0100 Subject: better handling for legacy config errors --- index.php | 30 ++++++++++++++---------------- lib/Exceptions.php | 1 + model/Conferences.php | 10 ++++++++-- 3 files changed, 23 insertions(+), 18 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 414dede..ef3944c 100644 --- a/index.php +++ b/index.php @@ -153,25 +153,23 @@ catch(Exception $e) } - // PER-CONFERENCE CODE -$conference = Conferences::getConference($mandator); - -// update template information -$tpl->set(array( - 'baseurl' => forceslash(baseurl()), - 'route' => $route, - 'canonicalurl' => joinpath([baseurl(), $mandator, $route]), - 'conference_assets' => forceslash($mandator), - - 'conference' => $conference, - 'feedback' => $conference->getFeedback(), - 'schedule' => $conference->getSchedule(), - 'subtitles' => $conference->getSubtitles(), -)); - ob_start(); try { + $conference = Conferences::getConference($mandator); + + // update template information + $tpl->set(array( + 'baseurl' => forceslash(baseurl()), + 'route' => $route, + 'canonicalurl' => joinpath([baseurl(), $mandator, $route]), + 'conference_assets' => forceslash($mandator), + + 'conference' => $conference, + 'feedback' => $conference->getFeedback(), + 'schedule' => $conference->getSchedule(), + 'subtitles' => $conference->getSubtitles(), + )); // ALWAYS AVAILABLE ROUTES if($route == 'feedback/read') diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 2e9109b..83bd380 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -10,3 +10,4 @@ set_error_handler("exception_error_handler"); class NotFoundException extends Exception {} class ScheduleException extends Exception {} +class ConfigException extends Exception {} diff --git a/model/Conferences.php b/model/Conferences.php index 77069ad..2dc9f35 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -73,8 +73,14 @@ class Conferences } public static function loadConferenceConfig($mandator) { - $config = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; - return include($config); + $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + $config = include($configfile); + + if(!is_array($config)) { + throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); + } + + return $config; } public static function getConference($mandator) { -- cgit v1.3.1 From 895b7fa70883b60ad7ee15fefed6f908020310b9 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 19:55:39 +0100 Subject: add linebreak to error message --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'index.php') diff --git a/index.php b/index.php index ef3944c..6c62e34 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ getSlug()); + + if(isset($conf['MAX_CONFERENCE_AGE'])) + { + date_diff() + return time() >= $this->endsAt(); + } + +} diff --git a/config.php b/config.php index 1dbea27..57be966 100644 --- a/config.php +++ b/config.php @@ -24,7 +24,7 @@ $GLOBALS['CONFIG']['PREVIEW_DOMAIN'] = 'xlocalhost'; * Protokollfreie URLs (welche, die mit // beginnen), werden automatisch mit dem korrekten Protokoll ergänzt. * In diesem Fall wird auch ein SSL-Umschalt-Button im Header angezeigt */ -if($_SERVER['SERVER_NAME'] == 'localhost') +if(@$_SERVER['SERVER_NAME'] == 'localhost') { // keine Konfiguration -> BASEURL wird automatisch erraten } @@ -38,3 +38,28 @@ else // Set a safe Default $GLOBALS['CONFIG']['BASEURL'] = '//streaming.media.ccc.de/'; } + + +/** + * Konfiguration für den Datei-Download Cronjob + */ +$GLOBALS['CONFIG']['DOWNLOAD'] = [ + /** + * Verweigeren Download, wenn der PHP-Prozess unter einem anderen Benutzer als diesem läuft + * Auskommentieren um alle Benutzer zu erlauben + */ + //'REQUIRE_USER' => 'www-data', + + /** + * Wartende HTTP-Downloads nach dieser Anzahl von Sekunden abbrechen + */ + 'HTTP_TIMEOUT' => 5 /* Sekunden */, + + /** + * Nur Dateien von Konferenzen herunterladen, die weniger als + * diese Aanzahl von Tagen alt sind (gemessen am END_DATE) + * + * Auskommentieren, um alle Konferenzen zu beachten + */ + 'MAX_CONFERENCE_AGE' => 30 /* Tage */, +]; diff --git a/index.php b/index.php index 6c62e34..9b4689c 100644 --- a/index.php +++ b/index.php @@ -27,6 +27,22 @@ require_once('model/Upcoming.php'); ob_start(); +if(isset($argv) && isset($argv[1])) +{ + require('lib/command-helper.php'); + + switch($argv[1]) + { + case 'download': + require('command/download.php'); + exit(0); + } + + stderr("Unknown Command: %s", $argv[1]); + exit(1); +} + + try { if(isset($_GET['htaccess'])) { -- cgit v1.3.1 From 3384e963da66e9089b71c546750c8981be8c6ed8 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 17 Dec 2016 14:11:47 +0100 Subject: change storage paths according to issue description --- command/download.php | 13 +++++-------- index.php | 3 +++ model/Relive.php | 2 +- model/Schedule.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'index.php') diff --git a/command/download.php b/command/download.php index 8deb454..17ae7c9 100644 --- a/command/download.php +++ b/command/download.php @@ -77,13 +77,13 @@ foreach ($conferences as $conference) ); } - foreach($conference->getExtraFiles() as $file) + foreach($conference->getExtraFiles() as $filename => $url) { download( 'extra-file', $conference, - $file, - get_file_cache($conference, $file) + $url, + get_file_cache($conference, $filename) ); } } @@ -91,12 +91,9 @@ foreach ($conferences as $conference) -function get_file_cache($conference, $url) +function get_file_cache($conference, $filename) { - $info = parse_url($url); - $host = trim(preg_replace('/[^a-z0-9]/i', '_', $info['host']), '_'); - $path = trim(preg_replace('/[^a-z0-9]/i', '_', $info['path']), '_'); - return sprintf('/tmp/file-cache-%s_%s_%s-%s', $conference->getSlug(), $host, $path, md5($url)); + return joinpath([$GLOBALS['BASEDIR'], 'configs/conferences', $conference->getSlug(), $filename]); } function download($what, $conference, $url, $cache) diff --git a/index.php b/index.php index 9b4689c..ca0a6d4 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,9 @@ if(!ini_get('short_open_tag')) die("`short_open_tag = On` is required\n"); +$GLOBALS['BASEDIR'] = dirname(__FILE__); +chdir($GLOBALS['BASEDIR']); + require_once('config.php'); require_once('lib/helper.php'); diff --git a/model/Relive.php b/model/Relive.php index 5676b62..1e8266a 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -26,7 +26,7 @@ class Relive public function getJsonCache() { - return sprintf('/tmp/relive-cache-%s', $this->getConference()->getSlug()); + return sprintf('/tmp/relive-cache-%s.json', $this->getConference()->getSlug()); } public function getTalks() diff --git a/model/Schedule.php b/model/Schedule.php index 4032ecb..6536864 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -272,7 +272,7 @@ class Schedule public function getScheduleCache() { - return sprintf('/tmp/schedule-cache-%s', $this->getConference()->getSlug()); + return sprintf('/tmp/schedule-cache-%s.xml', $this->getConference()->getSlug()); } public function getScheduleToRoomSlugMapping() -- cgit v1.3.1 From 35e7a2b2adad42b077de60d1566c22da62edeb77 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 18 Dec 2016 13:31:34 +0100 Subject: move upcoming & current logic from javascript/ajax into php --- assets/js/lustiges-script.js | 74 -------------------------------------------- index.php | 5 --- lib/helper.php | 31 +++++++++++++++++++ template/overview.phtml | 7 +++-- view/overview.php | 18 +++++++++++ view/schedule-json.php | 13 -------- 6 files changed, 53 insertions(+), 95 deletions(-) delete mode 100644 view/schedule-json.php (limited to 'index.php') diff --git a/assets/js/lustiges-script.js b/assets/js/lustiges-script.js index 78b8758..65fc6ef 100644 --- a/assets/js/lustiges-script.js +++ b/assets/js/lustiges-script.js @@ -176,80 +176,6 @@ $(function() { }); }); -// startpage schedule teaser -$(function() { - var - updateTimer = 5*1000, /* update display every 5 seconds */ - refetchTimer = 10*60*1000, /* re-request current / upcoming schedule every 10 minutes */ - scheduleData = {}, - $lecture = $('.room.has-schedule'); - - if($lecture.length == 0) - return; - - function fetchProgram() { - $.ajax({ - url: $('div[data-schedule-url]').data('schedule-url'), - dataType: 'json', - success: function(data) { - scheduleData = data; - updateProgtamTeaser(); - }, - - // success & error - complete: function() { - setTimeout(fetchProgram, refetchTimer); - } - }); - } - - function updateProgtamTeaser() { - var - // corrected "now" timestamp in unix-counting (seconds, not microseconds) - now = (Date.now() / 1000); - - $.each(scheduleData, function(room, talks) { - var currentTalk, nextTalk; - - $.each(talks, function(room, talk) { - - if(!talk.room_known) - return; - - if(talk.start < now && talk.end > now) - currentTalk = talk; - - if(!nextTalk && !talk.special && talk.start > now) - nextTalk = talk; - - }); - - var s = nextTalk ? new Date(nextTalk.start*1000) : new Date(); - if(currentTalk) - $lecture.filter('.room-'+room) - .find('.current-talk') - .removeClass('hidden') - .find('.t') - .text(currentTalk.special ? 'none' : currentTalk.title) - - if(nextTalk) - $lecture.filter('.room-'+room) - .find('.next-talk') - .toggleClass('hidden', !nextTalk || nextTalk.special || (nextTalk.start - now > 60*60)) - .find('strong') - .text(s.getHours()+':'+(s.getMinutes() < 10 ? '0' : '')+s.getMinutes()) - .end() - .find('.t') - .text(nextTalk ? nextTalk.title : '') - .end() - }); - - setTimeout(updateProgtamTeaser, updateTimer); - } - - fetchProgram(); -}); - // feedback form $(function() { $('.feedback-form').on('submit', function(e) { diff --git a/index.php b/index.php index ca0a6d4..409d75e 100644 --- a/index.php +++ b/index.php @@ -196,11 +196,6 @@ try { require('view/feedback-read.php'); } - else if($route == 'schedule.json') - { - require('view/schedule-json.php'); - } - else if($route == 'gen/main.css') { if(Conferences::hasCustomStyles($mandator)) diff --git a/lib/helper.php b/lib/helper.php index df7f329..1925382 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -114,3 +114,34 @@ function url_params() return ''; } + +/** + * returns the fielst element matching $predicate or null, if none matched. + * $predicate is a callable that receives one array value at a time and can + * return a bool'ish value + */ +function array_filter_first($array, $predicate) +{ + foreach ($array as $value) { + if( $predicate($value) ) { + return $value; + } + } + + return null; +} +/** + * returns the fielst element matching $predicate or null, if none matched. + * $predicate is a callable that receives one array value at a time and can + * return a bool'ish value + */ +function array_filter_last($array, $predicate) +{ + foreach (array_reverse($array) as $value) { + if( $predicate($value) ) { + return $value; + } + } + + return null; +} diff --git a/template/overview.phtml b/template/overview.phtml index 02f0b5f..39cca02 100644 --- a/template/overview.phtml +++ b/template/overview.phtml @@ -1,6 +1,6 @@ include("$assemblies/banner.phtml") ?> -