/[drupal]/contributions/modules/video_upload/video_upload.theme.inc
ViewVC logotype

Contents of /contributions/modules/video_upload/video_upload.theme.inc

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


Revision 1.13 - (show annotations) (download) (as text)
Sun Oct 11 22:06:52 2009 UTC (6 weeks, 4 days ago) by jhedstrom
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.12: +1 -1 lines
File MIME type: text/x-php
Initital 7.x port.
1 <?php
2
3 // $Id: video_upload.theme.inc,v 1.5.2.8 2009/09/04 20:51:16 jhedstrom Exp $
4
5 /**
6 * @file video_upload.theme.inc
7 * Theme functions for the Video Upload module.
8 */
9
10 /**
11 * Theme a video
12 */
13 function theme_video_upload_video($yt_id, $width = '480', $height = '295', $field = array(), $params = array(), $attributes = array()) {
14 if (!$yt_id) {
15 // Output the video image instead.
16 $attributes = array(
17 'alt' => t('Video processing'),
18 'title' => t('Video processing'),
19 );
20 return theme('video_upload_missing_image', 'full', $width, $height, $attributes);
21 }
22
23 // @todo: Abstract out YouTube.
24 video_upload_initialize_provider();
25 $video_url = VIDEO_UPLOAD_YOUTUBE_EMBED_URL . '/' . $yt_id;
26
27 if (!$field['widget']['display']['related_videos']) {
28 // Related videos.
29 $video_url .= '&rel=0';
30 }
31 if ($field['widget']['display']['autoplay']) {
32 // Autoplay.
33 $video_url .= '&autoplay=1';
34 }
35
36 $default_params = array(
37 'movie' => $video_url,
38 'wmode' => 'transparent',
39 'bgcolor' => '#FFFFFF',
40 );
41
42 if ($field['widget']['display']['fullscreen']) {
43 // Fullscreen.
44 $video_url .= '&fs=1';
45 $default_params['allowFullScreen'] = 'true';
46 }
47
48 $all_params = array_merge($default_params, $params);
49 foreach ($all_params as $p_name => $p_value) {
50 $parameters .= '
51 <param name="' . $p_name . '" value="' . $p_value .'" />
52 ';
53 }
54
55 static $v = 1;
56 $default_attributes = array(
57 'type' => 'application/x-shockwave-flash',
58 'height' => $height,
59 'width' => $width,
60 'data' => $video_url,
61 'id' => 'videoEmbed' . $v,
62 );
63 $v ++;
64
65 $all_attributes = array_merge($default_attributes, $attributes);
66
67 $embed_attributes = array(
68 'src' => $all_attributes['data'],
69 'type' => $all_attributes['type'],
70 'wmode' => 'transparent',
71 'width' => $all_attributes['width'],
72 'height' => $all_attributes['height'],
73 'allowFullScreen' => $all_attributes['allowFullScreen'],
74 );
75 $embed = '<embed ' . drupal_attributes($embed_attributes) . '></embed>';
76
77 return '
78 <object ' . drupal_attributes($all_attributes) . '>'
79 . $parameters . $embed . '</object>';
80 }
81
82 /**
83 * Theme a thumbnail.
84 * @param array $field
85 * CCK field definition
86 * @param array $item
87 * @param int $nid
88 * Associated node ID
89 * @param bool $as_link
90 * Display the thumbnail as link
91 * @todo offer random image (YT provides 3)
92 */
93 function theme_video_upload_video_thumb($field, $item, $nid, $as_link = FALSE) {
94 $width = $field['widget']['display']['thumb_width'];
95 $height = $field['widget']['display']['thumb_height'];
96
97 if (!isset($item['video_status'])) {
98 return;
99 }
100
101 if (!$item['video_id']) {
102 // Output the video image instead.
103 $attributes = array(
104 'alt' => t('Video processing'),
105 'title' => t('Video processing'),
106 );
107 $image = theme('video_upload_missing_image', 'thumbnail', $width, $height, $attributes);
108
109 if ($as_link && $nid) {
110 $image = l($image, 'node/' . $nid, array('html' => TRUE));
111 }
112
113 return $image;
114 }
115 else {
116 if ($item['video_status'] == VIDEO_UPLOAD_STATUS_UNKNOWN) {
117 // If the video isn't done processing, through a flag onto the end of the
118 // url so the user's browser doesn't cache the processing thumbnail
119 $flag = '?f=' . rand(0, 10);
120 $attributes['title'] = t('Video processing');
121 }
122
123 // @todo: Abstract out YouTube.
124 video_upload_initialize_provider();
125 $attributes['src'] = VIDEO_UPLOAD_YOUTUBE_THUMB_URL . '/' . $item['video_id'] . '/1.jpg' . $flag;
126 $attributes['alt'] = t('YouTube Thumbnail');
127 }
128
129 if ($width) {
130 $attributes['width'] = $width;
131 }
132 if ($height) {
133 $attributes['height'] = $height;
134 }
135 $img = '<img ' . drupal_attributes($attributes) . '/>';
136 if ($as_link && $nid) {
137 $img = l($img, 'node/' . $nid, array('html' => TRUE));
138 }
139 return $img;
140 }
141
142 /**
143 * Theme a specific video upload status message
144 * @fixme
145 * This function should be integrated with theme_video_upload_status_text(),
146 * as they do nearly the same thing in slightly different ways
147 */
148 function theme_video_upload_video_status_message($item, $message = NULL) {
149 if (!$message) {
150 $message = t('Video hasn\'t finished processing yet');
151 }
152 return '<div class="messages">' . $message . '</div>';
153 }
154
155 /**
156 * Theme the video upload admin form into a table/grid
157 */
158 function theme_video_upload_admin_video_form($form) {
159 // add css for this table
160 drupal_add_css(drupal_get_path('module', 'video_upload') . '/video_upload_admin.css');
161
162 // Overview table:
163 $select_all = $form['videos'] ? theme('table_select_header_cell') : array();
164 $header = array($select_all, t('Title'), t('Id'), t('Node'), t('Field Info'), t('Status'));
165
166 // Options
167 $output .= drupal_render($form['options']);
168
169 if (isset($form['id']) && is_array($form['id'])) {
170 foreach (element_children($form['id']) as $key) {
171 $row = array();
172 // checkbox
173 $row[] = drupal_render($form['videos'][$key]);
174 // video title
175 $row[] = drupal_render($form['title'][$key]);
176 // video id
177 $row[] = drupal_render($form['id'][$key]);
178 // link to node, if available
179 $row[] = $form['node'][$key] ? drupal_render($form['node'][$key]) : t('orphaned');
180 // field info, if available
181 $row[] = $form['field_name'][$key] ? drupal_render($form['field_name'][$key]) : t('n/a');
182 // video status
183 $row[] = drupal_render($form['status'][$key]);
184 // highlight orphaned videos
185 $class = $form['node'][$key] ? '' : 'video-upload-orphaned';
186 $rows[] = array('data' => $row, 'class' => $class);
187 }
188 }
189 else {
190 $rows[] = array(array('data' => t('No videos have been uploaded to this account'), 'colspan' => '6'));
191 }
192
193 $output .= theme('table', $header, $rows);
194 if ($form['pager']['#value']) {
195 $output .= drupal_render($form['pager']);
196 }
197
198 $output .= drupal_render($form);
199
200 return '<div class="video-upload-admin">' . $output . '</div>';
201
202 }
203
204 /**
205 * Theme the video status text
206 * @param mixed $status
207 * A status object or integer
208 */
209 function theme_video_upload_status_text($status) {
210 if (is_object($status)) {
211 $stat = $status->status;
212 }
213 else {
214 $stat = $status;
215 }
216
217 $class = 'video-upload-status';
218 switch ($stat) {
219 case VIDEO_UPLOAD_STATUS_ORPHANED :
220 // @todo: abstract out YouTube
221 $status_text = t('Video removed from YouTube');
222 $class .= ' video-upload-status-bad';
223 break;
224 case VIDEO_UPLOAD_STATUS_BAD :
225 $status_text = $status->message ? $status->message : t('Unknown Error');
226 $class .= ' video-upload-status-bad';
227 break;
228 case VIDEO_UPLOAD_STATUS_UPLOAD_PENDING:
229 $status_text = t('Video is being processed.');
230 $class .= ' video-upload-processing';
231 break;
232 case VIDEO_UPLOAD_STATUS_OK :
233 $status_text = t('OK');
234 $class .= ' video-upload-status-ok';
235 break;
236 case VIDEO_UPLOAD_STATUS_OK_SYNCED :
237 $status_text = t('Video up-to-date');
238 $class .= ' video-upload-status-ok-synced';
239 break;
240 case VIDEO_UPLOAD_STATUS_DELETE :
241 $status_text = t('Video is bad and queued for deletion');
242 $class .= ' video-upload-status-delete';
243 break;
244 case VIDEO_UPLOAD_STATUS_UNKNOWN :
245 default :
246 $status_text = t('Video status is unknown. This most likely means it has not yet been processed.');
247 $class .= ' video-upload-status-unknown';
248 }
249
250 $attributes = array(
251 'class' => $class,
252 );
253
254 return '<span' . drupal_attributes($attributes) . '>' . $status_text . '</span>';
255 }
256
257 /**
258 * Theme missing thumbnail image.
259 *
260 * @param string $style
261 * Thumbnail or full
262 * @param integer $width
263 * @param integer $height
264 * @param array $attributes
265 * html attributes for inside the image tag
266 */
267 function theme_video_upload_missing_image($style = 'full', $width = 425, $height = 350, $attributes = array()) {
268 global $base_path;
269 $file = $style == 'full' ? 'video.png' : 'video-thumbnail.png';
270 $image = $base_path . drupal_get_path('module', 'video_upload') . '/images/' . $file;
271
272 $defaults = array(
273 'alt' => t('Video'),
274 'width' => $width,
275 'height' => $height,
276 'src' => $image,
277 );
278
279 $attributes = array_merge($defaults, $attributes);
280 return '<img' . drupal_attributes($attributes) . '/>';
281
282 }
283
284 /**
285 * @defgroup "CCK Formatter theme functions."
286 * @{
287 */
288 function theme_video_upload_formatter_default($element) {
289 $field = content_fields($element['#field_name'], $element['#type_name']);
290 $display = $field['widget']['display'];
291 $item = $element['#item'];
292 if (!isset($item['video_status'])) {
293 return;
294 }
295
296 if (!$item['video_id']) {
297 drupal_set_message(theme('video_upload_status_text', $item['video_status']));
298 }
299 return theme('video_upload_video', $item['video_id'], $display['default_width'], $display['default_height'], $field);
300 }
301
302 function theme_video_upload_formatter_small($element) {
303 $field = content_fields($element['#field_name'], $element['#type_name']);
304 $display = $field['widget']['display'];
305 $item = $element['#item'];
306 if (!isset($item['video_status'])) {
307 return;
308 }
309
310 return theme('video_upload_video', $item['video_id'], $display['small_width'], $display['small_height'], $field);
311 }
312
313 function theme_video_upload_formatter_thumb($element) {
314 $field = content_fields($element['#field_name'], $element['#type_name']);
315 $display = $field['widget']['display'];
316 $item = $element['#item'];
317 if (!isset($item['video_status'])) {
318 return;
319 }
320
321 return theme('video_upload_video_thumb', $field, $item, $item['nid'], FALSE);
322 }
323
324 function theme_video_upload_formatter_thumb_link($element) {
325 $field = content_fields($element['#field_name'], $element['#type_name']);
326 $display = $field['widget']['display'];
327 $item = $element['#item'];
328 if (!isset($item['video_status'])) {
329 return;
330 }
331
332 return theme('video_upload_video_thumb', $field, $item, $item['nid'], TRUE);
333 }
334
335 /**
336 * @} End defgroup "CCK Formatter theme functions."
337 */

  ViewVC Help
Powered by ViewVC 1.1.2