/[drupal]/contributions/modules/mediafield_display/mediafield_display.module
ViewVC logotype

Contents of /contributions/modules/mediafield_display/mediafield_display.module

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


Revision 1.7 - (show annotations) (download) (as text)
Mon Jan 28 02:19:18 2008 UTC (21 months, 4 weeks ago) by colan
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +90 -23 lines
File MIME type: text/x-php
#193259: Added support for external audio in link fields
1 <?php
2 // $Id: mediafield_display.module,v 1.6 2008/01/27 06:45:49 colan Exp $
3
4 /**
5 * @file
6 * Provides display handlers for audio fields.
7 *
8 * When enabled, this module enables display alternatives for audio fields
9 * provided by Media Field and link fields containing audio files. These
10 * options are available in CCK field display administration and also in Views
11 * field configuration.
12 */
13
14 /**
15 * Implementation of hook_field_formatter_info().
16 */
17 function mediafield_display_field_formatter_info() {
18 $formatters = array();
19 if (module_exists('audiofield')) {
20 $path = drupal_get_path('module', 'mediafield_display') .'/players/';
21 if (file_exists($path .'1pixelout.swf')) {
22 $formatters['1pixelout'] = array(
23 'label' => t('1 Pixel Out player'),
24 'field types' => array('file_audio', 'link'),
25 );
26 $formatters['1pixelout_plus'] = array(
27 'label' => t('1 Pixel Out player plus download link'),
28 'field types' => array('file_audio'),
29 );
30 }
31 if (file_exists($path .'button.swf')) {
32 $formatters['button'] = array(
33 'label' => t('Button player'),
34 'field types' => array('file_audio', 'link'),
35 );
36 $formatters['button_plus'] = array(
37 'label' => t('Button player plus download link'),
38 'field types' => array('file_audio'),
39 );
40
41 }
42 }
43 return $formatters;
44 }
45
46 /**
47 * Implementation of hook_field_formatter().
48 */
49 function mediafield_display_field_formatter($field, $item, $formatter) {
50 global $base_url;
51
52 switch ($field['type']) {
53 case 'file_audio':
54 require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
55 if (!isset($item['fid']) || empty($item['fid'])) {
56 return '';
57 }
58 $file = _field_file_load($item['fid']);
59 $file_url = check_url($base_url .'/'. $file['filepath']);
60 $file_title = check_plain($file['description']);
61 $attributes = array();
62 $query = $fragment = NULL;
63 break;
64 case 'link':
65 if (empty($item['url']) && ($field['url'] != 'optional' || empty($item['title']))) {
66 return '';
67 }
68
69 $attributes = array();
70 $item['attributes'] = unserialize($item['attributes']);
71 // Add attributes defined at the widget level
72 if (is_array($item['attributes'])) {
73 foreach($item['attributes'] as $attribute => $attbvalue) {
74 if (isset($item['attributes'][$attribute]) && $field['attributes'][$attribute] == 'user') {
75 $attributes[$attribute] = $attbvalue;
76 }
77 }
78 }
79 // Add attributes defined at the field level
80 if (is_array($field['attributes'])) {
81 foreach($field['attributes'] as $attribute => $attbvalue) {
82 if (!empty($attbvalue) && $attbvalue != 'default' && $attbvalue != 'user') {
83 $attributes[$attribute] = $attbvalue;
84 }
85 }
86 }
87
88 // Replace URL tokens
89 if (module_exists('token') && $field['enable_tokens']) {
90 $item['url'] = token_replace($item['url'], 'node', $node);
91 }
92
93 $type = link_validate_url($item['url']);
94 $file_url = $url = link_cleanup_url($item['url']);
95
96 // Separate out the anchor if any
97 if (strpos($url, '#') !== FALSE) {
98 $fragment = substr($url, strpos($url, '#') + 1);
99 $url = substr($url, 0, strpos($url, '#'));
100 }
101 // Separate out the query string if any
102 if (strpos($url, '?') !== FALSE) {
103 $query = substr($url, strpos($url, '?') + 1);
104 $url = substr($url, 0, strpos($url, '?'));
105 }
106
107 // Build the title
108 if (strlen(trim($item['title'])) || ($field['title'] == 'value' && strlen(trim($field['title_value'])))) {
109 // Use the title defined at the field level
110 if ($field['title'] == 'value' && strlen(trim($field['title_value']))) {
111 $file_title = $field['title_value'];
112 }
113 // Use the title defined by the user at the widget level
114 else {
115 $file_title = $item['title'];
116 }
117 // Replace tokens
118 if (module_exists('token') && ($field['title'] == 'value' || $field['enable_tokens'])) {
119 $file_title = token_replace($file_title, 'node', $node);
120 }
121
122 $file_title = check_plain($file_title);
123 }
124
125 break;
126 }
127
128 switch ($formatter) {
129 case '1pixelout':
130 case 'button':
131 $output = theme('mediafield_display_'. $formatter, $file_title, $file_url, $item, $field);
132 break;
133 case '1pixelout_plus':
134 case 'button_plus':
135 $output = theme('mediafield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
136 $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
137 break;
138 }
139
140 return $output;
141 }
142
143 /**
144 * Theme a 1pixelout audio file.
145 */
146 function theme_mediafield_display_1pixelout($file_title, $file_url, $item, $field) {
147 global $base_url;
148
149 // Set the URL for the player.
150 $url = $base_url . '/' . drupal_get_path('module', 'mediafield_display') .
151 '/players/1pixelout.swf';
152
153 // Set some Flash variables.
154 $options = array();
155 $options['soundFile'] = $file_url;
156 $flashvars = drupal_query_string_encode($options);
157
158 // This is a fix for http://drupal.org/node/158687.
159 $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);
160
161 $output = <<<EOT
162 <object type="application/x-shockwave-flash" data="$url" width="290" height="24">
163 <param name="movie" value="$url" />
164 <param name="wmode" value="transparent" />
165 <param name="menu" value="false" />
166 <param name="quality" value="high" />
167 <param name="FlashVars" value="$flashvars" />
168 </object>
169 EOT;
170
171 return $output;
172 }
173
174 /**
175 * Theme a button audio file.
176 */
177 function theme_mediafield_display_button($file_title, $file_url, $item, $field) {
178 global $base_url;
179
180 $options = array();
181 $options['song_url'] = $file_url;
182 $options['song_title'] = check_plain($file_title);
183 // str_replace() is to fix issue in Drupal 5.2.
184 $url = $base_url .'/'. drupal_get_path('module', 'mediafield_display') .'/players/button.swf?'. str_replace('http%3A/%252F', 'http://', drupal_query_string_encode($options));
185
186 $output = <<<EOT
187 <object type="application/x-shockwave-flash" data="$url" width="17" height="17">';
188 <param name="movie" value="$url" />
189 <param name="wmode" value="transparent" />
190 <param name="quality" value="high" />
191 </object>
192 EOT;
193
194 return $output;
195 }

  ViewVC Help
Powered by ViewVC 1.1.2