PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/repository/picasa/lib.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 132 lines | 77 code | 21 blank | 34 comment | 3 complexity | e77f138caee8643c58c8a92b01217741 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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. * This plugin is used to access picasa pictures
  18. *
  19. * @since 2.0
  20. * @package repository_picasa
  21. * @copyright 2009 Dan Poltawski <talktodan@gmail.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require_once($CFG->dirroot . '/repository/lib.php');
  25. require_once($CFG->libdir.'/googleapi.php');
  26. /**
  27. * Picasa Repository Plugin
  28. *
  29. * @since 2.0
  30. * @package repository
  31. * @subpackage picasa
  32. * @copyright 2009 Dan Poltawski
  33. * @author Dan Poltawski <talktodan@gmail.com>
  34. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35. */
  36. class repository_picasa extends repository {
  37. private $googleoauth = null;
  38. public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
  39. parent::__construct($repositoryid, $context, $options);
  40. $returnurl = new moodle_url('/repository/repository_callback.php');
  41. $returnurl->param('callback', 'yes');
  42. $returnurl->param('repo_id', $this->id);
  43. $returnurl->param('sesskey', sesskey());
  44. $clientid = get_config('picasa', 'clientid');
  45. $secret = get_config('picasa', 'secret');
  46. $this->googleoauth = new google_oauth($clientid, $secret, $returnurl, google_picasa::REALM);
  47. $this->check_login();
  48. }
  49. public function check_login() {
  50. return $this->googleoauth->is_logged_in();
  51. }
  52. public function print_login() {
  53. $url = $this->googleoauth->get_login_url();
  54. if ($this->options['ajax']) {
  55. $popup = new stdClass();
  56. $popup->type = 'popup';
  57. $popup->url = $url->out(false);
  58. return array('login' => array($popup));
  59. } else {
  60. echo '<a target="_blank" href="'.$url->out(false).'">'.get_string('login', 'repository').'</a>';
  61. }
  62. }
  63. public function get_listing($path='', $page = '') {
  64. $picasa = new google_picasa($this->googleoauth);
  65. $ret = array();
  66. $ret['dynload'] = true;
  67. $ret['manage'] = google_picasa::MANAGE_URL;
  68. $ret['list'] = $picasa->get_file_list($path);
  69. $ret['path'] = array((object)array('name'=>get_string('home'), 'path' => ''));
  70. if ($path) {
  71. $ret['path'][] = (object)array('name'=>$picasa->get_last_album_name(), 'path' => $path);
  72. }
  73. return $ret;
  74. }
  75. public function search($search_text, $page = 0) {
  76. $picasa = new google_picasa($this->googleoauth);
  77. $ret = array();
  78. $ret['manage'] = google_picasa::MANAGE_URL;
  79. $ret['list'] = $picasa->do_photo_search($search_text);
  80. return $ret;
  81. }
  82. public function logout() {
  83. $this->googleoauth->log_out();
  84. return parent::logout();
  85. }
  86. public function supported_filetypes() {
  87. return array('web_image');
  88. }
  89. public function supported_returntypes() {
  90. return (FILE_INTERNAL | FILE_EXTERNAL);
  91. }
  92. public static function get_type_option_names() {
  93. return array('clientid', 'secret', 'pluginname');
  94. }
  95. public static function type_config_form($mform, $classname = 'repository') {
  96. $a = new stdClass;
  97. $a->docsurl = get_docs_url('Google_OAuth_2.0_setup');
  98. $a->callbackurl = google_oauth::callback_url()->out(false);
  99. $mform->addElement('static', null, '', get_string('oauthinfo', 'repository_picasa', $a));
  100. parent::type_config_form($mform);
  101. $mform->addElement('text', 'clientid', get_string('clientid', 'repository_picasa'));
  102. $mform->setType('clientid', PARAM_RAW_TRIMMED);
  103. $mform->addElement('text', 'secret', get_string('secret', 'repository_picasa'));
  104. $mform->setType('secret', PARAM_RAW_TRIMMED);
  105. $strrequired = get_string('required');
  106. $mform->addRule('clientid', $strrequired, 'required', null, 'client');
  107. $mform->addRule('secret', $strrequired, 'required', null, 'client');
  108. }
  109. }
  110. // Icon for this plugin retrieved from http://www.iconspedia.com/icon/picasa-2711.html
  111. // Where the license is said documented to be Free.