basic functionalities working
This commit is contained in:
commit
9c00c08235
4 changed files with 128 additions and 0 deletions
9
podcast_ror.info.yml
Normal file
9
podcast_ror.info.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
name: Podcast per ROR
|
||||||
|
type: module
|
||||||
|
description: 'Podcast specifici per radio ondarossa'
|
||||||
|
core: 8.x
|
||||||
|
version: 0.1
|
||||||
|
package: Ondarossa
|
||||||
|
dependencies:
|
||||||
|
- field
|
||||||
|
- link
|
9
podcast_ror.routing.yml
Normal file
9
podcast_ror.routing.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
podcast_ror.all:
|
||||||
|
path: '/podcast/all.xml'
|
||||||
|
defaults:
|
||||||
|
_controller: '\Drupal\podcast_ror\Controller\PodcastRorController::podcastAll'
|
||||||
|
_title: 'Global podcast'
|
||||||
|
requirements:
|
||||||
|
_access: 'TRUE'
|
||||||
|
options:
|
||||||
|
no_cache: 'TRUE'
|
61
src/Controller/PodcastRorController.php
Normal file
61
src/Controller/PodcastRorController.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
namespace Drupal\podcast_ror\Controller;
|
||||||
|
|
||||||
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Drupal\Core\Template\TwigEnvironment;
|
||||||
|
|
||||||
|
class PodcastRorController extends ControllerBase {
|
||||||
|
protected $state;
|
||||||
|
protected $twig;
|
||||||
|
public function __construct($state, TwigEnvironment $twig) {
|
||||||
|
$this->state = $state;
|
||||||
|
$this->twig = $twig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(ContainerInterface $container) {
|
||||||
|
return new static(
|
||||||
|
$container->get('state'),
|
||||||
|
$container->get('twig')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function query() {
|
||||||
|
//TODO: estrai argomento dall'url
|
||||||
|
$arg = 'ror_news';
|
||||||
|
$query = \Drupal::entityQuery('node');
|
||||||
|
$query
|
||||||
|
->condition('status', '1')
|
||||||
|
->condition('type', $arg)
|
||||||
|
->sort('nid', 'DESC')
|
||||||
|
->range(0, 10);
|
||||||
|
$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...
|
||||||
|
|
||||||
|
$data['audio'] = array();
|
||||||
|
$first = true;
|
||||||
|
foreach($data['nodes'] 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)));
|
||||||
|
$data['audio'][$nid][$ai] = $audio->toArray();
|
||||||
|
}
|
||||||
|
if($first === true) {
|
||||||
|
$first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
public function podcastAll() {
|
||||||
|
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
|
||||||
|
$tmpl_data = [ 'ror' => array('podcast' => $this->query()) ];
|
||||||
|
$xml = $template->render($tmpl_data);
|
||||||
|
$resp = new Response($xml, 200, array(
|
||||||
|
'Content-Type' => 'application/rss+xml'));
|
||||||
|
return $resp;
|
||||||
|
}
|
||||||
|
}
|
49
templates/podcast.html.twig
Normal file
49
templates/podcast.html.twig
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title>Radio Onda Rossa</title>
|
||||||
|
<language>it-it</language>
|
||||||
|
<itunes:subtitle>La radio di chi se la sente</itunes:subtitle>
|
||||||
|
<itunes:author>Ondarossa</itunes:author>
|
||||||
|
<itunes:summary>Podcast completo</itunes:summary>
|
||||||
|
<description>Tutti gli aggiornamenti, i redazionali, le trasmissioni della radio di chi se la sente</description>
|
||||||
|
<itunes:owner>
|
||||||
|
<itunes:name>Ondarossa</itunes:name>
|
||||||
|
<itunes:email>ondarossa@ondarossa.info</itunes:email>
|
||||||
|
</itunes:owner>
|
||||||
|
<itunes:explicit>no</itunes:explicit>
|
||||||
|
<itunes:image href="http://www.ondarossa.info/favicon.ico" />
|
||||||
|
<itunes:category text="News & Politics"/>
|
||||||
|
|
||||||
|
{% for nid, node in ror.podcast.nodes %}
|
||||||
|
<item>
|
||||||
|
{% 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 %}
|
||||||
|
<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#}
|
||||||
|
|
||||||
|
{# 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>
|
||||||
|
<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>
|
||||||
|
{% endfor %}
|
||||||
|
{# [fields]
|
||||||
|
{% for field in node.getFields() %}
|
||||||
|
[[ {{ field.getName() }} ]]
|
||||||
|
{% endfor %}
|
||||||
|
[/fields] #}
|
||||||
|
</item>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</channel>
|
||||||
|
</rss>
|
Loading…
Reference in a new issue