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'; }
echo '<tr>';
echo '<td>'.$key.'</td>';
if (is_array($value)) {
echo '<td>'.json_encode($value).'</td>';
} else {
echo '<td>'.Sanitize::html($value).'</td>';
}
echo '</tr>';
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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