MDL-32735 add missing message provider info for unmaintained enrol_authorize
[moodle.git] / repository / picasa / lib.php
blobbd43d8482423456891e326c7d90178736a6fe866
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * Picasa Repository Plugin
21 * @since 2.0
22 * @package repository
23 * @subpackage picasa
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()) {
35 global $USER;
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);
40 if($googletoken){
41 $gauth = new google_authsub(false, $googletoken); // will throw exception if fails
42 google_picasa::set_sesskey($gauth->get_sessiontoken(), $USER->id);
44 $this->check_login();
47 public function check_login() {
48 global $USER;
50 $sesskey = google_picasa::get_sesskey($USER->id);
52 if($sesskey){
53 try{
54 $gauth = new google_authsub($sesskey);
55 $this->subauthtoken = $sesskey;
56 return true;
57 }catch(Exception $e){
58 // sesskey is not valid, delete store and re-auth
59 google_picasa::delete_sesskey($USER->id);
63 return false;
66 public function print_login(){
67 global $CFG;
68 $returnurl = $CFG->wwwroot.'/repository/repository_callback.php?callback=yes&repo_id='.$this->id;
69 $authurl = google_authsub::login_url($returnurl, google_picasa::REALM);
70 if($this->options['ajax']){
71 $ret = array();
72 $popup_btn = new stdClass();
73 $popup_btn->type = 'popup';
74 $popup_btn->url = $authurl;
75 $ret['login'] = array($popup_btn);
76 return $ret;
77 } else {
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));
85 $ret = array();
86 $ret['dynload'] = true;
87 $ret['manage'] = google_picasa::MANAGE_URL;
88 $ret['list'] = $picasa->get_file_list($path);
89 $ret['path'] = array((object)array('name'=>get_string('home'), 'path' => ''));
90 if ($path) {
91 $ret['path'][] = (object)array('name'=>$picasa->get_last_album_name(), 'path' => $path);
93 return $ret;
96 public function search($search_text, $page = 0) {
97 $picasa = new google_picasa(new google_authsub($this->subauthtoken));
99 $ret = array();
100 $ret['manage'] = google_picasa::MANAGE_URL;
101 $ret['list'] = $picasa->do_photo_search($search_text);
102 return $ret;
105 public function logout(){
106 global $USER;
108 $token = google_picasa::get_sesskey($USER->id);
110 $gauth = new google_authsub($token);
111 // revoke token from google
112 $gauth->revoke_session_token();
114 google_picasa::delete_sesskey($USER->id);
115 $this->subauthtoken = '';
117 return parent::logout();
120 public function get_name(){
121 return get_string('pluginname', 'repository_picasa');
123 public function supported_filetypes() {
124 return array('web_image');
126 public function supported_returntypes() {
127 return (FILE_INTERNAL | FILE_EXTERNAL);
131 // Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
132 // Where the license is said documented to be Free