Refactor build_js_response function

Rename it to build_widget_response and move to libs/common/response.php
This commit is contained in:
Dmitriy Simushev 2013-05-16 15:25:35 +00:00
parent 5a3b2916d1
commit 52f00cbe59
3 changed files with 27 additions and 29 deletions

View File

@ -239,4 +239,30 @@ function add_params($servlet, $params)
return $servlet;
}
/**
* Builds JSONP response to the Mibew widget
*
* @param array $response Response data. It can contain following items:
* - 'load': associative array, specify files which must be loaded. Array keys
* are file aliases and values are URLs. One can use file alias to specify
* dependences (described below).
* - 'handlers': array, handlers which must be called (described below).
* - 'dependences': array, specify dependences between handlers and loaded
* files. Array keys are handlers names and values are arrays of file aliases
* from load item. Handler function will call only after all specified files
* loaded.
* - 'data': associative array, arbitrary structure which will be passed to all
* functions, specified in 'handlers' item.
* @return string JSONP response that ready to send to the widget
*/
function build_widget_response($response) {
$result = $response + array(
'load' => array(),
'handlers' => array(),
'dependences' => array(),
'data' => array()
);
return "mibewOnResponse(" . json_encode($result) . ");";
}
?>

View File

@ -1,27 +0,0 @@
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function build_js_response($response)
{
$result = array('load' => (isset($response['load'])?$response['load']:array()),
'handlers' => (isset($response['handlers'])?$response['handlers']:array()),
'dependences' => (isset($response['dependences'])?$response['dependences']:array()),
'data' => (isset($response['data'])?$response['data']:array()));
return "mibewOnResponse(" . json_encode($result) . ");";
}
?>

View File

@ -19,7 +19,6 @@ require_once('libs/init.php');
require_once('libs/invitation.php');
require_once('libs/operator.php');
require_once('libs/track.php');
require_once('libs/request.php');
$invited = FALSE;
$operator = array();
@ -81,7 +80,7 @@ if ($invited !== FALSE) {
}
start_js_output();
echo build_js_response($response);
echo build_widget_response($response);
exit;
?>