commit 58344a8d708efd98c1c1a450e7311f4834537274
Author: Assos Assos <assos+forge@centrale-marseille.fr>
Date:   Wed Jun 3 22:46:50 2015 +0200

    Weekly update of contrib modules

diff --git a/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeBrowser.inc b/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeBrowser.inc
deleted file mode 100644
index 1cd63aac..00000000
--- a/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeBrowser.inc
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-/**
- * @file media_youtube/includes/MediaYouTubeBrowser.inc
- *
- * Definition of MediaYouTubeBrowser.
- */
-
-/**
- * Media browser plugin for displaying a specific view and display.
- */
-class MediaYouTubeBrowser extends MediaBrowserPlugin {
-  /**
-   * Implements MediaBrowserPluginInterface::access().
-   */
-  public function access($account = NULL) {
-    return media_internet_access($account);
-  }
-
-  /**
-   * Implements MediaBrowserPlugin::view().
-   */
-  public function view() {
-    $build = array();
-    $params = $this->params;
-    $build['form'] = drupal_get_form('media_youtube_add', $params);
-
-    return $build;
-  }
-}
diff --git a/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeStreamWrapper.inc b/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeStreamWrapper.inc
index b8d10765..72f925f2 100644
--- a/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeStreamWrapper.inc
+++ b/drupal7/sites/all/modules/media_youtube/includes/MediaYouTubeStreamWrapper.inc
@@ -18,19 +18,18 @@ class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
 
   function getOriginalThumbnailPath() {
     $parts = $this->get_parameters();
-    $v = check_plain($parts['v']);
-    //  Attempt to pull a HD thumbnail from YouTube. If it exists pass it on
-    //  otherwise pass on the smaller one.
-    $thumbname = drupal_tempnam('temporary://', 'youtube');
-    $response = drupal_http_request('http://img.youtube.com/vi/' . $v . '/maxresdefault.jpg');
+    $uri = file_stream_wrapper_uri_normalize('youtube://v/' . check_plain($parts['v']));
+    $external_url = file_create_url($uri);
+    $oembed_url = url('http://www.youtube.com/oembed', array('query' => array('url' => $external_url, 'format' => 'json')));
+    $response = drupal_http_request($oembed_url);
+
     if (!isset($response->error)) {
-      file_unmanaged_save_data($response->data, $thumbname, $replace = FILE_EXISTS_REPLACE);
-    }
-    if ((filesize($thumbname)) == 0) {
-      return 'http://img.youtube.com/vi/' . $v . '/0.jpg';
+      $data = drupal_json_decode($response->data);
+      return $data['thumbnail_url'];
     }
     else {
-      return 'http://img.youtube.com/vi/' . $v . '/maxresdefault.jpg';
+      throw new Exception("Error Processing Request. (Error: {$response->code}, {$response->error})");
+      return;
     }
   }
 
diff --git a/drupal7/sites/all/modules/media_youtube/js/media-youtube.browser.js b/drupal7/sites/all/modules/media_youtube/js/media-youtube.browser.js
deleted file mode 100644
index 155f5877..00000000
--- a/drupal7/sites/all/modules/media_youtube/js/media-youtube.browser.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * @file
- * Handles the JS for the views file browser. Note that this does not currently
- * support multiple file selection
- */
-
-
-(function ($) {
-
-  Drupal.behaviors.mediaYouTubeBrowser = {
-    attach: function (context, settings) {
-
-      // Container for the files that get passed back to the browser
-      var files = {};
-
-      // Disable the links on media items list
-      $('ul#media-browser-library-list a').click(function() {
-        return false;
-      });
-
-      // Catch the click on a media item
-      $('#media-youtube-add .media-item').bind('click', function () {
-        // Remove all currently selected files
-        $('.media-item').removeClass('selected');
-        // Set the current item to active
-        $(this).addClass('selected');
-        // Add this FID to the array of selected files
-        var uri = $(this).parent('li.media-youtube-wrapper[data-uri]').attr('data-uri');
-        // Get the file from the settings which was stored in
-        // template_preprocess_media_views_view_media_browser()
-        var file = Drupal.settings.media.files[uri];
-        var files = new Array();
-        files.push(file);
-        Drupal.media.browser.selectMedia(files);
-        $("input[name='submitted-video']").val(uri);
-      });
-
-//      $('.')
-    }
-  }
-
-}(jQuery));
\ No newline at end of file
diff --git a/drupal7/sites/all/modules/media_youtube/js/media_youtube.fromurl.js b/drupal7/sites/all/modules/media_youtube/js/media_youtube.fromurl.js
deleted file mode 100644
index 000089cb..00000000
--- a/drupal7/sites/all/modules/media_youtube/js/media_youtube.fromurl.js
+++ /dev/null
@@ -1,127 +0,0 @@
-
-/**
- *  @file
- *  Create the 'YouTube' tab for the WYSIWYG plugins.
- */
-
-// (function ($) {
-//   namespace('Drupal.media.browser.plugin');
-//
-//   Drupal.media.browser.plugin.media_youtube = function(mediaBrowser, options) {
-//     return {
-//       init: function() {
-//         tabset = mediaBrowser.getTabset();
-//         tabset.tabs('add', '#media_youtube', 'YouTube');
-//         mediaBrowser.listen('tabs.show', function (e, id) {
-//           if (id == 'media_youtube') {
-//             // We only need to set this once.
-//             // We probably could set it upon load.
-//             if (mediaBrowser.getActivePanel().html() == '') {
-//               mediaBrowser.getActivePanel().html(options.media_youtube);
-//             }
-//           }
-//         });
-//       }
-//     }
-//   };
-//
-//   // For now, I guess self registration makes sense.
-//   // Really though, we should be doing it via drupal_add_js and some settings
-//   // from the drupal variable.
-//   //@todo: needs a review.
-//   Drupal.media.browser.register('media_youtube', Drupal.media.browser.plugin.media_youtube, {});
-// })(jQuery);
-
-(function ($) {
-  namespace('media.browser.plugin');
-
-  Drupal.media.browser.plugin.youtube_library = function(mediaBrowser, options) {
-
-    return {
-      mediaFiles: [],
-      init: function() {
-        tabset = mediaBrowser.getTabset();
-        tabset.tabs('add', '#youtube_library', 'YouTube');
-        var that = this;
-        mediaBrowser.listen('tabs.show', function (e, id) {
-          if (id == 'youtube_library') {
-            // This is kinda rough, I'm not sure who should delegate what here.
-            mediaBrowser.getActivePanel().addClass('throbber');
-            mediaBrowser.getActivePanel().html('');
-            //mediaBrowser.getActivePanel().addClass('throbber');
-
-            // Assumes we have to refresh everytime.
-            // Remove any existing content
-            mediaBrowser.getActivePanel().append('<ul></ul>');
-            that.browser = $('ul', mediaBrowser.getActivePanel());
-            that.browser.addClass('clearfix');
-            that.getMedia();
-          }
-        });
-      },
-
-      getStreams: function () {
-        return ['youtube://'];
-      },
-
-      getConditions: function () {
-        return {};
-        //return this.settings.conditions;
-      },
-
-      getMedia: function() {
-        var that = this;
-        var callback = mediaBrowser.getCallbackUrl('getMedia');
-        var params = {
-          conditions: JSON.stringify(this.getConditions()),
-          streams: JSON.stringify(this.getStreams())
-        };
-        jQuery.get(
-          callback,
-          params,
-          function(data, status) {
-            that.mediaFiles = data.media;
-            that.emptyMessage = data.empty;
-            that.pager = data.pager;
-            that.render();
-          },
-          'json'
-        );
-      },
-
-      render: function() {
-        var that = this;
-        mediaBrowser.getActivePanel().removeClass('throbber');
-        if (this.mediaFiles.length < 1) {
-          jQuery('<div id="media-empty-message" class="media-empty-message"></div>').appendTo(this.browser)
-            .html(this.emptyMessage);
-          return;
-        }
-
-        for (var m in this.mediaFiles) {
-          mediaFile = this.mediaFiles[m];
-
-          var listItem = jQuery('<li></li>').appendTo(this.browser)
-            .attr('id', 'media-file-' + mediaFile.fid)
-            .addClass('media-file');
-
-          var imgLink = jQuery('<a href="#"></a>').appendTo(listItem)
-            .html(mediaFile.preview)
-            .bind('click', mediaFile, function(e) {
-              // Notify the main browser
-              //this.selectedMedia = mediaFile;
-              $('div.media-thumbnail img').removeClass('selected');
-              $('div.media-thumbnail img', $(this)).addClass('selected');
-              mediaBrowser.notify('mediaSelected', {mediaFiles: [e.data]});
-              //that.settings.onSelect(mediaFile);
-              return false;
-            });
-        }
-        jQuery('<div id="media-pager" class="media-pager"></div>').appendTo(this.browser)
-          .html(this.pager);
-      }
-  };
-};
-
-  Drupal.media.browser.register('youtube_library', Drupal.media.browser.plugin.youtube_library);
-})(jQuery);
diff --git a/drupal7/sites/all/modules/media_youtube/media_youtube.file.inc b/drupal7/sites/all/modules/media_youtube/media_youtube.file.inc
new file mode 100644
index 00000000..6eb99520
--- /dev/null
+++ b/drupal7/sites/all/modules/media_youtube/media_youtube.file.inc
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * @file
+ * File hooks implemented by the Media: YouTube module.
+ */
+
+/**
+ * Implements hook_file_operations().
+ */
+function media_youtube_file_operations() {
+  $operations = array(
+    'media_youtube_refresh' => array(
+      'label' => t('Refresh YouTube information from source'),
+      'callback' => 'media_youtube_cache_clear',
+    ),
+  );
+
+  return $operations;
+}
+
+/**
+ * Clear the cached YouTube content for the selected files.
+ */
+function media_youtube_cache_clear($fids) {
+  $fids = array_keys($fids);
+
+  $query = new EntityFieldQuery();
+  $results = $query
+    ->entityCondition('entity_type', 'file')
+    ->propertyCondition('uri', 'youtube:', 'STARTS_WITH')
+    ->propertyCondition('fid', $fids)
+    ->execute();
+
+  $files = file_load_multiple(array_keys($results['file']));
+
+  foreach ($files as $file) {
+    $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
+    $local_path = $wrapper->getLocalThumbnailPath();
+    file_unmanaged_delete($local_path);
+  }
+}
diff --git a/drupal7/sites/all/modules/media_youtube/media_youtube.info b/drupal7/sites/all/modules/media_youtube/media_youtube.info
index 469b59e4..82763adb 100644
--- a/drupal7/sites/all/modules/media_youtube/media_youtube.info
+++ b/drupal7/sites/all/modules/media_youtube/media_youtube.info
@@ -7,11 +7,10 @@ dependencies[] = media_internet
 
 files[] = includes/MediaYouTubeStreamWrapper.inc
 files[] = includes/MediaInternetYouTubeHandler.inc
-files[] = includes/MediaYouTubeBrowser.inc
 
-; Information added by Drupal.org packaging script on 2015-03-23
-version = "7.x-2.0-rc5"
+; Information added by Drupal.org packaging script on 2015-05-28
+version = "7.x-3.0"
 core = "7.x"
 project = "media_youtube"
-datestamp = "1427094782"
+datestamp = "1432800182"
 
diff --git a/drupal7/sites/all/modules/media_youtube/media_youtube.module b/drupal7/sites/all/modules/media_youtube/media_youtube.module
index 3de90d6d..57e3d6c9 100644
--- a/drupal7/sites/all/modules/media_youtube/media_youtube.module
+++ b/drupal7/sites/all/modules/media_youtube/media_youtube.module
@@ -6,14 +6,6 @@
  * displaying YouTube videos.
  */
 
-/**
- * This is the rest point for the YouTube api.
- *
- * Avoid using the gdata api url when possible. Too many calls will result in
- * throttling and 403 errors.
- */
-define('MEDIA_YOUTUBE_REST_API', 'https://gdata.youtube.com/feeds/api/videos');
-
 // Load all YouTube file formatters.
 require_once dirname(__FILE__) . '/includes/media_youtube.formatters.inc';
 
@@ -83,338 +75,3 @@ function media_youtube_ctools_plugin_api($module, $api) {
     return array('version' => 1);
   }
 }
-
-/**
- * YouTube search tab for the Media browser.
- */
-
-/**
- * Implements hook_media_browser_plugin_info().
- *
- * Commented out for release versions, active in dev versions. To enable the
- * YouTube media browser tab, uncomment this function.
- */
-function media_youtube_media_browser_plugin_info() {
-  $info['youtube'] = array(
-    'title' => t('YouTube'),
-    'class' => 'MediaYouTubeBrowser',
-  );
-
-  return $info;
-}
-
-/**
- * Provides a form for adding media items from YouTube search.
- */
-function media_youtube_add($form, &$form_state = array()) {
-  module_load_include('inc', 'media', 'includes/media.browser');
-
-  // Our search term can come from the form, or from the pager.
-  $term = isset($form_state['input']['search']) ? $form_state['input']['search'] : (isset($_GET['search']) ? $_GET['search'] : '');
-
-  $form['search'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Search'),
-    '#description' => t('Input a phrase or tags to search.'),
-    '#default_value' => $term,
-  );
-  $form['apply'] = array(
-    '#type' => 'button',
-    '#value' => t('Apply'),
-  );
-
-  // This is our half-assed pager.
-  $page = isset($_GET['page-yt']) ? $_GET['page-yt'] : 0;
-  if (isset($form_state['input']['search'])) {
-    // Reset the pager when we press apply.
-    $page = 0;
-  }
-  if (!empty($term)) {
-    $search = media_youtube_video_search(array('q' => $term, 'max-results' => 12, 'start-index' => $page * 12 + 1));
-  }
-  $form['videos']['#prefix'] = '<div id="container"><div id="scrollbox"><ul id="media-browser-library-list" class="media-list-thumbnails">';
-  $form['videos']['#suffix'] = '</ul><div id="status"></div></div></div>';
-
-  $empty = FALSE;
-  $files = array();
-  if (!isset($search['entry'])) {
-    $empty = TRUE;
-  }
-  else {
-    // $search['entry'] is different depending on whether there is a single
-    // result or multiple results. So normalise it.
-    $videos = isset($search['entry']['id']) ? array($search['entry']) : $search['entry'];
-    foreach ($videos as $video) {
-      try {
-        $uri = media_parse_to_uri($video['link'][0]['@attributes']['href']);
-      }
-      catch (Exception $e) {
-        // Ignore invalid videos.
-        continue;
-      }
-      // Create a temporary file object for our retrieved video.
-      $file = file_uri_to_object($uri);
-      $file->type = 'video';
-      if (!isset($file->fid)) {
-        $file->fid = 0;
-      }
-      media_browser_build_media_item($file);
-      $attributes = array(
-        'data-uri' => $uri,
-        'class' => array('media-youtube-wrapper'),
-      );
-      $form['videos'][$uri] = array(
-        '#markup' => $file->preview,
-        '#prefix' => '<li' . drupal_attributes($attributes) . '>',
-        '#suffix' => '</li>',
-      );
-      $files[$uri] = $file;
-    }
-  }
-
-  if (!count($files)) {
-    $empty= TRUE;
-  }
-  if ($empty) {
-    $form['empty'] = array(
-      '#markup' => '<div class="empty-message">' . t('No videos match your search criteria. Please try again.') . '</div>',
-    );
-  }
-
-  $query = $_GET;
-  if ($term !== '') {
-    $query['search'] = $term;
-  }
-
-  $dest = $query['q'];
-  unset($query['q']);
-  $prev = $next = '';
-  if ($page) {
-    $query['page-yt'] = $page - 1;
-    $prev = l(t('previous'), $dest, array('query' => $query));
-  }
-  $query['page-yt'] = $page + 1;
-  if (!$empty) {
-    $next = l(t('next'), $dest, array('query' => $query));
-  }
-
-  $form['pager']= array(
-    '#markup' => $prev . ' ' . $next,
-  );
-
-  $form['submitted-video'] = array(
-    '#type' => 'hidden',
-    '#default_value' => FALSE,
-  );
-
-  // Add the files to JS so that they are accessible inside the browser
-  drupal_add_js(array('media' => array('files' => $files)), 'setting');
-
-  // Add media browser javascript and CSS.
-  drupal_add_js(drupal_get_path('module', 'media_youtube') . '/js/media-youtube.browser.js');
-
-  // @TODO: Remove deprecated library js and css. They're removed in Media,
-  // so let's comment out for now.
-  // drupal_add_js(drupal_get_path('module', 'media') . '/js/plugins/media.library.js');
-  // drupal_add_css(drupal_get_path('module', 'media') . '/js/plugins/media.library.css');
-
-  $form['actions'] = array('#type' => 'actions');
-  $form['actions']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Submit'),
-  );
-  return $form;
-}
-
-/**
- * Allow stream wrappers to have their chance at validation.
- *
- * Any module that implements hook_media_parse will have an
- * opportunity to validate this.
- *
- * @see media_parse_to_uri()
- */
-function media_youtube_add_validate($form, &$form_state) {
-  if ($form_state['values']['op'] == t('Apply')) {
-    return;
-  }
-  $uri = $form_state['values']['submitted-video'];
-  try {
-    $file = file_uri_to_object($uri, TRUE);
-  }
-  catch (Exception $e) {
-    form_set_error('url', $e->getMessage());
-    return;
-  }
-
-  if (!$file->uri) {
-    form_set_error('url', t('Please select a video.'));
-    return;
-  }
-
-  $validators = isset($form['#validators']) ? $form['#validators'] : array();
-  if ($validators) {
-    // Check for errors. @see media_add_upload_validate calls file_save_upload().
-    // this code is ripped from file_save_upload because we just want the validation part.
-    // Call the validation functions specified by this function's caller.
-    $errors = file_validate($file, $validators);
-
-    if (!empty($errors)) {
-      $message = t('%uri could not be added.', array('%uri' => $uri));
-      if (count($errors) > 1) {
-        $message .= theme('item_list', array('items' => $errors));
-      }
-      else {
-        $message .= ' ' . array_pop($errors);
-      }
-      form_set_error('url', $message);
-      return FALSE;
-    }
-  }
-  // @TODO: Validate that if we have no $uri that this is a valid file to
-  // save. For instance, we may only be interested in images, and it would
-  // be helpful to let the user know they passed the HTML page containing
-  // the image accidentally. That would also save us from saving the file
-  // in the submit step.
-
-  // This is kinda a hack of the same.
-
-  // This should use the file_validate routines that the upload form users.
-  // We need to fix the media_parse_to_file routine to allow for a validation.
-}
-
-/**
- * @TODO: Document this function.
- */
-function media_youtube_add_submit($form, &$form_state) {
-  $uri = $form_state['values']['submitted-video'];
-  try {
-    // Save the remote file
-    $file = file_uri_to_object($uri, TRUE);
-    file_save($file);
-  }
-  catch (Exception $e) {
-    form_set_error('url', $e->getMessage());
-    return;
-  }
-
-  if (!$file->fid) {
-    form_set_error('url', t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $uri)));
-    return;
-  }
-  else {
-    $form_state['file'] = $file;
-  }
-
-  // Redirect to the file edit page after submission.
-  if (media_youtube_access('update', $file)) {
-    $destination = array('destination' => 'admin/content/file');
-    if (isset($_GET['destination'])) {
-      $destination = drupal_get_destination();
-      unset($_GET['destination']);
-    }
-    $form_state['redirect'] = array('file/' . $file->fid . '/edit', array('query' => $destination));
-  }
-  else {
-    $form_state['redirect'] = 'admin/content/file';
-  }
-}
-
-/**
- * Determine if a user may perform the given operation on the specified file.
- *
- * Enables compatibility with Media 1.x and 2.x by providing a wrapper around
- * both media_access() and file_entity_access().
- *
- * @return boolean
- *   TRUE if the operation may be performed, FALSE otherwise.
- *
- * @see media_access()
- * @see file_entity_access()
- */
-function media_youtube_access($op, $file = NULL, $account = NULL) {
-  if (function_exists('file_entity_access')) {
-    $access = file_entity_access($op, $file, $account);
-  }
-  elseif (function_exists('media_access')) {
-    $access = media_access($op, $account);
-  }
-  else {
-    $access = FALSE;
-  }
-
-  return $access;
-}
-
-/**
- * @TODO: Document this function.
- */
-function media_youtube_video_search($options = array()) {
-  $options['v'] = 2;
-
-  $request = drupal_http_request(url(MEDIA_YOUTUBE_REST_API, array('query' => $options)));
-  if (!isset($request->error)) {
-    $entry = simplexml_load_string($request->data);
-  }
-  else {
-    throw new Exception("Error Processing Request. (Error: {$request->code}, {$request->error})");
-
-    //if request wasn't successful, create object for return to avoid errors
-    $entry = new SimpleXMLElement();
-  }
-
-  return media_youtube_unserialize_xml($entry);
-}
-
-/**
- * Recursively converts a SimpleXMLElement object into an array.
- *
- * @param object $xml
- *   The original XML object.
- */
-function media_youtube_unserialize_xml($xml) {
-  if ($xml instanceof SimpleXMLElement) {
-    $xml = (array) $xml;
-  }
-  if (is_array($xml)) {
-    foreach ($xml as $key => $item) {
-      $xml[$key] = media_youtube_unserialize_xml($item);
-    }
-  }
-  return $xml;
-}
-
-/**
- * Check to ensure that a given id is valid.
- *
- * @param string $id
- *   The YouTube video id.
- * @param boolean $refresh
- *   (Defaults to FALSE) If TRUE, then reset the value from the cache.
- * @return boolean
- *   Returns TRUE if the video is valid.
- *
- * @TODO: How does this compare to MediaInternetYouTubeHandler's validId
- * method, and can we refactor the code to rely on only one of them?
- */
-function media_youtube_valid_id($id, $refresh = FALSE) {
-  $ids = &drupal_static(__FUNCTION__, array());
-
-  // Return our cached id if allowed, and it exists.
-  if (!$refresh && isset($ids[$id])) {
-    return $ids[$id];
-  }
-  elseif (!$refresh && !isset($ids[$id])) {
-    return $id;
-  }
-  elseif (!$refresh && $cache = cache_get('media_youtube:id:' . $id, 'cache_media_xml')) {
-    $ids[$id] = $cache->data;
-    return $ids[$id];
-  }
-
-  $url = url(MEDIA_YOUTUBE_REST_API . '/' . $id);
-  $response = drupal_http_request($url, array('method' => 'HEAD'));
-  $ids[$id] = ($response->code == 200);
-  cache_set('media_youtube:id:' . $id, $ids[$id], 'cache_media_xml', media_variable_get('xml_cache_expire', 3600));
-  return $ids[$id];
-}
