@@ -14,68 +14,68 @@ |
||
| 14 | 14 | |
| 15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Main function for this page, when no specific actions are called. |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - * @throws ApiException |
|
| 22 | - */ |
|
| 23 | - final protected function main() |
|
| 24 | - { |
|
| 25 | - if (headers_sent()) { |
|
| 26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 27 | - } |
|
| 17 | + /** |
|
| 18 | + * Main function for this page, when no specific actions are called. |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + * @throws ApiException |
|
| 22 | + */ |
|
| 23 | + final protected function main() |
|
| 24 | + { |
|
| 25 | + if (headers_sent()) { |
|
| 26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // javascript access control |
|
| 30 | - $httpOrigin = WebRequest::origin(); |
|
| 29 | + // javascript access control |
|
| 30 | + $httpOrigin = WebRequest::origin(); |
|
| 31 | 31 | |
| 32 | - if ($httpOrigin !== null) { |
|
| 33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
| 32 | + if ($httpOrigin !== null) { |
|
| 33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
| 34 | 34 | |
| 35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
| 36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
| 37 | - } |
|
| 38 | - } |
|
| 35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
| 36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $responseData = $this->runApiPage(); |
|
| 40 | + $responseData = $this->runApiPage(); |
|
| 41 | 41 | |
| 42 | - ob_end_clean(); |
|
| 43 | - print($responseData); |
|
| 44 | - ob_start(); |
|
| 45 | - } |
|
| 42 | + ob_end_clean(); |
|
| 43 | + print($responseData); |
|
| 44 | + ob_start(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Method that runs API action |
|
| 49 | - * |
|
| 50 | - * @return object|array The modified API document |
|
| 51 | - */ |
|
| 52 | - public abstract function executeApiAction(); |
|
| 47 | + /** |
|
| 48 | + * Method that runs API action |
|
| 49 | + * |
|
| 50 | + * @return object|array The modified API document |
|
| 51 | + */ |
|
| 52 | + public abstract function executeApiAction(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - final public function runApiPage() |
|
| 58 | - { |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + final public function runApiPage() |
|
| 58 | + { |
|
| 59 | 59 | |
| 60 | - try { |
|
| 61 | - $apiDocument = $this->executeApiAction(); |
|
| 62 | - } |
|
| 63 | - catch (ApiException $ex) { |
|
| 64 | - $apiDocument = [ |
|
| 65 | - 'error' => $ex->getMessage(), |
|
| 66 | - ]; |
|
| 67 | - } |
|
| 60 | + try { |
|
| 61 | + $apiDocument = $this->executeApiAction(); |
|
| 62 | + } |
|
| 63 | + catch (ApiException $ex) { |
|
| 64 | + $apiDocument = [ |
|
| 65 | + 'error' => $ex->getMessage(), |
|
| 66 | + ]; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
| 69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
| 70 | 70 | |
| 71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
| 72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
| 73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
| 74 | - header("Content-Type: text/javascript"); |
|
| 75 | - } else { |
|
| 76 | - header("Content-Type: application/json"); |
|
| 77 | - } |
|
| 71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
| 72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
| 73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
| 74 | + header("Content-Type: text/javascript"); |
|
| 75 | + } else { |
|
| 76 | + header("Content-Type: application/json"); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $data; |
|
| 80 | - } |
|
| 79 | + return $data; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
| 34 | 34 | |
| 35 | 35 | if (in_array($httpOrigin, $CORSallowed)) { |
| 36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
| 36 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $targetVar = WebRequest::getString('targetVariable'); |
| 72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
| 73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
| 73 | + $data = $targetVar.' = '.$data.';'; |
|
| 74 | 74 | header("Content-Type: text/javascript"); |
| 75 | 75 | } else { |
| 76 | 76 | header("Content-Type: application/json"); |
@@ -72,7 +72,8 @@ |
||
| 72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
| 73 | 73 | $data = $targetVar . ' = ' . $data . ';'; |
| 74 | 74 | header("Content-Type: text/javascript"); |
| 75 | - } else { |
|
| 75 | + } |
|
| 76 | + else { |
|
| 76 | 77 | header("Content-Type: application/json"); |
| 77 | 78 | } |
| 78 | 79 | |