Bug fixes for API plugin
This commit is contained in:
parent
56eb4a3a93
commit
78cacae128
|
@ -77,14 +77,11 @@ class Pages extends dbJSON {
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
$contentRaw = $args['content'];
|
$contentRaw = (empty($args['content'])?'':$args['content']);
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
$parent = '';
|
$parent = (empty($args['parent'])?'':$args['parent']);
|
||||||
if (!empty($args['parent'])) {
|
|
||||||
$parent = $args['parent'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Slug from the title or the content
|
// Slug from the title or the content
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
|
@ -149,7 +146,6 @@ class Pages extends dbJSON {
|
||||||
// Old key
|
// Old key
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
$key = $args['key'];
|
$key = $args['key'];
|
||||||
|
|
||||||
$row = array();
|
$row = array();
|
||||||
// Check values on args or set default values
|
// Check values on args or set default values
|
||||||
foreach ($this->dbFields as $field=>$value) {
|
foreach ($this->dbFields as $field=>$value) {
|
||||||
|
@ -172,23 +168,19 @@ class Pages extends dbJSON {
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
$contentRaw = $args['content'];
|
$contentRaw = (empty($args['content'])?'':$args['content']);
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
// This variable is not belong to the database so is not defined in $row
|
// This variable is not belong to the database so is not defined in $row
|
||||||
$parent = '';
|
$parent = (empty($args['parent'])?'':$args['parent']);
|
||||||
if (!empty($args['parent'])) {
|
|
||||||
$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
|
// This variable is not belong to the database so is not defined in $row
|
||||||
if (empty($args['slug'])) {
|
if (empty($args['slug'])) {
|
||||||
if (!empty($row['title'])) {
|
$explode = explode('/', $key);
|
||||||
$slug = $this->generateSlug($row['title']);
|
$slug = end($explode);
|
||||||
} else {
|
|
||||||
$slug = $this->generateSlug($contentRaw);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$slug = $args['slug'];
|
$slug = $args['slug'];
|
||||||
}
|
}
|
||||||
|
@ -670,13 +662,11 @@ class Pages extends dbJSON {
|
||||||
if ($newKey!==$oldKey) {
|
if ($newKey!==$oldKey) {
|
||||||
// Verify if the key is already been used
|
// Verify if the key is already been used
|
||||||
if (isset($this->db[$newKey])) {
|
if (isset($this->db[$newKey])) {
|
||||||
if( !Text::endsWithNumeric($newKey) ) {
|
$i = 0;
|
||||||
$newKey = $newKey.'-0';
|
while (isset($this->db[$newKey.'-'.$i])) {
|
||||||
}
|
$i++;
|
||||||
|
|
||||||
while( isset($this->db[$newKey]) ) {
|
|
||||||
$newKey++;
|
|
||||||
}
|
}
|
||||||
|
$newKey = $newKey.'-'.$i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -416,12 +416,7 @@ class Page {
|
||||||
public function slug()
|
public function slug()
|
||||||
{
|
{
|
||||||
$explode = explode('/', $this->key());
|
$explode = explode('/', $this->key());
|
||||||
|
return end($explode);
|
||||||
// Remove the parent
|
|
||||||
if (!empty($explode[1])) {
|
|
||||||
return $explode[1];
|
|
||||||
}
|
|
||||||
return $explode[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the parent key, if the page doesn't have a parent returns FALSE
|
// Returns the parent key, if the page doesn't have a parent returns FALSE
|
||||||
|
|
|
@ -69,7 +69,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(400, 'Bad Request', array('message'=>'Missing method inputs.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ENDPOINT PARAMETERS
|
// ENDPOINT PARAMETERS
|
||||||
|
@ -77,7 +77,7 @@ 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(400, 'Bad Request', array('message'=>'Missing endpoint parameters.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// API TOKEN
|
// API TOKEN
|
||||||
|
@ -87,7 +87,7 @@ class pluginAPI extends Plugin {
|
||||||
|
|
||||||
// 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(400, 'Bad Request', array('message'=>'Missing API token.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the token is valid
|
// Check if the token is valid
|
||||||
|
|
Loading…
Reference in New Issue