Project

General

Profile

Paste
Download (1.18 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / media_youtube / media_youtube.file.inc @ a8cee257

1 58344a8d Assos Assos
<?php
2
3
/**
4
 * @file
5
 * File hooks implemented by the Media: YouTube module.
6
 */
7
8
/**
9
 * Implements hook_file_operations().
10
 */
11
function media_youtube_file_operations() {
12
  $operations = array(
13
    'media_youtube_refresh' => array(
14
      'label' => t('Refresh YouTube information from source'),
15
      'callback' => 'media_youtube_cache_clear',
16
    ),
17
  );
18
19
  return $operations;
20
}
21
22
/**
23
 * Clear the cached YouTube content for the selected files.
24
 */
25
function media_youtube_cache_clear($fids) {
26
  $fids = array_keys($fids);
27 a8cee257 Assos Assos
  $folder = variable_get('youtube_thumb_dir');
28 58344a8d Assos Assos
29
  $query = new EntityFieldQuery();
30
  $results = $query
31 a8cee257 Assos Assos
  ->entityCondition('entity_type', 'file')
32
  ->propertyCondition('uri', '%' . $folder . '%', 'LIKE')
33
  ->propertyCondition('fid', $fids)
34
  ->execute();
35 58344a8d Assos Assos
36 a8cee257 Assos Assos
  if (!empty($results)) {
37
    $files = file_load_multiple(array_keys($results['file']));
38 58344a8d Assos Assos
39 a8cee257 Assos Assos
    foreach ($files as $file) {
40
      foreach (image_styles() as $isid => $style) {
41
        $path = image_style_url($isid, $file->uri);
42
        if ($path) {
43
          image_path_flush($path);
44
        }
45
      }
46
      drupal_set_message(t('Refreshed thumbnail and derivatives for %filename', array('%filename' => $file->filename)));
47
    }
48 58344a8d Assos Assos
  }
49
}