function _file_entity_tokens_get_property in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7.2 file_entity.tokens.inc \_file_entity_tokens_get_property()
This helper function gets file properties for token replacement.
Parameters
array $files: An array of files that are values for the field.
string $property: The property to retrieve from the file info. See file_entity_token_info() for a list of properties.
string $array_handler: The optional array modifier, e.g. "count" or "join:,".
Return value
mixed Either a single value, the first of the array, or an array of values.
1 call to _file_entity_tokens_get_property()
- file_entity_tokens in ./
file_entity.tokens.inc - Provide replacement values for placeholder tokens.
File
- ./
file_entity.tokens.inc, line 288 - Token integration for the file_entity module.
Code
function _file_entity_tokens_get_property($files, $property, $array_handler = 'first') {
$value = NULL;
// If we only need the first variable
$return_first = $array_handler == 'first' || empty($array_handler) || $array_handler == 'value:0';
// This static variable stores image info
$info =& drupal_static(__FUNCTION__);
foreach ($files as $file) {
$file['url'] = file_create_url($file['uri']);
$file['https-url'] = str_replace('http://', 'https://', $file['url']);
// If values are: filename, filemime, type, url, https-url
if (isset($file[$property])) {
$value = $file[$property];
}
elseif (!empty($info[$file['fid']])) {
if (isset($info[$file['fid']][$property])) {
$value = $info[$file['fid']][$property];
}
else {
$value = NULL;
}
}
else {
// If file type is image
if ($file['type'] == 'image') {
$imageuri = $file['uri'];
}
elseif ($file['type'] == 'video' && strpos($file['uri'], '://v')) {
list($provider, $filename) = preg_split('!://v.*/!', $file['uri']);
$imageuri = "public://file_entity-{$provider}/{$filename}.jpg";
}
else {
$imageuri = FALSE;
}
if ($info[$file['fid']] = image_get_info($imageuri)) {
$info[$file['fid']]['image'] = file_create_url($imageuri);
$info[$file['fid']]['https-image'] = str_replace('http://', 'https://', $info[$file['fid']]['image']);
}
if (isset($info[$file['fid']][$property])) {
$value = $info[$file['fid']][$property];
}
else {
$value = NULL;
}
}
if ($return_first) {
return $value;
}
$values[] = $value;
}
return $values;
}