podcast pass feedvalidator.org
This commit is contained in:
parent
9c00c08235
commit
0d77de6c9f
2 changed files with 33 additions and 19 deletions
|
@ -29,16 +29,22 @@ class PodcastRorController extends ControllerBase {
|
||||||
->condition('status', '1')
|
->condition('status', '1')
|
||||||
->condition('type', $arg)
|
->condition('type', $arg)
|
||||||
->sort('nid', 'DESC')
|
->sort('nid', 'DESC')
|
||||||
->range(0, 10);
|
->range(0, 20);
|
||||||
$nids = $query->execute();
|
$nids = $query->execute();
|
||||||
// TODO: load contenuti_audio referenced entities
|
// TODO: load contenuti_audio referenced entities
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['nodes'] = \Drupal\node\Entity\Node::loadMultiple($nids);
|
$nodes_e = \Drupal\node\Entity\Node::loadMultiple($nids);
|
||||||
// TODO: metti anche qui toArray() ? sembra piu pratico...
|
$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();
|
$data['audio'] = array();
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach($data['nodes'] as $nid => $node) {
|
foreach($nodes_e as $nid => $node) {
|
||||||
$data['audio'][$nid] = array();
|
$data['audio'][$nid] = array();
|
||||||
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $audio) {
|
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $audio) {
|
||||||
// print_r(get_class_methods(get_class($audio)));
|
// print_r(get_class_methods(get_class($audio)));
|
||||||
|
@ -52,7 +58,10 @@ class PodcastRorController extends ControllerBase {
|
||||||
}
|
}
|
||||||
public function podcastAll() {
|
public function podcastAll() {
|
||||||
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
|
$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);
|
$xml = $template->render($tmpl_data);
|
||||||
$resp = new Response($xml, 200, array(
|
$resp = new Response($xml, 200, array(
|
||||||
'Content-Type' => 'application/rss+xml'));
|
'Content-Type' => 'application/rss+xml'));
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<channel>
|
||||||
|
<atom:link href="http://www.ondarossa.info{{ ror.url | escape("html_attr") }}" rel="self" type="application/rss+xml" />
|
||||||
<title>Radio Onda Rossa</title>
|
<title>Radio Onda Rossa</title>
|
||||||
|
<link>http://www.ondarossa.info</link>
|
||||||
<language>it-it</language>
|
<language>it-it</language>
|
||||||
<itunes:subtitle>La radio di chi se la sente</itunes:subtitle>
|
<itunes:subtitle>La radio di chi se la sente</itunes:subtitle>
|
||||||
<itunes:author>Ondarossa</itunes:author>
|
<itunes:author>Ondarossa</itunes:author>
|
||||||
|
@ -16,33 +18,36 @@
|
||||||
<itunes:category text="News & Politics"/>
|
<itunes:category text="News & Politics"/>
|
||||||
|
|
||||||
{% for nid, node in ror.podcast.nodes %}
|
{% for nid, node in ror.podcast.nodes %}
|
||||||
<item>
|
{% set num_audios = ror.podcast.audio[nid]|length %}
|
||||||
{% for num, audio in ror.podcast.audio[nid] %}
|
{% for num, audio in ror.podcast.audio[nid] %}
|
||||||
|
<item>
|
||||||
{% set audiourl = audio.field_audio_link[0].uri %}
|
{% set audiourl = audio.field_audio_link[0].uri %}
|
||||||
{% set ext = audiourl|split('.')|last %}
|
{% set ext = audiourl|split('.')|last %}
|
||||||
{% set durata = audio.field_durata[0].value %}
|
{% set durata = audio.field_durata[0].value %}
|
||||||
{% set duratamin = durata // 60 %}
|
{% set duratamin = durata // 60 %}
|
||||||
{% set duratasec = durata % 60 %}
|
{% set duratasec = durata % 60 %}
|
||||||
<title> {{node.getTitle()}} </title>
|
{% if num_audios > 1 %}
|
||||||
<itunes:summary>Description of podcast episode content</itunes:summary>
|
<title> {{node.title.0.value}} ({{num+1}}/{{num_audios}}) </title>
|
||||||
<description> {{ node.get('body').getValue().0.value }} </description>
|
{% else %}
|
||||||
<link>http://example.com/podcast-1</link> {# node.getLink#}
|
<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 | replace({"https://": "http://"}) | escape('html_attr') }}" type="audio/{{ext}}" length="1024"></enclosure>
|
||||||
<enclosure url="{{ audiourl }}" type="audio/{{ext}}" length="1024"></enclosure>
|
<pubDate>{{ "@#{node.created.0.value}" | date("r") }}</pubDate>
|
||||||
{# TODO: formatta pubDate #}
|
|
||||||
<pubDate>Thu, 21 Dec 2016 16:01:07 +0000</pubDate>
|
|
||||||
<itunes:author>Redazione Ondarossa</itunes:author>
|
<itunes:author>Redazione Ondarossa</itunes:author>
|
||||||
<itunes:duration>00:{{"%02d" | format(duratamin)}}:{{"%02d" | format(duratasec)}}</itunes:duration>
|
<itunes:duration>00:{{"%02d" | format(duratamin)}}:{{"%02d" | format(duratasec)}}</itunes:duration>
|
||||||
<itunes:explicit>no</itunes:explicit>
|
<itunes:explicit>no</itunes:explicit>
|
||||||
<guid>{{ audiourl }}</guid>
|
<guid>{{ audiourl }}</guid>
|
||||||
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{# [fields]
|
{# [fields]
|
||||||
{% for field in node.getFields() %}
|
{% for field in node.getFields() %}
|
||||||
[[ {{ field.getName() }} ]]
|
[[ {{ field.getName() }} ]]
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
[/fields] #}
|
[/fields] #}
|
||||||
</item>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</channel>
|
</channel>
|
||||||
|
|
Loading…
Reference in a new issue