Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * This plugin is used to access picasa pictures
  19   *
  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
  24   */
  25  require_once($CFG->dirroot . '/repository/lib.php');
  26  require_once($CFG->libdir.'/googleapi.php');
  27  
  28  /**
  29   * Picasa Repository Plugin
  30   *
  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
  37   */
  38  class repository_picasa extends repository {
  39      private $googleoauth = null;
  40  
  41      public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
  42          parent::__construct($repositoryid, $context, $options);
  43  
  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());
  48  
  49          $clientid = get_config('picasa', 'clientid');
  50          $secret = get_config('picasa', 'secret');
  51          $this->googleoauth = new google_oauth($clientid, $secret, $returnurl, google_picasa::REALM);
  52  
  53          $this->check_login();
  54      }
  55  
  56      public function check_login() {
  57          return $this->googleoauth->is_logged_in();
  58      }
  59  
  60      public function print_login() {
  61          $url = $this->googleoauth->get_login_url();
  62  
  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>';
  70          }
  71      }
  72  
  73      public function get_listing($path='', $page = '') {
  74          $picasa = new google_picasa($this->googleoauth);
  75  
  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);
  83          }
  84          return $ret;
  85      }
  86  
  87      public function search($search_text, $page = 0) {
  88          $picasa = new google_picasa($this->googleoauth);
  89  
  90          $ret = array();
  91          $ret['manage'] = google_picasa::MANAGE_URL;
  92          $ret['list'] =  $picasa->do_photo_search($search_text);
  93          return $ret;
  94      }
  95  
  96      public function logout() {
  97          $this->googleoauth->log_out();
  98          return parent::logout();
  99      }
 100  
 101      public function supported_filetypes() {
 102          return array('web_image');
 103      }
 104      public function supported_returntypes() {
 105          return (FILE_INTERNAL | FILE_EXTERNAL);
 106      }
 107  
 108      public static function get_type_option_names() {
 109          return array('clientid', 'secret', 'pluginname');
 110      }
 111  
 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);
 116  
 117          $mform->addElement('static', null, '', get_string('oauthinfo', 'repository_picasa', $a));
 118  
 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);
 124  
 125          $strrequired = get_string('required');
 126          $mform->addRule('clientid', $strrequired, 'required', null, 'client');
 127          $mform->addRule('secret', $strrequired, 'required', null, 'client');
 128      }
 129  }
 130  
 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.