Improves on the url system

This commit is contained in:
dignajar 2015-11-29 21:45:30 -03:00
parent aaac775983
commit ff54ff230b
14 changed files with 137 additions and 100 deletions

View File

@ -26,9 +26,13 @@
background: #1F5FC4; background: #1F5FC4;
} }
.uk-form legend { legend {
width: 70% !important; width: 70% !important;
margin-top: 40px; margin-top: 40px !important;
}
legend.first-child {
margin-top: 0px !important;
} }
.uk-navbar-nav > li > a { .uk-navbar-nav > li > a {

View File

@ -117,7 +117,9 @@ class HTML {
public static function legend($args) public static function legend($args)
{ {
$html = '<legend>'.$args['value'].'</legend>'; $class = empty($args['class']) ? '' : 'class="'.$args['class'].'"';
$html = '<legend '.$class.'>'.$args['value'].'</legend>';
echo $html; echo $html;
} }

View File

@ -19,7 +19,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal
'value'=>$_user['username'] 'value'=>$_user['username']
)); ));
HTML::legend(array('value'=>$L->g('Profile'))); HTML::legend(array('value'=>$L->g('Profile'), 'class'=>'first-child'));
HTML::formInputText(array( HTML::formInputText(array(
'name'=>'usernameDisable', 'name'=>'usernameDisable',

View File

@ -29,10 +29,10 @@ echo '
echo '<a class="configure" href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'">'.$L->g('Configure').'</a>'; echo '<a class="configure" href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'">'.$L->g('Configure').'</a>';
echo '<span class="separator"> | </span>'; echo '<span class="separator"> | </span>';
} }
echo '<a class="uninstall" href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'">'.$L->g('Uninstall').'</a>'; echo '<a class="uninstall" href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'">'.$L->g('Deactivate').'</a>';
} }
else { else {
echo '<a class="install" href="'.HTML_PATH_ADMIN_ROOT.'install-plugin/'.$Plugin->className().'">'.$L->g('Install').'</a>'; echo '<a class="install" href="'.HTML_PATH_ADMIN_ROOT.'install-plugin/'.$Plugin->className().'">'.$L->g('Activate').'</a>';
} }
echo ' echo '

View File

@ -9,7 +9,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'value'=>$Security->getTokenCSRF() 'value'=>$Security->getTokenCSRF()
)); ));
HTML::legend(array('value'=>$L->g('General'))); HTML::legend(array('value'=>$L->g('General'), 'class'=>'first-child'));
HTML::formSelect(array( HTML::formSelect(array(
'name'=>'postsperpage', 'name'=>'postsperpage',

View File

@ -10,7 +10,7 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'value'=>$Security->getTokenCSRF() 'value'=>$Security->getTokenCSRF()
)); ));
HTML::legend(array('value'=>$L->g('Site'))); HTML::legend(array('value'=>$L->g('Site information'), 'class'=>'first-child'));
HTML::formInputText(array( HTML::formInputText(array(
'name'=>'title', 'name'=>'title',

View File

@ -9,6 +9,8 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'value'=>$Security->getTokenCSRF() 'value'=>$Security->getTokenCSRF()
)); ));
HTML::legend(array('value'=>$L->g('General'), 'class'=>'first-child'));
HTML::formSelect(array( HTML::formSelect(array(
'name'=>'language', 'name'=>'language',
'label'=>$L->g('Language'), 'label'=>$L->g('Language'),
@ -35,6 +37,8 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>$L->g('you-can-use-this-field-to-define-a-set-off') 'tip'=>$L->g('you-can-use-this-field-to-define-a-set-off')
)); ));
HTML::legend(array('value'=>$L->g('Date and time formats')));
HTML::formInputText(array( HTML::formInputText(array(
'name'=>'dateFormat', 'name'=>'dateFormat',
'label'=>$L->g('Date format'), 'label'=>$L->g('Date format'),

View File

@ -25,7 +25,7 @@ echo '
'; ';
if($theme['dirname']!=$Site->theme()) { if($theme['dirname']!=$Site->theme()) {
echo '<a class="install" href="'.HTML_PATH_ADMIN_ROOT.'install-theme/'.$theme['dirname'].'">'.$L->g('Install').'</a>'; echo '<a class="install" href="'.HTML_PATH_ADMIN_ROOT.'install-theme/'.$theme['dirname'].'">'.$L->g('Activate').'</a>';
} }
echo ' echo '

View File

@ -194,11 +194,10 @@ define('PATH_THEME_JS', PATH_THEME.'js'.DS);
define('PATH_THEME_IMG', PATH_THEME.'img'.DS); define('PATH_THEME_IMG', PATH_THEME.'img'.DS);
define('PATH_THEME_LANG', PATH_THEME.'languages'.DS); define('PATH_THEME_LANG', PATH_THEME.'languages'.DS);
// Objects with dependency // --- Objects with dependency ---
$Language = new dbLanguage( $Site->locale() ); $Language = new dbLanguage( $Site->locale() );
$Login = new Login( $dbUsers ); $Login = new Login( $dbUsers );
$Url->checkFilters( $Site->uriFilters() ); $Url->checkFilters( $Site->uriFilters() );
// Objects shortcuts // --- Objects shortcuts ---
$L = $Language; $L = $Language;

View File

@ -152,6 +152,22 @@ class dbSite extends dbJSON
public function domain() public function domain()
{ {
// If the URL field is not set, try detect the domain.
if(Text::isEmpty( $this->url() ))
{
if(!empty($_SERVER['HTTPS'])) {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$domain = $_SERVER['HTTP_HOST'];
return $protocol.$domain.HTML_PATH_ROOT;
}
// Parse the domain from the field URL.
$parse = parse_url($this->url()); $parse = parse_url($this->url());
$domain = $parse['scheme']."://".$parse['host']; $domain = $parse['scheme']."://".$parse['host'];

View File

@ -165,11 +165,13 @@ class Text {
return ucfirst($string); return ucfirst($string);
} }
// Find position of first occurrence of substring in a string. // Find position of first occurrence of substring in a string otherwise returns FALSE.
public static function strpos($string, $substring) public static function stringPosition($string, $substring)
{ {
if(MB_STRING) if(MB_STRING) {
return mb_strpos($string, $substring, 0, 'UTF-8'); return mb_strpos($string, $substring, 0, 'UTF-8');
}
return strpos($string, $substring); return strpos($string, $substring);
} }

View File

@ -32,7 +32,7 @@ class Url
$this->filters = array(); $this->filters = array();
} }
// Filters may be changed for different languages // Filters change for different languages
// Ex (Spanish): Array('post'=>'/publicacion/', 'tag'=>'/etiqueta/', ....) // Ex (Spanish): Array('post'=>'/publicacion/', 'tag'=>'/etiqueta/', ....)
// Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....) // Ex (English): Array('post'=>'/post/', 'tag'=>'/tag/', ....)
public function checkFilters($filters) public function checkFilters($filters)
@ -41,35 +41,33 @@ class Url
$adminFilter['admin'] = $filters['admin']; $adminFilter['admin'] = $filters['admin'];
unset($filters['admin']); unset($filters['admin']);
// Sort by filter length // Sort filters by length
uasort($filters, array($this, 'sortByLength')); uasort($filters, array($this, 'sortByLength'));
// Push the admin filter first // Push the admin filter first
$filters = $adminFilter + $filters; $filters = $adminFilter + $filters;
$this->filters = $filters; $this->filters = $filters;
foreach($filters as $filterKey=>$filter) foreach($filters as $filterName=>$filterURI)
{ {
// getSlugAfterFilter() set the variable $this->slug // $slug will be FALSE if the filter is not included in the URI.
$slug = $this->getSlugAfterFilter($filter); $slug = $this->getSlugAfterFilter($filterURI);
// If the filter is included in the URI.
if($slug!==false) if($slug!==false)
{ {
// Where Am I is the filter now, because is in the URI. $this->slug = $slug;
$this->whereAmI = $filterKey; $this->whereAmI = $filterName;
// If the slug empty // If the slug is empty
if(empty($slug)) if(Text::isEmpty($slug))
{ {
if($filter==='/') if($filterURI==='/')
{ {
$this->whereAmI = 'home'; $this->whereAmI = 'home';
break; break;
} }
if($filter===$adminFilter['admin']) if($filterURI===$adminFilter['admin'])
{ {
$this->whereAmI = 'admin'; $this->whereAmI = 'admin';
$this->slug = 'dashboard'; $this->slug = 'dashboard';
@ -140,45 +138,52 @@ class Url
$this->notFound = $error; $this->notFound = $error;
} }
public function getDomain() // Returns the slug after the $filter, the slug could be an empty string
{
if(!empty($_SERVER['HTTPS'])) {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$domain = $_SERVER['HTTP_HOST'];
return $protocol.$domain.HTML_PATH_ROOT;
}
// Return the slug after the $filter
// If the filter is not included in the uri, returns FALSE // If the filter is not included in the uri, returns FALSE
// If the filter is included in the uri and the slug is not empty, returns the slug
// ex: http://domain.com/cms/$filter/slug123 => slug123 // 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) private function getSlugAfterFilter($filter)
{ {
if($filter=='/') { // Remove both slash from the filter
$filter = HTML_PATH_ROOT; $filter = trim($filter, '/');
}
// Add to the filter the root directory
$filter = HTML_PATH_ROOT.$filter;
// Check if the filter is in the uri. // Check if the filter is in the uri.
$position = Text::strpos($this->uri, $filter); $position = Text::stringPosition($this->uri, $filter);
// If the position is FALSE, the filter isn't in the URI.
if($position===false) { if($position===false) {
return false; return false;
} }
// Start position to cut
$start = $position + Text::length($filter); $start = $position + Text::length($filter);
// End position to cut
$end = $this->uriStrlen; $end = $this->uriStrlen;
// Get the slug from the URI
$slug = Text::cut($this->uri, $start, $end); $slug = Text::cut($this->uri, $start, $end);
$this->slug = trim($slug, '/');
if(Text::isEmpty($slug)) {
return '';
}
if($slug[0]=='/') {
return ltrim($slug, '/');
}
if($filter==HTML_PATH_ROOT) {
return $slug; 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

@ -213,5 +213,10 @@
"the-about-page-is-very-important": "The about page is an important and powerful tool for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information.", "the-about-page-is-very-important": "The about page is an important and powerful tool for potential clients and partners. For those who wonder who is behind the website, your About page is the first source of information.",
"change-this-pages-content-on-the-admin-panel": "Change this page's content on the admin panel, manage, pages and click on the about page.", "change-this-pages-content-on-the-admin-panel": "Change this page's content on the admin panel, manage, pages and click on the about page.",
"about-your-site-or-yourself": "About your site or yourself", "about-your-site-or-yourself": "About your site or yourself",
"welcome-to-bludit": "Welcome to Bludit" "welcome-to-bludit": "Welcome to Bludit",
"site-information": "Site information",
"date-and-time-formats": "Date and time formats",
"activate": "Activate",
"deactivate": "Deactivate"
} }

View File

@ -2,7 +2,7 @@
"theme-data": "theme-data":
{ {
"name": "Pure", "name": "Pure",
"description": "Simple and clean theme, based on the framework Pure.css.", "description": "Simple and clean, based on the framework Pure.css.",
"author": "Bludit", "author": "Bludit",
"email": "", "email": "",
"website": "https://github.com/dignajar/bludit-themes", "website": "https://github.com/dignajar/bludit-themes",