Bug fixes for API plugin

This commit is contained in:
Diego Najar 2019-02-08 08:53:26 +01:00
parent 56eb4a3a93
commit 78cacae128
3 changed files with 22 additions and 37 deletions

View File

@ -77,14 +77,11 @@ class Pages extends dbJSON {
// Content
// This variable is not belong to the database so is not defined in $row
$contentRaw = $args['content'];
$contentRaw = (empty($args['content'])?'':$args['content']);
// Parent
// This variable is not belong to the database so is not defined in $row
$parent = '';
if (!empty($args['parent'])) {
$parent = $args['parent'];
}
$parent = (empty($args['parent'])?'':$args['parent']);
// Slug from the title or the content
// This variable is not belong to the database so is not defined in $row
@ -149,7 +146,6 @@ class Pages extends dbJSON {
// Old key
// This variable is not belong to the database so is not defined in $row
$key = $args['key'];
$row = array();
// Check values on args or set default values
foreach ($this->dbFields as $field=>$value) {
@ -172,23 +168,19 @@ class Pages extends dbJSON {
// Content
// This variable is not belong to the database so is not defined in $row
$contentRaw = $args['content'];
$contentRaw = (empty($args['content'])?'':$args['content']);
// Parent
// This variable is not belong to the database so is not defined in $row
$parent = '';
if (!empty($args['parent'])) {
$parent = $args['parent'];
}
$parent = (empty($args['parent'])?'':$args['parent']);
// Slug from the title or the content
// Slug
// If the user change the slug the page key changes
// If the user send an empty slug the page key doesn't need to change
// This variable is not belong to the database so is not defined in $row
if (empty($args['slug'])) {
if (!empty($row['title'])) {
$slug = $this->generateSlug($row['title']);
} else {
$slug = $this->generateSlug($contentRaw);
}
$explode = explode('/', $key);
$slug = end($explode);
} else {
$slug = $args['slug'];
}
@ -670,13 +662,11 @@ class Pages extends dbJSON {
if ($newKey!==$oldKey) {
// Verify if the key is already been used
if (isset($this->db[$newKey])) {
if( !Text::endsWithNumeric($newKey) ) {
$newKey = $newKey.'-0';
}
while( isset($this->db[$newKey]) ) {
$newKey++;
$i = 0;
while (isset($this->db[$newKey.'-'.$i])) {
$i++;
}
$newKey = $newKey.'-'.$i;
}
}

View File

@ -416,12 +416,7 @@ class Page {
public function slug()
{
$explode = explode('/', $this->key());
// Remove the parent
if (!empty($explode[1])) {
return $explode[1];
}
return $explode[0];
return end($explode);
}
// Returns the parent key, if the page doesn't have a parent returns FALSE

View File

@ -69,7 +69,7 @@ class pluginAPI extends Plugin {
$inputs = $this->getMethodInputs();
if ( empty($inputs) ) {
$this->response(404, 'Not Found', array('message'=>'Missing method inputs.'));
$this->response(400, 'Bad Request', array('message'=>'Missing method inputs.'));
}
// ENDPOINT PARAMETERS
@ -77,7 +77,7 @@ class pluginAPI extends Plugin {
$parameters = $this->getEndpointParameters($URI);
if ( empty($parameters) ) {
$this->response(404, 'Not Found', array('message'=>'Missing endpoint parameters.'));
$this->response(400, 'Bad Request', array('message'=>'Missing endpoint parameters.'));
}
// API TOKEN
@ -87,7 +87,7 @@ class pluginAPI extends Plugin {
// Check empty token
if (empty($inputs['token'])) {
$this->response(404, 'Not Found', array('message'=>'Missing API token.'));
$this->response(400, 'Bad Request', array('message'=>'Missing API token.'));
}
// Check if the token is valid