Improve the router, added /blog/, minor changes on languages

This commit is contained in:
Diego Najar 2017-09-15 20:02:53 +02:00
parent 39b62882ad
commit 1389b74493
8 changed files with 48 additions and 77 deletions

View File

@ -97,6 +97,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>DOMAIN_CATEGORIES 'tip'=>DOMAIN_CATEGORIES
)); ));
HTML::formInputText(array(
'name'=>'uriBlog',
'label'=>$L->g('Blog'),
'value'=>$Site->uriFilters('blog'),
'class'=>'uk-width-1-2 uk-form-medium',
'tip'=>DOMAIN_BLOG
));
echo '<div class="uk-form-row"> echo '<div class="uk-form-row">
<div class="uk-form-controls"> <div class="uk-form-controls">
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button> <button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>

View File

@ -3,8 +3,8 @@
// Bludit version // Bludit version
define('BLUDIT_VERSION', '2.0'); define('BLUDIT_VERSION', '2.0');
define('BLUDIT_CODENAME', ''); define('BLUDIT_CODENAME', '');
define('BLUDIT_RELEASE_DATE', '2017-10-10'); define('BLUDIT_RELEASE_DATE', '2017-09-11');
define('BLUDIT_BUILD', '20171010'); define('BLUDIT_BUILD', '20170911');
// Debug mode // Debug mode
// Change to FALSE, for prevent warning or errors on browser // Change to FALSE, for prevent warning or errors on browser
@ -280,6 +280,9 @@ define('CATEGORY_URI_FILTER', $Url->filters('category'));
// Page URI filter // Page URI filter
define('PAGE_URI_FILTER', $Url->filters('page')); define('PAGE_URI_FILTER', $Url->filters('page'));
// Blog URI filter
define('BLOG_URI_FILTER', $Url->filters('blog'));
// Content order by: date / position // Content order by: date / position
define('ORDER_BY', $Site->orderBy()); define('ORDER_BY', $Site->orderBy());
@ -309,6 +312,7 @@ define('DOMAIN_UPLOADS_THUMBNAILS', DOMAIN.HTML_PATH_UPLOADS_THUMBNAILS);
define('DOMAIN_TAGS', Text::addSlashes(DOMAIN_BASE.TAG_URI_FILTER, false, true)); define('DOMAIN_TAGS', Text::addSlashes(DOMAIN_BASE.TAG_URI_FILTER, false, true));
define('DOMAIN_CATEGORIES', Text::addSlashes(DOMAIN_BASE.CATEGORY_URI_FILTER, false, true)); define('DOMAIN_CATEGORIES', Text::addSlashes(DOMAIN_BASE.CATEGORY_URI_FILTER, false, true));
define('DOMAIN_PAGES', Text::addSlashes(DOMAIN_BASE.PAGE_URI_FILTER, false, true)); define('DOMAIN_PAGES', Text::addSlashes(DOMAIN_BASE.PAGE_URI_FILTER, false, true));
define('DOMAIN_BLOG', Text::addSlashes(DOMAIN_BASE.BLOG_URI_FILTER, false, true));
$ADMIN_CONTROLLER = ''; $ADMIN_CONTROLLER = '';
$ADMIN_VIEW = ''; $ADMIN_VIEW = '';

View File

@ -99,6 +99,10 @@ if ($Site->homepage() && $Url->whereAmI()==='home') {
} }
} }
if ($Url->whereAmI()==='blog') {
$Url->setWhereAmI('home');
}
// Build specific page // Build specific page
if ($Url->whereAmI()==='page') { if ($Url->whereAmI()==='page') {
buildThePage(); buildThePage();

View File

@ -18,6 +18,7 @@ class dbSite extends dbJSON
'uriPage'=> array('inFile'=>false, 'value'=>'/'), 'uriPage'=> array('inFile'=>false, 'value'=>'/'),
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'), 'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'), 'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'),
'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'),
'url'=> array('inFile'=>false, 'value'=>''), 'url'=> array('inFile'=>false, 'value'=>''),
'emailFrom'=> array('inFile'=>false, 'value'=>''), 'emailFrom'=> array('inFile'=>false, 'value'=>''),
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'), 'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
@ -67,6 +68,7 @@ class dbSite extends dbJSON
$filters['page'] = $this->getField('uriPage'); $filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag'); $filters['tag'] = $this->getField('uriTag');
$filters['category'] = $this->getField('uriCategory'); $filters['category'] = $this->getField('uriCategory');
$filters['blog'] = $this->getField('uriBlog');
if(empty($filter)) { if(empty($filter)) {
return $filters; return $filters;
@ -91,7 +93,12 @@ class dbSite extends dbJSON
{ {
$filter = $this->getField('uriCategory'); $filter = $this->getField('uriCategory');
return $this->url().ltrim($filter, '/'); return $this->url().ltrim($filter, '/');
}
public function urlBlog()
{
$filter = $this->getField('uriBlog');
return $this->url().ltrim($filter, '/');
} }
// Returns the URL of the rss.xml file // Returns the URL of the rss.xml file

View File

@ -561,6 +561,10 @@ function editSettings($args) {
$args['uriCategory'] = Text::addSlashes($args['uriCategory']); $args['uriCategory'] = Text::addSlashes($args['uriCategory']);
} }
if (isset($args['uriBlog'])) {
$args['uriBlog'] = Text::addSlashes($args['uriBlog']);
}
if ($Site->set($args)) { if ($Site->set($args)) {
// Check current order-by if changed it reorder the content // Check current order-by if changed it reorder the content
if ($Site->orderBy()!=ORDER_BY) { if ($Site->orderBy()!=ORDER_BY) {

View File

@ -37,47 +37,34 @@ class Url
// Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....) // Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....)
public function checkFilters($filters) public function checkFilters($filters)
{ {
// Store the admin filter and remove // Put the "admin" filter first
$adminFilter['admin'] = $filters['admin']; $adminFilter['admin'] = $filters['admin'];
unset($filters['admin']); unset($filters['admin']);
// Sort filters by length
uasort($filters, array($this, 'sortByLength')); uasort($filters, array($this, 'sortByLength'));
$this->filters = $adminFilter + $filters;
// Push the admin filter first foreach ($this->filters as $filterName=>$filterURI) {
$filters = $adminFilter + $filters; // $filterName = 'category'
$this->filters = $filters; // $filterURI = '/category/'
foreach($filters as $filterName=>$filterURI) { $filterFull = ltrim($filterURI, '/');
$filterFull = HTML_PATH_ROOT.$filterFull;
$filterLenght = mb_strlen($filterFull, CHARSET);
// $slug will be FALSE if the filter is not included in the URI if (mb_substr($this->uri, 0, $filterLenght, CHARSET)==$filterURI) {
$slug = $this->getSlugAfterFilter($filterURI); $this->slug = mb_substr($this->uri, $filterLenght+1);
if($slug!==false) {
$this->slug = $slug;
$this->whereAmI = $filterName; $this->whereAmI = $filterName;
$this->activeFilter = $filterURI; $this->activeFilter = $filterURI;
// If the slug is empty if (empty($this->slug) && (($filterName=='blog') || ($filterURI=='/')) ) {
if( Text::isEmpty($slug) ) { $this->whereAmI = 'home';
if($filterURI==='/') {
$this->whereAmI = 'home';
break;
}
if($filterURI===$adminFilter['admin']) {
$this->whereAmI = 'admin';
$this->slug = 'dashboard';
break;
}
$this->setNotFound();
} }
break; return true;
} }
} }
$this->setNotFound();
} }
public function slug() public function slug()
@ -170,52 +157,6 @@ class Url
$this->httpMessage = $msg; $this->httpMessage = $msg;
} }
// Returns the slug after the $filter, the slug could be an empty string
// If the filter is not included in the uri, returns FALSE
// ex: http://domain.com/cms/$filter/slug123 => slug123
// ex: http://domain.com/cms/$filter/name/lastname => name/lastname
// ex: http://domain.com/cms/$filter/ => empty string
// ex: http://domain.com/cms/$filter => empty string
private function getSlugAfterFilter($filter)
{
// Remove both slash from the filter
$filter = trim($filter, '/');
// Add to the filter the root directory
$filter = HTML_PATH_ROOT.$filter;
// Check if the filter is in the uri.
$position = Text::stringPosition($this->uri, $filter);
// If the position is FALSE, the filter isn't in the URI.
if($position===false) {
return false;
}
// Start position to cut
$start = $position + Text::length($filter);
// End position to cut
$end = $this->uriStrlen;
// Get the slug from the URI
$slug = Text::cut($this->uri, $start, $end);
if(Text::isEmpty($slug)) {
return '';
}
if($slug[0]=='/') {
return ltrim($slug, '/');
}
if($filter==HTML_PATH_ROOT) {
return $slug;
}
return false;
}
private function sortByLength($a, $b) private function sortByLength($a, $b)
{ {
return strlen($b)-strlen($a); return strlen($b)-strlen($a);

View File

@ -201,5 +201,7 @@
"ip-address-has-been-blocked": "IP address has been blocked", "ip-address-has-been-blocked": "IP address has been blocked",
"try-again-in-a-few-minutes": "Try again in a few minutes", "try-again-in-a-few-minutes": "Try again in a few minutes",
"page-published-from-scheduler": "Page published from scheduler", "page-published-from-scheduler": "Page published from scheduler",
"installer-page-about-content": "The about page is an important and powerful for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information." "installer-page-about-content": "The about page is an important and powerful for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information.",
"blog": "Blog",
"complete-all-fields": "Complete all fields"
} }

View File

@ -356,6 +356,7 @@ function install($adminPassword, $email, $timezone)
'uriPage'=>'/', 'uriPage'=>'/',
'uriTag'=>'/tag/', 'uriTag'=>'/tag/',
'uriCategory'=>'/category/', 'uriCategory'=>'/category/',
'uriBlog'=>'/blog/',
'url'=>$siteUrl, 'url'=>$siteUrl,
'emailFrom'=>'no-reply@'.DOMAIN, 'emailFrom'=>'no-reply@'.DOMAIN,
'orderBy'=>'date' 'orderBy'=>'date'