Changeset 63
- Timestamp:
- 05/06/05 16:35:38 (3 years ago)
- Files:
-
- FlickrPublicPhotos/trunk/FlickrPublicPhotos.pl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FlickrPublicPhotos/trunk/FlickrPublicPhotos.pl
r61 r63 1 1 # A plugin for adding "FlickrPublicPhotos" container and related tags 2 2 # 3 # Release 0.1 0 (Mar 5, 2005)3 # Release 0.11 (Mar 6, 2005) 4 4 # 5 5 # This software is provided as-is. You may use it for commercial or … … 16 16 $plugin = new MT::Plugin(); 17 17 $plugin->name("FlickrPublicPhotos Plugin"); 18 $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.1 0");18 $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.11"); 19 19 $plugin->doc_link("http://as-is.net/hacks/2005/05/flickrpublicphotos_plugin.html"); 20 20 MT->add_plugin($plugin); … … 59 59 60 60 sub photo_title { 61 $_[0]->stash('flickr_public_photo')-> {title};61 $_[0]->stash('flickr_public_photo')->title; 62 62 } 63 63 64 64 sub photo_url { 65 my $photo = $_[0]->stash('flickr_public_photo'); 66 my $url = 'http://www.flickr.com/photos/' . $photo->{nsid} . '/' . $photo->{id} . '/'; 65 $_[0]->stash('flickr_public_photo')->url; 66 } 67 68 sub photo_img_url { 69 $_[0]->stash('flickr_public_photo')->img_url($_[1]->{size} || 't'); 70 } 71 72 package MT::Plugin::FlickrPublicPhotos::Photo; 73 74 sub new { 75 my ($class, $params) = @_; 76 $params ||= {}; 77 bless $params, $class; 78 } 79 80 sub title { 81 my $this = shift; 82 $this->{title} || ''; 83 } 84 85 sub url { 86 my $this = shift; 87 my $url = 'http://www.flickr.com/photos/' . $this->{nsid} . '/' . $this->{id} . '/'; 67 88 $url; 68 89 } 69 90 70 sub photo_img_url {71 my ($ctx, $args) = @_;72 my $photo = $ctx->stash('flickr_public_photo');73 my $size = $args->{size} ||'t';74 my $url = 'http://photos' . $ photo->{server} . '.flickr.com/' . $photo->{id} . '_' . $photo->{secret} . '_' . $size . '.jpg';91 sub img_url { 92 my $this = shift; 93 my ($size) = @_; 94 $size ||= 't'; 95 my $url = 'http://photos' . $this->{server} . '.flickr.com/' . $this->{id} . '_' . $this->{secret} . '_' . $size . '.jpg'; 75 96 $url; 76 }77 78 package MT::Plugin::FlickrPublicPhotos::Photo;79 use constant DEFAULT => {80 id => undef,81 nsid => undef,82 secret => undef,83 server => undef,84 title => undef85 };86 87 sub new {88 my $class = shift;89 my %params = @_;90 my $self = {};91 bless $self => $class;92 97 } 93 98 … … 98 103 99 104 sub new { 100 my $class = shift; 101 bless $class->SUPER::new({ key => API_KEY }) => $class; 105 my ($class, $params) = @_; 106 my $key = $params->{key} || API_KEY; 107 bless $class->SUPER::new({ key => $key }), $class; 102 108 } 103 109 104 110 sub resolve_nsid { 105 my $ class = shift;111 my $this = shift; 106 112 my ($uname) = @_; 107 113 return $uname if $uname =~ /^\d+\@N00$/; 108 my $rsp = $class->execute_method('flickr.people.findByUsername', 109 { username => $uname }); 114 115 my $rsp = ($uname =~ /^[^@]+@[^.]+\..+/) ? 116 $this->execute_method('flickr.people.findByEmail', 117 { find_email => $uname }) : 118 $this->execute_method('flickr.people.findByUsername', 119 { username => $uname }); 110 120 die "Flickr request failed: " . $rsp->{error_message} . "\n" 111 121 unless $rsp->{success} == 1; … … 117 127 118 128 sub photos { 119 my $ class = shift;129 my $this = shift; 120 130 my ($uname) = @_; 121 131 my @photos = (); 122 my $nsid = $ class->resolve_nsid($uname);123 my $rsp = $ class->execute_method('flickr.people.getPublicPhotos',124 { user_id => $nsid });132 my $nsid = $this->resolve_nsid($uname); 133 my $rsp = $this->execute_method('flickr.people.getPublicPhotos', 134 { user_id => $nsid }); 125 135 die "Flickr request failed: " . $rsp->{error_message} . "\n" 126 136 unless $rsp->{success} == 1;
