├── README.md ├── pix └── icon.png ├── lang └── en │ └── repository_wikirandom.php ├── db ├── access.php └── install.php ├── version.php └── lib.php /README.md: -------------------------------------------------------------------------------- 1 | Repository plugin for Moodle that shows random animal pictures. 2 | -------------------------------------------------------------------------------- /pix/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marinaglancy/moodle-repository_wikirandom/master/pix/icon.png -------------------------------------------------------------------------------- /lang/en/repository_wikirandom.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * Strings for component 'repository_wikimedia', language 'en', branch 'MOODLE_20_STABLE' 20 | * 21 | * @package repository_wikirandom 22 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['configplugin'] = 'Wikimedia random repository type configuration'; 27 | $string['pluginname'] = 'Wiki random'; 28 | $string['wikirandom:view'] = 'View wikimedia random repository'; 29 | -------------------------------------------------------------------------------- /db/access.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Plugin capabilities. 19 | * 20 | * @package repository_wikirandom 21 | * @copyright 2009 Dongsheng Cai 22 | * @author Dongsheng Cai 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | $capabilities = array( 29 | 30 | 'repository/wikirandom:view' => array( 31 | 'captype' => 'read', 32 | 'contextlevel' => CONTEXT_MODULE, 33 | 'archetypes' => array( 34 | 'user' => CAP_ALLOW 35 | ) 36 | ) 37 | ); 38 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details 19 | * 20 | * @package repository_wikirandom 21 | * @copyright 2009 Dongsheng Cai 22 | * @author Dongsheng Cai 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | $plugin->version = 2017072000; // The current plugin version (Date: YYYYMMDDXX) 29 | $plugin->requires = 2016052300.00; // Requires this Moodle version 30 | $plugin->component = 'repository_wikirandom'; // Full name of the plugin (used for diagnostics) 31 | 32 | $plugin->dependencies = array('repository_wikimedia' => 2016052300); 33 | -------------------------------------------------------------------------------- /db/install.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Installation file for the wikimedia repository 19 | * 20 | * @package repository_wikirandom 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | /** 25 | * Create a default instance of the wikimedia repository 26 | * 27 | * @return bool A status indicating success or failure 28 | */ 29 | function xmldb_repository_wikirandom_install() { 30 | global $CFG; 31 | $result = true; 32 | require_once($CFG->dirroot.'/repository/lib.php'); 33 | $wikimediaplugin = new repository_type('wikirandom', array(), true); 34 | if (!$id = $wikimediaplugin->create(true)) { 35 | $result = false; 36 | } 37 | return $result; 38 | } 39 | -------------------------------------------------------------------------------- /lib.php: -------------------------------------------------------------------------------- 1 | . 17 | 18 | /** 19 | * This plugin is used to access wikimedia files 20 | * 21 | * @since Moodle 2.0 22 | * @package repository_wikirandom 23 | * @copyright 2010 Dongsheng Cai {@link http://dongsheng.org} 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | require_once($CFG->dirroot . '/repository/lib.php'); 27 | require_once(__DIR__ . '/../wikimedia/wikimedia.php'); 28 | 29 | /** 30 | * repository_wikirandom class 31 | * This is a class used to browse images from wikimedia 32 | * 33 | * @since Moodle 2.0 34 | * @package repository_wikirandom 35 | * @copyright 2009 Dongsheng Cai {@link http://dongsheng.org} 36 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 | */ 38 | 39 | class repository_wikirandom extends repository { 40 | 41 | /** 42 | * Returns maximum width for images 43 | * 44 | * Takes the maximum width for images eithre from search form or from 45 | * user preferences, updates user preferences if needed 46 | * 47 | * @return int 48 | */ 49 | public function get_maxwidth() { 50 | $param = optional_param('wikimedia_maxwidth', 0, PARAM_INT); 51 | $pref = get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH); 52 | if ($param > 0 && $param != $pref) { 53 | $pref = $param; 54 | set_user_preference('repository_wikimedia_maxwidth', $pref); 55 | } 56 | return $pref; 57 | } 58 | 59 | /** 60 | * Returns maximum height for images 61 | * 62 | * Takes the maximum height for images eithre from search form or from 63 | * user preferences, updates user preferences if needed 64 | * 65 | * @return int 66 | */ 67 | public function get_maxheight() { 68 | $param = optional_param('wikimedia_maxheight', 0, PARAM_INT); 69 | $pref = get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH); 70 | if ($param > 0 && $param != $pref) { 71 | $pref = $param; 72 | set_user_preference('repository_wikimedia_maxheight', $pref); 73 | } 74 | return $pref; 75 | } 76 | 77 | public function get_listing($path = '', $page = '') { 78 | $client = new wikimedia; 79 | $list = array(); 80 | $list['page'] = (int)$page; 81 | if ($list['page'] < 1) { 82 | $list['page'] = 1; 83 | } 84 | $list['list'] = $client->search_images($this->keyword, $list['page'] - 1, 85 | array('iiurlwidth' => $this->get_maxwidth(), 86 | 'iiurlheight' => $this->get_maxheight())); 87 | $list['nologin'] = true; 88 | $list['norefresh'] = true; 89 | $list['nosearch'] = true; 90 | if (!empty($list['list'])) { 91 | $list['pages'] = -1; // means we don't know exactly how many pages there are but we can always jump to the next page 92 | } else if ($list['page'] > 1) { 93 | $list['pages'] = $list['page']; // no images available on this page, this is the last page 94 | } else { 95 | $list['pages'] = 0; // no paging 96 | } 97 | return $list; 98 | } 99 | // login 100 | public function check_login() { 101 | $keywords = [ 102 | 'ape', 103 | 'baboon', 104 | 'bat', 105 | 'bear', 106 | 'bird', 107 | 'bison', 108 | 'butterfly', 109 | 'cat', 110 | 'cheetah', 111 | 'cow', 112 | 'deer', 113 | 'dingo', 114 | 'dog', 115 | 'dolphin', 116 | 'duck', 117 | 'eagle', 118 | 'elephant', 119 | 'fish', 120 | 'fox', 121 | 'fox', 122 | 'gazelle', 123 | 'giraffe', 124 | 'hamster', 125 | 'hippo', 126 | 'horse', 127 | 'horse', 128 | 'kangaroo', 129 | 'kangaroo', 130 | 'koala', 131 | 'leopard', 132 | 'lion', 133 | 'lobster', 134 | 'monkey', 135 | 'mouse', 136 | 'ostrich', 137 | 'parrot', 138 | 'penguin', 139 | 'pig', 140 | 'pony', 141 | 'possum', 142 | 'quoll', 143 | 'rabbit', 144 | 'rhino', 145 | 'seal', 146 | 'sheep', 147 | 'spider', 148 | 'tiger', 149 | 'turkey', 150 | 'wallaby', 151 | 'whale', 152 | 'wolf', 153 | 'wombat', 154 | 'zebra', 155 | ]; 156 | $this->keyword = $keywords[rand(0, count($keywords)-1)]; 157 | return true; 158 | } 159 | 160 | //search 161 | // if this plugin support global search, if this function return 162 | // true, search function will be called when global searching working 163 | public function global_search() { 164 | return false; 165 | } 166 | 167 | public function search($search_text, $page = 0) { 168 | $client = new wikimedia; 169 | $search_result = array(); 170 | $search_result['list'] = $client->search_images($search_text); 171 | return $search_result; 172 | } 173 | 174 | // when logout button on file picker is clicked, this function will be 175 | // called. 176 | public function logout() { 177 | return $this->print_login(); 178 | } 179 | 180 | public function supported_returntypes() { 181 | return (FILE_INTERNAL | FILE_EXTERNAL); 182 | } 183 | 184 | /** 185 | * Return the source information 186 | * 187 | * @param stdClass $url 188 | * @return string|null 189 | */ 190 | public function get_file_source_info($url) { 191 | return $url; 192 | } 193 | 194 | /** 195 | * Is this repository accessing private data? 196 | * 197 | * @return bool 198 | */ 199 | public function contains_private_data() { 200 | return false; 201 | } 202 | } 203 | --------------------------------------------------------------------------------