Moodle release 2.6.4
[moodle.git] / lib / externallib.php
blob698a9efc12c05206b8863b6908611684ab424596
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) ? core_component::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 = core_component::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 = $context->get_parent_context_ids();
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);
361 * Get context from passed parameters.
362 * The passed array must either contain a contextid or a combination of context level and instance id to fetch the context.
363 * For example, the context level can be "course" and instanceid can be courseid.
365 * See context_helper::get_all_levels() for a list of valid context levels.
367 * @param array $param
368 * @since Moodle 2.6
369 * @throws invalid_parameter_exception
370 * @return context
372 protected static function get_context_from_params($param) {
373 $levels = context_helper::get_all_levels();
374 if (isset($param['contextid'])) {
375 return context::instance_by_id($param['contextid'], IGNORE_MISSING);
376 } else if (isset($param['contextlevel']) && isset($param['instanceid'])) {
377 $contextlevel = "context_".$param['contextlevel'];
378 if (!array_search($contextlevel, $levels)) {
379 throw new invalid_parameter_exception('Invalid context level = '.$param['contextlevel']);
381 return $contextlevel::instance($param['instanceid'], IGNORE_MISSING);
382 } else {
383 // No valid context info was found.
384 throw new invalid_parameter_exception('Missing parameters, please provide either context level with instance id or contextid');
390 * Common ancestor of all parameter description classes
392 * @package core_webservice
393 * @copyright 2009 Petr Skodak
394 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
395 * @since Moodle 2.0
397 abstract class external_description {
398 /** @var string Description of element */
399 public $desc;
401 /** @var bool Element value required, null not allowed */
402 public $required;
404 /** @var mixed Default value */
405 public $default;
408 * Contructor
410 * @param string $desc
411 * @param bool $required
412 * @param mixed $default
413 * @since Moodle 2.0
415 public function __construct($desc, $required, $default) {
416 $this->desc = $desc;
417 $this->required = $required;
418 $this->default = $default;
423 * Scalar value description class
425 * @package core_webservice
426 * @copyright 2009 Petr Skodak
427 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
428 * @since Moodle 2.0
430 class external_value extends external_description {
432 /** @var mixed Value type PARAM_XX */
433 public $type;
435 /** @var bool Allow null values */
436 public $allownull;
439 * Constructor
441 * @param mixed $type
442 * @param string $desc
443 * @param bool $required
444 * @param mixed $default
445 * @param bool $allownull
446 * @since Moodle 2.0
448 public function __construct($type, $desc='', $required=VALUE_REQUIRED,
449 $default=null, $allownull=NULL_ALLOWED) {
450 parent::__construct($desc, $required, $default);
451 $this->type = $type;
452 $this->allownull = $allownull;
457 * Associative array description class
459 * @package core_webservice
460 * @copyright 2009 Petr Skodak
461 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
462 * @since Moodle 2.0
464 class external_single_structure extends external_description {
466 /** @var array Description of array keys key=>external_description */
467 public $keys;
470 * Constructor
472 * @param array $keys
473 * @param string $desc
474 * @param bool $required
475 * @param array $default
476 * @since Moodle 2.0
478 public function __construct(array $keys, $desc='',
479 $required=VALUE_REQUIRED, $default=null) {
480 parent::__construct($desc, $required, $default);
481 $this->keys = $keys;
486 * Bulk array description class.
488 * @package core_webservice
489 * @copyright 2009 Petr Skodak
490 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
491 * @since Moodle 2.0
493 class external_multiple_structure extends external_description {
495 /** @var external_description content */
496 public $content;
499 * Constructor
501 * @param external_description $content
502 * @param string $desc
503 * @param bool $required
504 * @param array $default
505 * @since Moodle 2.0
507 public function __construct(external_description $content, $desc='',
508 $required=VALUE_REQUIRED, $default=null) {
509 parent::__construct($desc, $required, $default);
510 $this->content = $content;
515 * Description of top level - PHP function parameters.
517 * @package core_webservice
518 * @copyright 2009 Petr Skodak
519 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
520 * @since Moodle 2.0
522 class external_function_parameters extends external_single_structure {
526 * Generate a token
528 * @param string $tokentype EXTERNAL_TOKEN_EMBEDDED|EXTERNAL_TOKEN_PERMANENT
529 * @param stdClass|int $serviceorid service linked to the token
530 * @param int $userid user linked to the token
531 * @param stdClass|int $contextorid
532 * @param int $validuntil date when the token expired
533 * @param string $iprestriction allowed ip - if 0 or empty then all ips are allowed
534 * @return string generated token
535 * @author 2010 Jamie Pratt
536 * @since Moodle 2.0
538 function external_generate_token($tokentype, $serviceorid, $userid, $contextorid, $validuntil=0, $iprestriction=''){
539 global $DB, $USER;
540 // make sure the token doesn't exist (even if it should be almost impossible with the random generation)
541 $numtries = 0;
542 do {
543 $numtries ++;
544 $generatedtoken = md5(uniqid(rand(),1));
545 if ($numtries > 5){
546 throw new moodle_exception('tokengenerationfailed');
548 } while ($DB->record_exists('external_tokens', array('token'=>$generatedtoken)));
549 $newtoken = new stdClass();
550 $newtoken->token = $generatedtoken;
551 if (!is_object($serviceorid)){
552 $service = $DB->get_record('external_services', array('id' => $serviceorid));
553 } else {
554 $service = $serviceorid;
556 if (!is_object($contextorid)){
557 $context = context::instance_by_id($contextorid, MUST_EXIST);
558 } else {
559 $context = $contextorid;
561 if (empty($service->requiredcapability) || has_capability($service->requiredcapability, $context, $userid)) {
562 $newtoken->externalserviceid = $service->id;
563 } else {
564 throw new moodle_exception('nocapabilitytousethisservice');
566 $newtoken->tokentype = $tokentype;
567 $newtoken->userid = $userid;
568 if ($tokentype == EXTERNAL_TOKEN_EMBEDDED){
569 $newtoken->sid = session_id();
572 $newtoken->contextid = $context->id;
573 $newtoken->creatorid = $USER->id;
574 $newtoken->timecreated = time();
575 $newtoken->validuntil = $validuntil;
576 if (!empty($iprestriction)) {
577 $newtoken->iprestriction = $iprestriction;
579 $DB->insert_record('external_tokens', $newtoken);
580 return $newtoken->token;
584 * Create and return a session linked token. Token to be used for html embedded client apps that want to communicate
585 * with the Moodle server through web services. The token is linked to the current session for the current page request.
586 * It is expected this will be called in the script generating the html page that is embedding the client app and that the
587 * returned token will be somehow passed into the client app being embedded in the page.
589 * @param string $servicename name of the web service. Service name as defined in db/services.php
590 * @param int $context context within which the web service can operate.
591 * @return int returns token id.
592 * @since Moodle 2.0
594 function external_create_service_token($servicename, $context){
595 global $USER, $DB;
596 $service = $DB->get_record('external_services', array('name'=>$servicename), '*', MUST_EXIST);
597 return external_generate_token(EXTERNAL_TOKEN_EMBEDDED, $service, $USER->id, $context, 0);
601 * Delete all pre-built services (+ related tokens) and external functions information defined in the specified component.
603 * @param string $component name of component (moodle, mod_assignment, etc.)
605 function external_delete_descriptions($component) {
606 global $DB;
608 $params = array($component);
610 $DB->delete_records_select('external_tokens',
611 "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
612 $DB->delete_records_select('external_services_users',
613 "externalserviceid IN (SELECT id FROM {external_services} WHERE component = ?)", $params);
614 $DB->delete_records_select('external_services_functions',
615 "functionname IN (SELECT name FROM {external_functions} WHERE component = ?)", $params);
616 $DB->delete_records('external_services', array('component'=>$component));
617 $DB->delete_records('external_functions', array('component'=>$component));
621 * Standard Moodle web service warnings
623 * @package core_webservice
624 * @copyright 2012 Jerome Mouneyrac
625 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
626 * @since Moodle 2.3
628 class external_warnings extends external_multiple_structure {
631 * Constructor
633 * @since Moodle 2.3
635 public function __construct($itemdesc = 'item', $itemiddesc = 'item id',
636 $warningcodedesc = 'the warning code can be used by the client app to implement specific behaviour') {
638 parent::__construct(
639 new external_single_structure(
640 array(
641 'item' => new external_value(PARAM_TEXT, $itemdesc, VALUE_OPTIONAL),
642 'itemid' => new external_value(PARAM_INT, $itemiddesc, VALUE_OPTIONAL),
643 'warningcode' => new external_value(PARAM_ALPHANUM, $warningcodedesc),
644 'message' => new external_value(PARAM_TEXT,
645 'untranslated english message to explain the warning')
646 ), 'warning'),
647 'list of warnings', VALUE_OPTIONAL);
652 * A pre-filled external_value class for text format.
654 * Default is FORMAT_HTML
655 * This should be used all the time in external xxx_params()/xxx_returns functions
656 * as it is the standard way to implement text format param/return values.
658 * @package core_webservice
659 * @copyright 2012 Jerome Mouneyrac
660 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
661 * @since Moodle 2.3
663 class external_format_value extends external_value {
666 * Constructor
668 * @param string $textfieldname Name of the text field
669 * @param int $required if VALUE_REQUIRED then set standard default FORMAT_HTML
670 * @since Moodle 2.3
672 public function __construct($textfieldname, $required = VALUE_REQUIRED) {
674 $default = ($required == VALUE_DEFAULT) ? FORMAT_HTML : null;
676 $desc = $textfieldname . ' format (' . FORMAT_HTML . ' = HTML, '
677 . FORMAT_MOODLE . ' = MOODLE, '
678 . FORMAT_PLAIN . ' = PLAIN or '
679 . FORMAT_MARKDOWN . ' = MARKDOWN)';
681 parent::__construct(PARAM_INT, $desc, $required, $default);
686 * Validate text field format against known FORMAT_XXX
688 * @param array $format the format to validate
689 * @return the validated format
690 * @throws coding_exception
691 * @since 2.3
693 function external_validate_format($format) {
694 $allowedformats = array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN);
695 if (!in_array($format, $allowedformats)) {
696 throw new moodle_exception('formatnotsupported', 'webservice', '' , null,
697 'The format with value=' . $format . ' is not supported by this Moodle site');
699 return $format;
703 * Format the text to be returned properly as requested by the either the web service server,
704 * either by an internally call.
705 * The caller can change the format (raw, filter, file, fileurl) with the external_settings singleton
706 * All web service servers must set this singleton when parsing the $_GET and $_POST.
708 * @param string $text The content that may contain ULRs in need of rewriting.
709 * @param int $textformat The text format, by default FORMAT_HTML.
710 * @param int $contextid This parameter and the next two identify the file area to use.
711 * @param string $component
712 * @param string $filearea helps identify the file area.
713 * @param int $itemid helps identify the file area.
714 * @return array text + textformat
715 * @since Moodle 2.3
717 function external_format_text($text, $textformat, $contextid, $component, $filearea, $itemid) {
718 global $CFG;
720 // Get settings (singleton).
721 $settings = external_settings::get_instance();
723 if ($settings->get_fileurl()) {
724 require_once($CFG->libdir . "/filelib.php");
725 $text = file_rewrite_pluginfile_urls($text, $settings->get_file(), $contextid, $component, $filearea, $itemid);
728 if (!$settings->get_raw()) {
729 $textformat = FORMAT_HTML; // Force format to HTML when not raw.
730 $text = format_text($text, $textformat,
731 array('noclean' => true, 'para' => false, 'filter' => $settings->get_filter()));
734 return array($text, $textformat);
738 * Singleton to handle the external settings.
740 * We use singleton to encapsulate the "logic"
742 * @package core_webservice
743 * @copyright 2012 Jerome Mouneyrac
744 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
745 * @since Moodle 2.3
747 class external_settings {
749 /** @var object the singleton instance */
750 public static $instance = null;
752 /** @var boolean Should the external function return raw text or formatted */
753 private $raw = false;
755 /** @var boolean Should the external function filter the text */
756 private $filter = false;
758 /** @var boolean Should the external function rewrite plugin file url */
759 private $fileurl = true;
761 /** @var string In which file should the urls be rewritten */
762 private $file = 'webservice/pluginfile.php';
765 * Constructor - protected - can not be instanciated
767 protected function __construct() {
771 * Clone - private - can not be cloned
773 private final function __clone() {
777 * Return only one instance
779 * @return object
781 public static function get_instance() {
782 if (self::$instance === null) {
783 self::$instance = new external_settings;
786 return self::$instance;
790 * Set raw
792 * @param boolean $raw
794 public function set_raw($raw) {
795 $this->raw = $raw;
799 * Get raw
801 * @return boolean
803 public function get_raw() {
804 return $this->raw;
808 * Set filter
810 * @param boolean $filter
812 public function set_filter($filter) {
813 $this->filter = $filter;
817 * Get filter
819 * @return boolean
821 public function get_filter() {
822 return $this->filter;
826 * Set fileurl
828 * @param boolean $fileurl
830 public function set_fileurl($fileurl) {
831 $this->fileurl = $fileurl;
835 * Get fileurl
837 * @return boolean
839 public function get_fileurl() {
840 return $this->fileurl;
844 * Set file
846 * @param string $file
848 public function set_file($file) {
849 $this->file = $file;
853 * Get file
855 * @return string
857 public function get_file() {
858 return $this->file;