Fixed API and changes on themes

This commit is contained in:
Diego Najar 2017-08-30 20:02:31 +02:00
parent 24724a3c90
commit a1fccbac14
2 changed files with 8 additions and 5 deletions

View File

@ -60,7 +60,7 @@ class pluginAPI extends Plugin {
$inputs = $this->getMethodInputs(); $inputs = $this->getMethodInputs();
if ( empty($inputs) ) { 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 // ENDPOINT PARAMETERS
@ -68,19 +68,20 @@ class pluginAPI extends Plugin {
$parameters = $this->getEndpointParameters($URI); $parameters = $this->getEndpointParameters($URI);
if ( empty($parameters) ) { 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 // API TOKEN
// ------------------------------------------------------------ // ------------------------------------------------------------
// Token from the plugin, the user can change it on the settings of the plugin
$tokenAPI = $this->getValue('token'); $tokenAPI = $this->getValue('token');
// Check empty token // Check empty token
if ( empty($inputs['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) { if ($inputs['token']!==$tokenAPI) {
$this->response(401, 'Unauthorized', array('message'=>'Invalid API token.')); $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/{key} | GET | returns the page with the {key}
// /api/pages | POST | create a new page // /api/pages | POST | create a new page
$URI = ltrim($URI, '/');
$parameters = explode('/', $URI); $parameters = explode('/', $URI);
// Sanitize parameters // Sanitize parameters
@ -193,6 +195,7 @@ class pluginAPI extends Plugin {
private function response($code=200, $message='OK', $data=array()) private function response($code=200, $message='OK', $data=array())
{ {
header('HTTP/1.1 '.$code.' '.$message); header('HTTP/1.1 '.$code.' '.$message);
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json'); header('Content-Type: application/json');
$json = json_encode($data); $json = json_encode($data);
exit($json); exit($json);

View File

@ -1,5 +1,5 @@
<?php <?php
$GITHUB_BASE_URL = 'https://github.com/dignajar/bludit-documentation-english/tree/master/'; $GITHUB_BASE_URL = '__GITHUB_BASE_URL__';
if (!$Site->homepage()) { if (!$Site->homepage()) {
echo 'This theme need a home page defined, please select one page on <b>Admin panel->Settings->Advanced->Home page</b>'; echo 'This theme need a home page defined, please select one page on <b>Admin panel->Settings->Advanced->Home page</b>';