Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi aaron,
this patch stores an extra item (Flickr author) in emfield_flickr_data() to allow later use.
We had several projects which required providing explicit image credits to Flickr images without creating extra fields to store that data. While the patch is dead simple, it saves the trouble of the extra CCK fields and with theme override can be easily displayed.
e.g.
/**
* Override emimage themes.
* Add extra data to the image if it's provided by Media: Flickr and has an author
*/
function phptemplate_emimage_image($field, $item, $formatter, $node, $code, $width = NULL, $height = NULL, $title = '', $link = NULL, $options = array()) {
$url = emimage_image_url($field, $item, $formatter, $node, $code, $width, $height, $options);
$attributes = array();
if ($width) {
$attributes['width'] = $width;
}
if ($height) {
$attributes['height'] = $height;
}
if (!isset($width) || !isset($height)) {
// Find out the size of the actual image file, and scale accordingly
if ( $item['data']['width'] && $item['data']['height'] ) {
// The image's width & height are known
$scale_width = $item['data']['width'] / ($width ? $width : 1);
$scale_height = $item['data']['height'] / ($height ? $height : 1);
if ($scale_width > $scale_height) {
$attributes['width'] = $width;
}
else {
$attributes['height'] = $height;
}
}
else {
// We don't know the size of the image, so just make it fill the space available.
// It will probably be stretched in one direction, making it look odd.
$attributes['width'] = $width ? $width : NULL;
$attributes['height'] = $height ? $height : NULL;
}
}
if ($item['class']) {
$attributes['class'] = $item['class'];
}
else if ($item['provider']) {
$attributes['class'] = $item['provider'];
}
$output = theme('image', $url, $title, $title, $attributes, false);
if ($link) {
$output = l($output, $link, array('html' => true));
}
// Add image credits
if ($item['provider'] == 'flickr' && isset($item['data']['author']) ) {
// See W3C Figures & Captions w3.org/Style/Examples/007/figures
$output = '<div class="figure">' . $output . '<p class="caption">Photo by '
. l($item['data']['author'], $item['embed'] . '</p></div>';
}
return $output;
}
Of course the patch will apply to new content only (or one would have to resave older nodes).
Thought it could be of help to people
Comment | File | Size | Author |
---|---|---|---|
flick_inc_data_author.patch | 598 bytes | zerolab |
Comments
Comment #1
steinmb CreditAttribution: steinmb as a volunteer commented