*/
class core_webservice_renderer extends plugin_renderer_base {
- /**
+ /**
* Create documentation for a description object
* @param object $params a part of parameter/return description
* @return string the html to display
}
return $type." ".$paramdesc;
}
-
-
}
/**
* @param string $username
* @return string the html to diplay
*/
- public function documentation_html($functions, $username) {
+ public function documentation_html($functions, $username, $activatedprotocol) {
$brakeline = <<<EOF
$documentationhtml = "";
- $documentationhtml .= "<table style=\"margin-left:auto; margin-right:auto;\"><tr><td>";
+ $documentationhtml .= "<table style=\"margin-left:auto; margin-right:auto;\"><tr><td style=\"text-align=left\">";
$documentationhtml .= get_string('wsdocumentationintro', 'webservice', $username);
$documentationhtml .= "<br/><br/><br/>";
$documentationhtml .= "</div>";
$documentationhtml .= "<br/><br/>";
- $documentationhtml .= "<span style=\"color:#EA33A6\">Authentication</span><br/>";
- $documentationhtml .= "<span style=\"font-size:80%\">";
- $documentationhtml .= get_string('requireauthentication', 'webservice'/*,$description->type*/);
- $documentationhtml .= "</span>";
- $documentationhtml .= "<br/><br/>";
-
$documentationhtml .= "<span style=\"color:#EA33A6\">".get_string('arguments', 'webservice')."</span><br/>";
foreach ($description->parameters_desc->keys as $paramname => $paramdesc) {
$documentationhtml .= "<span style=\"font-size:80%\">";
$required = $paramdesc->required?get_string('required', 'webservice'):get_string('optional', 'webservice');
$documentationhtml .= "<b>".$paramname . "</b> (" .$required. ")<br/>";
$documentationhtml .= " ".$paramdesc->desc." <br/><br/>";
- $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FFF1BC;color:#222222;padding:4px;\">";
$documentationhtml .= "<pre>";
- $documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_".$paramname,'<b>'.get_string('xmlrpcstructure', 'webservice').'</b>',false,true,true);
- //echo '<b>'.get_string('xmlrpcstructure', 'webservice').'</b><br/>';
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FFF1BC;color:#222222;padding:4px;\">";
+ //$documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_".$paramname,'<b>'.get_string('generalstructure', 'webservice').'</b>',false,true,true);
+ $documentationhtml .= '<b>'.get_string('generalstructure', 'webservice').'</b><br/>';
$documentationhtml .= $brakeline.$this->detailed_description_html($paramdesc);
- $documentationhtml .= print_collapsible_region_end(true);
- $documentationhtml .= "</pre>";
- $documentationhtml .= "</div><br/>";
- $documentationhtml .= "<pre>";
- $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#DFEEE7;color:#222222;padding:4px;\">";
- $documentationhtml .= '<b>'.get_string('phpparam', 'webservice').'</b><br/>';
- $documentationhtml .= $brakeline.'['.$paramname.'] =>'.htmlentities($this->xmlrpc_param_description_html($paramdesc)). $brakeline. $brakeline;
- $documentationhtml .= "</div><br/>";
- $documentationhtml .= "</pre>";
- $documentationhtml .= "<pre>";
- $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FEEBE5;color:#222222;padding:4px;\">";
- $documentationhtml .= '<b>'.get_string('restparam', 'webservice').'</b><br/>';
- $documentationhtml .= $brakeline.htmlentities($this->rest_param_description_html($paramdesc,$paramname)). $brakeline. $brakeline;
+ //$documentationhtml .= print_collapsible_region_end(true);
$documentationhtml .= "</div>";
- $documentationhtml .= "</pre>";
+ $documentationhtml .= "</pre><br/>";
+ if (!empty($activatedprotocol['xmlrpc'])) {
+ $documentationhtml .= "<pre>";
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#DFEEE7;color:#222222;padding:4px;\">";
+ $documentationhtml .= '<b>'.get_string('phpparam', 'webservice').'</b><br/>';
+ $documentationhtml .= $brakeline.'['.$paramname.'] =>'.htmlentities($this->xmlrpc_param_description_html($paramdesc)). $brakeline. $brakeline;
+ $documentationhtml .= "</div><br/>";
+ $documentationhtml .= "</pre>";
+ }
+ if (!empty($activatedprotocol['rest'])) {
+ $documentationhtml .= "<pre>";
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FEEBE5;color:#222222;padding:4px;\">";
+ $documentationhtml .= '<b>'.get_string('restparam', 'webservice').'</b><br/>';
+ $documentationhtml .= $brakeline.htmlentities($this->rest_param_description_html($paramdesc,$paramname)). $brakeline. $brakeline;
+ $documentationhtml .= "</div>";
+ $documentationhtml .= "</pre>";
+ }
$documentationhtml .= "</span>";
}
$documentationhtml .= "<br/><br/>";
}
if (!empty($description->returns_desc)) {
- $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FFF1BC;color:#222222;padding:4px;\">";
$documentationhtml .= "<pre>";
- $documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_xmlrpc_return",'<b>'.get_string('xmlrpcstructure', 'webservice').'</b>',false,true,true);
- //echo '<b>'.get_string('xmlrpcstructure', 'webservice').'</b><br/>';
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FFF1BC;color:#222222;padding:4px;\">";
+ //$documentationhtml .= print_collapsible_region_start('', 'aera_'.$functionname."_xmlrpc_return",'<b>'.get_string('generalstructure', 'webservice').'</b>',false,true,true);
+ $documentationhtml .= '<b>'.get_string('generalstructure', 'webservice').'</b><br/>';
$documentationhtml .= $brakeline.$this->detailed_description_html($description->returns_desc);
- $documentationhtml .= print_collapsible_region_end(true);
- $documentationhtml .= "</pre>";
- $documentationhtml .= "</div><br/>";
- $documentationhtml .= "<pre>";
- $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#DFEEE7;color:#222222;padding:4px;\">";
- $documentationhtml .= '<b>'.get_string('phpresponse', 'webservice').'</b><br/>';
- $documentationhtml .= htmlentities($this->xmlrpc_param_description_html($description->returns_desc)).$brakeline.$brakeline;
+ //$documentationhtml .= print_collapsible_region_end(true);
$documentationhtml .= "</div>";
$documentationhtml .= "</pre><br/>";
- $documentationhtml .= $this->rest_response_html($functionname, $description->returns_desc);
+ if (!empty($activatedprotocol['xmlrpc'])) {
+ $documentationhtml .= "<pre>";
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#DFEEE7;color:#222222;padding:4px;\">";
+ $documentationhtml .= '<b>'.get_string('phpresponse', 'webservice').'</b><br/>';
+ $documentationhtml .= htmlentities($this->xmlrpc_param_description_html($description->returns_desc)).$brakeline.$brakeline;
+ $documentationhtml .= "</div>";
+ $documentationhtml .= "</pre><br/>";
+ }
+ if (!empty($activatedprotocol['rest'])) {
+ $documentationhtml .= $this->rest_response_html($functionname, $description->returns_desc);
+ }
}
$documentationhtml .= "</span>";
$documentationhtml .= "<br/><br/>";
+ if (!empty($activatedprotocol['rest'])) {
+ $documentationhtml .= "<span style=\"color:#EA33A6\">".get_string('errorcodes', 'webservice')."</span><br/>";
+ $documentationhtml .= "<span style=\"font-size:80%\">";
+ $documentationhtml .= "<pre>";
+ $documentationhtml .= "<div style=\"border:solid 1px #DEDEDE;background:#FEEBE5;color:#222222;padding:4px;\">";
- $documentationhtml .= "<span style=\"color:#EA33A6\">".get_string('errorcodes', 'webservice')."</span><br/>";
- $documentationhtml .= "<span style=\"font-size:80%\">";
- $documentationhtml .= get_string('noerrorcode', 'webservice');
- $documentationhtml .= "</span>";
- $documentationhtml .= "<br/><br/>";
-
-
- $documentationhtml .= "<span style=\"color:#EA33A6\">".get_string('apiexplorer', 'webservice')."</span><br/>";
- $documentationhtml .= "<span style=\"font-size:80%\">";
- $documentationhtml .= get_string('apiexplorernotavalaible', 'webservice');
+ $documentationhtml .= '<b>'.get_string('restexception', 'webservice').'</b><br/>';
+ $errormessage = get_string('invalidparameter', 'debug');
+ $restexceptiontext =<<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<EXCEPTION class="invalid_parameter_exception">
+ <MESSAGE>{$errormessage}</MESSAGE>
+ <DEBUGINFO></DEBUGINFO>
+</EXCEPTION>
+EOF;
+ $documentationhtml .= $brakeline.htmlentities($restexceptiontext);
+ $documentationhtml .= "</div>";
+ $documentationhtml .= "</pre><br/>";
$documentationhtml .= "</span>";
+ }
$documentationhtml .= "<br/><br/>";
$documentationhtml .= print_collapsible_region_end(true);
}
- $documentationhtml .= "</td></tr></table>";
+ $documentationhtml .= "</td>";
+
+ $documentationhtml .= "</tr></table>";
return $documentationhtml;
}
$htmlloginpage .= $OUTPUT->form($form, $contents);
-
$htmlloginpage .= "</td></tr></table>";
return $htmlloginpage;
// disable moodle specific debug messages and any errors in output
-define('NO_DEBUG_DISPLAY', true);
define('NO_MOODLE_COOKIES', true);
require_once('../config.php');
*/
class webservice_documentation_generator {
- /** @property array all external function description
- * they */
+ /** @property array all external function description*/
protected $functions;
/** @property string $username name of local user */
/** @property string $password password of the local user */
protected $password = null;
+ /** @property object $webserviceuser authenticated web service user */
+ protected $webserviceuser = null;
+
/**
* Contructor
*/
// init all properties from the request data
$this->get_authentication_parameters();
- // this sets up $USER
+ // this sets up $this->webserviceuser
try {
$this->authenticate_user();
} catch(moodle_exception $e) {
* @return void
*/
protected function generate_documentation() {
- global $USER, $DB;
+ global $DB;
/// first of all get a complete list of services user is allowed to access
$params = array();
JOIN {external_services_users} su ON (su.externalserviceid = s.id AND su.userid = :userid)
WHERE s.enabled = 1 AND su.validuntil IS NULL OR su.validuntil < :now $wscond2";
- $params = array_merge($params, array('userid'=>$USER->id, 'now'=>time()));
+ $params = array_merge($params, array('userid'=>$this->webserviceuser->id, 'now'=>time()));
$serviceids = array();
$rs = $DB->get_recordset_sql($sql, $params);
// make sure user may access at least one service
- $remoteaddr = getremoteaddr();
$allowed = false;
foreach ($rs as $service) {
if (isset($serviceids[$service->id])) {
if ($service->requiredcapability and !has_capability($service->requiredcapability, $this->restricted_context)) {
continue; // cap required, sorry
}
- if ($service->iprestriction and !address_in_subnet($remoteaddr, $service->iprestriction)) {
- continue; // wrong request source ip, sorry
- }
$serviceids[$service->id] = $service->id;
}
$rs->close();
/**
* Authenticate user using username+password
- * This function sets up $USER global.
+ * This function sets up $this->webserviceuser.
* called into the Moodle header
* @return void
*/
protected function authenticate_user() {
- global $CFG, $DB, $USER;
+ global $CFG, $DB;
if (!NO_MOODLE_COOKIES) {
throw new coding_exception('Cookies must be disabled!');
throw new webservice_access_exception('Wrong username or password');
}
- $USER = $DB->get_record('user', array('username'=>$this->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0), '*', MUST_EXIST);
+ $this->webserviceuser = $DB->get_record('user', array('username'=>$this->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'deleted'=>0), '*', MUST_EXIST);
}
* Generate and display the documentation
*/
protected function display_documentation_html() {
- global $PAGE, $OUTPUT, $SITE, $USER;
+ global $PAGE, $OUTPUT, $SITE;
$PAGE->set_url('/webservice/wsdoc');
$PAGE->set_docs_path('');
$PAGE->set_title($SITE->fullname." ".get_string('wsdocumentation', 'webservice'));
$PAGE->set_heading($SITE->fullname." ".get_string('wsdocumentation', 'webservice'));
$PAGE->set_pagelayout('popup');
- //unlog temporarly the user in order to not trigger environment.php called by Moodle header.
- //environment.php checkes the sessionkey that we don't have here.
- //emvrionment.php is just used to detect the flash player. We don't need
- //to check the flash player version.
- $userid = $USER->id;
- $USER->id = null;
+
echo $OUTPUT->header();
- $USER->id = $userid;
- $renderer = $PAGE->get_renderer('core', 'wsdoc');
- echo $renderer->documentation_html($this->functions, $this->username);
+
+ $activatedprotocol = array();
+ $activatedprotocol['rest'] = webservice_protocol_is_enabled('rest');
+ $activatedprotocol['xmlrpc'] = webservice_protocol_is_enabled('xmlrpc');
+ $renderer = $PAGE->get_renderer('core', 'webservice');
+ echo $renderer->documentation_html($this->functions, $this->username, $activatedprotocol);
+
echo $OUTPUT->footer();
}
/**
* Display login page to the web service documentation
- * @global <type> $PAGE
- * @global <type> $OUTPUT
- * @global <type> $SITE
- * @global <type> $CFG
+ * @global object $PAGE
+ * @global object $OUTPUT
+ * @global object $SITE
+ * @global object $CFG
* @param string $errormessage error message displayed if wrong login
*/
protected function display_login_page_html($errormessage) {