/[drupal]/contributions/modules/audio/contrib/feeds/audio_feeds.feeds.inc
ViewVC logotype

Diff of /contributions/modules/audio/contrib/feeds/audio_feeds.feeds.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Thu Sep 25 23:18:08 2008 UTC revision 1.2, Mon Sep 14 04:40:57 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: feeds.inc,v 1.5 2008/02/26 08:51:54 zirafa Exp $  // $Id: audio_feeds.feeds.inc,v 1.1 2008/09/25 23:18:08 drewish Exp $
3    
4  /**  /**
5   * @file   * @file
6   * This file provides various XML feeds for audio media.   * This file provides various XML feeds for audio media.
7   */   */
8    
   
9  /**  /**
10   * Menu Callback to generate M3U feed   * Menu Callback to generate M3U feed
11   */   */
# Line 16  function audio_feeds_m3u($node) { Line 16  function audio_feeds_m3u($node) {
16    $metadata = array('title' => $node->title);    $metadata = array('title' => $node->title);
17    
18    // prepare feed items    // prepare feed items
19    $children = $node->audio_attach;    $children = audio_feeds_children($node);
20    foreach ($children as $child) {    foreach ($children as $audio) {
21      $audio = node_load($child);      $items[] = array(
22      if (node_access('view', $audio)) {        'title' => $audio->audio_tags['title'],
23        $items[] = array(        'author' => $audio->audio_tags['artist'],
24          'title' => $audio->audio_tags['title'],        'duration' => $audio->audio_file['playtime'],
25          'author' => $audio->audio_tags['artist'],        'enclosure' => array('url' => $audio->url_play),
26          'duration' => $audio->audio_file['playtime'],      );
         'enclosure' => array('url' => $audio->url_play),  
       );  
     }  
27    }    }
28    audio_feeds_generate_m3u($items, $metadata);    audio_feeds_generate_m3u($items, $metadata);
29  }  }
30    
31  /**  /**
32    * Return XML for M3U feed   * Return XML for M3U feed
33    */   */
34  function audio_feeds_generate_m3u($items = array(), $metadata = array()) {  function audio_feeds_generate_m3u($items = array(), $metadata = array()) {
35    $output = "#EXTM3U\r\n";    $output = "#EXTM3U\r\n";
36    foreach ($items as $item) {    foreach ($items as $item) {
37        $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];      $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];
38        $output .= "#EXTINF:". check_plain($item['duration']) .",". check_plain($title) ."\r\n";      $output .= "#EXTINF:". check_plain($item['duration']) .",". check_plain($title) ."\r\n";
39        $output .= check_plain($item['enclosure']['url']) ."\r\n";      $output .= check_plain($item['enclosure']['url']) ."\r\n";
40    }    }
41    drupal_set_header("Pragma: no-cache"); // HTTP/1.0    drupal_set_header("Pragma: no-cache"); // HTTP/1.0
42    drupal_set_header("Cache-Control: private"); // HTTP/1.1    drupal_set_header("Cache-Control: private"); // HTTP/1.1
# Line 60  function audio_feeds_pls($node) { Line 57  function audio_feeds_pls($node) {
57    $metadata = array('title' => $node->title);    $metadata = array('title' => $node->title);
58    
59    // prepare feed items    // prepare feed items
60    $children = $node->audio_attach;    $children = audio_feeds_children($node);
61    foreach ($children as $child) {    foreach ($children as $audio) {
62      $audio = node_load($child);      $items[] = array(
63      if (node_access('view', $audio)) {        'title' => $audio->audio_tags['title'],
64        $items[] = array(        'author' => $audio->audio_tags['artist'],
65          'title' => $audio->audio_tags['title'],        'duration' => $audio->audio_file['playtime'],
66          'author' => $audio->audio_tags['artist'],        'enclosure' => array('url' => $audio->url_play),
67          'duration' => $audio->audio_file['playtime'],      );
         'enclosure' => array('url' => $audio->url_play),  
       );  
     }  
68    }    }
69    audio_feeds_generate_pls($items, $metadata);    audio_feeds_generate_pls($items, $metadata);
70  }  }
71    
72  /**  /**
73    * Return XML for PLS feed   * Return XML for PLS feed
74    */   */
75  function audio_feeds_generate_pls($items = array(), $metadata = array()) {  function audio_feeds_generate_pls($items = array(), $metadata = array()) {
76    $output = "[playlist]\r\n";    $output = "[playlist]\r\n";
77    $i = 1;    $i = 1;
78    foreach ($items as $item) {    foreach ($items as $item) {
79        $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];      $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];
80        $output .= "File$i=". check_plain($item['enclosure']['url']) ."\r\n";      $output .= "File$i=". check_plain($item['enclosure']['url']) ."\r\n";
81        $output .= "Title$i=". check_plain($title) ."\r\n";      $output .= "Title$i=". check_plain($title) ."\r\n";
82        $output .= "Length$i=". check_plain($item['duration']) ."\r\n";      $output .= "Length$i=". check_plain($item['duration']) ."\r\n";
83        $i++;      $i++;
84    }    }
85    $output .= "NumberOfEntries=". count($items) ."\r\n";    $output .= "NumberOfEntries=". count($items) ."\r\n";
86    $output .= "Version=2\r\n";    $output .= "Version=2\r\n";
# Line 104  function audio_feeds_generate_pls($items Line 98  function audio_feeds_generate_pls($items
98   */   */
99  function audio_feeds_xspf($node) {  function audio_feeds_xspf($node) {
100    global $base_url;    global $base_url;
101    $children = $node->audio_attach;    $children = audio_feeds_children($node);
102    
103    // prepare feed metadata    // prepare feed metadata
104    $metadata = array(    $metadata = array(
# Line 117  function audio_feeds_xspf($node) { Line 111  function audio_feeds_xspf($node) {
111    
112    // prepare feed items    // prepare feed items
113    $items = array();    $items = array();
114    foreach ($children as $child) {    foreach ($children as $audio) {
115      $audio = node_load($child);      // use the first image uploaded as the included image
116      if (node_access('view', $audio)) {      $image = is_array($audio->audio_images) ? current($audio->audio_images) : '';
117        // use the first image uploaded as the included image      $items[] = array(
118        $image = is_array($audio->audio_images) ? current($audio->audio_images) : '';        'title' => $audio->audio_tags['title'],
119        $items[] = array(        'author' => $audio->audio_tags['artist'],
120          'title' => $audio->audio_tags['title'],        'album' => $audio->audio_tags['album'],
121          'author' => $audio->audio_tags['artist'],        'duration' => $audio->audio_file['playtime'],
122          'album' => $audio->audio_tags['album'],        'link' => url('node/'. $audio->nid, array('absolute' => TRUE)),
123          'duration' => $audio->audio_file['playtime'],        'image' => array('url' => $base_url .'/'. $image['filepath']),
124          'link' => url('node/'. $audio->nid, array('absolute' => TRUE)),        'enclosure' => array('url' => $audio->url_play),
125          'image' => array('url' => $base_url .'/'. $image['filepath']),      );
         'enclosure' => array('url' => $audio->url_play),  
       );  
     }  
126    }    }
127    audio_feeds_generate_xspf($items, $metadata);    audio_feeds_generate_xspf($items, $metadata);
128  }  }
129    
130  /**  /**
131    * Return XML for XSPF feed   * Return XML for XSPF feed
132    */   */
133  function audio_feeds_generate_xspf($items = array(), $metadata = array()) {  function audio_feeds_generate_xspf($items = array(), $metadata = array()) {
134    $output = '<?xml version="1.0" encoding="UTF-8"?>';    $output = '<?xml version="1.0" encoding="UTF-8"?>';
135    $output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">';    $output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">';
# Line 150  function audio_feeds_generate_xspf($item Line 141  function audio_feeds_generate_xspf($item
141    $output .= "<license>". check_plain($metadata['copyright']) ."</license>";    $output .= "<license>". check_plain($metadata['copyright']) ."</license>";
142    $output .= '<trackList>';    $output .= '<trackList>';
143    foreach ($items as $item) {    foreach ($items as $item) {
144        $output .= '<track>';      $output .= '<track>';
145        $output .= "<location>". check_plain($item['enclosure']['url']) ."</location>";      $output .= "<location>". check_plain($item['enclosure']['url']) ."</location>";
146        $output .= "<creator>". check_plain($item['author']) ."</creator>";      $output .= "<creator>". check_plain($item['author']) ."</creator>";
147        $output .= "<album>". check_plain($item['album']) ."</album>";      $output .= "<album>". check_plain($item['album']) ."</album>";
148        $output .= "<title>". check_plain($item['title']) ."</title>";      $output .= "<title>". check_plain($item['title']) ."</title>";
149        $annotation = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];      $annotation = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title'];
150        $output .= "<annotation>". check_plain($annotation) ."</annotation>";      $output .= "<annotation>". check_plain($annotation) ."</annotation>";
151        $output .= "<duration>". check_plain($item['duration']) ."</duration>";      $output .= "<duration>". check_plain($item['duration']) ."</duration>";
152        $output .= "<image>". check_plain($item['image']['url']) ."</image>";      $output .= "<image>". check_plain($item['image']['url']) ."</image>";
153        $output .= "<info>". check_plain($item['link']) ."</info>";      $output .= "<info>". check_plain($item['link']) ."</info>";
154        $output .= '</track>';      $output .= '</track>';
155    }    }
156    $output .= '  </trackList>';    $output .= '  </trackList>';
157    $output .= '</playlist>';    $output .= '</playlist>';
# Line 172  function audio_feeds_generate_xspf($item Line 163  function audio_feeds_generate_xspf($item
163    drupal_set_header('Content-Type: text/xml; charset=utf-8');    drupal_set_header('Content-Type: text/xml; charset=utf-8');
164    print $output;    print $output;
165    exit();    exit();
166    }
167    
168    /**
169     * Get the attached audio nodes.
170     *
171     * @param object $node
172     *   The node whose audio nodes are to be retrieved.
173     * @return
174     *   An array containing all the audio nodes attached to a given node.
175     */
176    function audio_feeds_children($node) {
177      $children = array();
178    
179      // Find all nodereferences.
180      $fields = content_fields(NULL, $node->type);
181      foreach ($fields as $field_name => $field) {
182        if ($field['type'] == 'nodereference' && is_array($node->{$field_name})) {
183          foreach ($node->{$field_name} as $item) {
184            // Keep only those references that are actually accessible and
185            // downloadable audio nodes.
186            if (($child = node_load($item['nid'])) && node_access('view', $child) && _audio_allow_download($child)) {
187              $children[] = $child;
188            }
189          }
190        }
191      }
192    
193      return $children;
194  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2