mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-22 05:15:29 +09:00
issue 2596 add a js callback method.
git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@11774 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
3c79a21e67
commit
fcee2600f1
3 changed files with 29 additions and 3 deletions
|
|
@ -794,7 +794,7 @@ class Context {
|
||||||
function setResponseMethod($method='HTML') {
|
function setResponseMethod($method='HTML') {
|
||||||
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
|
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
|
||||||
|
|
||||||
$methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1);
|
$methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1, 'JS_CALLBACK' => 1);
|
||||||
$self->response_method = isset($methods[$method]) ? $method : 'HTML';
|
$self->response_method = isset($methods[$method]) ? $method : 'HTML';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -809,7 +809,7 @@ class Context {
|
||||||
if($self->response_method) return $self->response_method;
|
if($self->response_method) return $self->response_method;
|
||||||
|
|
||||||
$method = $self->getRequestMethod();
|
$method = $self->getRequestMethod();
|
||||||
$methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1);
|
$methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1, 'JS_CALLBACK' => 1);
|
||||||
|
|
||||||
return isset($methods[$method]) ? $method : 'HTML';
|
return isset($methods[$method]) ? $method : 'HTML';
|
||||||
}
|
}
|
||||||
|
|
@ -823,9 +823,12 @@ class Context {
|
||||||
function setRequestMethod($type='') {
|
function setRequestMethod($type='') {
|
||||||
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
|
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
|
||||||
|
|
||||||
|
$xe_js_callback = isset($_GET['xe_js_callback']) ? $_GET['xe_js_callback'] : $_POST['xe_js_callback'];
|
||||||
|
|
||||||
($type && $self->request_method=$type) or
|
($type && $self->request_method=$type) or
|
||||||
(strpos($_SERVER['CONTENT_TYPE'],'json') && $self->request_method='JSON') or
|
(strpos($_SERVER['CONTENT_TYPE'],'json') && $self->request_method='JSON') or
|
||||||
($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method='XMLRPC') or
|
($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method='XMLRPC') or
|
||||||
|
($xe_js_callback && $self->request_method='JS_CALLBACK') or
|
||||||
($self->request_method = $_SERVER['REQUEST_METHOD']);
|
($self->request_method = $_SERVER['REQUEST_METHOD']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,11 @@
|
||||||
require_once("./classes/display/JSONDisplayHandler.php");
|
require_once("./classes/display/JSONDisplayHandler.php");
|
||||||
$handler = new JSONDisplayHandler();
|
$handler = new JSONDisplayHandler();
|
||||||
}
|
}
|
||||||
|
else if(Context::getRequestMethod() == 'JS_CALLBACK')
|
||||||
|
{
|
||||||
|
require_once("./classes/display/JSCallbackDisplayHandler.php");
|
||||||
|
$handler = new JSCallbackDisplayHandler();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
require_once("./classes/display/HTMLDisplayHandler.php");
|
require_once("./classes/display/HTMLDisplayHandler.php");
|
||||||
$handler = new HTMLDisplayHandler();
|
$handler = new HTMLDisplayHandler();
|
||||||
|
|
@ -65,7 +70,7 @@
|
||||||
if($httpStatusCode && $httpStatusCode != 200) $this->_printHttpStatusCode($httpStatusCode);
|
if($httpStatusCode && $httpStatusCode != 200) $this->_printHttpStatusCode($httpStatusCode);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(Context::getResponseMethod() == 'JSON') $this->_printJSONHeader();
|
if(Context::getResponseMethod() == 'JSON' || Context::getResponseMethod() == 'JS_CALLBACK') $this->_printJSONHeader();
|
||||||
else if(Context::getResponseMethod() != 'HTML') $this->_printXMLHeader();
|
else if(Context::getResponseMethod() != 'HTML') $this->_printXMLHeader();
|
||||||
else $this->_printHTMLHeader();
|
else $this->_printHTMLHeader();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
classes/display/JSCallbackDisplayHandler.php
Normal file
18
classes/display/JSCallbackDisplayHandler.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class JSCallbackDisplayHandler{
|
||||||
|
/**
|
||||||
|
* Produce JSCallback compliant content given a module object.\n
|
||||||
|
* @param ModuleObject $oModule the module object
|
||||||
|
* @return string
|
||||||
|
**/
|
||||||
|
function toDoc(&$oModule)
|
||||||
|
{
|
||||||
|
$variables = $oModule->getVariables();
|
||||||
|
$variables['error'] = $oModule->getError();
|
||||||
|
$variables['message'] = $oModule->getMessage();
|
||||||
|
$json = str_replace(array("\r\n","\n","\t"),array('\n','\n','\t'),json_encode2($variables));
|
||||||
|
$output = sprintf('<script>%s(%s);</script>', Context::get('xe_js_callback'), $json);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue