Révision ca0757b9
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/file_entity/file_entity.module | ||
---|---|---|
38 | 38 |
*/ |
39 | 39 |
function file_entity_hook_info() { |
40 | 40 |
$hooks = array( |
41 |
'file_operation_info', |
|
42 |
'file_operation_info_alter', |
|
41 |
'file_operations', |
|
43 | 42 |
'file_type_info', |
44 | 43 |
'file_type_info_alter', |
45 | 44 |
'file_formatter_info', |
... | ... | |
84 | 83 |
$info += array_fill_keys($hooks, array('group' => 'file')); |
85 | 84 |
} |
86 | 85 |
|
86 |
/** |
|
87 |
* Implements hook_module_implements_alter(). |
|
88 |
*/ |
|
89 |
function file_entity_module_implements_alter(&$implementations, $hook) { |
|
90 |
// nginx_accel_redirect_file_transfer() is an accidental hook implementation. |
|
91 |
// @see https://www.drupal.org/node/2278625 |
|
92 |
if ($hook == 'file_transfer') { |
|
93 |
unset($implementations['nginx_accel_redirect']); |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
87 | 97 |
/** |
88 | 98 |
* Implements hook_help(). |
89 | 99 |
*/ |
... | ... | |
189 | 199 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
190 | 200 |
'weight' => -10, |
191 | 201 |
); |
202 |
$items['file/add/upload/file'] = array( |
|
203 |
'title' => 'File', |
|
204 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
|
205 |
'weight' => -10, |
|
206 |
); |
|
207 |
$items['file/add/upload/archive'] = array( |
|
208 |
'title' => 'Archive', |
|
209 |
'page callback' => 'drupal_get_form', |
|
210 |
'page arguments' => array('file_entity_upload_archive_form'), |
|
211 |
'access arguments' => array('administer files'), |
|
212 |
'file' => 'file_entity.pages.inc', |
|
213 |
'type' => MENU_LOCAL_TASK, |
|
214 |
'weight' => -5, |
|
215 |
); |
|
192 | 216 |
$items['file/%file'] = array( |
193 | 217 |
'title callback' => 'entity_label', |
194 | 218 |
'title arguments' => array('file', 1), |
... | ... | |
1113 | 1137 |
// Set $display['type'] to what hook_field_formatter_*() expects. |
1114 | 1138 |
$display['type'] = $field_formatter_type; |
1115 | 1139 |
|
1140 |
// Allow any attribute overrides (e.g. from the Media module) to be |
|
1141 |
// respected. |
|
1142 |
$item = (array) $file; |
|
1143 |
if (!empty($file->override['attributes'])) { |
|
1144 |
$item = array_merge($item, $file->override['attributes']); |
|
1145 |
} |
|
1146 |
|
|
1116 | 1147 |
// Set $items to what file field formatters expect. See file_field_load(), |
1117 | 1148 |
// and note that, here, $file is already a fully loaded entity. |
1118 |
$items = array((array) $file);
|
|
1149 |
$items = array($item);
|
|
1119 | 1150 |
|
1120 | 1151 |
// Invoke hook_field_formatter_prepare_view() and |
1121 | 1152 |
// hook_field_formatter_view(). Note that we are reusing field formatter |
... | ... | |
1878 | 1909 |
$file_conditions->exists($subquery); |
1879 | 1910 |
} |
1880 | 1911 |
// Otherwise attach it to the node query itself. |
1912 |
elseif ($table == 'file_managed') { |
|
1913 |
// Fix for https://drupal.org/node/2073085 |
|
1914 |
$db_or = db_or(); |
|
1915 |
$db_or->exists($subquery); |
|
1916 |
$db_or->isNull($falias . '.' . $field); |
|
1917 |
$query->condition($db_or); |
|
1918 |
} |
|
1881 | 1919 |
else { |
1882 | 1920 |
$query->exists($subquery); |
1883 | 1921 |
} |
... | ... | |
1917 | 1955 |
return file_get_content_headers($file); |
1918 | 1956 |
} |
1919 | 1957 |
|
1920 |
return NULL;
|
|
1958 |
return -1;
|
|
1921 | 1959 |
} |
1922 | 1960 |
|
1923 | 1961 |
/** |
... | ... | |
2151 | 2189 |
return $element; |
2152 | 2190 |
} |
2153 | 2191 |
|
2154 |
/** |
|
2155 |
* Implements hook_file_default_displays_alter() on behalf of image.module. |
|
2156 |
*/ |
|
2157 |
function image_file_default_displays_alter(&$file_displays) { |
|
2158 |
// Images should be displayed as unstyled images by default. |
|
2159 |
if (isset($file_displays['image__default__file_field_file_default'])) { |
|
2160 |
$file_displays['image__default__file_field_file_default']->status = FALSE; |
|
2161 |
} |
|
2162 |
|
|
2163 |
$file_display = new stdClass(); |
|
2164 |
$file_display->api_version = 1; |
|
2165 |
$file_display->name = 'image__default__file_field_image'; |
|
2166 |
$file_display->weight = 50; |
|
2167 |
$file_display->status = TRUE; |
|
2168 |
$file_display->settings = array( |
|
2169 |
'image_style' => '', |
|
2170 |
'image_link' => '', |
|
2171 |
); |
|
2172 |
$file_displays['image__default__file_field_image'] = $file_display; |
|
2173 |
|
|
2174 |
// Image previews should be displayed as image thumbnails by default. |
|
2175 |
if (isset($file_displays['image__preview__file_field_file_default'])) { |
|
2176 |
$file_displays['image__preview__file_field_file_default']->status = FALSE; |
|
2177 |
} |
|
2178 |
|
|
2179 |
$file_display = new stdClass(); |
|
2180 |
$file_display->api_version = 1; |
|
2181 |
$file_display->name = 'image__preview__file_field_image'; |
|
2182 |
$file_display->weight = 50; |
|
2183 |
$file_display->status = TRUE; |
|
2184 |
$file_display->settings = array( |
|
2185 |
'image_style' => 'thumbnail', |
|
2186 |
'image_link' => '', |
|
2187 |
); |
|
2188 |
$file_displays['image__preview__file_field_image'] = $file_display; |
|
2189 |
|
|
2190 |
// Image teasers should be displayed as medium images by default. |
|
2191 |
if (isset($file_displays['image__teaser__file_field_file_default'])) { |
|
2192 |
$file_displays['image__teaser__file_field_file_default']->status = FALSE; |
|
2193 |
} |
|
2194 |
|
|
2195 |
$file_display = new stdClass(); |
|
2196 |
$file_display->api_version = 1; |
|
2197 |
$file_display->name = 'image__teaser__file_field_image'; |
|
2198 |
$file_display->weight = 50; |
|
2199 |
$file_display->status = TRUE; |
|
2200 |
$file_display->settings = array( |
|
2201 |
'image_style' => 'medium', |
|
2202 |
'image_link' => 'content', |
|
2203 |
); |
|
2204 |
$file_displays['image__teaser__file_field_image'] = $file_display; |
|
2205 |
} |
|
2206 |
|
|
2207 | 2192 |
/** |
2208 | 2193 |
* @name pathauto_file Pathauto integration for the core file module. |
2209 | 2194 |
* @{ |
... | ... | |
2265 | 2250 |
*/ |
2266 | 2251 |
function pathauto_file_update_alias(stdClass $file, $op, array $options = array()) { |
2267 | 2252 |
// Skip processing if the user has disabled pathauto for the file. |
2268 |
if (isset($file->path['pathauto']) && empty($file->path['pathauto'])) { |
|
2253 |
if (isset($file->path['pathauto']) && empty($file->path['pathauto']) && empty($options['force'])) {
|
|
2269 | 2254 |
return; |
2270 | 2255 |
} |
2271 | 2256 |
|
... | ... | |
2482 | 2467 |
} |
2483 | 2468 |
|
2484 | 2469 |
/* |
2485 |
* Generate a file download CSRF token. |
|
2470 |
* Generates a token to protect a file download URL. |
|
2471 |
* |
|
2472 |
* This prevents unauthorized crawling of all file download URLs since the |
|
2473 |
* {file_managed}.fid column is an auto-incrementing serial field and is easy |
|
2474 |
* to guess or attempt many at once. This can be costly both in CPU time |
|
2475 |
* and bandwidth. |
|
2486 | 2476 |
* |
2487 |
* This is essentially a duplicate of drupal_get_token, that attempts to still |
|
2488 |
* work if the user is anonymous, by using ip_address() as the identifier |
|
2489 |
* rather than session_id(). |
|
2477 |
* @see image_style_path_token() |
|
2490 | 2478 |
* |
2491 | 2479 |
* @param object $file |
2492 | 2480 |
* A file entity object. |
2493 | 2481 |
* |
2494 | 2482 |
* @return string |
2495 |
* A CSRF token string. |
|
2483 |
* An eight-character token which can be used to protect file downloads |
|
2484 |
* against denial-of-service attacks. |
|
2496 | 2485 |
*/ |
2497 | 2486 |
function file_entity_get_download_token($file) { |
2498 |
$identifier = !empty($GLOBALS['user']->uid) ? session_id() : ip_address();
|
|
2499 |
return drupal_hmac_base64("file/$file->fid/download", $identifier . drupal_get_private_key() . drupal_get_hash_salt());
|
|
2487 |
// Return the first eight characters.
|
|
2488 |
return substr(drupal_hmac_base64("file/$file->fid/download:" . $file->uri, drupal_get_private_key() . drupal_get_hash_salt()), 0, 8);
|
|
2500 | 2489 |
} |
2501 | 2490 |
|
2502 | 2491 |
/** |
... | ... | |
2542 | 2531 |
foreach ($items as $delta => $item) { |
2543 | 2532 |
// If alt and title text is not specified, fall back to alt and |
2544 | 2533 |
// title text on the file. |
2545 |
if (empty($item['alt']) || empty($item['title'])) {
|
|
2534 |
if (!empty($item['fid']) && (empty($item['alt']) || empty($item['title']))) {
|
|
2546 | 2535 |
$file = file_load($item['fid']); |
2547 | 2536 |
foreach (array('alt', 'title') as $key) { |
2548 | 2537 |
if (empty($item[$key]) && !empty($file->{$key})) { |
Formats disponibles : Unified diff
Weekly update of contrib modules