View source
<?php
define('MEDIA_FLICKR_XSPF_CAPTION_TYPE_NONE', 0);
define('MEDIA_FLICKR_XSPF_CAPTION_TYPE_TITLE', 1);
define('MEDIA_FLICKR_XSPF_CAPTION_TYPE_DESCRIPTION', 2);
define('MEDIA_FLICKR_XSPF_CAPTION_TYPE_BOTH', 3);
define('MEDIA_FLICKR_XSPF_CAPTION_TYPE_DESCRIPTION_FALLBACK_TO_TITLE', 4);
function media_flickr_xspf_menu() {
$items = array();
$items['media/flickr/photoset/%media_flickr_photoset/xspf'] = array(
'page callback' => 'media_flickr_xspf_page',
'page arguments' => array(
3,
),
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function media_flickr_xspf_page($photoset, $delay = 10, $width = 0, $height = 0, $captions = MEDIA_FLICKR_XSPF_CAPTION_TYPE_TITLE) {
drupal_set_header('Content-Type: text/xml; charset=utf-8');
$output = array();
$output[] = '<playlist version="1" xmlns="http://xspf.org/ns/0/">';
$info = media_flickr_sets_request('flickr.photosets.getInfo', array(
'photoset_id' => $photoset['id'],
));
$title = $info['photoset']['title']['_content'];
$attributes = array(
'title' => t('@title', array(
'@title' => $title,
)),
);
$output[] = format_xml_elements($attributes) . '<trackList>';
$items = array();
$size = media_flickr_guess_size($width, $height);
$photos = media_flickr_photoset_load_photos($photoset, $size);
foreach ($photoset['photoset']['photo'] as $photoid => $photo) {
switch ($captions) {
case MEDIA_FLICKR_XSPF_CAPTION_TYPE_DESCRIPTION:
$title = t('@description', array(
'@description' => $photo['photo']['description']['_content'],
));
break;
case MEDIA_FLICKR_XSPF_CAPTION_TYPE_BOTH:
$title = t('@title - @description', array(
'@title' => $photo['photo']['title']['_content'],
'@description' => $photo['photo']['description']['_content'],
));
break;
case MEDIA_FLICKR_XSPF_CAPTION_TYPE_NONE:
$title = '';
break;
case MEDIA_FLICKR_XSPF_CAPTION_TYPE_DESCRIPTION_FALLBACK_TO_TITLE:
$title = t('@description', array(
'@description' => $photo['photo']['description']['_content'],
));
if ($title === '') {
$title = t('@title', array(
'@title' => $photo['photo']['title']['_content'],
));
}
break;
case MEDIA_FLICKR_XSPF_CAPTION_TYPE_TITLE:
default:
$title = t('@title', array(
'@title' => $photo['photo']['title']['_content'],
));
break;
}
$url = url($photos[$photoid], array(
'absolute' => TRUE,
));
$items[] = array(
'title' => $title,
'creator' => '',
'location' => $url,
'info' => '',
'image' => $url,
'duration' => $delay,
array(
'key' => 'meta',
'value' => $delay,
'attributes' => array(
'rel' => 'duration',
),
),
);
}
if (!empty($items)) {
foreach ($items as $item) {
$output[] = media_flickr_xspf_item($item);
}
}
$output[] = '</trackList>';
$output[] = '</playlist>';
print implode("\n", $output);
}
function media_flickr_xspf_item($item) {
$output = array();
$output[] = '<track>';
$output[] = format_xml_elements($item) . '</track>';
return implode("\n", $output);
}