Révision 937bad71
Ajouté par Assos Assos il y a presque 6 ans
drupal7/sites/all/modules/file_entity/file_entity.module | ||
---|---|---|
1249 | 1249 |
} |
1250 | 1250 |
} |
1251 | 1251 |
|
1252 |
/** |
|
1253 |
* Replace file entity title text. |
|
1254 |
* |
|
1255 |
* @param $file |
|
1256 |
* The file entity. |
|
1257 |
* @param $replace_options |
|
1258 |
* (Optional) Options to pass to token_replace(). |
|
1259 |
* @param $title |
|
1260 |
* (Optional) The title text to use. |
|
1261 |
* |
|
1262 |
* @return string |
|
1263 |
* Returns the replaced title text. |
|
1264 |
*/ |
|
1265 |
function file_entity_replace_title($file, $replace_options = array(), $title = NULL) { |
|
1266 |
$replace_options += array( |
|
1267 |
'clear' => TRUE, |
|
1268 |
'sanitize' => FALSE, |
|
1269 |
); |
|
1270 |
|
|
1271 |
$title_default = '[file:field_file_image_title_text]'; |
|
1272 |
if (!isset($title)) { |
|
1273 |
$title = variable_get('file_entity_title', $title_default); |
|
1274 |
} |
|
1275 |
// If the defaults are not changed then inlining replacement is much faster |
|
1276 |
// than dealing with the token system. |
|
1277 |
if ($title === $title_default) { |
|
1278 |
$title_items = field_get_items('file', $file, 'field_file_image_title_text'); |
|
1279 |
return $title_items ? $title_items[0]['value'] : ''; |
|
1280 |
} |
|
1281 |
elseif (!empty($title)) { |
|
1282 |
$token_replaced = token_replace($title, array('file' => $file), $replace_options); |
|
1283 |
return decode_entities($token_replaced); // Filter out possible XSS. |
|
1284 |
} |
|
1285 |
|
|
1286 |
return ''; |
|
1287 |
} |
|
1288 |
|
|
1289 |
/** |
|
1290 |
* Replace file entity alt. |
|
1291 |
* |
|
1292 |
* @param $file |
|
1293 |
* The file entity. |
|
1294 |
* @param $replace_options |
|
1295 |
* (Optional) Options to pass to token_replace(). |
|
1296 |
* @param $alt |
|
1297 |
* (Optional) The alt text to use. |
|
1298 |
* |
|
1299 |
* @return string |
|
1300 |
* Returns the replaced alt text. |
|
1301 |
*/ |
|
1302 |
function file_entity_replace_alt($file, $replace_options = array(), $alt = NULL) { |
|
1303 |
$replace_options += array( |
|
1304 |
'clear' => TRUE, |
|
1305 |
'sanitize' => FALSE, |
|
1306 |
); |
|
1307 |
|
|
1308 |
$alt_default = '[file:field_file_image_alt_text]'; |
|
1309 |
|
|
1310 |
if (!isset($alt)) { |
|
1311 |
$alt = variable_get('file_entity_alt', $alt_default); |
|
1312 |
} |
|
1313 |
|
|
1314 |
// If the defaults are not changed then inlining replacement is much faster |
|
1315 |
// than dealing with the token system. |
|
1316 |
if ($alt === $alt_default) { |
|
1317 |
$alt_items = field_get_items('file', $file, 'field_file_image_alt_text'); |
|
1318 |
return $alt_items ? $alt_items[0]['value'] : ''; |
|
1319 |
} |
|
1320 |
elseif (!empty($alt)) { |
|
1321 |
$token_replaced = token_replace($alt, array('file' => $file), $replace_options); |
|
1322 |
return decode_entities($token_replaced); // Filter out possible XSS. |
|
1323 |
} |
|
1324 |
} |
|
1325 |
|
|
1326 |
|
|
1327 | 1252 |
/** |
1328 | 1253 |
* Implements hook_file_formatter_FORMATTER_view(). |
1329 | 1254 |
* |
... | ... | |
1364 | 1289 |
'#path' => $file->uri, |
1365 | 1290 |
'#width' => isset($file->override['attributes']['width']) ? $file->override['attributes']['width'] : $file->metadata['width'], |
1366 | 1291 |
'#height' => isset($file->override['attributes']['height']) ? $file->override['attributes']['height'] : $file->metadata['height'], |
1367 |
'#alt' => file_entity_replace_alt($file, $replace_options, $display['settings']['alt']),
|
|
1368 |
'#title' => file_entity_replace_title($file, $replace_options, $display['settings']['title']),
|
|
1292 |
'#alt' => token_replace($display['settings']['alt'], array('file' => $file), $replace_options),
|
|
1293 |
'#title' => token_replace($display['settings']['title'], array('file' => $file), $replace_options),
|
|
1369 | 1294 |
); |
1370 | 1295 |
} |
1371 | 1296 |
else { |
... | ... | |
1374 | 1299 |
'#path' => $file->uri, |
1375 | 1300 |
'#width' => isset($file->override['attributes']['width']) ? $file->override['attributes']['width'] : $file->metadata['width'], |
1376 | 1301 |
'#height' => isset($file->override['attributes']['height']) ? $file->override['attributes']['height'] : $file->metadata['height'], |
1377 |
'#alt' => file_entity_replace_alt($file, $replace_options, $display['settings']['alt']),
|
|
1378 |
'#title' => file_entity_replace_title($file, $replace_options, $display['settings']['title']),
|
|
1302 |
'#alt' => token_replace($display['settings']['alt'], array('file' => $file), $replace_options),
|
|
1303 |
'#title' => token_replace($display['settings']['title'], array('file' => $file), $replace_options),
|
|
1379 | 1304 |
); |
1380 | 1305 |
} |
1381 | 1306 |
return $element; |
Formats disponibles : Unified diff
Weekly update of contrib modules