| | 76 | sub date_upload { |
| | 77 | my $args = $_[1]; |
| | 78 | my $t = $_[0]->stash('flickr_public_photo')->date_upload; # epoch format |
| | 79 | my @ts = $args->{utc} ? |
| | 80 | gmtime $t : offset_time_list($t, $_[0]->stash('blog_id')); |
| | 81 | $args->{ts} = sprintf "%04d%02d%02d%02d%02d%02d", $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0]; |
| | 82 | MT::Template::Context::_hdlr_date($_[0], $args); |
| | 83 | } |
| | 84 | |
| | 85 | sub date_taken { |
| | 86 | my $args = $_[1]; |
| | 87 | $args->{ts} = $_[0]->stash('flickr_public_photo')->date_taken; |
| | 88 | MT::Template::Context::_hdlr_date($_[0], $args); |
| | 89 | } |
| | 90 | |
| | 91 | sub owner_name { |
| | 92 | $_[0]->stash('flickr_public_photo')->owner_name; |
| | 93 | } |
| | 94 | |
| | 119 | } |
| | 120 | |
| | 121 | # INPUT/OUTPUT: UNIX epoch format (should be converted to "YYYYMMDDHHMMSS") |
| | 122 | sub date_upload { |
| | 123 | $_[0]->{dateupload} || ''; |
| | 124 | } |
| | 125 | |
| | 126 | # INPUT: MySQL datetime in owner's localtime |
| | 127 | # OUTPUT: "YYYYMMDDHHMMSS" format |
| | 128 | sub date_taken { |
| | 129 | my $date = $_[0]->{datetaken}; |
| | 130 | if ($date =~ /(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/) { |
| | 131 | sprintf "%04d%02d%02d%02d%02d%02d", $1, $2, $3, $4, $5, $6; |
| | 132 | } elsif ($date =~ /(\d\d\d\d)-(\d\d)/) { |
| | 133 | sprintf "%04d%02d01000000", $1, $2; |
| | 134 | } elsif ($date =~ /(\d\d\d\d)/) { |
| | 135 | sprintf "%04d0101000000", $1; |
| | 136 | } |
| | 137 | } |
| | 138 | |
| | 139 | sub owner_name { |
| | 140 | $_[0]->{ownername} || ''; |
| 139 | | $xpath->set_tree($rsp->{tree}); |
| 140 | | my @photoNodes = $xpath->select_nodes('/photos/photo'); |
| 141 | | for my $node (@photoNodes) { |
| 142 | | my $photo = new MT::Plugin::FlickrPublicPhotos::Photo(); |
| 143 | | $photo->{id} = $node->{attributes}{id}; |
| 144 | | $photo->{nsid} = $nsid; |
| 145 | | $photo->{secret} = $node->{attributes}{secret}; |
| 146 | | $photo->{server} = $node->{attributes}{server}; |
| 147 | | $photo->{title} = $node->{attributes}{title}; |
| 148 | | push @photos, $photo; |
| 149 | | } |
| | 179 | do { |
| | 180 | my $rsp = $this->execute_method('flickr.people.getPublicPhotos', |
| | 181 | { user_id => $nsid, |
| | 182 | page => $page, |
| | 183 | extras => 'license,date_upload,date_taken,owner_name,icon_server' |
| | 184 | }); |
| | 185 | die "Flickr request failed: " . $rsp->{error_message} . "\n" |
| | 186 | unless $rsp->{success} == 1; |
| | 187 | $xpath->set_tree($rsp->{tree}); |
| | 188 | $pages ||= ($xpath->select_nodes('//photos'))[0]->{attributes}{pages}; |
| | 189 | my @photoNodes = $xpath->select_nodes('/photos/photo'); |
| | 190 | for my $node (@photoNodes) { |
| | 191 | my $photo = new MT::Plugin::FlickrPublicPhotos::Photo(); |
| | 192 | $photo->{id} = $node->{attributes}{id}; |
| | 193 | $photo->{nsid} = $nsid; |
| | 194 | $photo->{secret} = $node->{attributes}{secret}; |
| | 195 | $photo->{server} = $node->{attributes}{server}; |
| | 196 | $photo->{title} = $node->{attributes}{title}; |
| | 197 | $photo->{license} = $node->{attributes}{license}; |
| | 198 | $photo->{dateupload} = $node->{attributes}{dateupload}; |
| | 199 | $photo->{datetaken} = $node->{attributes}{datetaken}; |
| | 200 | $photo->{datetakengranularity} = $node->{attributes}{datetakengranularity}; |
| | 201 | $photo->{ownername} = $node->{attributes}{ownername}; |
| | 202 | $photo->{iconserver} = $node->{attributes}{iconserver}; |
| | 203 | push @photos, $photo; |
| | 204 | } |
| | 205 | } while ($page++ < $pages); |