Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2ce3543c8a
Fetching contributors…

Cannot retrieve contributors at this time

file 94 lines (89 sloc) 3.262 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
<?php

// 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/>.

require_once('wikimedia.php');

/**
* repository_wikimedia class
* This is a class used to browse images from wikimedia
*
* @since 2.0
* @package moodlecore
* @subpackage repository
* @copyright 2009 Dongsheng Cai
* @author Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

class repository_wikimedia extends repository {
    public function __construct($repositoryid, $context = SITEID, $options = array()) {
        parent::__construct($repositoryid, $context, $options);
        $this->keyword = optional_param('wikimedia_keyword', '', PARAM_RAW);
    }
    public function get_listing($path = '', $page = '') {
        global $OUTPUT;
        $client = new wikimedia;
        $result = $client->search_images($this->keyword);
        $list = array();
        $list['list'] = array();
        foreach ($result as $title=>$url) {
            $list['list'][] = array(
                'title'=>substr($title, 5),
                'thumbnail'=>$OUTPUT->pix_url(file_extension_icon('xx.jpg', 32)),
                // plugin-dependent unique path to the file (id, url, path, etc.)
                'source'=>$url,
                // the accessible url of the file
                'url'=>$url
            );
        }
        return $list;
    }
    // login
    public function check_login() {
        return !empty($this->keyword);
    }
    // if check_login returns false,
    // this function will be called to print a login form.
    public function print_login() {
        $keyword->label = get_string('keyword', 'repository_wikimedia').': ';
        $keyword->id = 'input_text_keyword';
        $keyword->type = 'text';
        $keyword->name = 'wikimedia_keyword';
        $keyword->value = '';

        $form = array();
        $form['login'] = array($keyword);
        return $form;
    }
    //search
    // if this plugin support global search, if this function return
    // true, search function will be called when global searching working
    public function global_search() {
        return false;
    }
    public function search($text) {
        $search_result = array();
        $search_result['list'] = array();
        return $search_result;
    }
    // when logout button on file picker is clicked, this function will be
    // called.
    public function logout() {
        return true;
    }
    public static function get_type_option_names() {
        return null;
    }
    public function supported_returntypes() {
        return (FILE_INTERNAL | FILE_EXTERNAL);
    }
}
Something went wrong with that request. Please try again.