You are here

function media_flickr_xspf_page in Media: Flickr 6

Page callback for /media/flickr/[photoset]/xspf.

Displays an XSPF playlist for the photoset.

1 string reference to 'media_flickr_xspf_page'
media_flickr_xspf_menu in contrib/media_flickr_xspf/media_flickr_xspf.module
Implementation of hook_menu().

File

contrib/media_flickr_xspf/media_flickr_xspf.module, line 44
Create Flickr playlists for the Media: Flickr module, for use with the JW Image Rotator file.

Code

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

    // media_flickr_photo_load($photoid);
    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) {

      // Add another item.
      $output[] = media_flickr_xspf_item($item);
    }
  }
  $output[] = '</trackList>';
  $output[] = '</playlist>';
  print implode("\n", $output);
}