theme_morelikethis_flickr_block does foreach on $items, producing +1 (fake) image results
cryptographrix - February 4, 2009 - 09:01
| Project: | More Like This |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | emackn |
| Status: | active |
| Issue tags: | flickr, MLT, MLT_flickr, morelikethis |
Jump to:
Description
I've been trying to trace down this bug in the code, but it's late. If I figure it out before I go to bed, I'll post the bugfix here, but if not, this is just to log until either the devs get to it, or I figure it out.
Basically, this is a good example: http://www.voidfuchsia.com/node/2
Look on the right side - I have images returned set to 3 - MLT_flickr shows 3 ACTUAL flickr results, and one bad image file that points to a local single character. I am guessing that some result from flickr API module may be getting misinterpreted and put into $items, as the syntax of the line is correct, but does not point to an actual image file.

#1
figured it out:
just put:
unset($items['search_tags']);
after search_tags is put in output.
function theme_morelikethis_flickr_block($items) {
// todo: add flag for to disable this, since if you override
// the theme.. this becomes useless.
drupal_add_css(drupal_get_path('module', "morelikethis") . "/contrib/morelikethis_flickr/mlt_flickr.css");
drupal_add_js("
$(document).ready(function(){
$('ul.mlt-flickr li').hover(
function(){ $(this).children('.tags').show();},
function(){ $(this).children('.tags').hide();}
);
$('#block-morelikethis-flickr h2').hover(
function(){ $('#block-morelikethis-flickr .search-with').show();},
function(){ $('#block-morelikethis-flickr .search-with').hide();}
);
});", "inline");
$output = "<div class='search-with' style='display:none;'>".$items['search_tags']. "</div>";
$output .= "<ul class='mlt-flickr'>";
// Since search_tags was already used, I just unset it so it doesn't
// cause a problem once the foreach starts. Simple.
unset($items['search_tags']);
if($items) {
foreach($items as $photo) {
$output .= "<li>". theme('morelikethis_flickr_item', $photo);
$output .= "<div class='tags' style='display:none'>".$photo['tags']."</div>" . "</li>";
}
}
else
$output .= "<li>No photos found</li>";
$output .= "</ul>";
return $output;
}
#2
Thanks for the quick fix. I'm going to look and see if I can find out why that extra data turns up in the $items variable.
#3
#4
it looks like search_tags is used to show the tags that were used to query flickr, which are different than the keywords that display with each image. I think it's necessary, especially to verify what Calais chooses for specific articles, but since it was there once the foreach started, it was seen as another array value (since it's foreach and not for 0-2 or other numeric value).