From 6dc05b8a6e91d4df86d663e9e2c4f6c5d869443f Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Thu, 9 Nov 2017 18:05:52 +0100 Subject: [PATCH 01/66] St Maarten tussenstand --- .../Http/Controllers/SpecialController.php | 32 +++++++++++++++++++ api/routes/web.php | 1 + 2 files changed, 33 insertions(+) create mode 100644 api/app/Http/Controllers/SpecialController.php diff --git a/api/app/Http/Controllers/SpecialController.php b/api/app/Http/Controllers/SpecialController.php new file mode 100644 index 0000000..c7d93fe --- /dev/null +++ b/api/app/Http/Controllers/SpecialController.php @@ -0,0 +1,32 @@ +select('SELECT tussenstand, creationdt FROM stmaarten ORDER BY id DESC LIMIT 0, 1'); + if(count($query)) + { + $creationDt = (new \DateTimeImmutable($query[0]->creationdt)); + return response()->json(['lastupdate' => $creationDt, 'amount' => $query[0]->tussenstand]); + } + else + { + return abort(404); + } + } +} diff --git a/api/routes/web.php b/api/routes/web.php index ecfeada..bc3d825 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -46,5 +46,6 @@ $app->get('kerkdienst', 'KerkdienstController@get'); $app->get('kerkdienst/stream', 'KerkdienstController@podcast'); $app->get('kerkdienst/download', 'KerkdienstController@download'); +$app->get('special/stmaarten', 'SpecialController@stMaarten'); // live/onair // live/stream From 5cb66ec18c43d2d9efc8d89baf1021e3d03756ed Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Tue, 14 Nov 2017 10:09:36 +0100 Subject: [PATCH 02/66] Allow slash in podcast name --- api/app/Http/Controllers/PodcastController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/Http/Controllers/PodcastController.php b/api/app/Http/Controllers/PodcastController.php index 55e44ca..eca7e96 100644 --- a/api/app/Http/Controllers/PodcastController.php +++ b/api/app/Http/Controllers/PodcastController.php @@ -140,7 +140,7 @@ QUERY; } return response()->download($podcast->getSoundfile(), - '6FM Gemist - ' . $podcast->title . '.mp3'); + '6FM Gemist - ' . str_replace('/', '-', $podcast->title) . '.mp3'); } /*** From c8f7887761751ce4e415ed8a2c327e2192454d26 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Fri, 12 Jan 2018 09:45:08 +0100 Subject: [PATCH 03/66] Removed check in program that crashed the site and seems to be unneccesary(?) --- api/app/Http/Controllers/ProgramController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index d561525..bd667f0 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -106,7 +106,9 @@ QUERY; } // Only use this item if it is valid - if(($item[2]->startdate == null || $item[2]->startdate <= $activeProgramStart) && ($item[2]->enddate == null || $item[2]->enddate > $activeProgramStart)) + // MS 2018-01-12: Don't know why I originally had this, the list should only contain valid items. + // This crashed the site once because it skipped a program that should have been in the list but generated 'program not active at priorty' message later on. + // if(($item[2]->startdate == null || $item[2]->startdate <= $activeProgramStart) && ($item[2]->enddate == null || $item[2]->enddate > $activeProgramStart)) { if($DEBUG) print "{$item[1]->format('d-m-Y H:i')}: {$item[2]->name} {$item[2]->suffix} " . ($item[0] == $START ? "begint" : "eindigt") . "
"; @@ -161,10 +163,11 @@ QUERY; } else { return response()->abort(500, "Invalid item type: expected START ($START) or END ($END), but got {$item[0]}."); } - } else if($DEBUG) { - print "Skipped {$item[2]->name} {$item[2]->suffix} on {$item[1]->format('d-m-Y H:i')} " - . " because startdate is " . ($item[2]->startdate == null ? "[null]" : $item[2]->startdate->format('d-m-Y H:i')) - . " and end date is " . ($item[2]->enddate == null ? "[null]" : $item[2]->enddate->format('d-m-Y H:i')) . "
"; + //} else if($DEBUG) { + // print "Skipped {$item[2]->name} {$item[2]->suffix} on {$item[1]->format('d-m-Y H:i')}
" + // . "    because startdate is " . ($item[2]->startdate == null ? "[null]" : $item[2]->startdate->format('d-m-Y H:i')) . "
" + // . "    and end date is " . ($item[2]->enddate == null ? "[null]" : $item[2]->enddate->format('d-m-Y H:i')) . "
" + // . "    Active program " . ($activeProgram ? $activeProgram->name : '[null]') . " starts at " . $activeProgramStart->format('c') . "

"; } // The item will recur in a week From fc947b05ff9548958d1f5712f6c6b26fc5a5a55b Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 24 Jan 2018 18:03:06 +0100 Subject: [PATCH 04/66] Nieuws sorteren op publieke Laatst Bijgewerkt-datum, indien beschikbaar --- api/app/Http/Controllers/NewsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index ac564b5..9b17934 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -59,7 +59,7 @@ QUERY; $start = ($page - 1) * $count; $newsItems = app('db')->select(self::$BASE_SQL . $filterSql - . ' ORDER BY `published` DESC' + . ' ORDER BY COALESCE(`news`.`pubupdatedt`, `news`.`creationdt`) DESC' . ' LIMIT ' . (int)$start . ', ' . (int)$count, $params); $result = array(); @@ -95,7 +95,7 @@ QUERY; $newsItems = app('db')->select(self::$BASE_SQL . ' AND `news`.`creationdt` >= :startRange AND `news`.`creationdt` <= :endRange' . ' AND MATCH(`content`.`title`, `content`.`content`) AGAINST(:query IN BOOLEAN MODE)' - . ' ORDER BY `published` DESC' + . ' ORDER BY COALESCE(`news`.`pubupdatedt`, `news`.`creationdt`) DESC' . ' LIMIT 0, 20', [ 'category' => self::$NEWS_CATEGORY, 'startRange' => $searchRange[0]->format('Y-m-d'), From 23173e0e19ff60277bb7ebabb7363a343969708a Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Sun, 11 Feb 2018 12:43:18 +0100 Subject: [PATCH 05/66] Verberg podcasts met titel < 15 tekens --- api/app/Http/Controllers/PodcastController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/Http/Controllers/PodcastController.php b/api/app/Http/Controllers/PodcastController.php index eca7e96..533e2ad 100644 --- a/api/app/Http/Controllers/PodcastController.php +++ b/api/app/Http/Controllers/PodcastController.php @@ -17,7 +17,7 @@ SELECT `podcast`.`id`, `podcast`.`soundfilename`, FROM `podcast` INNER JOIN `podcast_meta` ON `podcast`.`id` = `podcast_meta`.`podcast` LEFT JOIN `programs` ON `podcast_meta`.`program` = `programs`.`id` - WHERE `podcast_meta`.`active` = 1 AND `podcast_meta`.`title` <> '' AND `podcast_meta`.`content` <> '' + WHERE `podcast_meta`.`active` = 1 AND LENGTH(`podcast_meta`.`title`) > 15 AND `podcast_meta`.`content` <> '' QUERY; /** From e7a3a8587b6efbad90c726d85bc1385d693c30ab Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Tue, 13 Mar 2018 00:50:44 +0100 Subject: [PATCH 06/66] Fixed another bug with the schedule --- .../Http/Controllers/ProgramController.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index bd667f0..5b1b440 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -53,7 +53,9 @@ QUERY; $startDay = $start->format('N'); $endDay = $end->format('N'); $schedule = []; - + +if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$end->format('Y-m-d H:i')}
\n"; + $START = 1; $END = -1; $WEEK = new \DateInterval('P7D'); $DAY = new \DateInterval('P1D'); $WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" /* == 0 and 7 */]; @@ -64,9 +66,11 @@ QUERY; foreach($scheduleItems as $item) { if($item->startdate) { $item->startdate = new \DateTimeImmutable($item->startdate); } if($item->enddate) { $item->enddate = (new \DateTimeImmutable($item->enddate))->add($DAY); } + // Find the start time and end time of the last occurrence on or before the start time $itemStart = new \DateTime("last " . $WEEKDAYS[$item->startday] . " " . $start->format('Y-m-d') . " " . $item->starttime); $itemEnd = new \DateTime("last " . $WEEKDAYS[$item->endday] . " " . $start->format('Y-m-d') . " " . $item->endtime); + if($itemEnd <= $itemStart) { $itemEnd->add($WEEK); } @@ -77,9 +81,18 @@ QUERY; $itemEnd->add($WEEK); } - // Create a list in which all start and end times are separate entries - $scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] ); - $scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] ); + if($DEBUG) { + print "Adding {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} to {$itemEnd->format('Y-m-d H:i')}.
\n"; + if($item->startdate) print " (Item start is {$item->startdate->format('Y-m-d H:i')})
\n"; + } + + if((!$item->startdate || $item->startdate <= $itemEnd) && (!$item->enddate || $item->enddate >= $itemStart)) { + // Create a list in which all start and end times are separate entries + $scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] ); + $scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] ); + } else if($DEBUG) { + print "Skipping {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} because it is out of range.
\n"; + } // Also keep track of all priorities seen $active[$item->priority] = null; @@ -88,7 +101,7 @@ QUERY; if($DEBUG) { print "

Schedule changes - initial state

    "; foreach(clone $scheduleChanges as $c) { - print "
  • {$c[1]->format('d-m-Y H:i')}: " . ($c[0] == $START ? 'Start' : 'Einde') . " {$c[2]->name} {$c[2]->suffix}
  • "; + print "
  • #{$c[2]->scheduleid}: {$c[1]->format('d-m-Y H:i')}: " . ($c[0] == $START ? 'Start' : 'Einde') . " {$c[2]->name} {$c[2]->suffix}
  • "; } print "

"; } From 4b81347cadef4d425710e4d5287c138b4dfb56e0 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Fri, 16 Mar 2018 18:44:01 +0100 Subject: [PATCH 07/66] Check podcast description length too --- api/app/Http/Controllers/PodcastController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/Http/Controllers/PodcastController.php b/api/app/Http/Controllers/PodcastController.php index 533e2ad..c2eec52 100644 --- a/api/app/Http/Controllers/PodcastController.php +++ b/api/app/Http/Controllers/PodcastController.php @@ -17,7 +17,7 @@ SELECT `podcast`.`id`, `podcast`.`soundfilename`, FROM `podcast` INNER JOIN `podcast_meta` ON `podcast`.`id` = `podcast_meta`.`podcast` LEFT JOIN `programs` ON `podcast_meta`.`program` = `programs`.`id` - WHERE `podcast_meta`.`active` = 1 AND LENGTH(`podcast_meta`.`title`) > 15 AND `podcast_meta`.`content` <> '' + WHERE `podcast_meta`.`active` = 1 AND LENGTH(`podcast_meta`.`title`) > 15 AND LENGTH(`podcast_meta`.`content`) > 15 QUERY; /** From d3bef132a472366a73badfb1406b73177cdce4b9 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 11 Apr 2018 02:04:32 +0200 Subject: [PATCH 08/66] Live now playing info --- .../Http/Controllers/ProgramController.php | 26 +++++++++- common/classes/Track.php | 52 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 common/classes/Track.php diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index 5b1b440..baa7ab9 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -246,6 +246,14 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$ return response()->json($program); } + + private function getTrack($next = false) { + $prefix = $next ? "next" : "current"; + $data = app('db')->select("SELECT {$prefix}_start AS start, {$prefix}_itemcode AS itemCode, {$prefix}_title AS title, {$prefix}_artist AS artist, {$prefix}_duration AS duration FROM `now_playing`"); + + return new \Model\Track($data[0]); + } + /** * Programmas nu en straks (24 uur vooruit) */ @@ -253,7 +261,23 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$ $start = new \DateTimeImmutable('now'); $einde = new \DateTimeImmutable('now + 1 second'); $schema = $this->createSchedule($start, $einde); - return response()->json(['current' => ['program' => true, 'name' => $schema['schedule'][0]['program']->name]]); + $program = $schema['schedule'][0]['program']; + if($program->nonstop) { + $current = $this->getTrack(); + $next = $this->getTrack(/* next: */ true); + $current->ends($next->start); + if($current->isLayout() || $current->secondsRemaining() < 0) { + if($next->isLayout()) { + return response()->json(['inProgram' => true, 'current' => $program->name]); + } + + $current = $next; + } + + return response()->json(['inProgram' => false, 'current' => $current]); + } else { + return response()->json(['inProgram' => true, 'current' => $program->name]); + } } /** diff --git a/common/classes/Track.php b/common/classes/Track.php new file mode 100644 index 0000000..9abcea2 --- /dev/null +++ b/common/classes/Track.php @@ -0,0 +1,52 @@ +start); + parent::ConvertToDateTime($this->ends); + } + + private static $IDENTS = ['NIEUWSOPEN ' => 'Nieuws', 'ANWB' => 'Verkeersinformatie', 'REGIO' => 'Regionieuws', 'CB' => 'Reclame']; + + public function isLayout() { + if(strlen($this->itemCode) > 0 && ($this->itemCode[0] == 'V')) { + foreach(self::$IDENTS as $ident => $display) { + if(substr($this->itemCode, 0, strlen($ident)) == $ident || substr($this->title, 0, strlen($ident)) == $ident) { + return false; + } + } + + return true; + } + + return false; + } + + public function ends($ends = null) { + $this->ends = $ends; + } + + public function secondsRemaining() { + return ($this->ends) ? ($this->ends->getTimestamp() - time()) : -1; + } + + public function display() { + foreach(self::$IDENTS as $ident => $display) { + if(substr($this->itemCode, 0, strlen($ident)) == $ident || substr($this->title, 0, strlen($ident)) == $ident) { + return $display; + } + } + + return $this->artist . ($this->artist ? ' - ' : '') . $this->title; + } +} From 3772f19a492570c1ca41cd56e458e1b693a166dc Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 2 May 2018 12:11:37 +0200 Subject: [PATCH 09/66] Now playing: allow seconds remaining to be negative --- api/app/Http/Controllers/ProgramController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index baa7ab9..0f47043 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -266,7 +266,7 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$ $current = $this->getTrack(); $next = $this->getTrack(/* next: */ true); $current->ends($next->start); - if($current->isLayout() || $current->secondsRemaining() < 0) { + if($current->isLayout() /* || $current->secondsRemaining() < 0 */) { if($next->isLayout()) { return response()->json(['inProgram' => true, 'current' => $program->name]); } From d9143848eacc50eabe6eff427189dfb32175a96f Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 2 May 2018 15:15:26 +0200 Subject: [PATCH 10/66] UURSLUITER toegevoegd als ident voor Nieuws in now playing --- common/classes/Track.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/classes/Track.php b/common/classes/Track.php index 9abcea2..ca05bfe 100644 --- a/common/classes/Track.php +++ b/common/classes/Track.php @@ -16,7 +16,7 @@ class Track extends Model { parent::ConvertToDateTime($this->ends); } - private static $IDENTS = ['NIEUWSOPEN ' => 'Nieuws', 'ANWB' => 'Verkeersinformatie', 'REGIO' => 'Regionieuws', 'CB' => 'Reclame']; + private static $IDENTS = ['UURSLUITER' => 'Nieuws', 'NIEUWSOPEN ' => 'Nieuws', 'ANWB' => 'Verkeersinformatie', 'REGIO' => 'Regionieuws', 'CB' => 'Reclame']; public function isLayout() { if(strlen($this->itemCode) > 0 && ($this->itemCode[0] == 'V')) { From 7c41a60f884df7ac556ee250c3381bd93cd3c34a Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Mon, 7 May 2018 19:55:08 +0200 Subject: [PATCH 11/66] Bugjes uit programmaschema --- .../Http/Controllers/ProgramController.php | 123 ++++++++---------- 1 file changed, 56 insertions(+), 67 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index 0f47043..6ab7f21 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -54,7 +54,7 @@ QUERY; $endDay = $end->format('N'); $schedule = []; -if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$end->format('Y-m-d H:i')}
\n"; + if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$end->format('Y-m-d H:i')}
\n"; $START = 1; $END = -1; $WEEK = new \DateInterval('P7D'); $DAY = new \DateInterval('P1D'); @@ -68,38 +68,46 @@ if($DEBUG) print "Creating schedule between {$start->format('Y-m-d H:i')} and {$ if($item->enddate) { $item->enddate = (new \DateTimeImmutable($item->enddate))->add($DAY); } // Find the start time and end time of the last occurrence on or before the start time - $itemStart = new \DateTime("last " . $WEEKDAYS[$item->startday] . " " . $start->format('Y-m-d') . " " . $item->starttime); - $itemEnd = new \DateTime("last " . $WEEKDAYS[$item->endday] . " " . $start->format('Y-m-d') . " " . $item->endtime); + $itemStart = new \DateTimeImmutable("last " . $WEEKDAYS[$item->startday] . " " . $start->format('Y-m-d') . " " . $item->starttime); + $itemEnd = new \DateTimeImmutable("last " . $WEEKDAYS[$item->endday] . " " . $start->format('Y-m-d') . " " . $item->endtime); if($itemEnd <= $itemStart) { - $itemEnd->add($WEEK); + $itemEnd = $itemEnd->add($WEEK); } // If the first occurrence is completely before the period of interest, look at the next week while($itemEnd < $start) { - $itemStart->add($WEEK); - $itemEnd->add($WEEK); + $itemStart = $itemStart->add($WEEK); + $itemEnd = $itemEnd->add($WEEK); } - if($DEBUG) { - print "Adding {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} to {$itemEnd->format('Y-m-d H:i')}.
\n"; - if($item->startdate) print " (Item start is {$item->startdate->format('Y-m-d H:i')})
\n"; - } - - if((!$item->startdate || $item->startdate <= $itemEnd) && (!$item->enddate || $item->enddate >= $itemStart)) { - // Create a list in which all start and end times are separate entries - $scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] ); - $scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] ); - } else if($DEBUG) { - print "Skipping {$item->name} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} because it is out of range.
\n"; - } - - // Also keep track of all priorities seen - $active[$item->priority] = null; + while($itemEnd <= $end) { + if($DEBUG) { + print "Considering {$item->name} {$item->suffix} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} to {$itemEnd->format('Y-m-d H:i')}.
\n"; + if($item->startdate) print "-- (Item start is {$item->startdate->format('Y-m-d H:i')}, end is ". ($item->enddate ? $item->enddate->format('Y-m-d H:i') : "never") . ")
\n"; + } + + if($item->startdate && $itemStart <= $item->startdate) { + if($DEBUG) print "-- Skipping {$item->name} {$item->suffix} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} because it is before the schedule instance start.
\n"; + } else if($item->enddate && $itemStart >= $item->enddate) { + if($DEBUG) print "-- Skipping {$item->name} {$item->suffix} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')} because it is after the schedule instance end.
\n"; + } else { + // if($DEBUG) print "-- Adding {$item->name} {$item->suffix} (#$item->scheduleid) at {$itemStart->format('Y-m-d H:i')}
\n"; + // Create a list in which all start and end times are separate entries + $scheduleChanges->insert( [$START, $itemStart, $item], [-$itemStart->getTimestamp(), -$START] ); + $scheduleChanges->insert( [$END, $itemEnd, $item], [-$itemEnd->getTimestamp(), -$END] ); + } + + // Also keep track of all priorities seen + $active[$item->priority] = null; + + $itemStart = $itemStart->add($WEEK); + $itemEnd = $itemEnd->add($WEEK); + } } if($DEBUG) { - print "

Schedule changes - initial state