2008-11-30 17:37:06 +00:00
|
|
|
<?php
|
2009-12-17 03:40:38 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-05-12 04:14:53 +08:00
|
|
|
/**
|
|
|
|
* This plugin is used to access picasa pictures
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @package repository_picasa
|
2012-05-17 13:55:03 +08:00
|
|
|
* @copyright 2009 Dan Poltawski <talktodan@gmail.com>
|
2012-05-12 04:14:53 +08:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
require_once($CFG->dirroot . '/repository/lib.php');
|
|
|
|
require_once($CFG->libdir.'/googleapi.php');
|
|
|
|
|
2008-11-30 17:37:06 +00:00
|
|
|
/**
|
|
|
|
* Picasa Repository Plugin
|
|
|
|
*
|
2009-12-17 03:40:38 +00:00
|
|
|
* @since 2.0
|
2010-09-06 11:29:21 +00:00
|
|
|
* @package repository
|
|
|
|
* @subpackage picasa
|
|
|
|
* @copyright 2009 Dan Poltawski
|
|
|
|
* @author Dan Poltawski <talktodan@gmail.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-11-30 17:37:06 +00:00
|
|
|
*/
|
|
|
|
class repository_picasa extends repository {
|
|
|
|
private $subauthtoken = '';
|
|
|
|
|
2010-03-16 03:21:59 +00:00
|
|
|
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
|
2008-11-30 17:37:06 +00:00
|
|
|
global $USER;
|
|
|
|
parent::__construct($repositoryid, $context, $options);
|
|
|
|
|
|
|
|
// TODO: I wish there was somewhere we could explicitly put this outside of constructor..
|
|
|
|
$googletoken = optional_param('token', false, PARAM_RAW);
|
|
|
|
if($googletoken){
|
|
|
|
$gauth = new google_authsub(false, $googletoken); // will throw exception if fails
|
|
|
|
google_picasa::set_sesskey($gauth->get_sessiontoken(), $USER->id);
|
|
|
|
}
|
2009-06-25 04:12:43 +00:00
|
|
|
$this->check_login();
|
2008-11-30 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function check_login() {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$sesskey = google_picasa::get_sesskey($USER->id);
|
|
|
|
|
|
|
|
if($sesskey){
|
|
|
|
try{
|
|
|
|
$gauth = new google_authsub($sesskey);
|
|
|
|
$this->subauthtoken = $sesskey;
|
|
|
|
return true;
|
|
|
|
}catch(Exception $e){
|
|
|
|
// sesskey is not valid, delete store and re-auth
|
|
|
|
google_picasa::delete_sesskey($USER->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:51:40 +00:00
|
|
|
public function print_login(){
|
2008-11-30 17:37:06 +00:00
|
|
|
global $CFG;
|
2010-07-12 04:53:31 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/repository/repository_callback.php?callback=yes&repo_id='.$this->id;
|
2009-06-22 03:30:25 +00:00
|
|
|
$authurl = google_authsub::login_url($returnurl, google_picasa::REALM);
|
|
|
|
if($this->options['ajax']){
|
2009-11-01 12:51:40 +00:00
|
|
|
$ret = array();
|
2010-09-21 08:54:01 +00:00
|
|
|
$popup_btn = new stdClass();
|
2009-11-01 12:51:40 +00:00
|
|
|
$popup_btn->type = 'popup';
|
2009-06-22 03:30:25 +00:00
|
|
|
$popup_btn->url = $authurl;
|
2009-11-01 12:51:40 +00:00
|
|
|
$ret['login'] = array($popup_btn);
|
|
|
|
return $ret;
|
2009-06-22 03:30:25 +00:00
|
|
|
} else {
|
|
|
|
echo '<a target="_blank" href="'.$authurl.'">Login</a>';
|
2008-11-30 17:37:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-18 06:52:54 +00:00
|
|
|
public function get_listing($path='', $page = '') {
|
2008-11-30 17:37:06 +00:00
|
|
|
$picasa = new google_picasa(new google_authsub($this->subauthtoken));
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
$ret['dynload'] = true;
|
2012-03-23 14:11:00 +08:00
|
|
|
$ret['manage'] = google_picasa::MANAGE_URL;
|
2008-11-30 17:37:06 +00:00
|
|
|
$ret['list'] = $picasa->get_file_list($path);
|
2012-05-03 11:30:08 +08:00
|
|
|
$ret['path'] = array((object)array('name'=>get_string('home'), 'path' => ''));
|
|
|
|
if ($path) {
|
|
|
|
$ret['path'][] = (object)array('name'=>$picasa->get_last_album_name(), 'path' => $path);
|
|
|
|
}
|
2008-11-30 17:37:06 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2012-03-26 11:47:15 +02:00
|
|
|
public function search($search_text, $page = 0) {
|
2008-11-30 17:37:06 +00:00
|
|
|
$picasa = new google_picasa(new google_authsub($this->subauthtoken));
|
|
|
|
|
|
|
|
$ret = array();
|
2012-03-23 14:11:00 +08:00
|
|
|
$ret['manage'] = google_picasa::MANAGE_URL;
|
2012-03-26 11:47:15 +02:00
|
|
|
$ret['list'] = $picasa->do_photo_search($search_text);
|
2008-11-30 17:37:06 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function logout(){
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
$token = google_picasa::get_sesskey($USER->id);
|
|
|
|
|
|
|
|
$gauth = new google_authsub($token);
|
|
|
|
// revoke token from google
|
|
|
|
$gauth->revoke_session_token();
|
|
|
|
|
|
|
|
google_picasa::delete_sesskey($USER->id);
|
|
|
|
$this->subauthtoken = '';
|
|
|
|
|
|
|
|
return parent::logout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_name(){
|
MDL-22984 using standard plugin name string for repositories
AMOS BEGIN
MOV [repositoryname,repository_alfresco],[pluginname,repository_alfresco]
MOV [repositoryname,repository_boxnet],[pluginname,repository_boxnet]
MOV [repositoryname,repository_dropbox],[pluginname,repository_dropbox]
MOV [repositoryname,repository_filesystem],[pluginname,repository_filesystem]
MOV [repositoryname,repository_flickr],[pluginname,repository_flickr]
MOV [repositoryname,repository_flickr_public],[pluginname,repository_flickr_public]
MOV [repositoryname,repository_googledocs],[pluginname,repository_googledocs]
MOV [repositoryname,repository_local],[pluginname,repository_local]
MOV [repositoryname,repository_merlot],[pluginname,repository_merlot]
MOV [repositoryname,repository_picasa],[pluginname,repository_picasa]
MOV [repositoryname,repository_recent],[pluginname,repository_recent]
MOV [repositoryname,repository_s3],[pluginname,repository_s3]
MOV [repositoryname,repository_upload],[pluginname,repository_upload]
MOV [repositoryname,repository_url],[pluginname,repository_url]
MOV [repositoryname,repository_user],[pluginname,repository_user]
MOV [repositoryname,repository_webdav],[pluginname,repository_webdav]
MOV [repositoryname,repository_wikimedia],[pluginname,repository_wikimedia]
MOV [repositoryname,repository_youtube],[pluginname,repository_youtube]
AMOS END
2010-07-04 12:52:10 +00:00
|
|
|
return get_string('pluginname', 'repository_picasa');
|
2008-11-30 17:37:06 +00:00
|
|
|
}
|
2008-12-09 06:55:12 +00:00
|
|
|
public function supported_filetypes() {
|
|
|
|
return array('web_image');
|
|
|
|
}
|
2009-11-02 06:45:12 +00:00
|
|
|
public function supported_returntypes() {
|
|
|
|
return (FILE_INTERNAL | FILE_EXTERNAL);
|
|
|
|
}
|
2008-11-30 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
|
|
|
|
// Where the license is said documented to be Free
|