. * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. * */ /* 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 * */ /** * @package gulliver.system */ class WebResource { var $_uri; /** * WebResource * * @param string $uri * @param string $post * * @return none */ function WebResource($uri, $post) { $this->_uri=$uri; if (isset($post['function'])&&$post['function']!='') { /*Call a function*/ header('Content-Type: text/json'); $parameters=json_decode((urldecode($post['parameters']))); $paramsRef=array(); foreach($parameters as $key => $value) { if (is_string($key)) $paramsRef[]="\$parameters['".addcslashes($key,'\\\'')."']"; else $paramsRef[]='$parameters['.$key.']'; } $res=eval('return ($this->'.$post['function'].'('.implode(',',$paramsRef).'));'); $res=G::json_encode($res); print($res); } else { /*Print class definition*/ $this->_encode(); } } /** * _encode * * @return none */ function _encode() { header('Content-Type: text/json'); $methods=get_class_methods(get_class($this)); print('{'); $first = true; foreach($methods as $method) { //To avoid PHP version incompatibilities, put the $method name in lowercase $method=strtolower($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('}'); } } /* end class WebResource */ if (!function_exists('json_encode')) { G::LoadThirdParty('pear/json','class.json'); function json_encode(&$value) { $json= new Services_JSON; return $json->encode($value); } } if (!function_exists('json_decode')) { G::LoadThirdParty('pear/json','class.json'); function json_decode(&$value) { $json= new Services_JSON; return $json->decode($value); } }