Compare commits

...

6 Commits

Author SHA1 Message Date
NH Gooi
54677c8372 Model changes voor nieuwe API 2024-09-12 15:33:53 +02:00
NH Gooi
d859df0ab4 API endpoint voor NLPO-dashboard 2024-06-03 16:04:26 +02:00
NH Gooi
0c16562e87 Podcast Hilversum heeft apart plaatje 2024-05-13 22:33:05 +02:00
NH Gooi
b87b7bfa75 Podcasts HTML entities 2024-05-06 16:26:47 +02:00
NH Gooi
e817ac577c Merge remote-tracking branch 'origin/release/dev' 2024-05-06 13:33:37 +02:00
NH Gooi
75e9fc79f3 Podcast RSS fixed 2024-05-06 13:29:40 +02:00
7 changed files with 152 additions and 46 deletions

View File

@@ -103,13 +103,19 @@ QUERY;
public function retrieveNewsItems($page, $count, $filter, $params) {
$filterSql = "";
$params = ['target' => self::$WEBSITE_TARGET, 'category' => self::$NEWS_CATEGORY, 'secondarycategory' => self::$EXTERNAL_NEWS_CATEGORY];
if($filter) {
foreach($filter as $field => $value) {
$paramName = preg_replace('/[^A-Za-z0-9]/', '', $field);
$filterSql .= " AND $field = :$paramName";
$params[$paramName] = $value;
}
$params['target'] = self::$WEBSITE_TARGET;
$params['category'] = self::$NEWS_CATEGORY;
$params['secondarycategory'] = self::$EXTERNAL_NEWS_CATEGORY;
if($filter) {
if(is_array($filter)) {
foreach($filter as $field => $value) {
$paramName = preg_replace('/[^A-Za-z0-9]/', '', $field);
$filterSql .= " AND $field = :$paramName";
$params[$paramName] = $value;
}
} else {
$filterSql .= ' AND ' . $filter;
}
}
$start = ($page - 1) * $count;
@@ -397,6 +403,64 @@ QUERY
return $item ? response()->json(new \Model\CalendarEvent($item['data'], $item['images'], $item['podcast'])) : abort(404);
}
/**
* Overzicht voor het NLPO-dashboard
*/
public function nlpo(Request $request) {
$from = $request->get('from');
if(!$from) { $from = date('Y-m-d', strtotime('-7 days')); }
$to = $request->get('to');
if(!$to) { $to = date('Y-m-d'); }
$filter = 'DATE(`news`.`creationdt`) >= :from AND DATE(`news`.`creationdt`) <= :to';
$items = $this->retrieveNewsItems(1, 10000,
$filter,
['from' => $from, 'to' => $to]);
$result = [];
foreach($items as $item) {
$tags = [];
if($item->theme) $tags[] = $item->theme->title;
if($item->region) $tags[] = $item->region->title;
$text = $item->content;
$source = app('db')->select('SELECT content FROM `news_target_content` WHERE news = :news AND target = 0 AND published = 1 AND active = 1',
['news' => $item->id]);
if(count($source)) {
$text = $source[0]->content;
$source_data = json_decode($source[0]->content);
if($source_data) {
$text = "";
foreach($source_data->article->blocks as $block) {
if($block->type == 'authors') {
$authors = [];
foreach($block->authors as $author) {
$authors[] = $author->name;
}
$item->author = implode(', ', $authors);
} else if(isset($block->text)) {
$text .= '<div class="' . $block->type . '">' . $block->text . '</div>';
}
}
} else {
$text = $source[0];
}
}
$result[] = [
'title' => $item->title,
'url' => 'https://nhgooi.nl/' . $item->url,
'text' => $text,
'date' => $item->published->format('Y-m-d\TH:i:s.z\Z'),
'art_id' => $item->id,
'author' => $item->author,
'excerpt' => strip_tags($item->content),
'categories' => $tags,
'tags' => $tags,
'comment_count' => 0
];
}
return response()->json($result);
}
private function itemFromCategory($category, $id) {
$params = ['id' => (int)$id, 'target' => self::$WEBSITE_TARGET];
if(is_array($category)) {

View File

@@ -3,21 +3,20 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
error_reporting(E_ALL);
ini_set('display_errors', true);
class PodcastController extends Controller
{
public static $BASE_SQL = <<<QUERY
SELECT `podcast`.`id`, `podcast`.`soundfilename`,
`podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`, `podcast_meta`.`imagefile`, `podcast_meta`.`imagecaption`,
SELECT `podcast`.`id`, `podcast`.`soundfilename`, `podcast`.`duration`,
`podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`,
`podcast_meta`.`imagefile`, `podcast_meta`.`imagecaption`,
`programs`.`longname` AS `program_name`, `programs`.`description` AS `program_description`
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 `podcast_meta`.`public` = 1
QUERY;
/**
@@ -37,6 +36,39 @@ QUERY;
return $this->getPodcastList($request, null, []);
}
/**
* RSS-feed van alle podcasts
*/
public function rss(Request $request) {
$page = (int)$request->get('page', 1);
if($page <= 0) {
return abort(400);
}
$podcasts = $this->retrievePodcasts($page, $count = 20, $filter = null, $params = []);
$view = view('rss.podcasts')->with('podcasts', $podcasts)->with('url', $request->url())->with('page', $page);
return response($view)->header('Content-Type', 'application/xml');
}
/**
* RSS-feed van alle podcasts van een programma (bv. podcastserie)
*/
public function program_rss(Request $request, $program) {
$page = (int)$request->get('page', 1);
if($page <= 0) {
return abort(400);
}
$programQuery = app('db')->select('SELECT `programs`.`id` AS `id`, `programs`.`longname` AS `name`, `programs`.`description` AS `description`, `programs`.`tagline` AS `tagline`, `programs`.`description` AS `description`, `programs`.`email` FROM `programs` WHERE `programs`.`id` = :id', ['id' => $program]);
$programDetails = new \Model\Program($programQuery[0]);
$filter = '`podcast_meta`.`program` = :program';
$params = ['program' => (int)$program];
$podcasts = $this->retrievePodcasts($page, $count = 1000, $filter, $params);
$view = view('rss.podcasts')->with('program', $programDetails)->with('podcasts', $podcasts)->with('url', $request->url())->with('page', $page);
return response($view)->header('Content-Type', 'application/xml');
}
/**
* Lijst van alle podcasts voor een specifiek programma
*/
@@ -70,22 +102,17 @@ QUERY;
public function findpodcast(Request $request, $query) {
$page = (int)$request->get('pagina', 1);
$count = (int)$request->get('aantal', 15);
if($page <= 0) {
return abort(400);
}
$start = ($page - 1) * $count;
$query = strip_tags(urldecode($query));
$searchRange = [
(new \DateTimeImmutable())->setDate(date('Y') + 1 - $page, 1, 1),
(new \DateTimeImmutable())->setDate(date('Y') + 2 - $page, 1, 1)];
$podcasts = app('db')->select(self::$BASE_SQL
. ' AND `podcast_meta`.`creationdt` >= :startRange AND `podcast_meta`.`creationdt` <= :endRange'
. ' AND MATCH(`podcast_meta`.`title`, `podcast_meta`.`content`) AGAINST(:query IN BOOLEAN MODE)'
. ' AND MATCH(`podcast_meta`.`title`, `podcast_meta`.`content`) AGAINST(:query IN NATURAL LANGUAGE MODE)'
. ' ORDER BY `creationdt` DESC'
. ' LIMIT 0, 20', [
'startRange' => $searchRange[0]->format('Y-m-d'),
'endRange' => $searchRange[1]->format('Y-m-d'),
. ' LIMIT ' . $start . ', ' . $count, [
'query' => $query
]);
@@ -102,12 +129,18 @@ QUERY;
private function getPodcastList(Request $request, $filter, $params)
{
$count = (int)$request->get('aantal', 15);
$page = (int)$request->get('pagina', 1);
$count = (int)$request->get('aantal', 15);
$page = (int)$request->get('pagina', 1);
if($count <= 0 || $page <= 0) {
return abort(400);
}
$result = $this->retrievePodcasts($page, $count, $filter, $params);
return response()->json(['page' => $page, 'count' => $count, 'podcasts' => $result]);
}
private function retrievePodcasts($page, $count, $filter, $params)
{
$start = ($page - 1) * $count;
$podcasts = app('db')->select(self::$BASE_SQL
. ($filter ? ' AND (' . $filter . ')' : '')
@@ -120,7 +153,7 @@ QUERY;
$result[] = new \Model\Podcast($podcast);
}
return response()->json(['page' => $page, 'count' => $count, 'podcasts' => $result]);
return $result;
}
/**
@@ -140,7 +173,7 @@ QUERY;
}
return response()->download($podcast->getSoundfile(),
'6FM Gemist - ' . str_replace('/', '-', $podcast->title) . '.mp3');
'NH Gooi Gemist - ' . str_replace('/', '-', $podcast->title) . '.mp3');
}
/***
@@ -174,7 +207,7 @@ QUERY;
public function latestNews(Request $request) {
$filename = '/var/audio/regionieuws.mp3';
return response()->download($filename,
'6FM Regionieuws ' . date('d-m-Y') . '.mp3');
'NH Gooi Regionieuws ' . date('d-m-Y') . '.mp3');
$size = filesize($filename);
$content = fread($file, $size);
@@ -196,14 +229,10 @@ QUERY;
$files = [];
$size = 0;
while($duration--) {
$file = '/var/audio/uitzending/' . $currentHour->format('Ymd_Hi');
if(file_exists($file . '.mp3')) {
$file .= '.mp3';
} else if(file_exists($file . '.MP3')) {
$file .= '.MP3';
} else {
return abort(404);
}
$file = '/var/audio/uitzending/' . $currentHour->format('Ymd_Hi') . '.mp3';
if(!file_exists($file)) {
return abort(404);
}
$size += ($filesize = filesize($file));
$files[] = [$file, $filesize];

View File

@@ -1,5 +1,6 @@
<?php header('Access-Control-Allow-Origin: *'); ?>
<?xml version="1.0" encoding="UTF-8"?>
<?php header('Content-Type: text/xml'); ?>
<{{ '' /* avoid PHP parsing this as short open tag */ }}?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:content="http://purl.org/rss/1.0/modules/content/"

View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Content-Type: text/xml'); ?>
<{{ '' /* avoid PHP parsing this as short open tag */ }}?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:spotify="http://www.spotify.com/ns/rss"
@@ -6,7 +8,7 @@
<channel>
<title>{{isset($program) ? $program->name : "NH Gooi Gemist"}}</title>
<description>{{isset($program) ? $program->description : "Fragmenten en interviews eerder te horen op NH Gooi Radio"}}</description>
<description><![CDATA[{!! isset($program) ? html_entity_decode($program->description) : "Fragmenten en interviews eerder te horen op NH Gooi Radio" !!}]]></description>
<link>https://nhgooi.nl{{isset($program) ? $program->url : ""}}</link>
<language>nl-nl</language>
@@ -19,7 +21,7 @@
<itunes:author>NH Gooi Radio</itunes:author>
<itunes:explicit>no</itunes:explicit>
<itunes:image href="https://nhgooi.nl/images/logo_sqr_hq.png" />
<itunes:image href="https://nhgooi.nl/images/{{ isset($program) && $program->id == 1097 ? "hilversum_oorlog.jpg" : "logo_sqr_hq.png" }}" />
<itunes:owner>
<itunes:name>NH Gooi Radio</itunes:name>
<itunes:email>{{isset($program) ? $program->email : 'info' }}@nhgooi.nl</itunes:email>
@@ -34,19 +36,21 @@
<item>
<guid>https://nhgooi.nl/podcast-{{$podcast->id}}</guid>
<title>{{html_entity_decode($podcast->title)}}</title>
<description>{{html_entity_decode($podcast->content)}}</description>
<description><![CDATA[{!! html_entity_decode($podcast->content) !!}]]></description>
<link>https://nhgooi.nl/gemist/fragment/{{$podcast->url}}</link>
<enclosure url="{{url('podcast/download' . $podcast->url . '?auth=' . $podcast->auth)}}" type="audio/mpeg" length="{{filesize($podcast->getSoundFile())}}"></enclosure>
<pubDate>{{$podcast->created->format('r')}}</pubDate>
<itunes:title>{{$podcast->title}}</itunes:title>
<itunes:author>NH Gooi Radio</itunes:author>
<itunes:summary>{{$podcast->content}}</itunes:summary>
<itunes:summary><![CDATA[{!! html_entity_decode($podcast->content) !!}]]></itunes:summary>
<itunes:duration>{{$podcast->formatDuration()}}</itunes:duration>
<itunes:explicit>no</itunes:explicit>
@if($podcast->image)
<itunes:image href="https://nhgooi.nl{{$podcast->image->url}}"/>
@endif
@if($podcast->image)
<itunes:image href="https://nhgooi.nl{{$podcast->image->url}}"/>
@elseif($podcast->program && $podcast->program->image)
<itunes:image href="https://nhgooi.nl{{$podcast->program->image->url}}"/>
@endif
</item>
@endforeach

View File

@@ -24,6 +24,7 @@ $app->get( 'menu/special', 'MenuController@special' );
$app->get('nieuws/overzicht', 'NewsController@newslist' );
$app->get('nieuws/kabelkrant', 'NewsController@tvlist' );
$app->get('nieuws/nlpo', 'NewsController@nlpo' );
$app->get('nieuws/regio/{region:[a-z0-9-]+}', 'NewsController@regionlist' );
$app->get('nieuws/thema/{theme:[a-z0-9-]+}', 'NewsController@themelist' );
$app->get('nieuws/zoeken/{query}', 'NewsController@findnews' );

View File

@@ -15,6 +15,7 @@ class CalendarEvent extends Model {
public $keywords;
public $url;
public $metadata;
public $tags;
public function __construct($data, $images = null, $podcast = null) {
parent::__construct($data);

View File

@@ -19,6 +19,7 @@ class NewsItem extends Model {
public $category;
public $theme;
public $region;
public $tags;
public $podcast;
public $images;
@@ -79,6 +80,11 @@ class NewsItem extends Model {
}
}
if(isset($data->tags)) {
foreach($data->tags as $tag) {
$this->theme = new \Model\NewsRegion($tag->titel, $tag->slug);
}
}
$images = ($images != null) ? $images
: (isset($data->images) ? $data->images : null);