|
@@ -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() {
|