use LWP::UserAgent;
use File::Temp qw(tempfile);
+use Carp;
+
BEGIN{
($VERSION) = q$Revision$ =~ /^Revision:\s+([^\s+])/;
$DEBUG = 0 unless defined $DEBUG;
@EXPORT = ();
- %EXPORT_TAGS = (libravatar => [qw(cache_valid serve_cache retrieve_libravatar)]
+ %EXPORT_TAGS = (libravatar => [qw(cache_valid retrieve_libravatar cache_location)]
);
@EXPORT_OK = ();
Exporter::export_ok_tags(keys %EXPORT_TAGS);
return 0;
}
-=item retreive_libravatar
+=over
+
+=item retrieve_libravatar
- $cache_location = retreive_libravatar(location => $cache_location,
+ $cache_location = retrieve_libravatar(location => $cache_location,
email => lc($param{email}),
);
=cut
-sub retreive_libravatar{
+sub retrieve_libravatar{
my %type_mapping =
(jpeg => 'jpg',
png => 'png',
return $cache_location.'.'.$dest_type;
}
+sub blocked_libravatar {
+ my ($email,$md5sum) = @_;
+ my $blocked = 0;
+ for my $blocker (@{$config{libravatar_blacklist}||[]}) {
+ for my $element ($email,$md5sum) {
+ next unless defined $element;
+ eval {
+ if ($element =~ /$blocker/) {
+ $blocked=1;
+ }
+ };
+ }
+ }
+ return $blocked;
+}
+
sub cache_location {
my %param = @_;
my $md5sum;
} else {
croak("cache_location must be called with one of md5sum or email");
}
+ return undef if blocked_libravatar($param{email},$md5sum);
for my $ext (qw(.png .jpg)) {
if (-e $config{libravatar_cache_dir}.'/'.$md5sum.$ext) {
return $config{libravatar_cache_dir}.'/'.$md5sum.$ext;
my $location = $r->location();
my ($email) = $uri =~ m/\Q$location\E\/?(.*)$/;
if (not length $email) {
- return Apache2::Const::NOT_FOUND;
+ return Apache2::Const::NOT_FOUND();
}
my $q = CGI::Simple->new();
my %param = cgi_parameters(query => $q,
}
$r->filename($cache_location);
$r->path_info('');
- $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM, $r->pool));
+ $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM(), $r->pool));
}
+=back
+
+=cut
1;