|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00018 require_once('wikimedia.php'); 00019 00032 class repository_wikimedia extends repository { 00033 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) { 00034 parent::__construct($repositoryid, $context, $options); 00035 $this->keyword = optional_param('wikimedia_keyword', '', PARAM_RAW); 00036 if (empty($this->keyword)) { 00037 $this->keyword = optional_param('s', '', PARAM_RAW); 00038 } 00039 } 00040 public function get_listing($path = '', $page = '') { 00041 $client = new wikimedia; 00042 $list = array(); 00043 $list['list'] = $client->search_images($this->keyword); 00044 $list['nologin'] = true; 00045 return $list; 00046 } 00047 // login 00048 public function check_login() { 00049 return !empty($this->keyword); 00050 } 00051 // if check_login returns false, 00052 // this function will be called to print a login form. 00053 public function print_login() { 00054 $keyword = new stdClass(); 00055 $keyword->label = get_string('keyword', 'repository_wikimedia').': '; 00056 $keyword->id = 'input_text_keyword'; 00057 $keyword->type = 'text'; 00058 $keyword->name = 'wikimedia_keyword'; 00059 $keyword->value = ''; 00060 00061 $form = array(); 00062 $form['login'] = array($keyword); 00063 return $form; 00064 } 00065 //search 00066 // if this plugin support global search, if this function return 00067 // true, search function will be called when global searching working 00068 public function global_search() { 00069 return false; 00070 } 00071 public function search($search_text) { 00072 $client = new wikimedia; 00073 $search_result = array(); 00074 $search_result['list'] = $client->search_images($search_text); 00075 return $search_result; 00076 } 00077 // when logout button on file picker is clicked, this function will be 00078 // called. 00079 public function logout() { 00080 return $this->print_login(); 00081 } 00082 public function supported_returntypes() { 00083 return (FILE_INTERNAL | FILE_EXTERNAL); 00084 } 00085 }