Skip to content

Commit

Permalink
Tekst TV 3.0 API Update (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmens authored Oct 18, 2024
1 parent e13b12d commit fa8a94d
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 154 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

# The Streekomroep WordPress Theme

This is a WordPress theme created for Streekomroep ZuidWest in the Netherlands. It utilizes Timber and Tailwind CSS, offering functionality for regional news, radio, and TV broadcasts. Use it with WordPress 6.6+ and PHP 8.2+.
This is a WordPress theme created for Streekomroep ZuidWest in the Netherlands. It utilizes Timber and Tailwind CSS, offering functionality for regional news, radio, and TV broadcasts. Use it with WordPress 6.6+ and PHP 8.2.

## How to build/install
It's not enough to download the theme and upload is to a server. The dependencies must be built first. Otherwise it will not work.
## How to install
Get the latest version from the [Releases tab](https://github.com/oszuidwest/streekomroep-wp/releases) and upload it as theme to your WordPress installation. Ensure to install all the hard dependencies too.

## How to manually build
You can also build the theme yourself.

Instructions for macOS:
- Install Homebrew ([https://brew.sh](https://brew.sh))
Expand All @@ -14,6 +17,7 @@ Instructions for macOS:

```bash
npm install
npx browserslist@latest --update-db
NODE_ENV=production npx tailwindcss build assets/style.css -o dist/style.css --minify
composer install --prefer-dist --no-dev --optimize-autoloader
```
Expand All @@ -23,7 +27,7 @@ For Linux users, use `apt` or `yum` instead of Homebrew. This theme has not been

### Hard dependencies
Install these before activating the theme:
- Timber 2.2.x: [[Use composer](https://timber.github.io/docs/v2/installation/installation/)]
- Timber 2.2: [Bundled, if you build yourself [use composer](https://timber.github.io/docs/v2/installation/installation/)]
- Advanced Custom Fields Pro 6.3.x: [[purchase](https://www.advancedcustomfields.com/pro/)]
- Classic Editor 1.x: [[free download](https://wordpress.org/plugins/classic-editor/)] _(we are giving the block editor more time to stabilize)_
- Yoast SEO Premium 23.x: [[purchase](https://yoast.com/wordpress/plugins/seo/)]
Expand Down
150 changes: 1 addition & 149 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function zw_filter_pre_oembed_result($default, $url, $args)

require_once 'lib/input_sanitizer.php';
require_once 'lib/push_adapter.php';
require_once 'lib/teksttv.php';

// Use default class for all post types, except for pages.
add_filter('timber/post/classmap', function ($base) {
Expand Down Expand Up @@ -300,22 +301,6 @@ function zw_rest_api_init()
);
}

register_rest_field(
'post',
'kabelkrant_text',
[
'get_callback' => function ($post_arr, $attr, $request, $object_type) {
$data = null;
$show = (bool)get_field('post_in_kabelkrant', $post_arr['id']);
if ($show) {
$data = get_field('post_kabelkrant_content', $post_arr['id']);
}

return $data;
},
]
);

register_rest_field(
'post',
'ranking',
Expand Down Expand Up @@ -502,142 +487,9 @@ function zw_rest_api_init()
}, $schedule->getTomorrow()->television),
];

$commercials = [];

if (!is_array($options['tv_reclame_slides'])) {
$options['tv_reclame_slides'] = [];
}

$now = new DateTime('now', wp_timezone());
foreach ($options['tv_reclame_slides'] as $slide) {
// Ignore slides with no image
if ($slide['tv_reclame_afbeelding'] === false) {
continue;
}

$start = DateTime::createFromFormat('d/m/Y', $slide['tv_reclame_start'], wp_timezone());
$start->setTime(0, 0);
// TODO: is end date inclusive?
$end = DateTime::createFromFormat('d/m/Y', $slide['tv_reclame_eind'], wp_timezone());
$end->setTime(24, 0);

if ($now >= $start && $now < $end) {
$commercials[] = $slide['tv_reclame_afbeelding']['url'];
}
}

$response['commercials'] = $commercials;

return $response;
}
]);

register_rest_route('zw/v1', '/desking', [
'methods' => 'GET',
'permission_callback' => '__return_true',
'callback' => function (WP_REST_Request $request) {
$output = [];
$blocks = get_field('desking_blokken_voorpagina', 'option');

foreach ($blocks as $block) {
switch ($block['acf_fc_layout']) {
case 'blok_top_stories':
$output[] = [
'type' => 'topstories',
];
break;

case 'blok_tv_gemist':
$output[] = [
'type' => 'recent_tv',
'title' => trim($block['tekst_boven_videos']),
'deduplicate' => $block['ontdubbel'],
'count' => $block['aantal_videos'],
];
break;

case 'blok_fm_gemist':
$output[] = [
'type' => 'recent_fm',
'title' => trim($block['tekst_boven_audio']),
];
break;

case 'blok_fragmenten_carrousel':
$title = $block['tekst_boven_fragmenten'];
if (empty($title)) {
$title = null;
}
$output[] = [
'type' => 'fragments',
'title' => $title,
];
break;

case 'blok_artikel_lijst':
$title = $block['tekst_boven_artikelen'];
if (empty($title)) {
$title = null;
}
$output[] = [
'type' => 'posts',
'title' => $title,
'count' => $block['aantal_artikelen'],
'offset' => $block['offset'],
];
break;

case 'blok_dossier':
$term = get_term($block['selecteer_dossier'], 'dossier');
$title = $block['tekst_boven_dossier'];
if (empty($title)) {
$title = $term->name;
}

$output[] = [
'type' => 'dossier',
'title' => $title,
'count' => $block['aantal_artikelen'],
'offset' => $block['offset'],
'term_id' => $term->term_id,
];
break;

case 'blok_dossiers_carrousel':
$title = $block['tekst_boven_dossiers'];
if (empty($title)) {
$title = 'Dossiers';
}

$output[] = [
'type' => 'dossier_carousel',
'title' => $title,
];
break;

case 'blok_nu_op_fmtv':
$output[] = [
'type' => 'now_onair'
];
break;

case 'blok_meest_gelezen':
$title = $block['tekst_boven_artikelen'];
if (empty($title)) {
$title = null;
}

$output[] = [
'type' => 'popular',
'title' => $title,
];
break;
}
}

return $output;
}
]);
}

function zw_bunny_parse_url($url)
Expand Down
Loading

0 comments on commit fa8a94d

Please sign in to comment.