From a1fccbac14bc8bec02f10aac738cf015f73786b6 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Wed, 30 Aug 2017 20:02:31 +0200 Subject: [PATCH] Fixed API and changes on themes --- bl-plugins/api/plugin.php | 11 +++++++---- bl-themes/docs/init.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index 9fa95f9e..5a060b53 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -60,7 +60,7 @@ class pluginAPI extends Plugin { $inputs = $this->getMethodInputs(); if ( empty($inputs) ) { - $this->response(404,'Not Found', array('message'=>'Missing method inputs.')); + $this->response(404, 'Not Found', array('message'=>'Missing method inputs.')); } // ENDPOINT PARAMETERS @@ -68,19 +68,20 @@ class pluginAPI extends Plugin { $parameters = $this->getEndpointParameters($URI); if ( empty($parameters) ) { - $this->response(404,'Not Found', array('message'=>'Missing endpoint parameters.')); + $this->response(404, 'Not Found', array('message'=>'Missing endpoint parameters.')); } // API TOKEN // ------------------------------------------------------------ + // Token from the plugin, the user can change it on the settings of the plugin $tokenAPI = $this->getValue('token'); // Check empty token if ( empty($inputs['token']) ) { - $this->response(404,'Not Found', array('message'=>'Missing API token.')); + $this->response(404, 'Not Found', array('message'=>'Missing API token.')); } - // Check the token is valid + // Check if the token is valid if ($inputs['token']!==$tokenAPI) { $this->response(401, 'Unauthorized', array('message'=>'Invalid API token.')); } @@ -164,6 +165,7 @@ class pluginAPI extends Plugin { // /api/pages/{key} | GET | returns the page with the {key} // /api/pages | POST | create a new page + $URI = ltrim($URI, '/'); $parameters = explode('/', $URI); // Sanitize parameters @@ -193,6 +195,7 @@ class pluginAPI extends Plugin { private function response($code=200, $message='OK', $data=array()) { header('HTTP/1.1 '.$code.' '.$message); + header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); $json = json_encode($data); exit($json); diff --git a/bl-themes/docs/init.php b/bl-themes/docs/init.php index 8d4879be..e059e63a 100644 --- a/bl-themes/docs/init.php +++ b/bl-themes/docs/init.php @@ -1,5 +1,5 @@ homepage()) { echo 'This theme need a home page defined, please select one page on Admin panel->Settings->Advanced->Home page';