function imagefield_focus_find in ImageField Focus 6
Find an focus-enabled imagefield from a given filepath. Inspired by filefield_file_download($filepath).
Return value
An imagefield object if found, FALSE otherwise.
2 calls to imagefield_focus_find()
File
- ./
imagefield_focus.module, line 250 - Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr> http://www.absyx.fr
Code
function imagefield_focus_find($filepath) {
$result = db_query("SELECT * FROM {files} WHERE filepath = '%s' ORDER BY fid DESC", $filepath);
// Ensure case-sensitivity of uploaded file names.
while ($file = db_fetch_object($result)) {
if (strcmp($file->filepath, $filepath) == 0) {
break;
}
}
// If the file is not found in the database, we're not responsible for it.
if (!isset($file)) {
return FALSE;
}
// Find out which field and node this file belongs to.
$imagefield = NULL;
foreach (content_fields() as $field) {
if ($field['type'] == 'filefield' && imagefield_focus_widget_support($field['widget']['type'])) {
$db_info = content_database_info($field);
$table = $db_info['table'];
$fid_column = $db_info['columns']['fid']['column'];
$columns = array(
'c.vid',
'c.nid',
'n.type',
);
foreach ($db_info['columns'] as $property_name => $column_info) {
$columns[] = $column_info['column'] . ' AS ' . $property_name;
}
$result = db_query('SELECT ' . implode(', ', $columns) . '
FROM {' . $table . '} c
INNER JOIN {node} n ON n.vid = c.vid
AND ' . $fid_column . ' = %d
ORDER BY tnid', $file->fid);
if ($imagefield = db_fetch_array($result)) {
break;
}
}
}
// If no imagefield item is involved with this file, we don't care about it.
if (!$imagefield) {
return FALSE;
}
// If focus is not enabled for this imagefield item, we don't care about it
// either.
$field = content_fields($field['field_name'], $imagefield['type']);
if (empty($field['widget']['focus'])) {
return FALSE;
}
// Complete the imagefield object.
$imagefield['data'] = unserialize($imagefield['data']);
$imagefield = (object) array_merge((array) $file, $imagefield);
return $imagefield;
}