diff options
author | dakkar <dakkar@luxion> | 2005-11-09 17:14:54 +0000 |
---|---|---|
committer | dakkar <dakkar@luxion> | 2005-11-09 17:14:54 +0000 |
commit | 27cff350e9e5fb832185bc14dee35b5b8f942a81 (patch) | |
tree | e89f9b5d457b711cce6d908ef0b33792cab20e75 /script | |
parent | ora il BookmarksManager gestisce per bene i tag multipli, e i template sono f... (diff) | |
download | Bookmarks-27cff350e9e5fb832185bc14dee35b5b8f942a81.tar.gz Bookmarks-27cff350e9e5fb832185bc14dee35b5b8f942a81.tar.bz2 Bookmarks-27cff350e9e5fb832185bc14dee35b5b8f942a81.zip |
* passati i template a HTML4, altrimenti l'autocompletamento non va
* aggiunto autocompletamento per i nomi di tag
* migliorato il caricatore da YAML
* aggiunto un convertitore XBEL -> YAML
* aggiunto campo 'tipo icona'
* aggiunta funzionalità di edit e delete di link
* dopo ogni update di un link, i tag non più riferiti vengono cancellati
* migliorato il recupero favicon, con tipo
Diffstat (limited to 'script')
-rwxr-xr-x | script/bookmarks_load.pl | 14 | ||||
-rw-r--r-- | script/bookmarks_makedb.pl | 1 | ||||
-rw-r--r-- | script/check_icons.pl | 39 | ||||
-rw-r--r-- | script/xbel2yaml.pl | 77 |
4 files changed, 126 insertions, 5 deletions
diff --git a/script/bookmarks_load.pl b/script/bookmarks_load.pl index 7b16fa1..6433f24 100755 --- a/script/bookmarks_load.pl +++ b/script/bookmarks_load.pl @@ -30,16 +30,20 @@ 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->{description}.=' [INVALID]'; - } + if (!Bookmarks::Utils::check_link($link->{href})) { + warn "Link $link->{href} non valido, marco come tale\n"; + $link->{description}.=' [INVALID]'; + } + else { + my ($icon,$type)=Bookmarks::Utils::get_site_icon($link->{href}); + $dblink->set_icon($icon); + $dblink->icon_type($type); + } $link->{created}||=time(); $link->{modified}||=time(); while (my ($f1,$f2) = each %fields) { $dblink->$f2($link->{$f1}); } - $dblink->set_icon(Bookmarks::Utils::get_site_icon($link->{href})); $dblink->update(); Bookmarks::M::DB::LinksTags->search({link => $dblink->pk()})->delete_all(); diff --git a/script/bookmarks_makedb.pl b/script/bookmarks_makedb.pl index 7b3ee1c..991cdd6 100644 --- a/script/bookmarks_makedb.pl +++ b/script/bookmarks_makedb.pl @@ -28,6 +28,7 @@ create table links ( title text, descr text, icon text, + icon_type text, add_date integer, last_access_date integer, access_count integer diff --git a/script/check_icons.pl b/script/check_icons.pl new file mode 100644 index 0000000..2afdc7d --- /dev/null +++ b/script/check_icons.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +use strict; +use warnings; +use FindBin; +use DBI; +use MIME::Base64; +use File::MMagic; +use Path::Class; + +my $DBHOME=dir($FindBin::Bin)->parent->file('bookmarks.db'); +my $db=DBI->connect("dbi:SQLite:$DBHOME"); + +my $magic=File::MMagic->new(); + +my $sth=$db->prepare('select pk,icon from links'); +$sth->execute(); +my ($pk,$icon,$type); +my @to_clean=();my %to_update; +while (($pk,$icon)=$sth->fetchrow_array()) { + $icon=decode_base64($icon); + $type=$magic->checktype_contents($icon); + if ($type =~ /^text/) { + push @to_clean,$pk; + } + else { + $to_update{$pk}=$type; + } +} + +$sth=$db->prepare(q{update links set icon='' where pk=?}); +for $pk (@to_clean) { + $sth->execute($pk); +} +$sth=$db->prepare(q{update links set icon_type=? where pk=?}); +while (($pk,$type)=each %to_update) { + $sth->execute($type,$pk); +} + +$db->disconnect; diff --git a/script/xbel2yaml.pl b/script/xbel2yaml.pl new file mode 100644 index 0000000..6cfb186 --- /dev/null +++ b/script/xbel2yaml.pl @@ -0,0 +1,77 @@ +#!/usr/bin/perl +use XML::SAX::ParserFactory; +use YAML; + +my $handler=XBEL::Handler->new(); +my $parser=XML::SAX::ParserFactory->parser(Handler=>$handler); +$parser->parse_uri($ARGV[0]); + +print Dump($handler->bookmarks()); + +package XBEL::Handler; +use base 'XML::SAX::Base'; +use Date::Parse; + +sub new { + my ($class)=@_; + return bless +{ + bookmarks=>[], + status=>'out', + tags=>[], + },$class; +} + +sub start_element { + my ($self,$el)=@_; + + if ($el->{LocalName} eq 'folder') { + $self->{status}='folder'; + push @{$self->{tags}},''; + } + elsif ($el->{LocalName} eq 'bookmark') { + $self->{status}='mark'; + my $mark={}; + $mark->{href}=$el->{Attributes}{'{}href'}{Value}; + $mark->{created}=convert_date($el->{Attributes}{'{}added'}{Value}); + $mark->{modified}=convert_date($el->{Attributes}{'{}modified'}{Value}); + $mark->{tags}=[@{$self->{tags}}]; # force a copy + push @{$self->{bookmarks}},$mark; + } + elsif ($el->{LocalName} eq 'title' and $self->{status} eq 'folder') { + $self->{status}='folder-title'; + } + elsif ($el->{LocalName} eq 'title' and $self->{status} eq 'mark') { + $self->{status}='mark-title'; + } +} + +sub end_element { + my ($self,$el)=@_; + + if ($el->{LocalName} eq 'folder') { + pop @{$self->{tags}}; + } + $self->{status}=''; +} + +sub characters { + my ($self,$data)=@_; + + if ($self->{status} eq 'mark-title') { + $self->{bookmarks}[-1]{description}.=$data->{Data}; + } + elsif ($self->{status} eq 'folder-title') { + $self->{tags}[-1].=$data->{Data}; + } +} + +sub convert_date { + return str2time($_[0]); +} + +sub bookmarks { + my ($self)=@_; + return $self->{bookmarks}; +} + +1; |