Révision 8dc4e7e8
Ajouté par Assos Assos il y a environ 5 ans
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