1 |
efrain |
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* Web services auto-generated documentation
|
|
|
20 |
*
|
|
|
21 |
* @package core_webservice
|
|
|
22 |
* @copyright 2009 Jerome Mouneyrac <jerome@moodle.com>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
require_once('../config.php');
|
|
|
27 |
require_once($CFG->dirroot . '/webservice/lib.php');
|
|
|
28 |
|
|
|
29 |
require_login();
|
|
|
30 |
|
|
|
31 |
$usercontext = context_user::instance($USER->id);
|
|
|
32 |
$tokenid = required_param('id', PARAM_INT);
|
|
|
33 |
|
|
|
34 |
// PAGE settings
|
|
|
35 |
$PAGE->set_context($usercontext);
|
|
|
36 |
$PAGE->set_url('/user/wsdoc.php');
|
|
|
37 |
$PAGE->set_title(get_string('wsdocumentation', 'webservice'));
|
|
|
38 |
$PAGE->set_pagelayout('standard');
|
|
|
39 |
|
|
|
40 |
// nav bar
|
|
|
41 |
$PAGE->navbar->ignore_active(true);
|
|
|
42 |
$PAGE->navbar->add(get_string('preferences'), new moodle_url('/user/preferences.php'));
|
|
|
43 |
$PAGE->navbar->add(get_string('useraccount'));
|
|
|
44 |
$PAGE->navbar->add(get_string('securitykeys', 'webservice'), new moodle_url('/user/managetoken.php'));
|
|
|
45 |
$PAGE->navbar->add(get_string('wsdocumentation', 'webservice'));
|
|
|
46 |
|
|
|
47 |
// check web service are enabled
|
|
|
48 |
if (empty($CFG->enablewsdocumentation)) {
|
|
|
49 |
echo get_string('wsdocumentationdisable', 'webservice');
|
|
|
50 |
die;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// check that the current user is the token user
|
|
|
54 |
$webservice = new webservice();
|
|
|
55 |
$token = $webservice->get_token_by_id($tokenid);
|
|
|
56 |
if (empty($token) or empty($token->userid) or empty($USER->id)
|
|
|
57 |
or ($token->userid != $USER->id)) {
|
|
|
58 |
throw new moodle_exception('docaccessrefused', 'webservice');
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// get the list of all functions related to the token
|
|
|
62 |
$functions = $webservice->get_external_functions(array($token->externalserviceid));
|
|
|
63 |
|
|
|
64 |
// get all the function descriptions
|
|
|
65 |
$functiondescs = array();
|
|
|
66 |
foreach ($functions as $function) {
|
|
|
67 |
$functiondescs[$function->name] = \core_external\external_api::external_function_info($function);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// TODO: MDL-76078 - Incorrect inter-communication, core cannot have plugin dependencies like this.
|
|
|
71 |
|
|
|
72 |
// get activated protocol
|
|
|
73 |
$activatedprotocol = array();
|
|
|
74 |
$activatedprotocol['rest'] = webservice_protocol_is_enabled('rest');
|
|
|
75 |
$activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc');
|
|
|
76 |
|
|
|
77 |
// Check if we are in printable mode
|
|
|
78 |
$printableformat = optional_param('print', false, PARAM_BOOL);
|
|
|
79 |
|
|
|
80 |
// OUTPUT
|
|
|
81 |
echo $OUTPUT->header();
|
|
|
82 |
|
|
|
83 |
$renderer = $PAGE->get_renderer('core', 'webservice');
|
|
|
84 |
echo $renderer->documentation_html($functiondescs,
|
|
|
85 |
$printableformat, $activatedprotocol, array('id' => $tokenid));
|
|
|
86 |
|
|
|
87 |
// trigger browser print operation
|
|
|
88 |
if (!empty($printableformat)) {
|
|
|
89 |
$PAGE->requires->js_function_call('window.print', array());
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
echo $OUTPUT->footer();
|