API improves, fixed url router

This commit is contained in:
Diego Najar 2017-09-22 23:11:08 +02:00
parent c167e00c19
commit 1bd75ac2ee
7 changed files with 97 additions and 65 deletions

View File

@ -32,7 +32,11 @@ function printTable($title, $array) {
elseif($value===true) { $value = 'true'; } elseif($value===true) { $value = 'true'; }
echo '<tr>'; echo '<tr>';
echo '<td>'.$key.'</td>'; echo '<td>'.$key.'</td>';
if (is_array($value)) {
echo '<td>'.json_encode($value).'</td>';
} else {
echo '<td>'.Sanitize::html($value).'</td>'; echo '<td>'.Sanitize::html($value).'</td>';
}
echo '</tr>'; echo '</tr>';
} }

View File

@ -4,6 +4,9 @@ HTML::title(array('title'=>$L->g('Developers'), 'icon'=>'support'));
echo '<h2>PHP version: '.phpversion().'</h2>'; echo '<h2>PHP version: '.phpversion().'</h2>';
// Loaded extensions
printTable('Server information', $_SERVER);
// Constanst defined by Bludit // Constanst defined by Bludit
$constants = get_defined_constants(true); $constants = get_defined_constants(true);
printTable('Constants', $constants['user']); printTable('Constants', $constants['user']);

View File

@ -6,7 +6,7 @@ Paginator::set('currentPage', $currentPage);
if($Url->whereAmI()=='admin') { if($Url->whereAmI()=='admin') {
$itemsPerPage = ITEMS_PER_PAGE_ADMIN; $itemsPerPage = ITEMS_PER_PAGE_ADMIN;
$amountOfItems = $dbPages->count(false); $amountOfItems = $dbPages->count(true);
} }
elseif($Url->whereAmI()=='tag') { elseif($Url->whereAmI()=='tag') {
$itemsPerPage = $Site->itemsPerPage(); $itemsPerPage = $Site->itemsPerPage();

View File

@ -18,7 +18,9 @@ class dbPages extends dbJSON
'category'=> array('inFile'=>false, 'value'=>''), 'category'=> array('inFile'=>false, 'value'=>''),
'md5file'=> array('inFile'=>false, 'value'=>''), 'md5file'=> array('inFile'=>false, 'value'=>''),
'uuid'=> array('inFile'=>false, 'value'=>''), 'uuid'=> array('inFile'=>false, 'value'=>''),
'allowComments'=> array('inFile'=>false, 'value'=>true) 'allowComments'=> array('inFile'=>false, 'value'=>true),
'parent'=> array('inFile'=>false, 'value'=>''),
'slug'=> array('inFile'=>false, 'value'=>'')
); );
function __construct() function __construct()
@ -32,8 +34,28 @@ class dbPages extends dbJSON
$dataForDb = array(); // This data will be saved in the database $dataForDb = array(); // This data will be saved in the database
$dataForFile = array(); // This data will be saved in the file $dataForFile = array(); // This data will be saved in the file
foreach ($this->dbFields as $field=>$options) {
if (isset($args[$field])) {
if ($field=='tags') {
$value = $this->generateTags($args['tags']);
} else {
if( !$options['inFile'] ) {
// Sanitize if will be stored on database
$value = Sanitize::html($args[$field]);
} else {
$value = $args[$field];
}
}
} else {
// Default value for the field
$value = $options['value'];
}
$args[$field] = $value;
}
// Generate slug from content if the title is empty // Generate slug from content if the title is empty
if (empty($args['title'])) { if (empty($args['title']) || empty($args['slug'])) {
$tmpslug = Text::removeHTMLTags($args['content']); $tmpslug = Text::removeHTMLTags($args['content']);
$args['slug'] = Text::truncate($tmpslug, 60, ''); $args['slug'] = Text::truncate($tmpslug, 60, '');
} }
@ -58,27 +80,10 @@ class dbPages extends dbJSON
} }
foreach ($this->dbFields as $field=>$options) { foreach ($this->dbFields as $field=>$options) {
if( isset($args[$field]) ) {
if($field=='tags') {
$value = $this->generateTags($args['tags']);
}
else {
if( !$options['inFile'] ) {
// Sanitize if will be stored on database
$value = Sanitize::html($args[$field]);
}
else {
$value = $args[$field]; $value = $args[$field];
}
}
}
else {
// Default value for the field
$value = $options['value'];
}
// Where the data is stored
if ($options['inFile']) { if ($options['inFile']) {
// Save on file
$dataForFile[$field] = $this->stylingFieldsForFile($field, $value); $dataForFile[$field] = $this->stylingFieldsForFile($field, $value);
} else { } else {
// Set type // Set type
@ -124,6 +129,26 @@ class dbPages extends dbJSON
$dataForDb = array(); $dataForDb = array();
$dataForFile = array(); $dataForFile = array();
foreach ($this->dbFields as $field=>$options) {
if (isset($args[$field])) {
if ($field=='tags') {
$value = $this->generateTags($args['tags']);
} else {
if( !$options['inFile'] ) {
// Sanitize if will be stored on database
$value = Sanitize::html($args[$field]);
} else {
$value = $args[$field];
}
}
} else {
// Default value for the field
$value = $options['value'];
}
$args[$field] = $value;
}
$newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']); $newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']);
// If the page is draft then the created time is the current // If the page is draft then the created time is the current
@ -136,30 +161,27 @@ class dbPages extends dbJSON
// Current UUID // Current UUID
$args['uuid'] = $this->db[$args['key']]['uuid']; $args['uuid'] = $this->db[$args['key']]['uuid'];
// Date
$currentDate = Date::current(DB_DATE_FORMAT);
// Modified date // Modified date
$args['dateModified'] = Date::current(DB_DATE_FORMAT); $args['dateModified'] = Date::current(DB_DATE_FORMAT);
foreach($this->dbFields as $field=>$options) { // Validate date
if( isset($args[$field]) ) { if ( !Valid::date($args['date'], DB_DATE_FORMAT) ) {
if($field=='tags') { $args['date'] = $currentDate;
$value = $this->generateTags($args['tags']);
}
else {
if( !$options['inFile'] ) {
// Sanitize if will be stored on database
$value = Sanitize::html($args[$field]);
}
else {
// Default value for the field
$value = $args[$field];
}
}
}
else {
$value = $options['value'];
} }
// Schedule page
if ( ($args['date']>$currentDate) && ($args['status']=='published') ) {
$args['status'] = 'scheduled';
}
foreach ($this->dbFields as $field=>$options) {
$value = $args[$field];
if ($options['inFile']) { if ($options['inFile']) {
// Save on file
$dataForFile[$field] = $this->stylingFieldsForFile($field, $value); $dataForFile[$field] = $this->stylingFieldsForFile($field, $value);
} else { } else {
// Set type // Set type

View File

@ -304,12 +304,13 @@ function createPage($args) {
// The user is always the one loggued // The user is always the one loggued
$args['username'] = Session::get('username'); $args['username'] = Session::get('username');
if ( Text::isEmpty($args['username']) ) { if ( empty($args['username']) ) {
Log::set('Function createPage()'.LOG_SEP.'Empty username.');
return false; return false;
} }
// External Cover Image // External Cover Image
if ( Text::isNotEmpty(($args['externalCoverImage'])) ) { if ( !empty($args['externalCoverImage']) ) {
$args['coverImage'] = $args['externalCoverImage']; $args['coverImage'] = $args['externalCoverImage'];
unset($args['externalCoverImage']); unset($args['externalCoverImage']);
} }
@ -350,21 +351,17 @@ function editPage($args) {
// The user is always the one loggued // The user is always the one loggued
$args['username'] = Session::get('username'); $args['username'] = Session::get('username');
if ( Text::isEmpty($args['username']) ) { if ( empty($args['username']) ) {
Log::set('Function editPage()'.LOG_SEP.'Empty username.'); Log::set('Function editPage()'.LOG_SEP.'Empty username.');
return false; return false;
} }
// External Cover Image // External Cover Image
if ( Text::isNotEmpty(($args['externalCoverImage'])) ) { if ( !empty($args['externalCoverImage']) ) {
$args['coverImage'] = $args['externalCoverImage']; $args['coverImage'] = $args['externalCoverImage'];
unset($args['externalCoverImage']); unset($args['externalCoverImage']);
} }
if (!isset($args['parent'])) {
$args['parent'] = '';
}
$key = $dbPages->edit($args); $key = $dbPages->edit($args);
if ($key) { if ($key) {
// Call the plugins after page modified // Call the plugins after page modified

View File

@ -67,7 +67,7 @@ class Url
} }
// Check coincidence with complete filterURI // Check coincidence with complete filterURI
if ($subString==$filterURI) { if ($subString==$filterFull) {
$this->slug = mb_substr($this->uri, $filterFullLenght); $this->slug = mb_substr($this->uri, $filterFullLenght);
$this->setWhereAmI($filterName); $this->setWhereAmI($filterName);
$this->activeFilter = $filterURI; $this->activeFilter = $filterURI;

View File

@ -168,6 +168,11 @@ class pluginAPI extends Plugin {
break; break;
} }
// Try to get raw data
if (empty($inputs)) {
$inputs = file_get_contents('php://input');
}
return $this->cleanInputs($inputs); return $this->cleanInputs($inputs);
} }
@ -199,10 +204,11 @@ class pluginAPI extends Plugin {
} }
} elseif(is_string($inputs)) { } elseif(is_string($inputs)) {
$tmp = json_decode($inputs, true); $tmp = json_decode($inputs, true);
if(json_last_error()===0) { if (json_last_error()!==JSON_ERROR_NONE) {
$tmp = array(); $tmp = array();
} }
} }
return $tmp; return $tmp;
} }
@ -264,7 +270,7 @@ class pluginAPI extends Plugin {
{ {
// This function is defined on functions.php // This function is defined on functions.php
$key = createPage($args); $key = createPage($args);
var_dump($key);exit;
if ($key===false) { if ($key===false) {
return array( return array(
'status'=>'1', 'status'=>'1',