- Timestamp:
- 05/27/13 14:46:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BookmarkApp.pm
r36 r37 12 12 13 13 use URI; 14 my $base_uri = URI->new;15 $base_uri->scheme('http');16 $base_uri->host($ENV{HTTP_X_FORWARDED_HOST} || $ENV{SERVER_NAME});17 $base_uri->port($ENV{SERVER_PORT});18 $base_uri->path($ENV{SCRIPT_NAME} . '/');19 14 20 15 my $dbname = 'fk.db'; 21 my $bookmarks = Bookmarks->new({22 dbname => $dbname,23 base_uri => $base_uri,24 });25 16 26 17 sub setup { … … 34 25 edit 35 26 }]); 36 } 27 my $base_uri = URI->new; 28 $base_uri->scheme('http'); 29 $base_uri->host($ENV{HTTP_X_FORWARDED_HOST} || $ENV{SERVER_NAME}); 30 $base_uri->port($ENV{SERVER_PORT}); 31 $base_uri->path($ENV{SCRIPT_NAME} . '/'); 32 33 my $bookmarks = Bookmarks->new({ 34 dbname => $dbname, 35 base_uri => $base_uri, 36 }); 37 38 $self->param( 39 base_uri => $base_uri, 40 bookmarks => $bookmarks, 41 ); 42 } 43 44 sub _bookmarks { $_[0]->param('bookmarks') } 37 45 38 46 sub list { … … 43 51 # see if a bookmark for that URI already exists 44 52 if (defined(my $uri = $q->param('uri'))) { 45 my $bookmark = $ bookmarks->get_bookmark({ uri => $uri });53 my $bookmark = $self->_bookmarks->get_bookmark({ uri => $uri }); 46 54 if ($bookmark) { 47 55 # redirect to the view of the existing bookmark … … 73 81 my $limit = $q->param('limit'); 74 82 my $offset = $q->param('offset'); 75 my @resources = $ bookmarks->get_bookmarks({83 my @resources = $self->_bookmarks->get_bookmarks({ 76 84 tag => \@tags, 77 85 limit => $limit, 78 86 offset => $offset, 79 87 }); 80 my @all_tags = $ bookmarks->get_tags({ selected => $tags[0] });81 my @cotags = $ bookmarks->get_cotags({ tag => \@tags });88 my @all_tags = $self->_bookmarks->get_tags({ selected => $tags[0] }); 89 my @cotags = $self->_bookmarks->get_cotags({ tag => \@tags }); 82 90 83 91 my $title = 'Bookmarks' . (@tags ? " tagged as " . join(' & ', @tags) : ''); … … 185 193 ); 186 194 for my $link (@links) { 187 $link->{href} = URI->new_abs($link->{path} || '', $ base_uri);195 $link->{href} = URI->new_abs($link->{path} || '', $self->param('base_uri')); 188 196 $link->{href}->query_form($link->{query}); 189 197 } … … 222 230 $feed->title($title); 223 231 224 my $feed_uri = URI->new_abs('feed', $ base_uri);232 my $feed_uri = URI->new_abs('feed', $self->param('base_uri')); 225 233 $feed_uri->query_form(tag => \@tags); 226 234 $feed->id($feed_uri->canonical); … … 235 243 $html_link->type('text/html'); 236 244 $html_link->rel('alternate'); 237 my $html_uri = $ base_uri->clone;245 my $html_uri = $self->param('base_uri')->clone; 238 246 $html_uri->query_form(tag => \@tags); 239 247 $html_link->href($html_uri->canonical); … … 241 249 242 250 # construct a feed from the most recent 12 bookmarks 243 for my $bookmark ($ bookmarks->get_bookmarks({ tag => \@tags, limit => 12 })) {251 for my $bookmark ($self->_bookmarks->get_bookmarks({ tag => \@tags, limit => 12 })) { 244 252 my $entry = XML::Atom::Entry->new; 245 253 $entry->id($bookmark->bookmark_uri->canonical); … … 268 276 my $format = $self->query->param('format') || 'html'; 269 277 270 my $bookmark = $ bookmarks->get_bookmark({ id => $id });278 my $bookmark = $self->_bookmarks->get_bookmark({ id => $id }); 271 279 if ($bookmark) { 272 280 if ($format eq 'json') { … … 305 313 my $field = $self->param('field'); 306 314 307 my $bookmark = $ bookmarks->get_bookmark({ id => $id });315 my $bookmark = $self->_bookmarks->get_bookmark({ id => $id }); 308 316 if ($bookmark) { 309 317 # respond with just the requested field as plain text … … 345 353 my $title = $q->param('title'); 346 354 my @tags = split ' ', $q->param('tags'); 347 $ bookmarks->add({355 $self->_bookmarks->add({ 348 356 uri => $uri, 349 357 title => $title,
Note: See TracChangeset
for help on using the changeset viewer.