From 1389b74493d0852454d9b1f0f4be7a13035c85e8 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Fri, 15 Sep 2017 20:02:53 +0200 Subject: [PATCH] Improve the router, added /blog/, minor changes on languages --- bl-kernel/admin/views/settings-advanced.php | 8 ++ bl-kernel/boot/init.php | 8 +- bl-kernel/boot/rules/69.pages.php | 4 + bl-kernel/dbsite.class.php | 7 ++ bl-kernel/functions.php | 4 + bl-kernel/url.class.php | 89 ++++----------------- bl-languages/en.json | 4 +- install.php | 1 + 8 files changed, 48 insertions(+), 77 deletions(-) diff --git a/bl-kernel/admin/views/settings-advanced.php b/bl-kernel/admin/views/settings-advanced.php index 6d728111..110f7ce6 100644 --- a/bl-kernel/admin/views/settings-advanced.php +++ b/bl-kernel/admin/views/settings-advanced.php @@ -97,6 +97,14 @@ HTML::formOpen(array('class'=>'uk-form-horizontal')); '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 '
diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 55102701..a90fde60 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -3,8 +3,8 @@ // Bludit version define('BLUDIT_VERSION', '2.0'); define('BLUDIT_CODENAME', ''); -define('BLUDIT_RELEASE_DATE', '2017-10-10'); -define('BLUDIT_BUILD', '20171010'); +define('BLUDIT_RELEASE_DATE', '2017-09-11'); +define('BLUDIT_BUILD', '20170911'); // Debug mode // Change to FALSE, for prevent warning or errors on browser @@ -280,6 +280,9 @@ define('CATEGORY_URI_FILTER', $Url->filters('category')); // Page URI filter define('PAGE_URI_FILTER', $Url->filters('page')); +// Blog URI filter +define('BLOG_URI_FILTER', $Url->filters('blog')); + // Content order by: date / position 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_CATEGORIES', Text::addSlashes(DOMAIN_BASE.CATEGORY_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_VIEW = ''; diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index 685cdabc..5542c122 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -99,6 +99,10 @@ if ($Site->homepage() && $Url->whereAmI()==='home') { } } +if ($Url->whereAmI()==='blog') { + $Url->setWhereAmI('home'); +} + // Build specific page if ($Url->whereAmI()==='page') { buildThePage(); diff --git a/bl-kernel/dbsite.class.php b/bl-kernel/dbsite.class.php index 51be3195..f6078e24 100644 --- a/bl-kernel/dbsite.class.php +++ b/bl-kernel/dbsite.class.php @@ -18,6 +18,7 @@ class dbSite extends dbJSON 'uriPage'=> array('inFile'=>false, 'value'=>'/'), 'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'), 'uriCategory'=> array('inFile'=>false, 'value'=>'/category/'), + 'uriBlog'=> array('inFile'=>false, 'value'=>'/blog/'), 'url'=> array('inFile'=>false, 'value'=>''), 'emailFrom'=> array('inFile'=>false, 'value'=>''), 'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'), @@ -67,6 +68,7 @@ class dbSite extends dbJSON $filters['page'] = $this->getField('uriPage'); $filters['tag'] = $this->getField('uriTag'); $filters['category'] = $this->getField('uriCategory'); + $filters['blog'] = $this->getField('uriBlog'); if(empty($filter)) { return $filters; @@ -91,7 +93,12 @@ class dbSite extends dbJSON { $filter = $this->getField('uriCategory'); 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 diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 14bc8a46..09c47c6c 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -561,6 +561,10 @@ function editSettings($args) { $args['uriCategory'] = Text::addSlashes($args['uriCategory']); } + if (isset($args['uriBlog'])) { + $args['uriBlog'] = Text::addSlashes($args['uriBlog']); + } + if ($Site->set($args)) { // Check current order-by if changed it reorder the content if ($Site->orderBy()!=ORDER_BY) { diff --git a/bl-kernel/url.class.php b/bl-kernel/url.class.php index a977d123..1c6341b6 100644 --- a/bl-kernel/url.class.php +++ b/bl-kernel/url.class.php @@ -37,47 +37,34 @@ class Url // Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....) public function checkFilters($filters) { - // Store the admin filter and remove + // Put the "admin" filter first $adminFilter['admin'] = $filters['admin']; unset($filters['admin']); - - // Sort filters by length uasort($filters, array($this, 'sortByLength')); + $this->filters = $adminFilter + $filters; - // Push the admin filter first - $filters = $adminFilter + $filters; - $this->filters = $filters; + foreach ($this->filters as $filterName=>$filterURI) { + // $filterName = 'category' + // $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 - $slug = $this->getSlugAfterFilter($filterURI); - - if($slug!==false) { - $this->slug = $slug; + if (mb_substr($this->uri, 0, $filterLenght, CHARSET)==$filterURI) { + $this->slug = mb_substr($this->uri, $filterLenght+1); $this->whereAmI = $filterName; $this->activeFilter = $filterURI; - // If the slug is empty - if( Text::isEmpty($slug) ) { - - if($filterURI==='/') { - $this->whereAmI = 'home'; - break; - } - - if($filterURI===$adminFilter['admin']) { - $this->whereAmI = 'admin'; - $this->slug = 'dashboard'; - break; - } - - $this->setNotFound(); + if (empty($this->slug) && (($filterName=='blog') || ($filterURI=='/')) ) { + $this->whereAmI = 'home'; } - break; + return true; } } + + $this->setNotFound(); } public function slug() @@ -170,52 +157,6 @@ class Url $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) { return strlen($b)-strlen($a); diff --git a/bl-languages/en.json b/bl-languages/en.json index cfb571c0..91afbae4 100644 --- a/bl-languages/en.json +++ b/bl-languages/en.json @@ -201,5 +201,7 @@ "ip-address-has-been-blocked": "IP address has been blocked", "try-again-in-a-few-minutes": "Try again in a few minutes", "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" } \ No newline at end of file diff --git a/install.php b/install.php index 5dfc636e..f99cd884 100644 --- a/install.php +++ b/install.php @@ -356,6 +356,7 @@ function install($adminPassword, $email, $timezone) 'uriPage'=>'/', 'uriTag'=>'/tag/', 'uriCategory'=>'/category/', + 'uriBlog'=>'/blog/', 'url'=>$siteUrl, 'emailFrom'=>'no-reply@'.DOMAIN, 'orderBy'=>'date'