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

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

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

revision 1.4 by zirafa, Tue Jan 22 19:39:30 2008 UTC revision 1.5 by drewish, Sun May 25 17:21:27 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: audio_feeds.module,v 1.3 2007/08/03 02:41:13 drewish Exp $  // $Id: audio_feeds.module,v 1.4 2008/01/22 19:39:30 zirafa Exp $
3  /**  /**
4   * @file   * @file
5   * This module provides XSPF, M3U, and PLS feeds for a list of audio files.   * This module provides XSPF, M3U, and PLS feeds for a list of audio files.
6   */   */
7    
   
8  include(drupal_get_path('module', 'audio_feeds') .'/feeds.inc');  include(drupal_get_path('module', 'audio_feeds') .'/feeds.inc');
9    
10  if (module_exists('views')) {  if (module_exists('views')) {
11    include(drupal_get_path('module', 'audio_feeds') .'/audio_feeds_views.inc');    include(drupal_get_path('module', 'audio_feeds') .'/audio_feeds_views.inc');
12  }  }
13    
   
14  /**  /**
15   * Implementation of hook_help().   * Implementation of hook_help().
16   */   */
17  function audio_feeds_help($section) {  function audio_feeds_help($section, $arg) {
18    switch ($section) {    switch ($section) {
19      case 'admin/help#audio_feeds':      case 'admin/help#audio_feeds':
20        return t('This module creates XSPF, M3U, and PLS audio feeds.');        return t('This module creates XSPF, M3U, and PLS audio feeds.');
# Line 26  function audio_feeds_help($section) { Line 24  function audio_feeds_help($section) {
24  /**  /**
25   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
26   */   */
27  function audio_feeds_form_alter($form_id, &$form) {  function audio_feeds_form_alter(&$form, &$form_state, $form_id) {
28    global $user;    global $user;
29    
30    switch ($form_id) {    switch ($form_id) {
31      case 'node_type_form':      case 'node_type_form':
32        if(isset($form['identity']['type']) && module_exists('audio_attach')) {        if (isset($form['identity']['type']) && module_exists('audio_attach')) {
33          $type = $form['#node_type']->type;          $type = $form['#node_type']->type;
34            $form['workflow']['audio_feeds_attach'] = array(          $form['workflow']['audio_feeds_attach'] = array(
35              '#type' => 'radios',            '#type' => 'radios',
36              '#title' => t('Audio Feeds'),            '#title' => t('Audio Feeds'),
37              '#default_value' => variable_get('audio_feeds_attach_'. $type, 0),            '#default_value' => variable_get('audio_feeds_attach_'. $type, 0),
38              '#options' => array(t('Disabled'), t('Enabled')),            '#options' => array(t('Disabled'), t('Enabled')),
39              '#description' => t('Should users be allowed to create XSPF, M3U, and PLS feeds of attached audio files?'),            '#description' => t('Should users be allowed to create XSPF, M3U, and PLS feeds of attached audio files?'),
40            );          );
41        }        }
42        break;        break;
43    }    }
44  }  }
45    
   
46  /**  /**
47   * Implementation of hook_link().   * Implementation of hook_link().
48   */   */
# Line 89  function audio_feeds_link($type, $node = Line 86  function audio_feeds_link($type, $node =
86    return $links;    return $links;
87  }  }
88    
   
89  /**  /**
90   * Implementation of hook_menu().   * Implementation of hook_menu().
91   */   */
92  function audio_feeds_menu($may_cache) {  function audio_feeds_menu() {
93    global $user;    // FIXME: This snippet isn't preserved by this new menu code:
94      // if (variable_get('audio_feeds_attach_'. $node->type, 0)) {
95    $items = array();    $items = array();
96    
97    if ($may_cache) {    $items['node/%node/xspf'] = array(
98        'title' => 'XSPF',
99    }      'page callback' => 'audio_feeds_xspf',
100    else if (arg(0) == 'node' && is_numeric(arg(1)) && module_exists('audio_attach')) {      'page arguments' => array(1),
101      $node = node_load(arg(1));      'type' => MENU_CALLBACK,
102      if (variable_get('audio_feeds_attach_'. $node->type, 0)) {    );
103        $items[] = array('path' => 'node/'. arg(1) .'/xspf',    $items['node/%node/m3u'] = array(
104          'title' => t('XSPF'),      'title' => 'M3U',
105          'type' => MENU_CALLBACK,      'page callback' => 'audio_feeds_m3u',
106          'callback' => 'audio_feeds_xspf',      'page arguments' => array(1),
107          'callback arguments' => arg(1)      'type' => MENU_CALLBACK,
108        );    );
109        $items[] = array('path' => 'node/'. arg(1) .'/m3u',    $items['node/%node/pls'] = array(
110          'title' => t('M3U'),      'title' => 'PLS',
111          'type' => MENU_CALLBACK,      'page callback' => 'audio_feeds_pls',
112          'callback' => 'audio_feeds_m3u',      'page arguments' => array(1),
113          'callback arguments' => arg(1)      'type' => MENU_CALLBACK,
114        );    );
       $items[] = array('path' => 'node/'. arg(1) .'/pls',  
         'title' => t('PLS'),  
         'type' => MENU_CALLBACK,  
         'callback' => 'audio_feeds_pls',  
         'callback arguments' => arg(1)  
       );  
     }  
   }  
115    
116    return $items;    return $items;
117  }  }
118    
   
   
   
119  /**  /**
120    * Menu Callback to generate M3U feed   * Menu Callback to generate M3U feed
121    */   */
122  function audio_feeds_m3u($nid) {  function audio_feeds_m3u($node) {
123    $items = array();    $items = array();
   $node = node_load($nid);  
124    
125    // prepare feed metadata    // prepare feed metadata
126    $metadata = array('title' => $node->title);    $metadata = array('title' => $node->title);
# Line 145  function audio_feeds_m3u($nid) { Line 130  function audio_feeds_m3u($nid) {
130    foreach ($children as $child) {    foreach ($children as $child) {
131      $audio = node_load($child);      $audio = node_load($child);
132      if (node_access('view', $audio)) {      if (node_access('view', $audio)) {
133        $items[] = array('title' => $audio->audio_tags['title'],        $items[] = array(
134                         'author' => $audio->audio_tags['artist'],          'title' => $audio->audio_tags['title'],
135                         'duration' => $audio->audio_file['playtime'],          'author' => $audio->audio_tags['artist'],
136                         'enclosure' => array('url' => $audio->url_play)          'duration' => $audio->audio_file['playtime'],
137                         );          'enclosure' => array('url' => $audio->url_play),
138          );
139      }      }
140    }    }
141    audio_feeds_generate_m3u($items, $metadata);    audio_feeds_generate_m3u($items, $metadata);
142  }  }
143    
   
144  /**  /**
145    *  Menu Callback to generate PLS feed   * Menu Callback to generate PLS feed
146    */   */
147  function audio_feeds_pls($nid) {  function audio_feeds_pls($node) {
148    $items = array();    $items = array();
   $node = node_load($nid);  
149    
150    // prepare feed metadata    // prepare feed metadata
151    $metadata = array('title' => $node->title);    $metadata = array('title' => $node->title);
# Line 171  function audio_feeds_pls($nid) { Line 155  function audio_feeds_pls($nid) {
155    foreach ($children as $child) {    foreach ($children as $child) {
156      $audio = node_load($child);      $audio = node_load($child);
157      if (node_access('view', $audio)) {      if (node_access('view', $audio)) {
158        $items[] = array('title' => $audio->audio_tags['title'],        $items[] = array(
159                         'author' => $audio->audio_tags['artist'],          'title' => $audio->audio_tags['title'],
160                         'duration' => $audio->audio_file['playtime'],          'author' => $audio->audio_tags['artist'],
161                         'enclosure' => array('url' => $audio->url_play)          'duration' => $audio->audio_file['playtime'],
162                         );          'enclosure' => array('url' => $audio->url_play),
163          );
164      }      }
165    }    }
166    audio_feeds_generate_pls($items, $metadata);    audio_feeds_generate_pls($items, $metadata);
167  }  }
168    
169  /**  /**
170    *  Menu Callback to generate XSPF feed   * Menu Callback to generate XSPF feed
171    */   */
172  function audio_feeds_xspf($nid) {  function audio_feeds_xspf($node) {
173    global $base_url;    global $base_url;
   $node = node_load($nid);  
174    $children = $node->audio_attach;    $children = $node->audio_attach;
175    
176    // prepare feed metadata    // prepare feed metadata
177    $metadata = array('title' =>$node->title,    $metadata = array(
178                      'author' => $node->name,      'title' => $node->title,
179                      'link' => url('node/'.$node->nid, NULL,NULL, TRUE),      'author' => $node->name,
180                      'feed_url' => url('node/'.$node->nid.'/xspf', NULL,NULL, TRUE)      'link' => url('node/'. $node->nid, array('absolute' => TRUE)),
181                      );      'feed_url' => url('node/'. $node->nid .'/xspf', array('absolute' => TRUE)),
182                      //'copyright' => $node->playlist_info['copyright']      //'copyright' => $node->playlist_info['copyright']
183      );
184    
185    // prepare feed items    // prepare feed items
186    $items = array();    $items = array();
# Line 204  function audio_feeds_xspf($nid) { Line 189  function audio_feeds_xspf($nid) {
189      if (node_access('view', $audio)) {      if (node_access('view', $audio)) {
190        // use the first image uploaded as the included image        // use the first image uploaded as the included image
191        $image = is_array($audio->audio_images) ? current($audio->audio_images) : '';        $image = is_array($audio->audio_images) ? current($audio->audio_images) : '';
192        $items[] = array('title' => $audio->audio_tags['title'],        $items[] = array(
193                         'author' => $audio->audio_tags['artist'],          'title' => $audio->audio_tags['title'],
194                         'album' => $audio->audio_tags['album'],          'author' => $audio->audio_tags['artist'],
195                         'duration' => $audio->audio_file['playtime'],          'album' => $audio->audio_tags['album'],
196                         'link' => url('node/'.$audio->nid, NULL,NULL, TRUE),          'duration' => $audio->audio_file['playtime'],
197                         'image' => array('url' => $base_url .'/'. $image['filepath']),          'link' => url('node/'. $audio->nid, array('absolute' => TRUE)),
198                         'enclosure' => array('url' => $audio->url_play)          'image' => array('url' => $base_url .'/'. $image['filepath']),
199                         );          'enclosure' => array('url' => $audio->url_play),
200          );
201      }      }
202    }    }
203    audio_feeds_generate_xspf($items, $metadata);    audio_feeds_generate_xspf($items, $metadata);

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.3