Files
luos/gulliver/system/class.webResource.php

144 lines
4.2 KiB
PHP
Raw Permalink Normal View History

2010-12-02 23:34:41 +00:00
<?php
2010-12-02 23:34:41 +00:00
/**
* class.webResource.php
*
* @package gulliver.system
2011-01-24 21:07:14 +00:00
*
2010-12-02 23:34:41 +00:00
* ProcessMaker Open Source Edition
2011-01-24 21:07:14 +00:00
* Copyright (C) 2004 - 2011 Colosa Inc.
*
2010-12-02 23:34:41 +00:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2010-12-02 23:34:41 +00:00
* GNU Affero General Public License for more details.
*
2010-12-02 23:34:41 +00:00
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
2010-12-02 23:34:41 +00:00
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
2010-12-02 23:34:41 +00:00
*/
/* Web Resource (v1.0 PHP4)
* This class permit create PHP/Javascript classes accesible by
* HTTPRequest (see skins/grest.js)
* _Function = don't encode
* JS_function = javascript function.
* @example: h2b2x/territoriesAjax.php
* @dependencies: grest.js *
2011-01-14 11:51:34 +00:00
*/
/**
*
2011-01-14 11:51:34 +00:00
* @package gulliver.system
2010-12-02 23:34:41 +00:00
*/
class WebResource
{
var $_uri;
2010-12-02 23:34:41 +00:00
/**
* WebResource
*
* @param string $uri
* @param string $post
*
2019-08-02 15:57:22 -04:00
* @return void
*/
2019-08-02 15:57:22 -04:00
public function __construct($uri, $post)
{
$this->_uri = $uri;
2019-08-02 15:57:22 -04:00
if (isset($post['function']) && $post['function'] != '') {
/*Call a function*/
2019-08-02 15:57:22 -04:00
header('Content-Type: text/json');
//$parameters=G::json_decode((urldecode($post['parameters']))); //for %AC
2019-08-02 15:57:22 -04:00
$parameters = G::json_decode(($post['parameters']));
$paramsRef = array();
foreach ($parameters as $key => $value) {
2019-08-02 15:57:22 -04:00
if (is_string($key)) {
$paramsRef[] = "\$parameters['" . addcslashes($key, '\\\'') . "']";
} else {
$paramsRef[] = '$parameters[' . $key . ']';
}
}
2019-08-02 15:57:22 -04:00
$paramsRef = implode(',', $paramsRef);
2017-08-02 16:06:56 -04:00
2015-03-11 17:51:50 -04:00
$filter = new InputFilter();
$post['function'] = $filter->validateInput($post['function']);
$paramsRef = $filter->validateInput($paramsRef);
2019-08-02 15:57:22 -04:00
$res = eval('return ($this->' . $post['function'] . '(' . $paramsRef . '));');
$res = G::json_encode($res);
print ($res);
} else {
/*Print class definition*/
$this->_encode();
}
2010-12-02 23:34:41 +00:00
}
/**
* _encode
*
* @return none
*/
function _encode ()
{
2017-08-02 16:06:56 -04:00
2015-03-11 17:51:50 -04:00
$filter = new InputFilter();
header( 'Content-Type: text/json' );
$methods = get_class_methods( get_class( $this ) );
2015-03-11 17:51:50 -04:00
$methods = $filter->xssFilterHard($methods);
$this->_uri = $filter->xssFilterHard($this->_uri);
print ('{') ;
$first = true;
foreach ($methods as $method) {
//To avoid PHP version incompatibilities, put the $method name in lowercase
$method = strtolower( $method );
2015-03-11 17:51:50 -04:00
$method = $filter->xssFilterHard($method);
if ((substr( $method, 0, 1 ) === '_') || (strcasecmp( $method, 'WebResource' ) == 0) || (strcasecmp( $method, get_class( $this ) ) == 0)) {
} elseif (strcasecmp( substr( $method, 0, 3 ), 'js_' ) == 0) {
if (! $first) {
print (',') ;
}
$this->{$method}();
$first = false;
} else {
if (! $first) {
print (',') ;
}
print ($method . ':function(){return __wrCall("' . addslashes( $this->_uri ) . '","' . $method . '",arguments);}') ;
$first = false;
}
}
print ('}') ;
2010-12-02 23:34:41 +00:00
}
}
/* end class WebResource */
/*if (! function_exists( 'json_encode' )) {
2017-08-02 16:06:56 -04:00
function json_encode (&$value)
{
$json = new Services_JSON();
return $json->encode( $value );
}
2010-12-02 23:34:41 +00:00
}
if (! function_exists( 'json_decode' )) {
2017-08-02 16:06:56 -04:00
function json_decode (&$value)
{
$json = new Services_JSON();
return $json->decode( $value );
}
}*/