Révision 8dc4e7e8
Ajouté par Assos Assos il y a environ 5 ans
drupal7/sites/all/modules/remote_stream_wrapper/remote_stream_wrapper.image.inc | ||
---|---|---|
9 | 9 |
array_shift($args); |
10 | 10 |
$target = implode('/', $args); |
11 | 11 |
|
12 |
// Check that the style is defined, the scheme is valid, and the image |
|
13 |
// derivative token is valid. (Sites which require image derivatives to be |
|
14 |
// generated without a token can set the 'image_allow_insecure_derivatives' |
|
15 |
// variable to TRUE to bypass the latter check, but this will increase the |
|
16 |
// site's vulnerability to denial-of-service attacks. To prevent this |
|
17 |
// variable from leaving the site vulnerable to the most serious attacks, a |
|
18 |
// token is always required when a derivative of a derivative is requested.) |
|
19 |
$valid = !empty($style) && file_stream_wrapper_valid_scheme($scheme); |
|
20 |
if (!variable_get('image_allow_insecure_derivatives', FALSE) || strpos(ltrim($target, '\/'), 'styles/') === 0) { |
|
21 |
$valid = $valid && isset($_GET[IMAGE_DERIVATIVE_TOKEN]) && $_GET[IMAGE_DERIVATIVE_TOKEN] === image_style_path_token($style['name'], $scheme . '://' . $target); |
|
22 |
} |
|
23 |
if (!$valid) { |
|
24 |
return MENU_ACCESS_DENIED; |
|
25 |
} |
|
26 |
|
|
12 | 27 |
$image_uri = $scheme . '://' . $target; |
13 | 28 |
$derivative_uri = remote_stream_wrapper_image_style_path($style['name'], $image_uri); |
14 | 29 |
|
... | ... | |
22 | 37 |
// Don't start generating the image if the derivative already exists or if |
23 | 38 |
// generation is in progress in another thread. |
24 | 39 |
$lock_name = 'image_style_deliver:' . $style['name'] . ':' . drupal_hash_base64($image_uri); |
25 |
if (!is_file($derivative_uri)) {
|
|
40 |
if (!file_exists($derivative_uri)) {
|
|
26 | 41 |
$lock_acquired = lock_acquire($lock_name); |
27 | 42 |
if (!$lock_acquired) { |
28 | 43 |
// Tell client to retry again in 3 seconds. Currently no browsers are known |
... | ... | |
36 | 51 |
|
37 | 52 |
// Try to generate the image, unless another thread just did it while we were |
38 | 53 |
// acquiring the lock. |
39 |
$success = is_file($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);
|
|
54 |
$success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);
|
|
40 | 55 |
|
41 | 56 |
if (!empty($lock_acquired)) { |
42 | 57 |
lock_release($lock_name); |
drupal7/sites/all/modules/remote_stream_wrapper/remote_stream_wrapper.inc | ||
---|---|---|
110 | 110 |
* Implements realpath(). |
111 | 111 |
*/ |
112 | 112 |
function realpath() { |
113 |
return $this->getLocalPath();
|
|
113 |
return FALSE;
|
|
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
/** |
drupal7/sites/all/modules/remote_stream_wrapper/remote_stream_wrapper.info | ||
---|---|---|
1 |
name = Remote stream wrapper
|
|
1 |
name = Remote Stream Wrapper
|
|
2 | 2 |
description = Provides the ability to use external files with filefields without saving the files to your local files directory. |
3 | 3 |
core = 7.x |
4 | 4 |
files[] = remote_stream_wrapper.inc |
... | ... | |
8 | 8 |
suggests[] = media |
9 | 9 |
suggests[] = image |
10 | 10 |
|
11 |
; Information added by Drupal.org packaging script on 2014-04-22
|
|
12 |
version = "7.x-1.0-rc1"
|
|
11 |
; Information added by Drupal.org packaging script on 2019-07-09
|
|
12 |
version = "7.x-1.0" |
|
13 | 13 |
core = "7.x" |
14 | 14 |
project = "remote_stream_wrapper" |
15 |
datestamp = "1398126831" |
|
16 |
|
|
15 |
datestamp = "1562684598" |
drupal7/sites/all/modules/remote_stream_wrapper/remote_stream_wrapper.module | ||
---|---|---|
85 | 85 |
* Return a list of remote stream wrappers. |
86 | 86 |
*/ |
87 | 87 |
function file_get_remote_stream_wrappers() { |
88 |
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_REMOTE); |
|
89 |
foreach ($wrappers as $scheme => $wrapper) { |
|
90 |
if (empty($wrapper['remote'])) { |
|
91 |
unset($wrappers[$scheme]); |
|
88 |
$wrappers = &drupal_static(__FUNCTION__); |
|
89 |
if (!isset($wrappers)) { |
|
90 |
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_REMOTE); |
|
91 |
foreach ($wrappers as $scheme => $wrapper) { |
|
92 |
if (empty($wrapper['remote'])) { |
|
93 |
unset($wrappers[$scheme]); |
|
94 |
} |
|
92 | 95 |
} |
96 |
//$wrappers = array_diff_key($wrappers, file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL_NORMAL |
|
93 | 97 |
} |
94 |
//$wrappers = array_diff_key($wrappers, file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL_NORMAL)); |
|
95 | 98 |
return $wrappers; |
96 | 99 |
} |
97 | 100 |
|
... | ... | |
108 | 111 |
*/ |
109 | 112 |
function remote_stream_wrapper_file_url_alter(&$uri) { |
110 | 113 |
$scheme = file_uri_scheme($uri); |
111 |
$wrappers = file_get_remote_stream_wrappers(); |
|
112 |
if ($scheme && isset($wrappers[$scheme]) && strpos($uri, "$scheme://styles/") === 0) { |
|
114 |
if ($scheme && file_is_scheme_remote($scheme) && strpos($uri, "$scheme://styles/") === 0) { |
|
113 | 115 |
$uri = file_default_scheme() . '://' . file_uri_target($uri); |
116 |
if (!variable_get('clean_url') && file_uri_scheme($uri) == 'public' && !file_exists($uri)) { |
|
117 |
$directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath(); |
|
118 |
$uri = url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE)); |
|
119 |
} |
|
114 | 120 |
} |
115 | 121 |
} |
116 | 122 |
|
... | ... | |
143 | 149 |
* Validation callback for remote URLs. |
144 | 150 |
*/ |
145 | 151 |
function remote_stream_wrapper_validate_url($element, &$form_state) { |
146 |
$value = $element['#value'];
|
|
152 |
$value = trim($element['#value']);
|
|
147 | 153 |
if ($value != '' && !valid_url($value, TRUE)) { |
148 | 154 |
form_error($element, t('Invalid URL %url.', array('%url' => $value))); |
149 | 155 |
} |
... | ... | |
267 | 273 |
* @see DrupalRemoteStreamWrapper |
268 | 274 |
*/ |
269 | 275 |
function remote_stream_wrapper_file_add_form_submit($form, &$form_state) { |
270 |
$uri = $url = $form_state['values']['url'];
|
|
276 |
$uri = $url = trim($form_state['values']['url']);
|
|
271 | 277 |
|
272 | 278 |
try { |
273 | 279 |
$file = remote_stream_wrapper_file_load_by_uri($uri); |
... | ... | |
301 | 307 |
$form_state['redirect'] = 'admin/content/file'; |
302 | 308 |
} |
303 | 309 |
} |
310 |
|
|
311 |
/** |
|
312 |
* Implements hook_file_delete(). |
|
313 |
*/ |
|
314 |
function remote_stream_wrapper_file_delete($file) { |
|
315 |
$scheme = file_uri_scheme($file->uri); |
|
316 |
if ($scheme && file_is_scheme_remote($scheme)) { |
|
317 |
remote_stream_wrapper_image_path_flush($file->uri); |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
function remote_stream_wrapper_image_path_flush($path) { |
|
322 |
$styles = image_styles(); |
|
323 |
foreach ($styles as $style) { |
|
324 |
$image_path = remote_stream_wrapper_image_style_path($style['name'], $path); |
|
325 |
if (file_exists($image_path)) { |
|
326 |
file_unmanaged_delete($image_path); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules