| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: audio.pages.inc,v 1.2 2008/10/02 18:03:44 drewish Exp $ 3 4 5 /** 6 * Provide a way to browse the audio by metadata. 7 * 8 * @param $tag 9 * ID3 tag name. 10 * @param $value 11 * Value of the tag. It'll be "cleaned" of non-alphanumeric values characters 12 * comparing it. 13 */ 14 function audio_page_browse_by($tag = NULL, $value = NULL) { 15 $output = ''; 16 $breadcrumb = array(l(t('Audio'), 'audio')); 17 18 if (isset($tag)) { 19 $breadcrumb[] = l(t('Browse by'), 'audio/by'); 20 21 if (isset($value)) { 22 $breadcrumb[] = l(t('@tag', array('@tag' => $tag)), 'audio/by/'. $tag); 23 24 $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, a.tag, a.value FROM {node} n INNER JOIN {audio_metadata} a ON n.vid = a.vid WHERE a.tag = '%s' AND a.clean = '%s' AND n.status = 1 ORDER BY n.created ASC"), $tag, audio_clean_tag($value)); 25 while ($obj = db_fetch_object($result)) { 26 if ($node = node_load($obj->nid)) { 27 $output .= node_view($node, TRUE); 28 } 29 } 30 } 31 else { 32 $items = array(); 33 $result = db_query(db_rewrite_sql("SELECT a.value, a.clean, COUNT(a.clean) AS count FROM {node} n INNER JOIN {audio_metadata} a ON n.vid = a.vid WHERE a.tag = '%s' AND n.status = 1 GROUP BY a.value, a.clean ORDER BY a.value ASC"), $tag); 34 while ($obj = db_fetch_object($result)) { 35 $items[] = l($obj->value, "audio/by/{$tag}/{$obj->clean}") ." ({$obj->count})"; 36 } 37 $output = theme('item_list', $items); 38 } 39 } 40 else { 41 $items = array(); 42 $settings = audio_get_tag_settings(); 43 $result = db_query(db_rewrite_sql('SELECT DISTINCT a.tag FROM {node} n INNER JOIN {audio_metadata} a ON n.vid = a.vid WHERE n.status = 1 ORDER BY a.tag ASC')); 44 while ($obj = db_fetch_object($result)) { 45 if ($settings[$obj->tag]['browsable']) { 46 $items[] = l($obj->tag, 'audio/by/'. $obj->tag); 47 } 48 } 49 $output = theme('item_list', $items); 50 } 51 52 drupal_set_breadcrumb($breadcrumb); 53 54 return $output; 55 } 56 57 58 /** 59 * Fetches an audio file, allows "shorthand" urls such of the form: 60 * audio/view/$nid (e.g. audio/download/25/ or audio/download/14) 61 * 62 * @param $nid 63 * Node ID. 64 */ 65 function audio_download($node) { 66 // Increment the play count. 67 db_query('UPDATE {audio} SET download_count = download_count + 1 WHERE vid = %d', $node->vid); 68 69 // Downloading counts as "viewing" the node. 70 node_tag_new($node->nid); 71 72 // Notify other modules. 73 audio_invoke_audioapi('download', $node); 74 75 // The mime_header_encode function does not (yet) support 76 // quoted-string encoding of ASCII strings with special 77 // characters. See discussion at http://drupal.org/node/82614 78 $filename = $node->audio['file']->filename; 79 // If the string contains non-ASCII characters, process it through 80 // the mime_header_encode function. 81 if (preg_match('/[^\x20-\x7E]/', $filename)) { 82 $filename = mime_header_encode($filename); 83 } 84 // Otherwise, if the string contains special characters (like 85 // space), perform quoted-string encoding. 86 elseif (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $filename)) { 87 $filename = '"'. str_replace('"', '\"', $filename) .'"'; 88 } 89 $headers = array( 90 'Content-Type: '. mime_header_encode($node->audio['file']->filemime), 91 'Content-Length: '. $node->audio['file']->filesize, 92 'Content-Disposition: attachment; filename='. $filename, 93 ); 94 audio_file_transfer($node->audio['file']->filepath, $headers); 95 } 96 97 /** 98 * Similar to audio_download, but for streaming playback instead of download. 99 * 100 * @param $nid 101 * Node ID. 102 */ 103 function audio_play($node = FALSE) { 104 // Increment the play count. 105 db_query('UPDATE {audio} SET play_count = play_count + 1 WHERE vid = %d', $node->vid); 106 107 // Playing counts as "viewing" the node. 108 node_tag_new($node->nid); 109 110 // Notify other modules. 111 audio_invoke_audioapi('play', $node); 112 113 $headers = array( 114 'Pragma: public', 115 'Expires: 0', 116 'Cache-Control: must-revalidate, post-check=0, pre-check=0, private', 117 'Content-Type: '. mime_header_encode($node->audio['file']->filemime), 118 'Content-Length: '. $node->audio['file']->filesize, 119 'Content-Disposition: inline;', 120 'Content-Transfer-Encoding: binary', 121 ); 122 // Required for IE, otherwise Content-disposition is ignored. 123 ini_set('zlib.output_compression', 'Off'); 124 audio_file_transfer($node->audio['file']->filepath, $headers); 125 } 126 127 /** 128 * Transfer a file to the client. 129 * 130 * Variation on Drupal's file_transfer() function. The only difference 131 * is that set_time_limit() is called to allow for large files. 132 * 133 * @param $source 134 * String specifying the file to transfer. 135 * @param $headers 136 * An array of http headers to send along with file. 137 */ 138 function audio_file_transfer($source, $headers) { 139 @ob_end_clean(); 140 141 foreach ($headers as $header) { 142 // To prevent HTTP header injection, we delete new lines that are 143 // not followed by a space or a tab. 144 // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 145 $header = preg_replace('/\r?\n(?!\t| )/', '', $header); 146 header($header); 147 } 148 149 $source = file_create_path($source); 150 151 // Transfer file in 1024 byte chunks to save memory usage. 152 if ($fd = fopen($source, 'rb')) { 153 if (!ini_get('safe_mode')) { 154 set_time_limit(0); 155 } 156 while (!feof($fd)) { 157 print fread($fd, 1024); 158 } 159 fclose($fd); 160 } 161 else { 162 drupal_not_found(); 163 } 164 exit(); 165 }
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 |