diff --git a/src/Controller/PodcastRorController.php b/src/Controller/PodcastRorController.php index 3633ee4..be633ee 100644 --- a/src/Controller/PodcastRorController.php +++ b/src/Controller/PodcastRorController.php @@ -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')); diff --git a/templates/podcast.html.twig b/templates/podcast.html.twig index 6fc053c..ed88c84 100644 --- a/templates/podcast.html.twig +++ b/templates/podcast.html.twig @@ -1,7 +1,9 @@ - + + Radio Onda Rossa +http://www.ondarossa.info it-it La radio di chi se la sente Ondarossa @@ -16,33 +18,36 @@ {% for nid, node in ror.podcast.nodes %} - + {% set num_audios = ror.podcast.audio[nid]|length %} {% for num, audio in ror.podcast.audio[nid] %} + {% 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 %} - {{node.getTitle()}} - Description of podcast episode content - {{ node.get('body').getValue().0.value }} - http://example.com/podcast-1 {# node.getLink#} + {% if num_audios > 1 %} + {{node.title.0.value}} ({{num+1}}/{{num_audios}}) + {% else %} + {{node.title.0.value}} + {% endif %} + {{ node.summary | raw }} + {{ node.body.0.value }} + http://www.ondarossa.info{{node.path.0.alias}} - {# TODO: detect ogg/mp3 #} - - {# TODO: formatta pubDate #} - Thu, 21 Dec 2016 16:01:07 +0000 + + {{ "@#{node.created.0.value}" | date("r") }} Redazione Ondarossa 00:{{"%02d" | format(duratamin)}}:{{"%02d" | format(duratasec)}} no {{ audiourl }} + {% endfor %} {# [fields] - {% for field in node.getFields() %} - [[ {{ field.getName() }} ]] - {% endfor %} + {% for field in node.getFields() %} + [[ {{ field.getName() }} ]] + {% endfor %} [/fields] #} - {% endfor %}