Show
Ignore:
Timestamp:
05/06/05 16:35:38 (4 years ago)
Author:
ogawa
Message:

Code cleanup

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FlickrPublicPhotos/trunk/FlickrPublicPhotos.pl

    r61 r63  
    11# A plugin for adding "FlickrPublicPhotos" container and related tags 
    22# 
    3 # Release 0.10 (Mar 5, 2005) 
     3# Release 0.11 (Mar 6, 2005) 
    44# 
    55# This software is provided as-is. You may use it for commercial or  
     
    1616    $plugin = new MT::Plugin(); 
    1717    $plugin->name("FlickrPublicPhotos Plugin"); 
    18     $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.10"); 
     18    $plugin->description("Add FlickrPublicPhotos container and related tags. Version 0.11"); 
    1919    $plugin->doc_link("http://as-is.net/hacks/2005/05/flickrpublicphotos_plugin.html"); 
    2020    MT->add_plugin($plugin); 
     
    5959 
    6060sub photo_title { 
    61     $_[0]->stash('flickr_public_photo')->{title}; 
     61    $_[0]->stash('flickr_public_photo')->title; 
    6262} 
    6363 
    6464sub 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 
     68sub photo_img_url { 
     69    $_[0]->stash('flickr_public_photo')->img_url($_[1]->{size} || 't'); 
     70} 
     71 
     72package MT::Plugin::FlickrPublicPhotos::Photo; 
     73 
     74sub new { 
     75    my ($class, $params) = @_; 
     76    $params ||= {}; 
     77    bless $params, $class; 
     78} 
     79 
     80sub title { 
     81    my $this = shift; 
     82    $this->{title} || ''; 
     83} 
     84 
     85sub url { 
     86    my $this = shift; 
     87    my $url = 'http://www.flickr.com/photos/' . $this->{nsid} . '/' . $this->{id} . '/'; 
    6788    $url; 
    6889} 
    6990 
    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'; 
     91sub 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'; 
    7596    $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 => undef 
    85 }; 
    86  
    87 sub new { 
    88     my $class = shift; 
    89     my %params = @_; 
    90     my $self = {}; 
    91     bless $self => $class; 
    9297} 
    9398 
     
    98103 
    99104sub 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; 
    102108} 
    103109 
    104110sub resolve_nsid { 
    105     my $class = shift; 
     111    my $this = shift; 
    106112    my ($uname) = @_; 
    107113    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 }); 
    110120    die "Flickr request failed: " . $rsp->{error_message} . "\n" 
    111121        unless $rsp->{success} == 1; 
     
    117127 
    118128sub photos { 
    119     my $class = shift; 
     129    my $this = shift; 
    120130    my ($uname) = @_; 
    121131    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 }); 
    125135    die "Flickr request failed: " . $rsp->{error_message} . "\n" 
    126136        unless $rsp->{success} == 1;