Fixed regex for Cli mode

This commit is contained in:
Diego Najar 2017-08-21 19:45:57 +02:00
parent ad9c6ce6ef
commit 92fe6db09e
1 changed files with 21 additions and 14 deletions

View File

@ -8,7 +8,7 @@ class Page {
{ {
$this->vars = false; $this->vars = false;
if( $this->build($key) ) { if ($this->build($key)) {
$this->vars['key'] = $key; $this->vars['key'] = $key;
} }
} }
@ -19,7 +19,7 @@ class Page {
$filePath = PATH_PAGES.$key.DS.FILENAME; $filePath = PATH_PAGES.$key.DS.FILENAME;
// Check if the file exists // Check if the file exists
if( !Sanitize::pathFile($filePath) ) { if (!Sanitize::pathFile($filePath)) {
return false; return false;
} }
@ -29,28 +29,35 @@ class Page {
// Split the line in 2 parts, limiter by : // Split the line in 2 parts, limiter by :
$parts = explode(':', $line, 2); $parts = explode(':', $line, 2);
// Remove all characters except letters and dash - $field = $parts[0]; // title, date, slug
$parts[0] = preg_replace('/[^A-Za-z\-]/', '', $parts[0]); $value = isset($parts[1])?$parts[1]:false; // value of title, value of date
// Lowercase // Remove all characters except letters and dash - from field
$parts[0] = Text::lowercase($parts[0]); $field = preg_replace('/[^A-Za-z\-]/', '', $field);
// Field to lowercase
$field = Text::lowercase($field);
// Check if the current line start the content of the page // Check if the current line start the content of the page
// We have two breakers, the word content or 3 dash --- // We have two breakers, the word content or 3 dash ---
if( ($parts[0]==='content') || ($parts[0]==='---') ) { if( ($field==='content') || ($field==='---') ) {
$tmp = $lineNumber; $tmp = $lineNumber;
break; break;
} }
if( !empty($parts[0]) && !empty($parts[1]) ) { if( !empty($field) && !empty($value) ) {
// remove missing dashs - // Remove missing dashs -
$field = preg_replace('/[^A-Za-z]/', '', $parts[0]); $field = preg_replace('/[^A-Za-z]/', '', $field);
// remove empty spaces on borders // Remove <-- and -->
$value = trim($parts[1]); $value = preg_replace('/<\-\-/', '', $value);
$value = preg_replace('/\-\->/', '', $value);
// position accept only integers // Remove empty spaces on borders
if($field=='position') { $value = trim($value);
// Position accepts only integers
if ($field=='position') {
$value = preg_replace('/[^0-9]/', '', $value); $value = preg_replace('/[^0-9]/', '', $value);
} }