Projet

Général

Profil

Révision 70a4c29b

Ajouté par Assos Assos il y a environ 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/media_youtube/media_youtube.module
1 1
<?php
2 2

  
3 3
/**
4
 * @file media_youtube/media_youtube.module
5
 *
6
 * Media: YouTube provides a stream wrapper and formatters for videos provided
7
 * by YouTube, available at http://youtube.com/.
8
 *
9
 * @TODO:
10
 * Get the YouTube tab working.
11
 *  - Search by video name, user name, and channel.
12
 *  - Default to user's channel videos.
13
 * Review all code and remove cruft.
14
 * Assess if M:YT 3.x could be formatters added on to the OEmbed module.
4
 * @file
5
 * Provides a stream wrapper and formatters appropriate for accessing and
6
 * displaying YouTube videos.
15 7
 */
16 8

  
17 9
/**
......
22 14
 */
23 15
define('MEDIA_YOUTUBE_REST_API', 'https://gdata.youtube.com/feeds/api/videos');
24 16

  
25
// Hooks and callbacks for integrating with File Entity module for display.
17
// Load all YouTube file formatters.
26 18
require_once dirname(__FILE__) . '/includes/media_youtube.formatters.inc';
27 19

  
28 20
/**
29 21
 * Implements hook_media_internet_providers().
30 22
 */
31 23
function media_youtube_media_internet_providers() {
32
  $info['MediaInternetYouTubeHandler'] = array(
33
    'title' => t('YouTube'),
24
  return array(
25
    'MediaInternetYouTubeHandler' => array(
26
      'title' => t('YouTube'),
27
    ),
34 28
  );
35

  
36
  return $info;
37 29
}
38 30

  
39 31
/**
......
44 36
    'youtube' => array(
45 37
      'name' => t('YouTube videos'),
46 38
      'class' => 'MediaYouTubeStreamWrapper',
47
      'description' => t('Videos provided by YouTube.'),
39
      'description' => t('Remote videos hosted on the YouTube video-sharing website.'),
48 40
      'type' => STREAM_WRAPPERS_READ_VISIBLE,
49 41
    ),
50 42
  );
......
78 70

  
79 71
/**
80 72
 * Implements hook_file_mimetype_mapping_alter().
81
 *
82
 * Register the video/youtube mimetype.
83 73
 */
84 74
function media_youtube_file_mimetype_mapping_alter(&$mapping) {
85 75
  $mapping['mimetypes'][] = 'video/youtube';
86 76
}
87 77

  
78
/**
79
 * Implements hook_ctools_plugin_api().
80
 */
81
function media_youtube_ctools_plugin_api($module, $api) {
82
  if ($module == 'file_entity' && $api == 'file_default_displays') {
83
    return array('version' => 1);
84
  }
85
}
86

  
88 87
/**
89 88
 * YouTube search tab for the Media browser.
90 89
 */
......
142 141
    $empty = TRUE;
143 142
  }
144 143
  else {
145
    foreach ($search['entry'] as $video) {
144
    // $search['entry'] is different depending on whether there is a single
145
    // result or multiple results. So normalise it.
146
    $videos = isset($search['entry']['id']) ? array($search['entry']) : $search['entry'];
147
    foreach ($videos as $video) {
146 148
      try {
147 149
        $uri = media_parse_to_uri($video['link'][0]['@attributes']['href']);
148 150
      }
......
157 159
        $file->fid = 0;
158 160
      }
159 161
      media_browser_build_media_item($file);
160
      $file->preview = l($file->preview, 'media/browser', array(
161
        'html' => TRUE,
162
        'attributes' => array(
163
          'data-uri' => $uri,
164
        ),
165
        'query' => array('render' => 'media-popup', 'uri' => $uri),
166
      ));
162
      $attributes = array(
163
        'data-uri' => $uri,
164
        'class' => array('media-youtube-wrapper'),
165
      );
167 166
      $form['videos'][$uri] = array(
168 167
        '#markup' => $file->preview,
169
        '#prefix' => '<li>',
168
        '#prefix' => '<li' . drupal_attributes($attributes) . '>',
170 169
        '#suffix' => '</li>',
171 170
      );
172 171
      $files[$uri] = $file;
......
253 252
    return;
254 253
  }
255 254

  
256
  $validators = $form['#validators'];
255
  $validators = isset($form['#validators']) ? $form['#validators'] : array();
257 256
  if ($validators) {
258 257
    // Check for errors. @see media_add_upload_validate calls file_save_upload().
259 258
    // this code is ripped from file_save_upload because we just want the validation part.
......
308 307
  }
309 308

  
310 309
  // Redirect to the file edit page after submission.
311
  // @TODO: media_access() is a wrapper for file_entity_access(). Switch to the
312
  // new function when Media 1.x is deprecated.
313
  if (media_access('update', $file)) {
310
  if (media_youtube_access('update', $file)) {
314 311
    $destination = array('destination' => 'admin/content/file');
315 312
    if (isset($_GET['destination'])) {
316 313
      $destination = drupal_get_destination();
......
323 320
  }
324 321
}
325 322

  
323
/**
324
 * Determine if a user may perform the given operation on the specified file.
325
 *
326
 * Enables compatibility with Media 1.x and 2.x by providing a wrapper around
327
 * both media_access() and file_entity_access().
328
 *
329
 * @return boolean
330
 *   TRUE if the operation may be performed, FALSE otherwise.
331
 *
332
 * @see media_access()
333
 * @see file_entity_access()
334
 */
335
function media_youtube_access($op, $file = NULL, $account = NULL) {
336
  if (function_exists('file_entity_access')) {
337
    $access = file_entity_access($op, $file, $account);
338
  }
339
  elseif (function_exists('media_access')) {
340
    $access = media_access($op, $account);
341
  }
342
  else {
343
    $access = FALSE;
344
  }
345

  
346
  return $access;
347
}
348

  
326 349
/**
327 350
 * @TODO: Document this function.
328 351
 */

Formats disponibles : Unified diff