Merge branch 'MDL-40255_M25' of git://github.com/lazydaisy/moodle into MOODLE_25_STABLE
[moodle.git] / lib / externallib.php
blob578ed48097a1b5197762c990865bca0e784ba164
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.
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/>.
18 /**
19 * Support for external API
21 * @package core_webservice
22 * @copyright 2009 Petr Skodak
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * Returns detailed function information
31 * @param string|object $function name of external function or record from external_function
32 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
33 * MUST_EXIST means throw exception if no record or multiple records found
34 * @return stdClass description or false if not found or exception thrown
35 * @since Moodle 2.0
37 function external_function_info($function, $strictness=MUST_EXIST) {
38 global $DB, $CFG;
40 if (!is_object($function)) {
41 if (!$function = $DB->get_record('external_functions', array('name'=>$function), '*', $strictness)) {
42 return false;
46 //first find and include the ext implementation class
47 $function->classpath = empty($function->classpath) ? get_component_directory($function->component).'/externallib.php' : $CFG->dirroot.'/'.$function->classpath;
48 if (!file_exists($function->classpath)) {
49 throw new coding_exception('Can not find file with external function implementation');
51 require_once($function->classpath);
53 $function->parameters_method = $function->methodname.'_parameters';
54 $function->returns_method = $function->methodname.'_returns';
56 // make sure the implementaion class is ok
57 if (!method_exists($function->classname, $function->methodname)) {
58 throw new coding_exception('Missing implementation method of '.$function->classname.'::'.$function->methodname);
60 if (!method_exists($function->classname, $function->parameters_method)) {
61 throw new coding_exception('Missing parameters description');
63 if (!method_exists($function->classname, $function->returns_method)) {
64 throw new coding_exception('Missing returned values description');
67 // fetch the parameters description
68 $function->parameters_desc = call_user_func(array($function->classname, $function->parameters_method));
69 if (!($function->parameters_desc instanceof external_function_parameters)) {
70 throw new coding_exception('Invalid parameters description');
73 // fetch the return values description
74 $function->returns_desc = call_user_func(array($function->classname, $function->returns_method));
75 // null means void result or result is ignored
76 if (!is_null($function->returns_desc) and !($function->returns_desc instanceof external_description)) {
77 throw new coding_exception('Invalid return description');
80 //now get the function description
81 //TODO MDL-31115 use localised lang pack descriptions, it would be nice to have
82 // easy to understand descriptions in admin UI,
83 // on the other hand this is still a bit in a flux and we need to find some new naming
84 // conventions for these descriptions in lang packs
85 $function->description = null;
86 $servicesfile = get_component_directory($function->component).'/db/services.php';
87 if (file_exists($servicesfile)) {
88 $functions = null;
89 include($servicesfile);
90 if (isset($functions[$function->name]['description'])) {
91 $function->description = $functions[$function->name]['description'];
93 if (isset($functions[$function->name]['testclientpath'])) {
94 $function->testclientpath = $functions[$function->name]['testclientpath'];
98 return $function;
102 * Exception indicating user is not allowed to use external function in the current context.
104 * @package core_webservice
105 * @copyright 2009 Petr Skodak
106 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
107 * @since Moodle 2.0
109 class restricted_context_exception extends moodle_exception {
111 * Constructor
113 * @since Moodle 2.0
115 function __construct() {
116 parent::__construct('restrictedcontextexception', 'error');
121 * Base class for external api methods.
123 * @package core_webservice
124 * @copyright 2009 Petr Skodak
125 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
126 * @since Moodle 2.0
128 class external_api {
130 /** @var stdClass context where the function calls will be restricted */
131 private static $contextrestriction;
134 * Set context restriction for all following subsequent function calls.
136 * @param stdClass $context the context restriction
137 * @since Moodle 2.0
139 public static function set_context_restriction($context) {
140 self::$contextrestriction = $context;
144 * This method has to be called before every operation
145 * that takes a longer time to finish!
147 * @param int $seconds max expected time the next operation needs
148 * @since Moodle 2.0
150 public static function set_timeout($seconds=360) {
151 $seconds = ($seconds < 300) ? 300 : $seconds;
152 set_time_limit($seconds);
156 * Validates submitted function parameters, if anything is incorrect
157 * invalid_parameter_exception is thrown.
158 * This is a simple recursive method which is intended to be called from
159 * each implementation method of external API.
161 * @param external_description $description description of parameters
162 * @param mixed $params the actual parameters
163 * @return mixed params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
164 * @since Moodle 2.0
166 public static function validate_parameters(external_description $description, $params) {
167 if ($description instanceof external_value) {
168 if (is_array($params) or is_object($params)) {
169 throw new invalid_parameter_exception('Scalar type expected, array or object received.');
172 if ($description->type == PARAM_BOOL) {
173 // special case for PARAM_BOOL - we want true/false instead of the usual 1/0 - we can not be too strict here ;-)
174 if (is_bool($params) or $params === 0 or $params === 1 or $params === '0' or $params === '1') {
175 return (bool)$params;
178 $debuginfo = 'Invalid external api parameter: the value is "' . $params .
179 '", the server was expecting "' . $description->type . '" type';
180 return validate_param($params, $description->type, $description->allownull, $debuginfo);
182 } else if ($description instanceof external_single_structure) {
183 if (!is_array($params)) {
184 throw new invalid_parameter_exception('Only arrays accepted. The bad value is: \''
185 . print_r($params, true) . '\'');
187 $result = array();
188 foreach ($description->keys as $key=>$subdesc) {
189 if (!array_key_exists($key, $params)) {
190 if ($subdesc->required == VALUE_REQUIRED) {
191 throw new invalid_parameter_exception('Missing required key in single structure: '. $key);
193 if ($subdesc->required == VALUE_DEFAULT) {
194 try {
195 $result[$key] = self::validate_parameters($subdesc, $subdesc->default);
196 } catch (invalid_parameter_exception $e) {
197 //we are only interested by exceptions returned by validate_param() and validate_parameters()
198 //(in order to build the path to the faulty attribut)
199 throw new invalid_parameter_exception($key." => ".$e->getMessage() . ': ' .$e->debuginfo);
202 } else {
203 try {
204 $result[$key] = self::validate_parameters($subdesc, $params[$key]);
205 } catch (invalid_parameter_exception $e) {
206 //we are only interested by exceptions returned by validate_param() and validate_parameters()
207 //(in order to build the path to the faulty attribut)
208 throw new invalid_parameter_exception($key." => ".$e->getMessage() . ': ' .$e->debuginfo);
211 unset($params[$key]);
213 if (!empty($params)) {
214 throw new invalid_parameter_exception('Unexpected keys (' . implode(', ', array_keys($params)) . ') detected in parameter array.');
216 return $result;
218 } else if ($description instanceof external_multiple_structure) {
219 if (!is_array($params)) {
220 throw new invalid_parameter_exception('Only arrays accepted. The bad value is: \''
221 . print_r($params, true) . '\'');
223 $result = array();
224 foreach ($params as $param) {
225 $result[] = self::validate_parameters($description->content, $param);
227 return $result;
229 } else {
230 throw new invalid_parameter_exception('Invalid external api description');
235 * Clean response
236 * If a response attribute is unknown from the description, we just ignore the attribute.
237 * If a response attribute is incorrect, invalid_response_exception is thrown.
238 * Note: this function is similar to validate parameters, however it is distinct because
239 * parameters validation must be distinct from cleaning return values.
241 * @param external_description $description description of the return values
242 * @param mixed $response the actual response
243 * @return mixed response with added defaults for optional items, invalid_response_exception thrown if any problem found
244 * @author 2010 Jerome Mouneyrac
245 * @since Moodle 2.0
247 public static function clean_returnvalue(external_description $description, $response) {
248 if ($description instanceof external_value) {
249 if (is_array($response) or is_object($response)) {
250 throw new invalid_response_exception('Scalar type expected, array or object received.');
253 if ($description->type == PARAM_BOOL) {
254 // special case for PARAM_BOOL - we want true/false instead of the usual 1/0 - we can not be too strict here ;-)
255 if (is_bool($response) or $response === 0 or $response === 1 or $response === '0' or $response === '1') {
256 return (bool)$response;
259 $debuginfo = 'Invalid external api response: the value is "' . $response .
260 '", the server was expecting "' . $description->type . '" type';
261 try {
262 return validate_param($response, $description->type, $description->allownull, $debuginfo);
263 } catch (invalid_parameter_exception $e) {
264 //proper exception name, to be recursively catched to build the path to the faulty attribut
265 throw new invalid_response_exception($e->debuginfo);
268 } else if ($description instanceof external_single_structure) {
269 if (!is_array($response) && !is_object($response)) {
270 throw new invalid_response_exception('Only arrays/objects accepted. The bad value is: \'' .
271 print_r($response, true) . '\'');
274 // Cast objects into arrays.
275 if (is_object($response)) {
276 $response = (array) $response;
279 $result = array();
280 foreach ($description->keys as $key=>$subdesc) {
281 if (!array_key_exists($key, $response)) {
282 if ($subdesc->required == VALUE_REQUIRED) {
283 throw new invalid_response_exception('Error in response - Missing following required key in a single structure: ' . $key);
285 if ($subdesc instanceof external_value) {
286 if ($subdesc->required == VALUE_DEFAULT) {
287 try {
288 $result[$key] = self::clean_returnvalue($subdesc, $subdesc->default);
289 } catch (invalid_response_exception $e) {
290 //build the path to the faulty attribut
291 throw new invalid_response_exception($key." => ".$e->getMessage() . ': ' . $e->debuginfo);
295 } else {
296 try {
297 $result[$key] = self::clean_returnvalue($subdesc, $response[$key]);
298 } catch (invalid_response_exception $e) {
299 //build the path to the faulty attribut
300 throw new invalid_response_exception($key." => ".$e->getMessage() . ': ' . $e->debuginfo);
303 unset($response[$key]);
306 return $result;
308 } else if ($description instanceof external_multiple_structure) {
309 if (!is_array($response)) {
310 throw new invalid_response_exception('Only arrays accepted. The bad value is: \'' .
311 print_r($response, true) . '\'');
313 $result = array();
314 foreach ($response as $param) {
315 $result[] = self::clean_returnvalue($description->content, $param);
317 return $result;
319 } else {
320 throw new invalid_response_exception('Invalid external api response description');
325 * Makes sure user may execute functions in this context.
327 * @param stdClass $context
328 * @since Moodle 2.0
330 protected static function validate_context($context) {
331 global $CFG;
333 if (empty($context)) {
334 throw new invalid_parameter_exception('Context does not exist');
336 if (empty(self::$contextrestriction)) {
337 self::$contextrestriction = context_system::instance();
339 $rcontext = self::$contextrestriction;
341 if ($rcontext->contextlevel == $context->contextlevel) {
342 if ($rcontext->id != $context->id) {
343 throw new restricted_context_exception();
345 } else if ($rcontext->contextlevel > $context->contextlevel) {
346 throw new restricted_context_exception();
347 } else {
348 $parents = get_parent_contexts($context);
349 if (!in_array($rcontext->id, $parents)) {
350 throw new restricted_context_exception();
354 if ($context->contextlevel >= CONTEXT_COURSE) {
355 list($context, $course, $cm) = get_context_info_array($context->id);
356 require_login($course, false, $cm, false, true);
362 * Common ancestor of all parameter description classes
364 * @package core_webservice
365 * @copyright 2009 Petr Skodak
366 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
367 * @since Moodle 2.0
369 abstract class external_description {
370 /** @var string Description of element */
371 public $desc;
373 /** @var bool Element value required, null not allowed */
374 public $required;
376 /** @var mixed Default value */
377 public $default;
380 * Contructor
382 * @param string $desc
383 * @param bool $required
384 * @param mixed $default
385 * @since Moodle 2.0
387 public function __construct($desc, $required, $default) {
388 $this->desc = $desc;
389 $this->required = $required;
390 $this->default = $default;
395 * Scalar value description class
397 * @package core_webservice
398 * @copyright 2009 Petr Skodak
399 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
400 * @since Moodle 2.0
402 class external_value extends external_description {
404 /** @var mixed Value type PARAM_XX */
405 public $type;
407 /** @var bool Allow null values */
408 public $allownull;
411 * Constructor
413 * @param mixed $type
414 * @param string $desc
415 * @param bool $required
416 * @param mixed $default
417 * @param bool $allownull
418 * @since Moodle 2.0
420 public function __construct($type, $desc='', $required=VALUE_REQUIRED,
421 $default=null, $allownull=NULL_ALLOWED) {
422 parent::__construct($desc, $required, $default);
423 $this->type = $type;
424 $this->allownull = $allownull;
429 * Associative array description class
431 * @package core_webservice
432 * @copyright 2009 Petr Skodak
433 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
434 * @since Moodle 2.0
436 class external_single_structure extends external_description {
438 /** @var array Description of array keys key=>external_description */
439 public $keys;
442 * Constructor
444 * @param array $keys
445 * @param string $desc
446 * @param bool $required
447 * @param array $default
448 * @since Moodle 2.0
450 public function __construct(array $keys, $desc='',
451 $required=VALUE_REQUIRED, $default=null) {
452 parent::__construct($desc, $required, $default);
453 $this->keys = $keys;
458 * Bulk array description class.
460 * @package core_webservice
461 * @copyright 2009 Petr Skodak
462 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
463 * @since Moodle 2.0
465 class external_multiple_structure extends external_description {
467 /** @var external_description content */
468 public $content;
471 * Constructor
473 * @param external_description $content
474 * @param string $desc
475 * @param bool $required
476 * @param array $default
477 * @since Moodle 2.0
479 public function __construct(external_description $content, $desc='',
480 $required=VALUE_REQUIRED, $default=null) {
481 parent::__construct($desc, $required, $default);
482 $this->content = $content;
487 * Description of top level - PHP function parameters.
489 * @package core_webservice
490 * @copyright 2009 Petr Skodak
491 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
492 * @since Moodle 2.0
494 class external_function_parameters extends external_single_structure {
498 * Generate a token
500 * @param string $tokentype EXTERNAL_TOKEN_EMBEDDED|EXTERNAL_TOKEN_PERMANENT
501 * @param stdClass|int $serviceorid service linked to the token
502 * @param int $userid user linked to the token
503 * @param stdClass|int $contextorid
504 * @param int $validuntil date when the token expired
505 * @param string $iprestriction allowed ip - if 0 or empty then all ips are allowed
506 * @return string generated token
507 * @author 2010 Jamie Pratt
508 * @since Moodle 2.0
510 function external_generate_token($tokentype, $serviceorid, $userid, $contextorid, $validuntil=0, $iprestriction=''){
511 global $DB, $USER;
512 // make sure the token doesn't exist (even if it should be almost impossible with the random generation)
513 $numtries = 0;
514 do {
515 $numtries ++;
516 $generatedtoken = md5(uniqid(rand(),1));
517 if ($numtries > 5){
518 throw new moodle_exception('tokengenerationfailed');
520 } while ($DB->record_exists('external_tokens', array('token'=>$generatedtoken)));
521 $newtoken = new stdClass();
522 $newtoken->token = $generatedtoken;
523 if (!is_object($serviceorid)){
524 $service = $DB->get_record('external_services', array('id' => $serviceorid));
525 } else {
526 $service = $serviceorid;
528 if (!is_object($contextorid)){
529 $context = context::instance_by_id($contextorid, MUST_EXIST);
530 } else {
531 $context = $contextorid;
533 if (empty($service->requiredcapability) || has_capability($service->requiredcapability, $context, $userid)) {
534 $newtoken->externalserviceid = $service->id;
535 } else {
536 throw new moodle_exception('nocapabilitytousethisservice');
538 $newtoken->tokentype = $tokentype;
539 $newtoken->userid = $userid;
540 if ($tokentype == EXTERNAL_TOKEN_EMBEDDED){
541 $newtoken->sid = session_id();
544 $newtoken->contextid = $context->id;
545 $newtoken->creatorid = $USER->id;
546 $newtoken->timecreated = time();
547 $newtoken->validuntil = $validuntil;
548 if (!empty($iprestriction)) {
549 $newtoken->iprestriction = $iprestriction;
551 $DB->insert_record('external_tokens', $newtoken);
552 return $newtoken->token;
556 * Create and return a session linked token. Token to be used for html embedded client apps that want to communicate
557 * with the Moodle server through web services. The token is linked to the current session for the current page request.
558 * It is expected this will be called in the script generating the html page that is embedding the client app and that the
559 * returned token will be somehow passed into the client app being embedded in the page.
561 * @param string $servicename name of the web service. Service name as defined in db/services.php
562 * @param int $context context within which the web service can operate.
563 * @return int returns token id.
564 * @since Moodle 2.0
566 function external_create_service_token($servicename, $context){
567 global $USER, $DB;
568 $service = $DB->get_record('external_services', array('name'=>$servicename), '*', MUST_EXIST);
569 return external_generate_token(EXTERNAL_TOKEN_EMBEDDED, $service, $USER->id, $context, 0);
573 * Delete all pre-built services (+ related tokens) and external functions information defined in the specified component.
575 * @param string $component name of component (moodle, mod_assignment, etc.)
577 function external_delete_descriptions($component) {
578 global $DB;
580 $params = array($component);
582 $DB->delete_records_select('external_tokens',
583 "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
584 $DB->delete_records_select('external_services_users',
585 "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
586 $DB->delete_records_select('external_services_functions',
587 "functionname IN (SELECT name FROM {external_functions} WHERE component = ?)", $params);
588 $DB->delete_records('external_services', array('component'=>$component));
589 $DB->delete_records('external_functions', array('component'=>$component));
593 * Standard Moodle web service warnings
595 * @package core_webservice
596 * @copyright 2012 Jerome Mouneyrac
597 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
598 * @since Moodle 2.3
600 class external_warnings extends external_multiple_structure {
603 * Constructor
605 * @since Moodle 2.3
607 public function __construct($itemdesc = 'item', $itemiddesc = 'item id',
608 $warningcodedesc = 'the warning code can be used by the client app to implement specific behaviour') {
610 parent::__construct(
611 new external_single_structure(
612 array(
613 'item' => new external_value(PARAM_TEXT, $itemdesc, VALUE_OPTIONAL),
614 'itemid' => new external_value(PARAM_INT, $itemiddesc, VALUE_OPTIONAL),
615 'warningcode' => new external_value(PARAM_ALPHANUM, $warningcodedesc),
616 'message' => new external_value(PARAM_TEXT,
617 'untranslated english message to explain the warning')
618 ), 'warning'),
619 'list of warnings', VALUE_OPTIONAL);
624 * A pre-filled external_value class for text format.
626 * Default is FORMAT_HTML
627 * This should be used all the time in external xxx_params()/xxx_returns functions
628 * as it is the standard way to implement text format param/return values.
630 * @package core_webservice
631 * @copyright 2012 Jerome Mouneyrac
632 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
633 * @since Moodle 2.3
635 class external_format_value extends external_value {
638 * Constructor
640 * @param string $textfieldname Name of the text field
641 * @param int $required if VALUE_REQUIRED then set standard default FORMAT_HTML
642 * @since Moodle 2.3
644 public function __construct($textfieldname, $required = VALUE_REQUIRED) {
646 $default = ($required == VALUE_DEFAULT) ? FORMAT_HTML : null;
648 $desc = $textfieldname . ' format (' . FORMAT_HTML . ' = HTML, '
649 . FORMAT_MOODLE . ' = MOODLE, '
650 . FORMAT_PLAIN . ' = PLAIN or '
651 . FORMAT_MARKDOWN . ' = MARKDOWN)';
653 parent::__construct(PARAM_INT, $desc, $required, $default);
658 * Validate text field format against known FORMAT_XXX
660 * @param array $format the format to validate
661 * @return the validated format
662 * @throws coding_exception
663 * @since 2.3
665 function external_validate_format($format) {
666 $allowedformats = array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN);
667 if (!in_array($format, $allowedformats)) {
668 throw new moodle_exception('formatnotsupported', 'webservice', '' , null,
669 'The format with value=' . $format . ' is not supported by this Moodle site');
671 return $format;
675 * Format the text to be returned properly as requested by the either the web service server,
676 * either by an internally call.
677 * The caller can change the format (raw, filter, file, fileurl) with the external_settings singleton
678 * All web service servers must set this singleton when parsing the $_GET and $_POST.
680 * @param string $text The content that may contain ULRs in need of rewriting.
681 * @param int $textformat The text format, by default FORMAT_HTML.
682 * @param int $contextid This parameter and the next two identify the file area to use.
683 * @param string $component
684 * @param string $filearea helps identify the file area.
685 * @param int $itemid helps identify the file area.
686 * @return array text + textformat
687 * @since Moodle 2.3
689 function external_format_text($text, $textformat, $contextid, $component, $filearea, $itemid) {
690 global $CFG;
692 // Get settings (singleton).
693 $settings = external_settings::get_instance();
695 if ($settings->get_fileurl()) {
696 require_once($CFG->libdir . "/filelib.php");
697 $text = file_rewrite_pluginfile_urls($text, $settings->get_file(), $contextid, $component, $filearea, $itemid);
700 if (!$settings->get_raw()) {
701 $textformat = FORMAT_HTML; // Force format to HTML when not raw.
702 $text = format_text($text, $textformat,
703 array('noclean' => true, 'para' => false, 'filter' => $settings->get_filter()));
706 return array($text, $textformat);
710 * Singleton to handle the external settings.
712 * We use singleton to encapsulate the "logic"
714 * @package core_webservice
715 * @copyright 2012 Jerome Mouneyrac
716 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
717 * @since Moodle 2.3
719 class external_settings {
721 /** @var object the singleton instance */
722 public static $instance = null;
724 /** @var boolean Should the external function return raw text or formatted */
725 private $raw = false;
727 /** @var boolean Should the external function filter the text */
728 private $filter = false;
730 /** @var boolean Should the external function rewrite plugin file url */
731 private $fileurl = true;
733 /** @var string In which file should the urls be rewritten */
734 private $file = 'webservice/pluginfile.php';
737 * Constructor - protected - can not be instanciated
739 protected function __construct() {
743 * Clone - private - can not be cloned
745 private final function __clone() {
749 * Return only one instance
751 * @return object
753 public static function get_instance() {
754 if (self::$instance === null) {
755 self::$instance = new external_settings;
758 return self::$instance;
762 * Set raw
764 * @param boolean $raw
766 public function set_raw($raw) {
767 $this->raw = $raw;
771 * Get raw
773 * @return boolean
775 public function get_raw() {
776 return $this->raw;
780 * Set filter
782 * @param boolean $filter
784 public function set_filter($filter) {
785 $this->filter = $filter;
789 * Get filter
791 * @return boolean
793 public function get_filter() {
794 return $this->filter;
798 * Set fileurl
800 * @param boolean $fileurl
802 public function set_fileurl($fileurl) {
803 $this->fileurl = $fileurl;
807 * Get fileurl
809 * @return boolean
811 public function get_fileurl() {
812 return $this->fileurl;
816 * Set file
818 * @param string $file
820 public function set_file($file) {
821 $this->file = $file;
825 * Get file
827 * @return string
829 public function get_file() {
830 return $this->file;