diff --git a/youtube.inc b/youtube.inc
index f1dc5ba..a1fc079 100644
--- a/youtube.inc
+++ b/youtube.inc
@@ -81,21 +81,26 @@ function youtube_get_dimensions($size = NULL, $width = NULL, $height = NULL) {
}
/**
- * Retreve youtube thumbnail image via YouTube API.
+ * Retrieves youtube thumbnail image via YouTube API.
*
- * @param $id
+ * @param integer $id
* The video_id of the particular YouTube video.
- * @param $force_small
- * When TRUE, this function should return the standard size image regardless
- * of what the youtube_thumb_hires variable is set to. This is used should
- * the high resolution image be found to not exist for a particular video.
+ * @param bool $force_small
+ * (optional) When TRUE, this function should return the standard size image
+ * regardless of what the youtube_thumb_hires variable is set to. This is used
+ * should the high resolution image be found to not exist for a particular video.
*
- * Returns either the Drupal $file object of saved image, or FALSE if image save failed
+ * @return bool|stdClass
+ * Either the Drupal $file object of saved image, or FALSE if image save failed.
*/
function youtube_get_remote_image($id = NULL, $force_small = FALSE) {
- // Maxresdefault, the highest available resolution thumbnail, is not guaranteed
- // to exist, but we'll check for it first if this setting returns true.
+ // This variable is TRUE when higher resolution thumbnails should be saved.
+ // The only thumbnail resolution higher than the standard 480 is
+ // 'maxresdefault'. This resolution image is not guaranteed to exist.
+ // If there's an error retrieving the hi-res image, we try again for small.
$youtube_thumb_hires = variable_get('youtube_thumb_hires', FALSE);
+ // This boolean is TRUE if we're obtaining a hi-res thumbnail, unless the
+ // first attempt failed, then it'll be forced to FALSE.
$get_hires = ($youtube_thumb_hires && !$force_small);
if ($get_hires) {
@@ -108,10 +113,13 @@ function youtube_get_remote_image($id = NULL, $force_small = FALSE) {
// Download file and save it as managed Drupal file.
$image = drupal_http_request($src);
if ($image->code != 200) {
- // Silently retry for small image if hires did not exist, otherwise
- // log and error and return false.
- if ($get_hires) return youtube_get_remote_image($id, TRUE);
- watchdog('youtube', 'HTTP request for video ID %id failed (error code: %err).',
+ // Silently retry for small image if hi-res did not exist, otherwise
+ // log an error and return FALSE.
+ if ($get_hires) {
+ return youtube_get_remote_image($id, TRUE);
+ }
+ watchdog('youtube',
+ 'HTTP request for video ID %id failed (error code: %err).',
array('%id', $id, '%err', $image->code),
WATCHDOG_ERROR);
return FALSE;
@@ -121,7 +129,10 @@ function youtube_get_remote_image($id = NULL, $force_small = FALSE) {
$youtube_path = variable_get('youtube_thumb_dir', 'youtube');
$youtube_dir = file_default_scheme() . '://' . $youtube_path;
if (!file_prepare_directory($youtube_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
- watchdog('youtube', 'Failed to create YouTube thumbnail directory: %dir', array('%dir' => $youtube_dir), WATCHDOG_ERROR);
+ watchdog('youtube',
+ 'Failed to create YouTube thumbnail directory: %dir',
+ array('%dir' => $youtube_dir),
+ WATCHDOG_ERROR);
return FALSE;
}
$destination = $youtube_dir . '/' . $id . '.jpg';
@@ -154,31 +165,32 @@ function youtube_thumb_delete_all($form, &$form_state) {
$files = file_scan_directory($youtube_path, '/^.*\.(jpg|png)$/');
- $legacy_files = false;
+ $legacy_files = FALSE;
foreach ($files as $raw_file) {
// Check if file is being managed by Drupal.
$uri = $youtube_dir . '/' . $raw_file->filename;
$managed_file = db_select('file_managed', 'fm')
->fields('fm')
- ->condition('uri', '%'. $uri, 'LIKE')
+ ->condition('uri', '%' . $uri, 'LIKE')
->execute()
->fetchAssoc();
if (!$managed_file) {
// Old files exist before module used managed files, notify user.
$legacy_files = file_unmanaged_delete($raw_file->uri);
- } else {
+ }
+ else {
$file = file_load($managed_file['fid']);
- // File_delete invokes hooks to refresh associated image files.
+ // file_delete() invokes hooks to refresh associated image files.
file_delete($file);
}
}
if ($legacy_files) {
- drupal_set_message(t('Some un-managed files from an older version of the ' .
- 'youtube module were deleted, so their associated' .
- ' image styles were not deleted. Image style flush' .
- ' may help with that. Alternatively, `drush image-flush` will reset any image ' .
- ' styles you may be using for youtube thumbnails. New thumbnails will not have this issue.',
+ drupal_set_message(t('Some un-managed files from an older version of the' .
+ ' youtube module were deleted, so their associated image styles were not' .
+ ' deleted. Image style flush may help with' .
+ ' that. Alternatively, `drush image-flush` will reset any image styles you' .
+ ' may be using for youtube thumbnails. New thumbnails will not have this issue.',
array('@imagestyleflush' => 'https://www.drupal.org/project/imagestyleflush')));
}
}