diff options
author | dakkar <dakkar@luxion> | 2005-11-09 20:14:46 +0000 |
---|---|---|
committer | dakkar <dakkar@luxion> | 2005-11-09 20:14:46 +0000 |
commit | b9108b0bc2b63e83e6a79063ef0749581edf557c (patch) | |
tree | 031f53418e2d9263a555a0af91755c0571a933f2 /lib | |
parent | * passati i template a HTML4, altrimenti l'autocompletamento non va (diff) | |
download | Bookmarks-b9108b0bc2b63e83e6a79063ef0749581edf557c.tar.gz Bookmarks-b9108b0bc2b63e83e6a79063ef0749581edf557c.tar.bz2 Bookmarks-b9108b0bc2b63e83e6a79063ef0749581edf557c.zip |
aggiunta l'icona di default, e corretto il codice icone in generale
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bookmarks/C/Main.pm | 9 | ||||
-rw-r--r-- | lib/Bookmarks/M/DB/Links.pm | 4 | ||||
-rw-r--r-- | lib/Bookmarks/Utils.pm | 8 |
3 files changed, 13 insertions, 8 deletions
diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm index d4c5a66..244abab 100644 --- a/lib/Bookmarks/C/Main.pm +++ b/lib/Bookmarks/C/Main.pm @@ -3,6 +3,7 @@ package Bookmarks::C::Main; use strict; use base 'Catalyst::Base'; use Bookmarks::Utils; +use File::Slurp; =head1 NAME @@ -65,8 +66,8 @@ sub icon : Global { $c->res->body($icon); } else { - $c->res->status(404); - $c->res->body('nonce'); + $c->res->content_type('image/png'); + $c->res->body(scalar read_file($c->config->{root}.'/root.png')); } } @@ -118,7 +119,9 @@ sub add : Global { } $dblink->set(%pre_link); - $dblink->set_icon(Bookmarks::Utils::get_site_icon($pre_link{url})); + my ($icon,$type)=Bookmarks::Utils::get_site_icon($pre_link{url}); + $dblink->set_icon($icon); + $dblink->icon_type($type); $dblink->update(); for my $tagname (@tags) { diff --git a/lib/Bookmarks/M/DB/Links.pm b/lib/Bookmarks/M/DB/Links.pm index 350e3d5..5c0d37f 100644 --- a/lib/Bookmarks/M/DB/Links.pm +++ b/lib/Bookmarks/M/DB/Links.pm @@ -12,11 +12,11 @@ for my $col_name (qw(add_date last_access_date)) { sub set_icon { my ($self,$icon)=@_; - $self->icon(encode_base64($icon)); + $self->icon(encode_base64($icon||'')); } sub get_icon { my ($self)=@_; - return decode_base64($self->icon()); + return decode_base64($self->icon()||''); } __PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] ); diff --git a/lib/Bookmarks/Utils.pm b/lib/Bookmarks/Utils.pm index a876340..b9fec9c 100644 --- a/lib/Bookmarks/Utils.pm +++ b/lib/Bookmarks/Utils.pm @@ -20,7 +20,9 @@ sub get_site_icon { return if $url!~/^http:/; print "Provo nella pagina\n"; - my $page=get($url); + my $res=$ua->get($url); + return unless $res->is_success(); + my $page=$res->decoded_content(); my ($favicon)= grep {defined $_ and $_ ne ''} ($page =~ m{<link @@ -40,9 +42,9 @@ sub get_site_icon { print "Trovato: '$favicon'"; $favicon=URI::URL->new($favicon,$url)->abs->canonical->as_string; print ", ovvero '$favicon'\n"; - my $res=$ua->get($favicon); + $res=$ua->get($favicon); - if ($res->is_success()) { + if ($res->is_success() and $res->header('Content-type') !~ /^text/) { return ($res->decoded_content(),$res->header('Content-type')); } else { |