[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Mandatory public API of url module 20 * 21 * @package mod_url 22 * @copyright 2009 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die; 27 28 /** 29 * List of features supported in URL module 30 * @param string $feature FEATURE_xx constant for requested feature 31 * @return mixed True if module supports feature, false if not, null if doesn't know 32 */ 33 function url_supports($feature) { 34 switch($feature) { 35 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE; 36 case FEATURE_GROUPS: return false; 37 case FEATURE_GROUPINGS: return false; 38 case FEATURE_MOD_INTRO: return true; 39 case FEATURE_COMPLETION_TRACKS_VIEWS: return true; 40 case FEATURE_GRADE_HAS_GRADE: return false; 41 case FEATURE_GRADE_OUTCOMES: return false; 42 case FEATURE_BACKUP_MOODLE2: return true; 43 case FEATURE_SHOW_DESCRIPTION: return true; 44 45 default: return null; 46 } 47 } 48 49 /** 50 * Returns all other caps used in module 51 * @return array 52 */ 53 function url_get_extra_capabilities() { 54 return array('moodle/site:accessallgroups'); 55 } 56 57 /** 58 * This function is used by the reset_course_userdata function in moodlelib. 59 * @param $data the data submitted from the reset course. 60 * @return array status array 61 */ 62 function url_reset_userdata($data) { 63 return array(); 64 } 65 66 /** 67 * List the actions that correspond to a view of this module. 68 * This is used by the participation report. 69 * 70 * Note: This is not used by new logging system. Event with 71 * crud = 'r' and edulevel = LEVEL_PARTICIPATING will 72 * be considered as view action. 73 * 74 * @return array 75 */ 76 function url_get_view_actions() { 77 return array('view', 'view all'); 78 } 79 80 /** 81 * List the actions that correspond to a post of this module. 82 * This is used by the participation report. 83 * 84 * Note: This is not used by new logging system. Event with 85 * crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING 86 * will be considered as post action. 87 * 88 * @return array 89 */ 90 function url_get_post_actions() { 91 return array('update', 'add'); 92 } 93 94 /** 95 * Add url instance. 96 * @param object $data 97 * @param object $mform 98 * @return int new url instance id 99 */ 100 function url_add_instance($data, $mform) { 101 global $CFG, $DB; 102 103 require_once($CFG->dirroot.'/mod/url/locallib.php'); 104 105 $parameters = array(); 106 for ($i=0; $i < 100; $i++) { 107 $parameter = "parameter_$i"; 108 $variable = "variable_$i"; 109 if (empty($data->$parameter) or empty($data->$variable)) { 110 continue; 111 } 112 $parameters[$data->$parameter] = $data->$variable; 113 } 114 $data->parameters = serialize($parameters); 115 116 $displayoptions = array(); 117 if ($data->display == RESOURCELIB_DISPLAY_POPUP) { 118 $displayoptions['popupwidth'] = $data->popupwidth; 119 $displayoptions['popupheight'] = $data->popupheight; 120 } 121 if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) { 122 $displayoptions['printintro'] = (int)!empty($data->printintro); 123 } 124 $data->displayoptions = serialize($displayoptions); 125 126 $data->externalurl = url_fix_submitted_url($data->externalurl); 127 128 $data->timemodified = time(); 129 $data->id = $DB->insert_record('url', $data); 130 131 return $data->id; 132 } 133 134 /** 135 * Update url instance. 136 * @param object $data 137 * @param object $mform 138 * @return bool true 139 */ 140 function url_update_instance($data, $mform) { 141 global $CFG, $DB; 142 143 require_once($CFG->dirroot.'/mod/url/locallib.php'); 144 145 $parameters = array(); 146 for ($i=0; $i < 100; $i++) { 147 $parameter = "parameter_$i"; 148 $variable = "variable_$i"; 149 if (empty($data->$parameter) or empty($data->$variable)) { 150 continue; 151 } 152 $parameters[$data->$parameter] = $data->$variable; 153 } 154 $data->parameters = serialize($parameters); 155 156 $displayoptions = array(); 157 if ($data->display == RESOURCELIB_DISPLAY_POPUP) { 158 $displayoptions['popupwidth'] = $data->popupwidth; 159 $displayoptions['popupheight'] = $data->popupheight; 160 } 161 if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) { 162 $displayoptions['printintro'] = (int)!empty($data->printintro); 163 } 164 $data->displayoptions = serialize($displayoptions); 165 166 $data->externalurl = url_fix_submitted_url($data->externalurl); 167 168 $data->timemodified = time(); 169 $data->id = $data->instance; 170 171 $DB->update_record('url', $data); 172 173 return true; 174 } 175 176 /** 177 * Delete url instance. 178 * @param int $id 179 * @return bool true 180 */ 181 function url_delete_instance($id) { 182 global $DB; 183 184 if (!$url = $DB->get_record('url', array('id'=>$id))) { 185 return false; 186 } 187 188 // note: all context files are deleted automatically 189 190 $DB->delete_records('url', array('id'=>$url->id)); 191 192 return true; 193 } 194 195 /** 196 * Given a course_module object, this function returns any 197 * "extra" information that may be needed when printing 198 * this activity in a course listing. 199 * 200 * See {@link get_array_of_activities()} in course/lib.php 201 * 202 * @param object $coursemodule 203 * @return cached_cm_info info 204 */ 205 function url_get_coursemodule_info($coursemodule) { 206 global $CFG, $DB; 207 require_once("$CFG->dirroot/mod/url/locallib.php"); 208 209 if (!$url = $DB->get_record('url', array('id'=>$coursemodule->instance), 210 'id, name, display, displayoptions, externalurl, parameters, intro, introformat')) { 211 return NULL; 212 } 213 214 $info = new cached_cm_info(); 215 $info->name = $url->name; 216 217 //note: there should be a way to differentiate links from normal resources 218 $info->icon = url_guess_icon($url->externalurl, 24); 219 220 $display = url_get_final_display_type($url); 221 222 if ($display == RESOURCELIB_DISPLAY_POPUP) { 223 $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1"; 224 $options = empty($url->displayoptions) ? array() : unserialize($url->displayoptions); 225 $width = empty($options['popupwidth']) ? 620 : $options['popupwidth']; 226 $height = empty($options['popupheight']) ? 450 : $options['popupheight']; 227 $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes"; 228 $info->onclick = "window.open('$fullurl', '', '$wh'); return false;"; 229 230 } else if ($display == RESOURCELIB_DISPLAY_NEW) { 231 $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&redirect=1"; 232 $info->onclick = "window.open('$fullurl'); return false;"; 233 234 } 235 236 if ($coursemodule->showdescription) { 237 // Convert intro to html. Do not filter cached version, filters run at display time. 238 $info->content = format_module_intro('url', $url, $coursemodule->id, false); 239 } 240 241 return $info; 242 } 243 244 /** 245 * Return a list of page types 246 * @param string $pagetype current page type 247 * @param stdClass $parentcontext Block's parent context 248 * @param stdClass $currentcontext Current context of block 249 */ 250 function url_page_type_list($pagetype, $parentcontext, $currentcontext) { 251 $module_pagetype = array('mod-url-*'=>get_string('page-mod-url-x', 'url')); 252 return $module_pagetype; 253 } 254 255 /** 256 * Export URL resource contents 257 * 258 * @return array of file content 259 */ 260 function url_export_contents($cm, $baseurl) { 261 global $CFG, $DB; 262 require_once("$CFG->dirroot/mod/url/locallib.php"); 263 $contents = array(); 264 $context = context_module::instance($cm->id); 265 266 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 267 $urlrecord = $DB->get_record('url', array('id'=>$cm->instance), '*', MUST_EXIST); 268 269 $fullurl = str_replace('&', '&', url_get_full_url($urlrecord, $cm, $course)); 270 $isurl = clean_param($fullurl, PARAM_URL); 271 if (empty($isurl)) { 272 return null; 273 } 274 275 $url = array(); 276 $url['type'] = 'url'; 277 $url['filename'] = clean_param(format_string($urlrecord->name), PARAM_FILE); 278 $url['filepath'] = null; 279 $url['filesize'] = 0; 280 $url['fileurl'] = $fullurl; 281 $url['timecreated'] = null; 282 $url['timemodified'] = $urlrecord->timemodified; 283 $url['sortorder'] = null; 284 $url['userid'] = null; 285 $url['author'] = null; 286 $url['license'] = null; 287 $contents[] = $url; 288 289 return $contents; 290 } 291 292 /** 293 * Register the ability to handle drag and drop file uploads 294 * @return array containing details of the files / types the mod can handle 295 */ 296 function url_dndupload_register() { 297 return array('types' => array( 298 array('identifier' => 'url', 'message' => get_string('createurl', 'url')) 299 )); 300 } 301 302 /** 303 * Handle a file that has been uploaded 304 * @param object $uploadinfo details of the file / content that has been uploaded 305 * @return int instance id of the newly created mod 306 */ 307 function url_dndupload_handle($uploadinfo) { 308 // Gather all the required data. 309 $data = new stdClass(); 310 $data->course = $uploadinfo->course->id; 311 $data->name = $uploadinfo->displayname; 312 $data->intro = '<p>'.$uploadinfo->displayname.'</p>'; 313 $data->introformat = FORMAT_HTML; 314 $data->externalurl = clean_param($uploadinfo->content, PARAM_URL); 315 $data->timemodified = time(); 316 317 // Set the display options to the site defaults. 318 $config = get_config('url'); 319 $data->display = $config->display; 320 $data->popupwidth = $config->popupwidth; 321 $data->popupheight = $config->popupheight; 322 $data->printintro = $config->printintro; 323 324 return url_add_instance($data, null); 325 } 326 327 /** 328 * Mark the activity completed (if required) and trigger the course_module_viewed event. 329 * 330 * @param stdClass $url url object 331 * @param stdClass $course course object 332 * @param stdClass $cm course module object 333 * @param stdClass $context context object 334 * @since Moodle 3.0 335 */ 336 function url_view($url, $course, $cm, $context) { 337 338 // Trigger course_module_viewed event. 339 $params = array( 340 'context' => $context, 341 'objectid' => $url->id 342 ); 343 344 $event = \mod_url\event\course_module_viewed::create($params); 345 $event->add_record_snapshot('course_modules', $cm); 346 $event->add_record_snapshot('course', $course); 347 $event->add_record_snapshot('url', $url); 348 $event->trigger(); 349 350 // Completion. 351 $completion = new completion_info($course); 352 $completion->set_module_viewed($cm); 353 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |