[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/audio/contrib/feeds/ -> audio_feeds.views.inc (source)

   1  <?php
   2  // $Id: audio_feeds.views.inc,v 1.1 2008/09/25 23:18:08 drewish Exp $
   3  
   4  /**
   5   * @file
   6   * This file provides various XML feeds for audio views.
   7   */
   8  
   9  function audio_feeds_views_style_plugins() {
  10    $items = array();
  11    $items['audio_feeds'] = array(
  12      'name' => t('Audio: XSPF/M3U/PLS Playlist'),
  13      'theme' => 'audio_feeds_views_xspf',
  14      'summary_theme' => 'views_summary',
  15    );
  16    return $items;
  17  }
  18  
  19  /**
  20   *  Theme function to handle the XSPF view
  21   */
  22  function theme_audio_feeds_views_xspf($view, $nodes, $type) {
  23    if (isset($_GET['xspf'])) {
  24      return audio_feeds_views_prepare_xspf(views_get_title($view, $type), url($view->real_url, array('absolute' => true)), $nodes);
  25    }
  26    elseif (isset($_GET['m3u'])) {
  27      return theme('audio_feeds_views_m3u', $view, $nodes, $type);
  28    }
  29    elseif (isset($_GET['pls'])) {
  30      return theme('audio_feeds_views_pls', $view, $nodes, $type);
  31    }
  32    else {
  33      $player = audio_get_players('name', variable_get('audio_feeds_default_player', 'xspf_extended'));
  34      $query_string = array();
  35      if ($_GET) {
  36        foreach ($_GET as $key => $value) {
  37          // filter out the standard drupal q string, leaving everything else
  38          if ($key != 'q') {
  39            $query_string[$key] = $value;
  40          }
  41        }
  42      }
  43      $filters = $query_string ? audio_feeds_query_string_encode($query_string) .'%26xspf' : 'xspf';
  44      $playlist_url = url($view->real_url, array('query' => $filters, 'absolute' => TRUE));
  45      $output = theme($player['theme_xspf'], $playlist_url);
  46      $output .= theme('audio_feeds_views_links', $view, $query_string);
  47      return $output;
  48    }
  49  }
  50  
  51  /**
  52   *  Prepare data for XML generation and return the feed
  53   */
  54  function audio_feeds_views_prepare_xspf($title, $url, $nodes) {
  55    global $base_url;
  56  
  57    // prepare feed metadata
  58    $metadata = array(
  59      'title' => $title,
  60      'author' => $base_url,
  61      'link' => $base_url,
  62      'feed_url' => $url
  63    );
  64  
  65    // prepare feed items
  66    foreach ($nodes as $n) {
  67      $audio = node_load($n->nid);
  68      // use the first image uploaded as the included image if it exists
  69      $image = is_array($audio->audio_images) ? current($audio->audio_images) : '';
  70      $items[] = array(
  71        'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title,
  72        'author' => $audio->audio_tags['artist'],
  73        'album' => $audio->audio_tags['album'],
  74        'duration' => $audio->audio_file['playtime'],
  75        'link' => url('node/'. $audio->nid, array('absolute' => TRUE)),
  76        'image' => $image ? array('url' => $base_url .'/'. $image['filepath']) : '',
  77        'enclosure' => array('url' => $audio->url_play)
  78      );
  79    }
  80    audio_feeds_generate_xspf($items, $metadata);
  81  }
  82  
  83  
  84  /**
  85   *  Theme function to handle the M3U view
  86   */
  87  function theme_audio_feeds_views_m3u($view, $nodes, $type) {
  88    return audio_feeds_views_prepare_m3u(views_get_title($view, $type), $nodes);
  89  }
  90  
  91  /**
  92   *  Prepare data for XML generation and return the feed
  93   */
  94  function audio_feeds_views_prepare_m3u($title, $nodes) {
  95  
  96    // prepare feed metadata
  97    $metadata = array('title' => $title);
  98  
  99    // prepare feed items
 100    foreach ($nodes as $n) {
 101      $audio = node_load($n->nid);
 102      $items[] = array(
 103        'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title,
 104        'author' => $audio->audio_tags['artist'],
 105        'duration' => $audio->audio_file['playtime'],
 106        'enclosure' => array('url' => $audio->url_play)
 107      );
 108    }
 109    audio_feeds_generate_m3u($items, $metadata);
 110  }
 111  
 112  
 113  /**
 114   *  Theme function to handle the PLS view
 115   */
 116  function theme_audio_feeds_views_pls($view, $nodes, $type) {
 117    return audio_feeds_views_prepare_pls(views_get_title($view, $type), $nodes);
 118  }
 119  
 120  /**
 121   *  Prepare data for XML generation and return the feed
 122   */
 123  function audio_feeds_views_prepare_pls($title, $nodes) {
 124  
 125    // prepare feed metadata
 126    $metadata = array('title' => $title);
 127  
 128    // prepare feed items
 129    foreach ($nodes as $n) {
 130      $audio = node_load($n->nid);
 131      $items[] = array(
 132        'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title,
 133        'author' => $audio->audio_tags['artist'],
 134        'duration' => $audio->audio_file['playtime'],
 135        'enclosure' => array('url' => $audio->url_play)
 136      );
 137    }
 138    audio_feeds_generate_pls($items, $metadata);
 139  }
 140  
 141  /**
 142   *  Format the links to the xml feeds for the view
 143   */
 144  function theme_audio_feeds_views_links($view, $query_string = null) {
 145    $m3u_filter = $query_string ? drupal_query_string_encode($query_string) .'&m3u' : 'm3u';
 146    $pls_filter = $query_string ? drupal_query_string_encode($query_string) .'&pls' : 'pls';
 147    $xspf_filter = $query_string ? drupal_query_string_encode($query_string) .'&xspf' : 'xspf';
 148  
 149    $links = array();
 150    $links['m3u']['title'] = t('m3u');
 151    $links['m3u']['href'] = url($view->real_url, array('query' => $m3u_filter, 'absolute' => true));
 152    $links['pls']['title'] = t('pls');
 153    $links['pls']['href'] = url($view->real_url, array('query' => $pls_filter, 'absolute' => true));
 154    $links['xspf']['title'] = t('xspf');
 155    $links['xspf']['href'] = url($view->real_url, array('query' => $xspf_filter, 'absolute' => true));
 156    return theme('links', $links);
 157  }
 158  
 159  
 160  /**
 161   * Parse an array into a valid urlencoded query string.
 162   *
 163   * This function is a work-around for a flash url encode issue with views exposed filters
 164   * See: http://drupal.org/node/147888 for details.
 165   *
 166   * @param $query
 167   *   The array to be processed e.g. $_GET.
 168   * @param $exclude
 169   *   The array filled with keys to be excluded. Use parent[child] to exclude
 170   *   nested items.
 171   * @param $parent
 172   *   Should not be passed, only used in recursive calls.
 173   * @return
 174   *   urlencoded string which can be appended to/as the URL query string.
 175   */
 176  function audio_feeds_query_string_encode($query, $exclude = array(), $parent = '') {
 177    $params = array();
 178  
 179    foreach ($query as $key => $value) {
 180      $key = urlencode($key);
 181      if ($parent) {
 182        $key = $parent .'['. $key .']';
 183      }
 184  
 185      if (in_array($key, $exclude)) {
 186        continue;
 187      }
 188  
 189      if (is_array($value)) {
 190        $params[] = audio_feeds_query_string_encode($value, $exclude, $key);
 191      }
 192      else {
 193        $params[] = $key .'='. urlencode($value);
 194      }
 195    }
 196  
 197    return implode('%26', $params);
 198  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7