From: Andrew Ruthven Date: Sun, 5 Oct 2008 08:37:28 +0000 (+1300) Subject: Allow specifying tags in the config file, default to Favorites. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c010a4995a01a751f96c13b47e50977686cac19c;p=picture-display.git Allow specifying tags in the config file, default to Favorites. --- diff --git a/lib/Display/Plugins/Photo/FSpot.pm b/lib/Display/Plugins/Photo/FSpot.pm index 9358a7e..e3d4a80 100644 --- a/lib/Display/Plugins/Photo/FSpot.pm +++ b/lib/Display/Plugins/Photo/FSpot.pm @@ -25,7 +25,11 @@ sub find_photo { my $self = shift; $self->{'kernel'}->post('FSpotDB', - single => { sql => $self->{'sql'}, event => 'find_photo_result' } + single => { + sql => $self->{'sql'}, + placeholders => $self->{'tags'}, + event => 'find_photo_result', + } ); } @@ -59,7 +63,26 @@ SELECT uri FROM photos, photo_tags, tags WHERE photos.id = photo_tags.photo_id AND photo_tags.tag_id = tags.id - AND tags.name = 'Brooke' + "; + + if (defined $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'}) { + $self->{'tags'} = $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'}; + + if (scalar (@{ $self->{'tags'} })) { + my $holders = "?, " x scalar(@{ $self->{'tags'} }); + $holders =~ s/, $//; + + $self->{'sql'} .= "AND tags.name IN ($holders)"; + } else { + $self->{'sql'} .= "AND tags.name = '?'"; + } + + $self->{'tags'} = $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'}; + } else { + $self->{'sql'} .= "AND tags.name = 'Favorites'"; # Sigh + } + + $self->{'sql'} .= " ORDER BY random() LIMIT 1 ";