Fixed regex for Cli mode
This commit is contained in:
parent
ad9c6ce6ef
commit
92fe6db09e
|
@ -29,27 +29,34 @@ 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
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
|
// Position accepts only integers
|
||||||
if ($field=='position') {
|
if ($field=='position') {
|
||||||
$value = preg_replace('/[^0-9]/', '', $value);
|
$value = preg_replace('/[^0-9]/', '', $value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue