function bg_image_get_image_path_from_node in Background Images 7
Same name and namespace in other branches
- 6 bg_image.module \bg_image_get_image_path_from_node()
Determines the path of an image on the configured image field on a node and returns it.
Parameters
$nid: The nid of the node to check for an image
$build_url: Optional parameter to return the full URL of the image rather than just the uri
Return value
The path of the image if the node has it, or FALSE.
2 calls to bg_image_get_image_path_from_node()
- bg_image_add_background_image_from_node in ./
bg_image.module - Adds a background image to the page using an image from a node. The node must have an image (or media) field and the field must be configured on the bg_image configuration page for this to work.
- theme_bg_image_ui_paths_table in bg_image_ui/
bg_image_ui.module - Theme the background image paths form into a table
File
- ./
bg_image.module, line 379 - Allows for customizable background images per page
Code
function bg_image_get_image_path_from_node($nid, $build_url = TRUE) {
$fields = field_info_fields();
$field_name = variable_get('bg_image_node_field', '');
$node = node_load($nid);
$image_path = FALSE;
if ($node && $field_name) {
if (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'media') {
if ($node->{$field_name}) {
$items = field_get_items('node', $node, $field_name);
$file = file_load($items[0]['fid']);
if ($file && $file->type == 'image') {
$image_path = $file->uri;
}
}
}
elseif (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'image') {
if ($node->{$field_name}) {
$items = field_get_items('node', $node, $field_name);
if (isset($items[0]['uri'])) {
$image_path = $items[0]['uri'];
}
}
}
elseif (isset($fields[$field_name]) && $fields[$field_name]['type'] == 'atom_reference') {
if ($node->{$field_name}) {
$items = field_get_items('node', $node, $field_name);
if (isset($items[0]['sid'])) {
$atom = scald_atom_load($items[0]['sid']);
if ($atom->type == 'image') {
$image_path = $atom->file_source;
}
}
}
}
}
if ($image_path && $build_url) {
$image_path = file_create_url($image_path);
}
return $image_path;
}