diff --git a/podcast_ror.routing.yml b/podcast_ror.routing.yml index fb6cceb..bf55e44 100644 --- a/podcast_ror.routing.yml +++ b/podcast_ror.routing.yml @@ -6,7 +6,7 @@ podcast_ror.all: requirements: _access: 'TRUE' options: - no_cache: 'TRUE' + no_cache: 'FALSE' podcast_ror.bytype: path: '/podcast/by-type/{contentType}/podcast.xml' defaults: @@ -15,7 +15,7 @@ podcast_ror.bytype: requirements: _access: 'TRUE' options: - no_cache: 'TRUE' + no_cache: 'FALSE' podcast_ror.bytrxid: path: '/podcast/by-trx-id/{trxID}/podcast.xml' defaults: @@ -24,4 +24,4 @@ podcast_ror.bytrxid: requirements: _access: 'TRUE' options: - no_cache: 'TRUE' + no_cache: 'FALSE' diff --git a/src/Controller/PodcastRorController.php b/src/Controller/PodcastRorController.php index f3d2b11..83dc8e5 100644 --- a/src/Controller/PodcastRorController.php +++ b/src/Controller/PodcastRorController.php @@ -94,18 +94,34 @@ class PodcastRorController extends ControllerBase { public function podcast($query, $description) { // TODO: add $title argument to the function $template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig'); - $tmpl_data = [ 'ror' => array('podcast' => $this->query($query), + $query_results = $this->query($query); + $tmpl_data = [ 'ror' => array('podcast' => $query_results, 'url' => \Drupal::service('path.current')->getPath(), 'description' => $description, 'title' => 'Radio Onda Rossa', )]; - //$variables['ror']['url'] = - $xml = $template->render($tmpl_data); - $resp = new Response($xml, 200, array( + $headers = array( 'Content-Type' => 'application/rss+xml', 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET', - )); + ); + $nodes = $tmpl_data['ror']['podcast']['nodes']; + $lastmodtime = 0; + if( !empty($nodes) ) { + foreach($nodes as $nid => $node) { + $modtime = intval($node['changed'][0]['value']); + if($modtime > $lastmodtime) { + $lastmodtime = $modtime; + } + } + } + $xml = $template->render($tmpl_data); + $resp = new Response($xml, 200, $headers); + $resp->setPublic(); + $resp->setTtl(300); + if($lastmodtime !== 0) { + $resp->setLastModified(\DateTime::createFromFormat('U',$lastmodtime)); + } return $resp; } public function podcastAll() {