MDL-67009 behat: get rid of invalid void type hinting for php70
[moodle.git] / repository / picasa / lib.php
blob362289bf1f148ad04d152d49a0abc1b64d093898
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This plugin is used to access picasa pictures
20 * @since Moodle 2.0
21 * @package repository_picasa
22 * @copyright 2009 Dan Poltawski <talktodan@gmail.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once($CFG->dirroot . '/repository/lib.php');
26 require_once($CFG->libdir.'/googleapi.php');
28 /**
29 * Picasa Repository Plugin
31 * @since Moodle 2.0
32 * @package repository
33 * @subpackage picasa
34 * @copyright 2009 Dan Poltawski
35 * @author Dan Poltawski <talktodan@gmail.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class repository_picasa extends repository {
39 private $googleoauth = null;
41 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
42 parent::__construct($repositoryid, $context, $options);
44 $returnurl = new moodle_url('/repository/repository_callback.php');
45 $returnurl->param('callback', 'yes');
46 $returnurl->param('repo_id', $this->id);
47 $returnurl->param('sesskey', sesskey());
49 $clientid = get_config('picasa', 'clientid');
50 $secret = get_config('picasa', 'secret');
51 $this->googleoauth = new google_oauth($clientid, $secret, $returnurl, google_picasa::REALM);
53 $this->check_login();
56 public function check_login() {
57 return $this->googleoauth->is_logged_in();
60 public function print_login() {
61 $url = $this->googleoauth->get_login_url();
63 if ($this->options['ajax']) {
64 $popup = new stdClass();
65 $popup->type = 'popup';
66 $popup->url = $url->out(false);
67 return array('login' => array($popup));
68 } else {
69 echo '<a target="_blank" href="'.$url->out(false).'">'.get_string('login', 'repository').'</a>';
73 public function get_listing($path='', $page = '') {
74 $picasa = new google_picasa($this->googleoauth);
76 $ret = array();
77 $ret['dynload'] = true;
78 $ret['manage'] = google_picasa::MANAGE_URL;
79 $ret['list'] = $picasa->get_file_list($path);
80 $ret['path'] = array((object)array('name'=>get_string('home'), 'path' => ''));
81 if ($path) {
82 $ret['path'][] = (object)array('name'=>$picasa->get_last_album_name(), 'path' => $path);
84 return $ret;
87 public function search($search_text, $page = 0) {
88 $picasa = new google_picasa($this->googleoauth);
90 $ret = array();
91 $ret['manage'] = google_picasa::MANAGE_URL;
92 $ret['list'] = $picasa->do_photo_search($search_text);
93 return $ret;
96 public function logout() {
97 $this->googleoauth->log_out();
98 return parent::logout();
101 public function supported_filetypes() {
102 return array('web_image');
104 public function supported_returntypes() {
105 return (FILE_INTERNAL | FILE_EXTERNAL);
108 public static function get_type_option_names() {
109 return array('clientid', 'secret', 'pluginname');
112 public static function type_config_form($mform, $classname = 'repository') {
113 $a = new stdClass;
114 $a->docsurl = get_docs_url('Google_OAuth_2.0_setup');
115 $a->callbackurl = google_oauth::callback_url()->out(false);
117 $mform->addElement('static', null, '', get_string('oauthinfo', 'repository_picasa', $a));
119 parent::type_config_form($mform);
120 $mform->addElement('text', 'clientid', get_string('clientid', 'repository_picasa'));
121 $mform->setType('clientid', PARAM_RAW_TRIMMED);
122 $mform->addElement('text', 'secret', get_string('secret', 'repository_picasa'));
123 $mform->setType('secret', PARAM_RAW_TRIMMED);
125 $strrequired = get_string('required');
126 $mform->addRule('clientid', $strrequired, 'required', null, 'client');
127 $mform->addRule('secret', $strrequired, 'required', null, 'client');
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.