Project

General

Profile

Revision 70a4c29b

Added by Assos Assos over 9 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/media_youtube/includes/media_youtube.formatters.inc
1 1
<?php
2 2

  
3 3
/**
4
 * @file media_youtube/includes/media_youtube.formatters.inc
5
 *
6
 * Formatters for Media: YouTube.
4
 * @file
5
 * File formatters for YouTube videos.
7 6
 */
8 7

  
9 8
/**
......
13 12
  $formatters['media_youtube_video'] = array(
14 13
    'label' => t('YouTube Video'),
15 14
    'file types' => array('video'),
16
    'default settings' => array(),
15
    'default settings' => array(
16
      'width' => 640,
17
      'height' => 390,
18
      'autohide' => 2,
19
      'autoplay' => FALSE,
20
      'color' => 'red',
21
      'enablejsapi' => FALSE,
22
      'loop' => FALSE,
23
      'modestbranding' => FALSE,
24
      'nocookie' => FALSE,
25
      'origin' => '',
26
      'protocol' => 'https:',
27
      'protocol_specify' => FALSE,
28
      'rel' => TRUE,
29
      'showinfo' => TRUE,
30
      'theme' => 'dark',
31
      'captions' => FALSE,
32
    ),
17 33
    'view callback' => 'media_youtube_file_formatter_video_view',
18 34
    'settings callback' => 'media_youtube_file_formatter_video_settings',
19 35
    'mime types' => array('video/youtube'),
20 36
  );
21 37

  
22
  $formatters['media_youtube_video']['default settings'] = array(
23
    'width' => 640,
24
    'height' => 390,
25
    'autohide' => 2,
26
    'autoplay' => FALSE,
27
    'color' => 'red',
28
    'enablejsapi' => FALSE,
29
    'loop' => FALSE,
30
    'modestbranding' => FALSE,
31
    'nocookie' => FALSE,
32
    'origin' => '',
33
    'protocol' => 'https:',
34
    'protocol_specify' => FALSE,
35
    'rel' => TRUE,
36
    'showinfo' => TRUE,
37
    'theme' => 'dark',
38
  );
39

  
40 38
  $formatters['media_youtube_image'] = array(
41 39
    'label' => t('YouTube Preview Image'),
42 40
    'file types' => array('video'),
......
56 54
 */
57 55
function media_youtube_file_formatter_video_view($file, $display, $langcode) {
58 56
  $scheme = file_uri_scheme($file->uri);
57

  
59 58
  // WYSIWYG does not yet support video inside a running editor instance.
60 59
  if ($scheme == 'youtube' && empty($file->override['wysiwyg'])) {
61 60
    $element = array(
......
67 66
    // Fake a default for attributes so the ternary doesn't choke.
68 67
    $display['settings']['attributes'] = array();
69 68

  
70
    foreach (array('width', 'height', 'autohide', 'autoplay', 'color', 'enablejsapi', 'loop', 'modestbranding', 'nocookie', 'origin', 'protocol', 'protocol_specify', 'rel', 'showinfo', 'theme', 'attributes') as $setting) {
69
    foreach (array('width', 'height', 'autohide', 'autoplay', 'color', 'enablejsapi', 'loop', 'modestbranding', 'nocookie', 'origin', 'protocol', 'protocol_specify', 'rel', 'showinfo', 'theme', 'attributes', 'captions') as $setting) {
71 70
      $element['#options'][$setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
72 71
    }
72

  
73 73
    return $element;
74 74
  }
75 75
}
......
124 124
    ),
125 125
    '#default_value' => $settings['autohide'],
126 126
  );
127
  $element['captions'] = array(
128
    '#title' => t('Captions displaying options'),
129
    '#type' => 'radios',
130
    '#options' => array(
131
      '0' => t('Turns captions off by default'),
132
      '1' => t('Turns captions on by default'),
133
      '2' => t('Turns captions on and set the caption language for the video by default'),
134
    ),
135
    '#default_value' => $settings['captions'],
136
  );
127 137

  
128 138
  // Single Options.
129 139
  $element['autoplay'] = array(
......
207 217
 * Validation for width and height.
208 218
 */
209 219
function _youtube_validate_video_width_and_height($element, &$form_state, $form) {
210

  
211 220
  // Check if the value is a number with an optional decimal or percentage sign, or "auto".
212 221
  if (!empty($element['#value']) && !preg_match('/^(auto|([0-9]*(\.[0-9]+)?%?))$/', $element['#value'])) {
213 222
    form_error($element, t("The value entered for @dimension is invalid. Please insert a unitless integer for pixels, a percent, or \"auto\". Note that percent and auto may not function correctly depending on the browser and doctype.", array('@dimension' => $element['#title'])));
......
218 227
 * Validation for Js API Origin.
219 228
 */
220 229
function _youtube_validate_jsapi_domain ($element, &$form_state, $form) {
221

  
222 230
  // Check if the value is a url with http/s and no trailing directories.
223 231
  if (!empty($element['#value']) && !preg_match('/^https?\:\/\/[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}){1,2}$/', $element['#value'])) {
224 232
    form_error($element, t('Please insert a valid domain in the format http://www.yourdomain.com'));
......
234 242
    $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
235 243
    $image_style = $display['settings']['image_style'];
236 244
    $valid_image_styles = image_style_options(FALSE);
237
    // @TODO: If autosubmit is removed and we allow view modes that insert
238
    // images in the WYSIWYG, add file->overrides handling.
245

  
239 246
    if (empty($image_style) || !isset($valid_image_styles[$image_style])) {
240 247
      $element = array(
241 248
        '#theme' => 'image',
242
        '#path' => $wrapper->getOriginalThumbnailPath(),
249
        '#path' => str_replace('http:', '', $wrapper->getOriginalThumbnailPath()),
243 250
        '#alt' => isset($file->override['attributes']['alt']) ? $file->override['attributes']['alt'] : $file->filename,
244 251
      );
245 252
    }
......
261 268
 */
262 269
function media_youtube_file_formatter_image_settings($form, &$form_state, $settings) {
263 270
  $element = array();
271

  
264 272
  $element['image_style'] = array(
265 273
    '#title' => t('Image style'),
266 274
    '#type' => 'select',
......
268 276
    '#default_value' => $settings['image_style'],
269 277
    '#empty_option' => t('None (original image)'),
270 278
  );
271
  return $element;
272
}
273

  
274
/**
275
 * Implements hook_file_default_displays_alter().
276
 */
277
function media_youtube_file_default_displays_alter(&$file_displays) {
278
  // Video previews should be displayed using a large filetype icon.
279
  $file_display = new stdClass();
280
  $file_display->api_version = 1;
281
  $file_display->name = 'video__default__media_youtube_video';
282
  $file_display->weight = 0;
283
  $file_display->status = TRUE;
284
  $file_display->settings = array(
285
    'width' => '640',
286
    'height' => '390',
287
    'theme' => 'dark',
288
    'color' => 'red',
289
    'autohide' => '2',
290
    'autoplay' => 0,
291
    'loop' => 0,
292
    'showinfo' => 1,
293
    'modestbranding' => 0,
294
    'rel' => 1,
295
    'nocookie' => 0,
296
    'protocol_specify' => 0,
297
    'protocol' => 'https:',
298
    'enablejsapi' => 0,
299
    'origin' => '',
300
  );
301
  $file_displays['video__default__media_youtube_video'] = $file_display;
302

  
303
  $file_display = new stdClass();
304
  $file_display->api_version = 1;
305
  $file_display->name = 'video__preview__media_youtube_image';
306
  $file_display->weight = 0;
307
  $file_display->status = TRUE;
308
  $file_display->settings = array(
309
    'image_style' => 'media_thumbnail',
310
  );
311
  $file_displays['video__preview__media_youtube_image'] = $file_display;
312 279

  
313
  $file_display = new stdClass();
314
  $file_display->api_version = 1;
315
  $file_display->name = 'video__teaser__media_youtube_video';
316
  $file_display->weight = 0;
317
  $file_display->status = TRUE;
318
  $file_display->settings = array(
319
    'width' => '560',
320
    'height' => '340',
321
    'theme' => 'dark',
322
    'color' => 'red',
323
    'autohide' => '2',
324
    'autoplay' => 0,
325
    'loop' => 0,
326
    'showinfo' => 1,
327
    'modestbranding' => 0,
328
    'rel' => 1,
329
    'nocookie' => 0,
330
    'protocol_specify' => 0,
331
    'protocol' => 'https:',
332
    'enablejsapi' => 0,
333
    'origin' => '',
334
  );
335
  $file_displays['video__teaser__media_youtube_video'] = $file_display;
280
  return $element;
336 281
}

Also available in: Unified diff