summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2005-10-20 11:27:13 +0000
committerdakkar <dakkar@luxion>2005-10-20 11:27:13 +0000
commit86a26a896db925d5d3ee8e0d6ed226a565214912 (patch)
tree376c14bfa44a20e7bb128e4ccee5bf54eebfdfd2 /lib
parentrelazioni, e inizio lavori (diff)
downloadBookmarks-86a26a896db925d5d3ee8e0d6ed226a565214912.tar.gz
Bookmarks-86a26a896db925d5d3ee8e0d6ed226a565214912.tar.bz2
Bookmarks-86a26a896db925d5d3ee8e0d6ed226a565214912.zip
comincia a far finta di andare. le icone non vengono caricate, non so perché
Diffstat (limited to 'lib')
-rw-r--r--lib/Bookmarks.pm2
-rw-r--r--lib/Bookmarks/C/Main.pm36
-rw-r--r--lib/Bookmarks/M/DB/Links.pm8
-rw-r--r--lib/Bookmarks/M/DB/Tags.pm17
-rw-r--r--lib/Bookmarks/Utils.pm45
5 files changed, 95 insertions, 13 deletions
diff --git a/lib/Bookmarks.pm b/lib/Bookmarks.pm
index fb270bd..56e098c 100644
--- a/lib/Bookmarks.pm
+++ b/lib/Bookmarks.pm
@@ -31,7 +31,7 @@ Catalyst based application.
sub default : Private {
my ( $self, $c ) = @_;
- $c->res->output('Congratulations, Bookmarks is on Catalyst!');
+ $c->res->redirect($c->req->base.'tags');
}
=back
diff --git a/lib/Bookmarks/C/Main.pm b/lib/Bookmarks/C/Main.pm
index 7182a9e..89c985d 100644
--- a/lib/Bookmarks/C/Main.pm
+++ b/lib/Bookmarks/C/Main.pm
@@ -23,17 +23,43 @@ Catalyst component.
=cut
-sub default : Private {
- my ( $self, $c ) = @_;
- $c->res->redirect($c->req->base,'/tags');
-}
-
sub tags : Global {
my ( $self, $c ) = @_;
$c->stash->{template}='tags';
$c->stash->{tags}=[Bookmarks::M::DB::Tags->get_all_tags_by_popularity()];
}
+sub tag : Regex('^tag/(.*)$') {
+ my ( $self, $c ) = @_;
+
+ my $tagname=$c->req->snippets->[0];
+ my ($tag)=Bookmarks::M::DB::Tags->search({name=>$tagname});
+ if (!defined $tag) {
+ $c->stash->{tagname}=$tagname;
+ $c->stash->{template}='notag';
+ }
+ else {
+ my @links=$tag->ordered_links();
+ $c->stash->{tag}=$tag;
+ $c->stash->{links}=[@links];
+ $c->stash->{template}='links';
+ }
+}
+
+sub icon : Global {
+ my ( $self, $c ) = @_;
+
+ my $link=Bookmarks::M::DB::Links->retrieve($c->req->param('link'));
+ if ($link->icon()) {
+ $c->res->content_type('image/x-icon');
+ $c->res->body($link->icon());
+ }
+ else {
+ $c->res->status(404);
+ $c->res->body('nonce');
+ }
+}
+
=back
diff --git a/lib/Bookmarks/M/DB/Links.pm b/lib/Bookmarks/M/DB/Links.pm
index 851d9a3..3ae761d 100644
--- a/lib/Bookmarks/M/DB/Links.pm
+++ b/lib/Bookmarks/M/DB/Links.pm
@@ -1,15 +1,17 @@
package Bookmarks::M::DB::Links;
-
use strict;
+use DBI;
for my $col_name (qw(add_date last_access_date)) {
__PACKAGE__->has_a( $col_name => 'DateTime',
- inflate => sub { DateTime->from_epoch( epoch => $_ ) },
+ inflate => sub { DateTime->from_epoch( epoch => $_[0] ) },
deflate => 'epoch',
);
}
-__PACKAGE__->has_many( tags => [Bookmarks::M::DB::LinkTags => 'tag'] );
+__PACKAGE__->has_many( tags => ['Bookmarks::M::DB::LinksTags' => 'tag'] );
+
+__PACKAGE__->data_type( icon => DBI::SQL_BINARY );
=head1 NAME
diff --git a/lib/Bookmarks/M/DB/Tags.pm b/lib/Bookmarks/M/DB/Tags.pm
index e9057a8..c1e1f0b 100644
--- a/lib/Bookmarks/M/DB/Tags.pm
+++ b/lib/Bookmarks/M/DB/Tags.pm
@@ -2,9 +2,9 @@ package Bookmarks::M::DB::Tags;
use strict;
-__PACKAGE__->has_many( links => [Bookmarks::M::DB::LinkTags => 'link'] );
+__PACKAGE__->has_many( links => ['Bookmarks::M::DB::LinksTags' => 'link'] );
-__PACKAGE__->set_sql('related_tags' <<'END_SQL');
+__PACKAGE__->set_sql('related_tags', <<'END_SQL');
SELECT tags.pk
FROM tags, links_tags lt1, links_tags lt2
WHERE tags.pk = lt1.tag
@@ -12,13 +12,16 @@ SELECT tags.pk
AND lt2.tag = ?
END_SQL
-__PACKAGE__->set_sql('popularity' <<'END_SQL');
+__PACKAGE__->set_sql('popularity', <<'END_SQL');
SELECT tags.pk, COUNT(links_tags.link) AS how_many
FROM tags, links_tags
WHERE tags.pk = links_tags.tag
-ORDER BY how_many
+GROUP BY links_tags.tag
+ORDER BY how_many DESC
END_SQL
+__PACKAGE__->columns(TEMP=> 'how_wany');
+
sub count_links {
my ($self)=@_;
return scalar $self->links();
@@ -34,6 +37,12 @@ sub get_all_tags_by_popularity {
return $_[0]->search_popularity();
}
+sub ordered_links {
+ my ($self)=@_;
+ my @links=$self->links();
+ return sort {$a->access_count <=> $b->access_count} @links;
+}
+
=head1 NAME
Bookmarks::M::DB::Tags - CDBI Model Component Table Class
diff --git a/lib/Bookmarks/Utils.pm b/lib/Bookmarks/Utils.pm
new file mode 100644
index 0000000..fd0b68d
--- /dev/null
+++ b/lib/Bookmarks/Utils.pm
@@ -0,0 +1,45 @@
+package Bookmarks::Utils;
+use strict;
+use warnings;
+use LWP::Simple;
+use URI::URL;
+
+sub check_link {
+ my ($url)=@_;
+ return 1 if $url!~/^http:/;
+ #my ($type,$length,$update,$expires,$server)=head($url);
+ #return defined $type;
+ return scalar head($url);
+}
+
+sub get_site_icon {
+ my ($url)=@_;
+
+ return if $url!~/^http:/;
+
+ print "Provo nella pagina\n";
+ my $page=get($url);
+ my ($favicon)= grep {defined $_ and $_ ne ''}
+ ($page =~
+ m{<link
+ \s+
+ (?:
+ rel="shortcut\ icon"
+ \s+
+ href="(.*?)"
+ )|(?:
+ href="(.*?)"
+ \s+
+ rel="shortcut\ icon"
+ )}smx);
+ if (!$favicon) {
+ $favicon='/favicon.ico';
+ }
+ print "Trovato: '$favicon'";
+ $favicon=URI::URL->new($favicon,$url)->abs->canonical->as_string;
+ print ", ovvero '$favicon'\n";
+ my $icon=get($favicon);
+ return $icon;
+}
+
+1;