3 * Picasa Portfolio Plugin
5 * @author Dan Poltawski <talktodan@gmail.com>
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 require_once($CFG->libdir.'/googleapi.php');
12 class portfolio_plugin_picasa extends portfolio_plugin_push_base {
15 public static function supported_formats() {
16 return array(PORTFOLIO_FORMAT_IMAGE, PORTFOLIO_FORMAT_VIDEO);
19 public static function get_name() {
20 return get_string('pluginname', 'portfolio_picasa');
23 public function prepare_package() {
24 // we send the files as they are, no prep required
28 public function get_continue_url(){
29 return 'http://picasaweb.google.com/';
32 public function expected_time($callertime) {
36 public function send_package() {
37 if(!$this->sessionkey){
38 throw new portfolio_plugin_exception('noauthtoken', 'portfolio_picasa');
41 $picasa = new google_picasa(new google_authsub($this->sessionkey));
43 foreach ($this->exporter->get_tempfiles() as $file) {
45 if(!$picasa->send_file($file)){
46 throw new portfolio_plugin_exception('sendfailed', 'portfolio_picasa', $file->get_filename());
51 public function steal_control($stage) {
53 if ($stage != PORTFOLIO_STAGE_CONFIG) {
57 $sesskey = google_picasa::get_sesskey($this->get('user')->id);
61 $gauth = new google_authsub($sesskey);
62 $this->sessionkey = $sesskey;
65 // sesskey is not valid, delete store and re-auth
66 google_picasa::delete_sesskey($this->get('user')->id);
70 return google_authsub::login_url($CFG->wwwroot.'/portfolio/add.php?postcontrol=1', google_picasa::REALM);
73 public function post_control($stage, $params) {
74 if ($stage != PORTFOLIO_STAGE_CONFIG) {
78 if(!array_key_exists('token', $params)){
79 throw new portfolio_plugin_exception('noauthtoken', 'portfolio_picasa');
82 // we now have our auth token, get a session token..
83 $gauth = new google_authsub(false, $params['token']);
85 $this->sessionkey = $gauth->get_sessiontoken();
87 google_picasa::set_sesskey($this->sessionkey, $this->get('user')->id);
93 * Registers to the user_deleted event to revoke any
94 * subauth tokens we have from them
96 * @param $user user object
97 * @return boolean true in all cases as its only minor cleanup
99 function portfolio_picasa_user_deleted($user){
100 // it is only by luck that the user prefstill exists now?
101 // We probably need a pre-delete event?
102 if($sesskey = google_picasa::get_sesskey($user->id)){
104 $gauth = new google_authsub($sesskey);
106 $gauth->revoke_session_token();
107 }catch(Exception $e){
108 // we don't care that much about success- just being good
109 // google api citzens