#!/usr/bin/perl5.8.4 eval 'exec /usr/bin/perl5.8.5 -S $0 ${1+"$@"}' if 0; # not running under some shell use warnings; use strict; use CGI; use Config::Tiny; use OpenGuides::Config; use OpenGuides::Template; use OpenGuides::Utils; use URI::Escape; use Flickr::API; use Flickr::Upload; my $q = CGI->new; my $config = OpenGuides::Config->new( file => "wiki.conf" ); my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); if ($q->param('submit')) { my $photo = $q->param("photo"); my $title = $q->param('title') || "No Title"; if ($photo) { open(FD, ">/tmp/$photo"); while(<$photo>) { print FD $_; } close(FD); my $ua = Flickr::Upload->new( { 'key' => $config->flickr_key, 'secret' => $config->flickr_secret } ); my $id = $ua->upload( 'photo' => "/tmp/$photo", 'auth_token' => $config->flickr_auth_token, 'tags' => 'openguide', 'title' => $title, 'is_public' => 1, 'is_friend' => 1, 'is_family' => 1 ) or die "Failed to upload $photo"; my $api = new Flickr::API({'key' => $config->flickr_key, 'secret' => $config->flickr_secret}); my $response = $api->execute_method('flickr.photos.getInfo', { 'photo_id' => $id }); my $data = $response->content(); $data =~ m/output( wiki => $wiki, config => $config, template => "uploaded.tt", vars => { not_editable => 1, not_deletable => 1, id => $1, secret => $2, server => $3, url => $config->script_name . "?id=" . $q->escape($wiki->formatter->node_name_to_node_param($title)) . ";action=edit", title => $title } ); } } else { print OpenGuides::Template->output( wiki => $wiki, config => $config, template => "upload.tt", vars => { not_editable => 1, not_deletable => 1, } ); }