podcast pass feedvalidator.org

This commit is contained in:
root 2018-09-14 17:59:08 +02:00
parent 9c00c08235
commit 0d77de6c9f
2 changed files with 33 additions and 19 deletions

View file

@ -29,16 +29,22 @@ class PodcastRorController extends ControllerBase {
->condition('status', '1')
->condition('type', $arg)
->sort('nid', 'DESC')
->range(0, 10);
->range(0, 20);
$nids = $query->execute();
// TODO: load contenuti_audio referenced entities
$data = array();
$data['nodes'] = \Drupal\node\Entity\Node::loadMultiple($nids);
// TODO: metti anche qui toArray() ? sembra piu pratico...
$nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids);
$data['nodes'] = array();
foreach($nodes_e as $nid => $node) {
$data['nodes'][$nid] = $node->toArray();
$data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
0, 3500), ENT_XML1, 'UTF-8');
}
$data['audio'] = array();
$first = true;
foreach($data['nodes'] as $nid => $node) {
foreach($nodes_e as $nid => $node) {
$data['audio'][$nid] = array();
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $audio) {
// print_r(get_class_methods(get_class($audio)));
@ -52,7 +58,10 @@ class PodcastRorController extends ControllerBase {
}
public function podcastAll() {
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
$tmpl_data = [ 'ror' => array('podcast' => $this->query()) ];
$tmpl_data = [ 'ror' => array('podcast' => $this->query(),
'url' => \Drupal::service('path.current')->getPath(),
)];
$variables['ror']['url'] =
$xml = $template->render($tmpl_data);
$resp = new Response($xml, 200, array(
'Content-Type' => 'application/rss+xml'));

View file

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<atom:link href="http://www.ondarossa.info{{ ror.url | escape("html_attr") }}" rel="self" type="application/rss+xml" />
<title>Radio Onda Rossa</title>
<link>http://www.ondarossa.info</link>
<language>it-it</language>
<itunes:subtitle>La radio di chi se la sente</itunes:subtitle>
<itunes:author>Ondarossa</itunes:author>
@ -16,33 +18,36 @@
<itunes:category text="News &amp; Politics"/>
{% for nid, node in ror.podcast.nodes %}
<item>
{% set num_audios = ror.podcast.audio[nid]|length %}
{% for num, audio in ror.podcast.audio[nid] %}
<item>
{% set audiourl = audio.field_audio_link[0].uri %}
{% set ext = audiourl|split('.')|last %}
{% set durata = audio.field_durata[0].value %}
{% set duratamin = durata // 60 %}
{% set duratasec = durata % 60 %}
<title> {{node.getTitle()}} </title>
<itunes:summary>Description of podcast episode content</itunes:summary>
<description> {{ node.get('body').getValue().0.value }} </description>
<link>http://example.com/podcast-1</link> {# node.getLink#}
{% if num_audios > 1 %}
<title> {{node.title.0.value}} ({{num+1}}/{{num_audios}}) </title>
{% else %}
<title> {{node.title.0.value}} </title>
{% endif %}
<itunes:summary>{{ node.summary | raw }}</itunes:summary>
<description> {{ node.body.0.value }} </description>
<link>http://www.ondarossa.info{{node.path.0.alias}}</link>
{# TODO: detect ogg/mp3 #}
<enclosure url="{{ audiourl }}" type="audio/{{ext}}" length="1024"></enclosure>
{# TODO: formatta pubDate #}
<pubDate>Thu, 21 Dec 2016 16:01:07 +0000</pubDate>
<enclosure url="{{ audiourl | replace({"https://": "http://"}) | escape('html_attr') }}" type="audio/{{ext}}" length="1024"></enclosure>
<pubDate>{{ "@#{node.created.0.value}" | date("r") }}</pubDate>
<itunes:author>Redazione Ondarossa</itunes:author>
<itunes:duration>00:{{"%02d" | format(duratamin)}}:{{"%02d" | format(duratasec)}}</itunes:duration>
<itunes:explicit>no</itunes:explicit>
<guid>{{ audiourl }}</guid>
</item>
{% endfor %}
{# [fields]
{% for field in node.getFields() %}
[[ {{ field.getName() }} ]]
{% endfor %}
{% for field in node.getFields() %}
[[ {{ field.getName() }} ]]
{% endfor %}
[/fields] #}
</item>
{% endfor %}
</channel>