3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Picasa Repository Plugin
23 * @subpackage repository
24 * @copyright 2009 Dan Poltawski
25 * @author Dan Poltawski <talktodan@gmail.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 require_once($CFG->libdir.'/googleapi.php');
31 class repository_picasa extends repository {
32 private $subauthtoken = '';
34 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
36 parent::__construct($repositoryid, $context, $options);
38 // TODO: I wish there was somewhere we could explicitly put this outside of constructor..
39 $googletoken = optional_param('token', false, PARAM_RAW);
41 $gauth = new google_authsub(false, $googletoken); // will throw exception if fails
42 google_picasa::set_sesskey($gauth->get_sessiontoken(), $USER->id);
47 public function check_login() {
50 $sesskey = google_picasa::get_sesskey($USER->id);
54 $gauth = new google_authsub($sesskey);
55 $this->subauthtoken = $sesskey;
58 // sesskey is not valid, delete store and re-auth
59 google_picasa::delete_sesskey($USER->id);
66 public function print_login(){
68 $returnurl = $CFG->wwwroot.'/repository/repository_ajax.php?callback=yes&repo_id='.$this->id;
69 $authurl = google_authsub::login_url($returnurl, google_picasa::REALM);
70 if($this->options['ajax']){
72 $popup_btn = new stdclass;
73 $popup_btn->type = 'popup';
74 $popup_btn->url = $authurl;
75 $ret['login'] = array($popup_btn);
78 echo '<a target="_blank" href="'.$authurl.'">Login</a>';
82 public function get_listing($path='', $page = '') {
83 $picasa = new google_picasa(new google_authsub($this->subauthtoken));
86 $ret['dynload'] = true;
87 $ret['list'] = $picasa->get_file_list($path);
91 public function search($query){
92 $picasa = new google_picasa(new google_authsub($this->subauthtoken));
95 $ret['list'] = $picasa->do_photo_search($query);
99 public function logout(){
102 $token = google_picasa::get_sesskey($USER->id);
104 $gauth = new google_authsub($token);
105 // revoke token from google
106 $gauth->revoke_session_token();
108 google_picasa::delete_sesskey($USER->id);
109 $this->subauthtoken = '';
111 return parent::logout();
114 public function get_name(){
115 return get_string('pluginname', 'repository_picasa');
117 public function supported_filetypes() {
118 return array('web_image');
120 public function supported_returntypes() {
121 return (FILE_INTERNAL | FILE_EXTERNAL);
125 // Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
126 // Where the license is said documented to be Free