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 --- lib/helper.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/helper.php b/lib/helper.php index 4fce91e..df7f329 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -18,14 +18,20 @@ function baseurl() if(startswith('//', $base)) $base = proto().':'.$base; - return forceslash(forceslash($base).@$GLOBALS['MANDATOR']); + return forceslash($base); } $base = ssl() ? 'https://' : 'http://'; $base .= $_SERVER['HTTP_HOST']; $base .= forceslash(dirname($_SERVER['SCRIPT_NAME'])); - return forceslash(forceslash($base).@$GLOBALS['MANDATOR']); + return forceslash($base); +} + +function joinpath($parts) +{ + $parts = array_map('forceslash', $parts); + return rtrim(implode('', $parts), '/'); } function forceslash($url) -- 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 'lib') 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 3c3d0ac7301e818b14d01b9bbc949ca13d2cf798 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 19:57:20 +0100 Subject: commandline helper functions --- lib/command-helper.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/command-helper.php (limited to 'lib') diff --git a/lib/command-helper.php b/lib/command-helper.php new file mode 100644 index 0000000..c406b9e --- /dev/null +++ b/lib/command-helper.php @@ -0,0 +1,15 @@ + 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") ?> -