3 * Picasa Portfolio Plugin
5 * @author Dan Poltawski <talktodan@gmail.com>
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 require_once($CFG->libdir.'/portfolio/plugin.php');
9 require_once($CFG->libdir.'/googleapi.php');
11 class portfolio_plugin_picasa extends portfolio_plugin_push_base {
14 public function supported_formats() {
15 return array(PORTFOLIO_FORMAT_IMAGE, PORTFOLIO_FORMAT_VIDEO);
18 public static function get_name() {
19 return get_string('pluginname', 'portfolio_picasa');
22 public function prepare_package() {
23 // we send the files as they are, no prep required
27 public function get_interactive_continue_url(){
28 return 'http://picasaweb.google.com/';
31 public function expected_time($callertime) {
35 public function send_package() {
36 if(!$this->sessionkey){
37 throw new portfolio_plugin_exception('noauthtoken', 'portfolio_picasa');
40 $picasa = new google_picasa(new google_authsub($this->sessionkey));
42 foreach ($this->exporter->get_tempfiles() as $file) {
44 if(!$picasa->send_file($file)){
45 throw new portfolio_plugin_exception('sendfailed', 'portfolio_picasa', $file->get_filename());
50 public function steal_control($stage) {
52 if ($stage != PORTFOLIO_STAGE_CONFIG) {
56 $sesskey = google_picasa::get_sesskey($this->get('user')->id);
60 $gauth = new google_authsub($sesskey);
61 $this->sessionkey = $sesskey;
64 // sesskey is not valid, delete store and re-auth
65 google_picasa::delete_sesskey($this->get('user')->id);
69 return google_authsub::login_url($CFG->wwwroot.'/portfolio/add.php?postcontrol=1&id=' . $this->exporter->get('id') . '&sesskey=' . sesskey(), google_picasa::REALM);
72 public function post_control($stage, $params) {
73 if ($stage != PORTFOLIO_STAGE_CONFIG) {
77 if(!array_key_exists('token', $params)){
78 throw new portfolio_plugin_exception('noauthtoken', 'portfolio_picasa');
81 // we now have our auth token, get a session token..
82 $gauth = new google_authsub(false, $params['token']);
84 $this->sessionkey = $gauth->get_sessiontoken();
86 google_picasa::set_sesskey($this->sessionkey, $this->get('user')->id);
89 public static function allows_multiple_instances() {
95 * Registers to the user_deleted event to revoke any
96 * subauth tokens we have from them
98 * @param $user user object
99 * @return boolean true in all cases as its only minor cleanup
101 function portfolio_picasa_user_deleted($user){
102 // it is only by luck that the user prefstill exists now?
103 // We probably need a pre-delete event?
104 if($sesskey = google_picasa::get_sesskey($user->id)){
106 $gauth = new google_authsub($sesskey);
108 $gauth->revoke_session_token();
109 }catch(Exception $e){
110 // we don't care that much about success- just being good
111 // google api citzens