Skip to content

Commit

Permalink
Merge pull request #51 from thite-amol/master
Browse files Browse the repository at this point in the history
Correct output override path
  • Loading branch information
coolbung authored Aug 11, 2017
2 parents 18120b6 + 58d3266 commit 2571e89
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions code/site/controllers/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
class ApiControllerHttp extends ApiController
{

public $callbackname = 'callback';

/**
Expand Down Expand Up @@ -62,26 +61,28 @@ public function display($cachable = false, $urlparams = array())
}

/**
* Method description
* Send the response in the correct format
*
* @param OBJECT $exception exception
* @param OBJECT $response exception
*
* @return json
*
* @since 1.0
* @since 2.0
*/
private function respond($response)
{
$app = JFactory::getApplication();
$accept = $app->input->server->get('HTTP_ACCEPT', 'application/json', 'STRING');
$compatibility = $app->input->server->get('HTTP_X_COMPATIBILITY_MODE', 0, 'INT');

// Enforce JSON in compatibility mode
if ($compatibility)
{
$output = new \stdClass;
header("Content-type: application/json");
if ($response instanceof Exception) {

if ($response instanceof Exception)
{
$output->message = $response->getMessage();
$output->code = $response->getCode();
}
Expand All @@ -95,7 +96,8 @@ private function respond($response)
die();
}

switch($accept) {
switch ($accept)
{
case 'application/json':
default:
header("Content-type: application/json");
Expand All @@ -108,17 +110,18 @@ private function respond($response)
break;
}

$output_overrride = JPATH_ROOT . '/' . $app->getTemplate() . '/'.$format.'/api.php';
$output_overrride = JPATH_ROOT . '/templates/' . $app->getTemplate() . '/' . $format . '/api.php';

if (file_exists($output_overrride)) {
if (file_exists($output_overrride))
{
require_once $output_overrride;
}
else
{
require_once JPATH_COMPONENT . '/libraries/response/'.$format.'response.php';
require_once JPATH_COMPONENT . '/libraries/response/' . $format . 'response.php';
}

$classname = 'API'.ucfirst($format).'Response';
$classname = 'API' . ucfirst($format) . 'Response';
$output = new $classname($response);

echo $output->__toString();
Expand Down

0 comments on commit 2571e89

Please sign in to comment.