From 4e380e6e3fb55cdb63e2399614184a85e4475e30 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 20 Oct 2005 13:41:27 +0000 Subject: ora gestisce le icone, ma devo tenerle in un TEXT, base64, causa bug in DBD::SQLite --- lib/Bookmarks/C/Main.pm | 4 ++-- lib/Bookmarks/M/DB/Links.pm | 13 ++++++++++--- script/bookmarks_load.pl | 16 ++++++---------- script/bookmarks_makedb.pl | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm index 89c985d..b25ef9a 100644 --- a/lib/Bookmarks/C/Main.pm +++ b/lib/Bookmarks/C/Main.pm @@ -50,9 +50,9 @@ sub icon : Global { my ( $self, $c ) = @_; my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link')); - if ($link->icon()) { + if ($link->get_icon()) { $c->res->content_type('image/x-icon'); - $c->res->body($link->icon()); + $c->res->body($link->get_icon()); } else { $c->res->status(404); diff --git a/lib/Bookmarks/M/DB/Links.pm b/lib/Bookmarks/M/DB/Links.pm index 92fd74b..1719770 100644 --- a/lib/Bookmarks/M/DB/Links.pm +++ b/lib/Bookmarks/M/DB/Links.pm @@ -1,6 +1,6 @@ package Bookmarks::M::DB::Links; use strict; -use DBI; +use MIME::Base64; for my $col_name (qw(add_date last_access_date)) { __PACKAGE__->has_a( $col_name => 'DateTime', @@ -9,9 +9,16 @@ for my $col_name (qw(add_date last_access_date)) { ); } -__PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] ); +sub set_icon { + my ($self,$icon)=@_; + $self->icon(encode_base64($icon)); +} +sub get_icon { + my ($self)=@_; + return decode_base64($self->icon()); +} -__PACKAGE__->data_type( icon => DBI::SQL_BLOB ); +__PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] ); =head1 NAME diff --git a/script/bookmarks_load.pl b/script/bookmarks_load.pl index 8535348..9862f87 100755 --- a/script/bookmarks_load.pl +++ b/script/bookmarks_load.pl @@ -14,8 +14,6 @@ my $links; $yaml = <>; $links=YAML::Load($yaml); } -my $icon=do {local $/;open my $fh,'<:raw','favicon.ico';<$fh>}; -print "Icon is $icon\n"; my %fields=( description => 'title', @@ -32,20 +30,18 @@ for my $link (@$links) { my $dblink=Bookmarks::M::DB::Links->find_or_create({ url => $link->{href}, }); -# if (!Bookmarks::Utils::check_link($link->{href})) { -# warn "Link $link->{href} non valido, marco come tale\n"; -# $link->{title}.=' [INVALID]'; -# } + if (!Bookmarks::Utils::check_link($link->{href})) { + warn "Link $link->{href} non valido, marco come tale\n"; + $link->{title}.=' [INVALID]'; + } $link->{created}||=time(); $link->{modified}||=time(); while (my ($f1,$f2) = each %fields) { $dblink->$f2($link->{$f1}); } -# $dblink->icon(Bookmarks::Utils::get_site_icon($link->{href})); - $dblink->icon($icon); - print 'Set icon to: ',$dblink->icon(),"\n"; + $dblink->set_icon(Bookmarks::Utils::get_site_icon($link->{href})); $dblink->update(); - print 'Set icon to: ',$dblink->icon(),"\n"; + for my $tagname (@{$link->{tags}}) { my $dbtag=Bookmarks::M::DB::Tags->find_or_create({ name => $tagname, diff --git a/script/bookmarks_makedb.pl b/script/bookmarks_makedb.pl index 93027a7..7b3ee1c 100644 --- a/script/bookmarks_makedb.pl +++ b/script/bookmarks_makedb.pl @@ -27,7 +27,7 @@ create table links ( url text unique, title text, descr text, - icon blob, + icon text, add_date integer, last_access_date integer, access_count integer -- cgit v1.2.3