Merge
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
@@ -11,7 +12,7 @@ ini_set('display_errors', true);
|
||||
class PodcastController extends Controller
|
||||
{
|
||||
public static $BASE_SQL = <<<QUERY
|
||||
SELECT `podcast`.`id`, `podcast`.`soundfilename`,
|
||||
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`
|
||||
@@ -38,6 +39,15 @@ QUERY;
|
||||
return $this->getPodcastList($request, null, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* RSS-feed van alle podcasts
|
||||
*/
|
||||
public function rss(Request $request) {
|
||||
$podcasts = $this->retrievePodcasts($page = 1, $count = 20, $filter = null, $params = []);
|
||||
$view = view('rss.podcasts')->with('podcasts', $podcasts);
|
||||
return response($view)->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* Lijst van alle podcasts voor een specifiek programma
|
||||
*/
|
||||
@@ -103,12 +113,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,8 +136,8 @@ QUERY;
|
||||
foreach($podcasts as $podcast) {
|
||||
$result[] = new \Model\Podcast($podcast);
|
||||
}
|
||||
|
||||
return response()->json(['page' => $page, 'count' => $count, 'podcasts' => $result]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
40
api/resources/views/rss/podcasts.blade.php
Normal file
40
api/resources/views/rss/podcasts.blade.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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"
|
||||
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
||||
|
||||
<channel>
|
||||
<title>NH Gooi Gemist</title>
|
||||
<description>Fragmenten en interviews eerder te horen op NH Gooi Radio</description>
|
||||
<link>https://nhgooi.nl</link>
|
||||
<language>nl-nl</language>
|
||||
<itunes:author>NH Gooi Radio</itunes:author>
|
||||
<itunes:explicit>no</itunes:explicit>
|
||||
<itunes:image href="https://nhgooi.nl/images/logo.png" />
|
||||
<itunes:owner>
|
||||
<itunes:email>info@nhgooi.nl</itunes:email>
|
||||
</itunes:owner>
|
||||
<itunes:category text="News & Politics"></itunes:category>
|
||||
<spotify:countryOfOrigin>nl</spotify:countryOfOrigin><spotify:countryOfOrigin>nl</spotify:countryOfOrigin>
|
||||
|
||||
@foreach($podcasts as $podcast)
|
||||
<item>
|
||||
<title>{{$podcast->title}}</title>
|
||||
<itunes:summary>{{$podcast->content}}</itunes:summary>
|
||||
<description>{{$podcast->content}}</description>
|
||||
<link>https://nhgooi.nl/podcast/download/{{$podcast->url}}</link>
|
||||
<pubDate>{{$podcast->created->format('r')}}</pubDate>
|
||||
<itunes:author>NH Gooi Radio</itunes:author>
|
||||
<itunes:duration>{{$podcast->formatDuration()}}</itunes:duration>
|
||||
<itunes:explicit>no</itunes:explicit>
|
||||
@if($podcast->image)
|
||||
<itunes:image href="https://nhgooi.nl{{$podcast->image->url}}"/>
|
||||
@endif
|
||||
<guid>https://nhgooi.nl/podcast-{{$podcast->id}}</guid>
|
||||
</item>
|
||||
@endforeach
|
||||
|
||||
</channel>
|
||||
</rss>
|
||||
|
||||
@@ -11,10 +11,13 @@
|
||||
|
|
||||
*/
|
||||
|
||||
|
||||
$app->get('/', function () use ($app) {
|
||||
return redirect('docs');
|
||||
});
|
||||
|
||||
$app->get( 'rss/podcasts', 'PodcastController@rss' );
|
||||
|
||||
$app->get( 'menu/special', 'MenuController@special' );
|
||||
|
||||
$app->get('nieuws/overzicht', 'NewsController@newslist' );
|
||||
|
||||
@@ -14,6 +14,7 @@ class Podcast extends Model {
|
||||
public $url;
|
||||
public $auth;
|
||||
public $download;
|
||||
public $duration;
|
||||
public $image;
|
||||
private $key;
|
||||
|
||||
@@ -59,6 +60,17 @@ class Podcast extends Model {
|
||||
return '/var/audio/podcast/' . $this->soundfilename;
|
||||
}
|
||||
|
||||
public function formatDuration() {
|
||||
$seconds = $this->duration / 1000;
|
||||
$milliseconds = $this->duration % 1000;
|
||||
|
||||
$hours = ($seconds > 3600) ? floor($seconds / 3600) : 0;
|
||||
$seconds %= 3600;
|
||||
return str_pad($hours, 2, '0', STR_PAD_LEFT)
|
||||
. gmdate(':i:s', $seconds)
|
||||
. ($milliseconds ? ".$milliseconds" : '') ;
|
||||
}
|
||||
|
||||
public function excerpt() {
|
||||
$maxLength = 500;
|
||||
return '<p class="news-excerpt long">' .
|
||||
|
||||
Reference in New Issue
Block a user