- Timestamp:
- 03/25/12 15:45:11 (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BookmarkApp.pm
r8 r9 30 30 $self->run_modes([qw{ 31 31 list 32 feed 32 33 view 33 34 edit … … 104 105 ); 105 106 } 107 } 108 109 sub feed { 110 my $self = shift; 111 my $q = $self->query; 112 113 my $tag = $q->param('tag'); 114 115 require XML::Atom::Feed; 116 require XML::Atom::Entry; 117 require XML::Atom::Link; 118 119 my $feed = XML::Atom::Feed->new; 120 $feed->title('Bookmarks'); 121 $feed->id($base_uri . 'feed'); 122 123 # construct a feed from the most recent 12 bookmarks 124 for my $bookmark ($bookmarks->get_resources({ tag => $tag, limit => 12 })) { 125 my $entry = XML::Atom::Entry->new; 126 $entry->id($bookmark->{bookmark_uri}); 127 $entry->title($bookmark->{title}); 128 my $link = XML::Atom::Link->new; 129 $link->href($bookmark->{uri}); 130 $entry->add_link($link); 131 $entry->summary('Tags: ' . join(', ', @{ $bookmark->{tags} })); 132 $feed->add_entry($entry); 133 } 134 135 $self->header_props( 136 -type => 'application/atom+xml', 137 -charset => 'UTF-8', 138 ); 139 return $feed->as_xml; 106 140 } 107 141 -
trunk/Bookmarks.pm
r7 r9 2 2 3 3 use Class::Accessor 'antlers'; 4 use SQL::Interp qw{:all}; 4 5 use Bookmark; 5 6 … … 36 37 my $params = shift; 37 38 my $tag = $params->{tag}; 38 my $sth_resource; 39 if ($tag) { 40 $sth_resource = $self->dbh->prepare('select * from resources join tags on resources.uri = tags.uri join bookmarks on resources.uri = bookmarks.uri where tags.tag = ? order by ctime desc'); 41 $sth_resource->execute($tag); 42 } else { 43 $sth_resource = $self->dbh->prepare('select * from resources join bookmarks on resources.uri = bookmarks.uri order by ctime desc'); 44 $sth_resource->execute; 45 } 39 my $limit = $params->{limit}; 40 41 my ($sql, @bind) = sql_interp( 42 'select * from resources join bookmarks on resources.uri = bookmarks.uri', 43 ($tag ? ('join tags on resources.uri = tags.uri where tags.tag =', \$tag) : ''), 44 'order by ctime desc', 45 ($limit ? ('limit', \$limit) : ''), 46 ); 47 48 my $sth_resource = $self->dbh->prepare($sql); 49 $sth_resource->execute(@bind); 46 50 47 51 my $sth_tag = $self->dbh->prepare('select tag from tags where uri = ? order by tag'); -
trunk/index.cgi
r5 r9 9 9 table => [ 10 10 '[get]' => { app => 'BookmarkApp', rm => 'list' }, 11 'list[get]' => { app => 'BookmarkApp', rm => 'list' }, 12 'feed[get]' => { app => 'BookmarkApp', rm => 'feed' }, 11 13 ':id/:field?[get]' => { app => 'BookmarkApp', rm => 'view' }, 12 14 ':id?[post]' => { app => 'BookmarkApp', rm => 'edit' },
Note: See TracChangeset
for help on using the changeset viewer.