1
|
<?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
|
$folder = variable_get('youtube_thumb_dir');
|
28
|
|
29
|
$query = new EntityFieldQuery();
|
30
|
$results = $query
|
31
|
->entityCondition('entity_type', 'file')
|
32
|
->propertyCondition('uri', '%' . $folder . '%', 'LIKE')
|
33
|
->propertyCondition('fid', $fids)
|
34
|
->execute();
|
35
|
|
36
|
if (!empty($results)) {
|
37
|
$files = file_load_multiple(array_keys($results['file']));
|
38
|
|
39
|
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
|
}
|
49
|
}
|