From db406d8aeaa9b7cb3f1d8f23e9fc286bdb0b9e04 Mon Sep 17 00:00:00 2001 From: rmens Date: Thu, 24 Oct 2024 22:54:39 +0200 Subject: [PATCH 1/2] Add dagen to teksttv --- .../group_66c5010145df1.json | 80 ++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/streekomroep-acf-json/group_66c5010145df1.json b/streekomroep-acf-json/group_66c5010145df1.json index 2eeec14..ad1aad9 100644 --- a/streekomroep-acf-json/group_66c5010145df1.json +++ b/streekomroep-acf-json/group_66c5010145df1.json @@ -116,7 +116,7 @@ "required": 1, "conditional_logic": 0, "wrapper": { - "width": "30", + "width": "20", "class": "", "id": "" }, @@ -129,8 +129,32 @@ "max_height": "", "max_size": "", "mime_types": "", + "allow_in_bindings": 1, "preview_size": "thumbnail" }, + { + "key": "field_669d49c2261cd", + "label": "Seconden", + "name": "seconden", + "aria-label": "", + "type": "number", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "15", + "class": "", + "id": "" + }, + "default_value": 10, + "min": "", + "max": "", + "allow_in_bindings": 1, + "placeholder": "", + "step": "", + "prepend": "", + "append": "" + }, { "key": "field_669d49968fbc3", "label": "Datum in", @@ -141,13 +165,14 @@ "required": 0, "conditional_logic": 0, "wrapper": { - "width": "27.5", + "width": "15", "class": "", "id": "" }, "display_format": "d\/m\/Y", "return_format": "d\/m\/Y", - "first_day": 1 + "first_day": 1, + "allow_in_bindings": 1 }, { "key": "field_669d49a58fbc4", @@ -159,35 +184,54 @@ "required": 0, "conditional_logic": 0, "wrapper": { - "width": "27.5", + "width": "15", "class": "", "id": "" }, "display_format": "d\/m\/Y", "return_format": "d\/m\/Y", - "first_day": 1 + "first_day": 1, + "allow_in_bindings": 1 }, { - "key": "field_669d49c2261cd", - "label": "Seconden", - "name": "seconden", + "key": "field_671ab2972f163", + "label": "Dagen", + "name": "dagen", "aria-label": "", - "type": "number", + "type": "checkbox", "instructions": "", "required": 0, "conditional_logic": 0, "wrapper": { - "width": "15", + "width": "30", "class": "", "id": "" }, - "default_value": 10, - "min": "", - "max": "", - "placeholder": "", - "step": "", - "prepend": "", - "append": "" + "choices": { + "1": "ma", + "2": "di", + "3": "wo", + "4": "do", + "5": "vr", + "6": "za", + "7": "zo" + }, + "default_value": [ + "ma", + "di", + "wo", + "do", + "vr", + "za", + "zo" + ], + "return_format": "value", + "allow_custom": 0, + "allow_in_bindings": 0, + "layout": "horizontal", + "toggle": 0, + "save_custom": 0, + "custom_choice_button_text": "Nieuwe keuze toevoegen" } ], "min": "", @@ -320,5 +364,5 @@ "active": true, "description": "", "show_in_rest": 0, - "modified": 1727807462 + "modified": 1729803241 } From 1d094c9a5db2d949d61a4c030dd82467f2ed1ff9 Mon Sep 17 00:00:00 2001 From: rmens Date: Thu, 24 Oct 2024 23:02:12 +0200 Subject: [PATCH 2/2] Date and day filter for images --- lib/teksttv.php | 43 +++++++++++++++++++++++++++++++++++++++---- style.css | 2 +- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/teksttv.php b/lib/teksttv.php index a29fffc..4c93414 100644 --- a/lib/teksttv.php +++ b/lib/teksttv.php @@ -4,6 +4,7 @@ use WP_Query; use WP_REST_Response; +use DateTime; class TekstTVAPI { @@ -126,8 +127,11 @@ private function get_article_slides($block) // Skip if the post's expiration date has passed $end_date = get_field('post_kabelkrant_datum_uit', get_the_ID()); - if (!empty($end_date) && strtotime($end_date) < current_time('timestamp')) { - continue; + if (!empty($end_date)) { + $end_date_obj = DateTime::createFromFormat('d/m/Y', $end_date); + if ($end_date_obj && $end_date_obj->getTimestamp() < current_time('timestamp')) { + continue; + } } // Skip if this post isn't for TekstTV @@ -190,13 +194,44 @@ private function get_primary_category_image($post_id) return get_the_post_thumbnail_url($post_id, 'large'); } - // Generate an image slide from a block + // Generate an image slide from a block with day and date filtering private function get_image_slide($block) { + $current_timestamp = current_time('timestamp'); + + // Check date range if 'datum_in' or 'datum_uit' is set + if (!empty($block['datum_in'])) { + $start_date = DateTime::createFromFormat('d/m/Y', $block['datum_in']); + if ($start_date && $current_timestamp < $start_date->getTimestamp()) { + // Current date is before the start date + return null; + } + } + + if (!empty($block['datum_uit'])) { + $end_date = DateTime::createFromFormat('d/m/Y', $block['datum_uit']); + if ($end_date && $current_timestamp > $end_date->getTimestamp()) { + // Current date is after the end date + return null; + } + } + + // Check day filter if 'dagen' is set + if (!empty($block['dagen'])) { + $today = date('N'); // 1 (Monday) to 7 (Sunday) + $allowed_days = $block['dagen']; // Array of strings ["1", "2", ..., "7"] + + if (!in_array((string)$today, $allowed_days, true)) { + // Today is not in the allowed days + return null; + } + } + + // If all checks pass, return the image slide if (!empty($block['afbeelding']) && !empty($block['afbeelding']['url'])) { return [ 'type' => 'image', - 'duration' => intval($block['seconden']) * 1000, + 'duration' => intval($block['seconden']) * 1000, // Convert to milliseconds 'url' => $block['afbeelding']['url'], ]; } diff --git a/style.css b/style.css index 4fd33c0..e084d97 100644 --- a/style.css +++ b/style.css @@ -2,5 +2,5 @@ * Theme Name: Streekomroep * Description: This is a WordPress theme made for Streekomroep ZuidWest in the Netherlands. It's made using Timber and Tailwind CSS and provides functionality for regional news, radio and television broadcasts. * Author: Streekomroep ZuidWest - * Version: 1.10.0-beta5 + * Version: 1.10.0-beta6 */