function launch() { // not checked below refer to testing returning results through utf8 encoding. plb 2-6-2015 $valid_json_methods = array('GetSuggestions', 'GetListTitles', 'getOverDriveSummary', 'GetPreferredBranches', 'requestPinReset', 'getCreateListForm', 'getBulkAddToListForm', 'AddList', 'getEmailMyListForm', 'sendMyListEmail', 'setListEntryPositions', 'removeTag', 'saveSearch', 'deleteSavedSearch', 'cancelHold', 'cancelHolds', 'freezeHold', 'thawHold', 'getChangeHoldLocationForm', 'changeHoldLocation', 'getReactivationDateForm', 'renewItem', 'renewAll', 'renewSelectedItems', 'getPinResetForm'); $method = $_GET['method']; if (in_array($method, $valid_json_methods)) { header('Content-type: application/json'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $result = $this->{$method}(); try { require_once ROOT_DIR . '/sys/Utils/ArrayUtils.php'; $utf8EncodedValue = ArrayUtils::utf8EncodeArray($result); $output = json_encode($utf8EncodedValue); $error = json_last_error(); if ($error != JSON_ERROR_NONE || $output === FALSE) { if (function_exists('json_last_error_msg')) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error_msg())); } else { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error())); } global $configArray; if ($configArray['System']['debug']) { print_r($utf8EncodedValue); } } } catch (Exception $e) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => $e)); global $logger; $logger->log("Error encoding json data {$e}", PEAR_LOG_ERR); } echo $output; } elseif (in_array($method, array('LoginForm', 'getBulkAddToListForm', 'getPinUpdateForm', 'getCitationFormatsForm'))) { header('Content-type: text/html'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past echo $this->{$method}(); } else { header('Content-type: text/xml'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $xml = '<?xml version="1.0" encoding="UTF-8"?' . ">\n" . "<AJAXResponse>\n"; if (is_callable(array($this, $_GET['method']))) { $xml .= $this->{$_GET}['method'](); } else { $xml .= '<Error>Invalid Method</Error>'; } $xml .= '</AJAXResponse>'; echo $xml; } }
/** * Processes method to determine return type and calls the correct method. * Should not be called directly. * * @see Action::launch() * @access private * @author Mark Noble <*****@*****.**> */ function launch() { //header('Content-type: application/json'); header('Content-type: text/html'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past if (is_callable(array($this, $_GET['method']))) { try { $result = $this->{$_GET}['method'](); require_once ROOT_DIR . '/sys/Utils/ArrayUtils.php'; $utf8EncodedValue = ArrayUtils::utf8EncodeArray(array('result' => $result)); $output = json_encode($utf8EncodedValue); $error = json_last_error(); if ($error != JSON_ERROR_NONE || $output === FALSE) { if (function_exists('json_last_error_msg')) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error_msg())); } else { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error())); } global $configArray; if ($configArray['System']['debug']) { print_r($utf8EncodedValue); } } } catch (Exception $e) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => $e)); global $logger; $logger->log("Error encoding json data {$e}", PEAR_LOG_ERR); } } else { $output = json_encode(array('error' => 'invalid_method')); } echo $output; }
function launch() { global $analytics; $analytics->disableTracking(); $method = $_REQUEST['method']; $text_methods = array('GetAutoSuggestList', 'SysListTitles', 'GetStatusSummaries', 'getEmailForm', 'sendEmail', 'getDplaResults'); //TODO reconfig to use the JSON outputting here. $json_methods = array('getMoreSearchResults', 'GetListTitles'); // Plain Text Methods // if (in_array($method, $text_methods)) { header('Content-type: text/plain'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past $this->{$method}(); } elseif (in_array($method, $json_methods)) { // $response = $this->$method(); // header ('Content-type: application/json'); header('Content-type: text/html'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past if (is_callable(array($this, $method))) { try { $result = $this->{$method}(); require_once ROOT_DIR . '/sys/Utils/ArrayUtils.php'; // $utf8EncodedValue = ArrayUtils::utf8EncodeArray(array('result'=>$result)); $utf8EncodedValue = ArrayUtils::utf8EncodeArray($result); $output = json_encode($utf8EncodedValue); $error = json_last_error(); if ($error != JSON_ERROR_NONE || $output === FALSE) { if (function_exists('json_last_error_msg')) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error_msg())); } else { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error())); } global $configArray; if ($configArray['System']['debug']) { print_r($utf8EncodedValue); } } } catch (Exception $e) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => $e)); global $logger; $logger->log("Error encoding json data {$e}", PEAR_LOG_ERR); } } else { $output = json_encode(array('error' => 'invalid_method')); } echo $output; } else { header('Content-type: text/xml'); header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past echo '<?xml version="1.0" encoding="UTF-8"?' . ">\n"; echo "<AJAXResponse>\n"; if (is_callable(array($this, $method))) { $this->{$method}(); } else { echo '<Error>Invalid Method</Error>'; } echo '</AJAXResponse>'; } }
function json_utf8_encode($result) { // TODO: add to other ajax.php or make part of a ajax base class try { require_once ROOT_DIR . '/sys/Utils/ArrayUtils.php'; $utf8EncodedValue = ArrayUtils::utf8EncodeArray($result); $output = json_encode($utf8EncodedValue); $error = json_last_error(); if ($error != JSON_ERROR_NONE || $output === FALSE) { if (function_exists('json_last_error_msg')) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error_msg())); } else { $output = json_encode(array('error' => 'error_encoding_data', 'message' => json_last_error())); } global $configArray; if ($configArray['System']['debug']) { print_r($utf8EncodedValue); } } } catch (Exception $e) { $output = json_encode(array('error' => 'error_encoding_data', 'message' => $e)); global $logger; $logger->log("Error encoding json data {$e}", PEAR_LOG_ERR); } return $output; }