Comparing revisions for RESTHandler

Additions:
# @version 0.91
# @output returns a UTF-8 string (empty if no match)
function numeric_html_entities ($string)
function uri_suffix_to_xpath_request (array $params)
$tag = isset($params[1]) ? $params[1] : '';
$attr = isset($params[3]) ? $params[3] : '';
$val = isset($params[5]) ? $params[5] : '';
|| (!preg_match('/^[0-9]*$/', $rank))
$xpath .= $attr ? ('[@'. $attr .($val ? '=\''.$val.'\'' : '') .']') : '';
return(array($xpath, $rank));
if (preg_match('/^([a-zA-Z_][A-Za-z0-9:_\-\.]*)?(\/([a-zA-Z_][A-Za-z0-9:_\-\.]*)?(\/([^\/]*))?(\/([^\/]*))?)?/', $this->RESTreq, $matches))
list($xpath_req, $rank) = uri_suffix_to_xpath_request($matches);
if ($xpath_req)
$my_page = '<div class="page">'."\n";
$my_page .= '<div style="clear: both"></div>'."\n";
{ // silent failure
$output = '';
echo ($output);
print($this->Method('rest'));
Deletions:
# @version 0.94
# @output returns a XML document formatted as a UTF-8 string
# @uses Wakka::Format()
# @uses Wakka::Href()
if (!defined('REST_ERROR_NOT_SUPPORTED')) define('REST_ERROR_NOT_SUPPORTED', 'MethodUnsupported');
if (!defined('REST_ERROR_SYNTAX')) define('REST_ERROR_SYNTAX', 'SyntaxError');
if (!defined('REST_ERROR_BAD_PARAMETERS')) define('REST_ERROR_BAD_PARAMETERS', 'IllegalParameters');
if (!defined('REST_ERROR_XPATH_FAILURE')) define('REST_ERROR_XPATH_FAILURE', 'XPathFailure');
if (!defined('REST_FORMAT_ERROR_MSG')) define('REST_FORMAT_ERROR_MSG', '<Error><Code>%s</Code><Message>%s</Message><Resource>%s %s</Resource></Error>');
$REST_RETURN_CODES_ARRAY = array(
'MethodUnsupported' => array('Method not supported', 'HTTP/1.1 501 Not Implemented'),
'SyntaxError' => array('Could not parse request string', 'HTTP/1.1 400 Bad Request'),
'IllegalParameters' => array('Illegal parameter(s) value', 'HTTP/1.1 400 Bad Request'),
'XPathFailure' => array('Could not process query', 'HTTP/1.1 500 Server Error')
);
function numeric_html_entities($string)
function uri_suffix_to_xpath_request(array $params)
$tag = isset($params[1]) ? ($params[1]!='*' ? $params[1] : '') : '';
$attr = isset($params[3]) ? ($params[3]!='*' ? $params[3] : '') : '';
$val = isset($params[5]) ? ($params[5]!='*' ? $params[5] : '') : '';
|| (!preg_match('/^([1-9][0-9]*)?$/', $rank))
$error_code = REST_ERROR_BAD_PARAMETERS;
$xpath .= $attr ? (($val ? '[contains(concat(concat(" ", @'. $attr. '), " "), concat(concat(" ", \''. $val .'\'), " "))]' : '[@'. $attr .']')) : '';
$error_code = '';
return(array($xpath, $rank, $error_code));
if ($_SERVER['REQUEST_METHOD'] != 'GET')
{ // not supported
$error_code = REST_ERROR_NOT_SUPPORTED;
elseif (preg_match('/^([a-zA-Z_\*][A-Za-z0-9:_\-\.]*)?(\/([a-zA-Z_*][A-Za-z0-9:_\-\.]*)?(\/([^\/]*))?(\/([^\/]*))?)?/', $this->RESTreq, $matches))
list($xpath_req, $rank, $error_code) = uri_suffix_to_xpath_request($matches);
$error_code = REST_ERROR_SYNTAX;
if (!$error_code)
$my_page = '<div class="page">'. "\n";
$my_page .= '<div style="clear: both"></div>'. "\n";
$error_code = REST_ERROR_XPATH_FAILURE;
// if a '< ?xml version="1.0"? >' first line has been added, remove it
$output = preg_replace('/^\<\?xml[^\>]*?\>/i', '', $output);
if ($error_code)
{ // send 'Status' HTTP Header
header($REST_RETURN_CODES_ARRAY[$error_code][1]);
$output = sprintf(REST_FORMAT_ERROR_MSG, $error_code, $REST_RETURN_CODES_ARRAY[$error_code][0], $_SERVER['REQUEST_METHOD'], numeric_html_entities($this->RESTreq));
$output = '<wikkapage>'. $output .'</wikkapage>';
// the 'Content-Type' HTTP Header is sent in libs/Wakka.class.php
print ('<?xml version="1.0" encoding="utf-8" ?>'. "\n". $output);
header("Content-Type: text/xml; charset=utf-8");
$output = (version_compare(PHP_VERSION, '5.0.0', '<')) ? '<Error>Unsupported: requires PHP version 5.0.0 or higher</Error>' : $this->Method('rest');
print ($output);
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki