| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: audio_feeds.feeds.inc,v 1.4 2009/11/25 19:33:13 drewish Exp $ 3 4 /** 5 * @file 6 * This file provides various XML feeds for audio media. 7 */ 8 9 /** 10 * Menu Callback to generate M3U feed 11 */ 12 function audio_feeds_m3u($node) { 13 $items = array(); 14 15 // prepare feed metadata 16 $metadata = array('title' => $node->title); 17 18 // prepare feed items 19 $children = audio_feeds_children($node); 20 foreach ($children as $audio) { 21 $items[] = array( 22 'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title, 23 'author' => $audio->audio_tags['artist'], 24 'duration' => $audio->audio_file['playtime'], 25 'enclosure' => array('url' => $audio->url_play), 26 ); 27 } 28 audio_feeds_generate_m3u($items, $metadata); 29 } 30 31 /** 32 * Return XML for M3U feed 33 */ 34 function audio_feeds_generate_m3u($items = array(), $metadata = array()) { 35 $output = "#EXTM3U\r\n"; 36 foreach ($items as $item) { 37 $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title']; 38 $output .= "#EXTINF:". check_plain($item['duration']) .",". check_plain($title) ."\r\n"; 39 $output .= check_plain($item['enclosure']['url']) ."\r\n"; 40 } 41 drupal_set_header("Pragma: no-cache"); // HTTP/1.0 42 drupal_set_header("Cache-Control: private"); // HTTP/1.1 43 drupal_set_header("Content-Type: audio/mpegurl", TRUE); 44 drupal_set_header("Content-Length: ". strlen($output), TRUE); 45 drupal_set_header("Content-Disposition: attachment; filename=\"". check_plain($metadata['title']) .".m3u\"", TRUE); 46 print $output; 47 exit(); 48 } 49 50 /** 51 * Menu Callback to generate PLS feed 52 */ 53 function audio_feeds_pls($node) { 54 $items = array(); 55 56 // prepare feed metadata 57 $metadata = array('title' => $node->title); 58 59 // prepare feed items 60 $children = audio_feeds_children($node); 61 foreach ($children as $audio) { 62 $items[] = array( 63 'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title, 64 'author' => $audio->audio_tags['artist'], 65 'duration' => $audio->audio_file['playtime'], 66 'enclosure' => array('url' => $audio->url_play), 67 ); 68 } 69 audio_feeds_generate_pls($items, $metadata); 70 } 71 72 /** 73 * Return XML for PLS feed 74 */ 75 function audio_feeds_generate_pls($items = array(), $metadata = array()) { 76 $output = "[playlist]\r\n"; 77 $i = 1; 78 foreach ($items as $item) { 79 $title = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title']; 80 $output .= "File$i=". check_plain($item['enclosure']['url']) ."\r\n"; 81 $output .= "Title$i=". check_plain($title) ."\r\n"; 82 $output .= "Length$i=". check_plain($item['duration']) ."\r\n"; 83 $i++; 84 } 85 $output .= "NumberOfEntries=". count($items) ."\r\n"; 86 $output .= "Version=2\r\n"; 87 drupal_set_header("Pragma: no-cache"); // HTTP/1.0 88 drupal_set_header("Cache-Control: private"); // HTTP/1.1 89 drupal_set_header("Content-Type: audio/x-scpls", TRUE); 90 drupal_set_header("Content-Length: ". strlen($output), TRUE); 91 drupal_set_header("Content-Disposition: attachment; filename=\"". check_plain($metadata['title']) .".pls\"", TRUE); 92 print $output; 93 exit(); 94 } 95 96 /** 97 * Menu Callback to generate XSPF feed 98 */ 99 function audio_feeds_xspf($node) { 100 global $base_url; 101 $children = audio_feeds_children($node); 102 103 // prepare feed metadata 104 $metadata = array( 105 'title' => $node->title, 106 'author' => $node->name, 107 'link' => url('node/'. $node->nid, array('absolute' => TRUE)), 108 'feed_url' => url('node/'. $node->nid .'/xspf', array('absolute' => TRUE)), 109 //'copyright' => $node->playlist_info['copyright'] 110 ); 111 112 // prepare feed items 113 $items = array(); 114 foreach ($children as $audio) { 115 // use the first image uploaded as the included image 116 $image = is_array($audio->audio_images) ? current($audio->audio_images) : ''; 117 $items[] = array( 118 'title' => $audio->audio_tags['title'] ? $audio->audio_tags['title'] : $audio->title, 119 'author' => $audio->audio_tags['artist'], 120 'album' => $audio->audio_tags['album'], 121 'duration' => $audio->audio_file['playtime'], 122 'link' => url('node/'. $audio->nid, array('absolute' => TRUE)), 123 'image' => array('url' => $base_url .'/'. $image['filepath']), 124 'enclosure' => array('url' => $audio->url_play), 125 ); 126 } 127 audio_feeds_generate_xspf($items, $metadata); 128 } 129 130 /** 131 * Return XML for XSPF feed 132 */ 133 function audio_feeds_generate_xspf($items = array(), $metadata = array()) { 134 $output = '<?xml version="1.0" encoding="UTF-8"?>'; 135 $output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">'; 136 $output .= "<title>". check_plain($metadata['title']) ."</title>"; 137 $output .= "<annotation>". check_plain($metadata['author']) ."</annotation>"; 138 $output .= "<creator>". check_plain($metadata['author']) ."</creator>"; 139 $output .= "<info>". check_plain($metadata['link']) ."</info>"; 140 $output .= "<location>". check_plain($metadata['feed_url']) ."</location>"; 141 $output .= "<license>". check_plain($metadata['copyright']) ."</license>"; 142 $output .= '<trackList>'; 143 foreach ($items as $item) { 144 $output .= '<track>'; 145 $output .= "<location>". check_plain($item['enclosure']['url']) ."</location>"; 146 $output .= "<creator>". check_plain($item['author']) ."</creator>"; 147 $output .= "<album>". check_plain($item['album']) ."</album>"; 148 $output .= "<title>". check_plain($item['title']) ."</title>"; 149 $annotation = $item['author'] ? $item['author'] ." - ". $item['title'] : $item['title']; 150 $output .= "<annotation>". check_plain($annotation) ."</annotation>"; 151 $output .= "<duration>". check_plain($item['duration']) ."</duration>"; 152 $output .= "<image>". check_plain($item['image']['url']) ."</image>"; 153 $output .= "<info>". check_plain($item['link']) ."</info>"; 154 $output .= '</track>'; 155 } 156 $output .= ' </trackList>'; 157 $output .= '</playlist>'; 158 159 // hopefully fixing 212913, i suspect nul's are making this choke 160 // remove any nul characters 161 $output = str_replace("\0", '', $output); 162 163 drupal_set_header('Content-Type: text/xml; charset=utf-8'); 164 print $output; 165 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_play($child)) { 187 $children[] = $child; 188 } 189 } 190 } 191 } 192 193 return $children; 194 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |