refactor to remove Theme helper

This commit is contained in:
Diego Najar 2021-03-19 16:48:04 -03:00
parent ae1c99c813
commit 1c5992477f
19 changed files with 235 additions and 56 deletions

View file

@ -22,8 +22,8 @@
<!-- Javascript -->
<?php
echo Theme::jquery();
echo Theme::jsBootstrap();
echo HTML::jquery();
echo HTML::jsBootstrap();
?>
<!-- Execute plugins for the login page inside the HTML <head> tag -->

View file

@ -38,7 +38,7 @@ $staticContent = $staticPages = buildStaticPages();
// Execute the scheduler
if ($pages->scheduler()) {
// Execute plugins with the hook afterPageCreate
Theme::plugins('afterPageCreate');
execPluginsByHook('afterPageCreate');
reindexTags();
reindexCategories();

View file

@ -21,7 +21,7 @@ if ($url->whereAmI()=='admin') {
}
// Execute hook from plugins
Theme::plugins('paginator');
execPluginsByHook('paginator');
// Items per page
Paginator::set('itemsPerPage', $itemsPerPage);

View file

@ -4,7 +4,7 @@
include(PATH_RULES.'60.plugins.php');
// Plugins before all
Theme::plugins('beforeAll');
execPluginsByHook('beforeAll');
// Load rules
include(PATH_RULES.'60.router.php');
@ -14,7 +14,7 @@ include(PATH_RULES.'99.paginator.php');
include(PATH_RULES.'99.themes.php');
// Plugins before site loaded
Theme::plugins('beforeSiteLoad');
execPluginsByHook('beforeSiteLoad');
// Theme init.php
if (Sanitize::pathFile(PATH_THEMES.$site->theme().DS.'init.php')) {
@ -29,7 +29,7 @@ if (Sanitize::pathFile(PATH_THEMES.$site->theme().DS.'index.php')) {
}
// Plugins after site loaded
Theme::plugins('afterSiteLoad');
execPluginsByHook('afterSiteLoad');
// Plugins after all
Theme::plugins('afterAll');
execPluginsByHook('afterAll');

View file

@ -82,6 +82,185 @@ class HTML {
return '<script '.$attributes.' src="'.DOMAIN_CORE_VENDORS.'bootstrap-html5sortable/jquery.sortable.min.js?version='.BLUDIT_VERSION.'"></script>'.PHP_EOL;
}
// --- CHECK OLD
public static function charset($charset)
{
return '<meta charset="'.$charset.'">'.PHP_EOL;
}
public static function viewport($content)
{
return '<meta name="viewport" content="'.$content.'">'.PHP_EOL;
}
public static function src($file, $base=DOMAIN_THEME)
{
return $base.$file;
}
public static function socialNetworks()
{
global $site;
$socialNetworks = array(
'github'=>'Github',
'gitlab'=>'GitLab',
'twitter'=>'Twitter',
'facebook'=>'Facebook',
'instagram'=>'Instagram',
'codepen'=>'Codepen',
'linkedin'=>'Linkedin',
'xing'=>'Xing',
'mastodon'=>'Mastodon',
'vk'=>'VK'
);
foreach ($socialNetworks as $key=>$label) {
if (!$site->{$key}()) {
unset($socialNetworks[$key]);
}
}
return $socialNetworks;
}
public static function title()
{
global $site;
return $site->title();
}
public static function description()
{
global $site;
return $site->description();
}
public static function slogan()
{
global $site;
return $site->slogan();
}
public static function footer()
{
global $site;
return $site->footer();
}
public static function lang()
{
global $language;
return $language->currentLanguageShortVersion();
}
public static function rssUrl()
{
if (pluginActivated('pluginRSS')) {
return DOMAIN_BASE.'rss.xml';
}
return false;
}
public static function sitemapUrl()
{
if (pluginActivated('pluginSitemap')) {
return DOMAIN_BASE.'sitemap.xml';
}
return false;
}
// Returns the absolute URL of the site
// Ex. https://example.com the method returns https://example.com/
// Ex. https://example.com/bludit/ the method returns https://example.com/bludit/
public static function siteUrl()
{
return DOMAIN_BASE;
}
// Returns the absolute URL of admin panel
// Ex. https://example.com/admin/ the method returns https://example.com/admin/
// Ex. https://example.com/bludit/admin/ the method returns https://example.com/bludit/admin/
public static function adminUrl()
{
return DOMAIN_ADMIN;
}
public static function metaTags($tag)
{
if ($tag=='title') {
return self::metaTagTitle();
} elseif ($tag=='description') {
return self::metaTagDescription();
}
}
public static function metaTagTitle()
{
global $url;
global $site;
global $tags;
global $categories;
global $WHERE_AM_I;
global $page;
if ($WHERE_AM_I=='page') {
$format = $site->titleFormatPages();
$format = Text::replace('{{page-title}}', $page->title(), $format);
$format = Text::replace('{{page-description}}', $page->description(), $format);
} elseif ($WHERE_AM_I=='tag') {
try {
$tagKey = $url->slug();
$tag = new Tag($tagKey);
$format = $site->titleFormatTag();
$format = Text::replace('{{tag-name}}', $tag->name(), $format);
} catch (Exception $e) {
// Tag doesn't exist
}
} elseif ($WHERE_AM_I=='category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
$format = $site->titleFormatCategory();
$format = Text::replace('{{category-name}}', $category->name(), $format);
} catch (Exception $e) {
// Category doesn't exist
}
} else {
$format = $site->titleFormatHomepage();
}
$format = Text::replace('{{site-title}}', $site->title(), $format);
$format = Text::replace('{{site-slogan}}', $site->slogan(), $format);
$format = Text::replace('{{site-description}}', $site->description(), $format);
return '<title>'.$format.'</title>'.PHP_EOL;
}
public static function metaTagDescription()
{
global $site;
global $WHERE_AM_I;
global $page;
global $url;
$description = $site->description();
if ($WHERE_AM_I=='page') {
$description = $page->description();
} elseif ($WHERE_AM_I=='category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
$description = $category->description();
} catch (Exception $e) {
// description from the site
}
}
return '<meta name="description" content="'.$description.'">'.PHP_EOL;
}
}
?>

View file

@ -109,13 +109,13 @@ class Site extends dbJSON {
return false;
}
// DEPRECATED in v3.0, use Theme::rssUrl()
// DEPRECATED in v3.0, use HTML::rssUrl()
public function rss()
{
return DOMAIN_BASE.'rss.xml';
}
// DEPRECATED in v3.0, use Theme::sitemapUrl()
// DEPRECATED in v3.0, use HTML::sitemapUrl()
public function sitemap()
{
return DOMAIN_BASE.'sitemap.xml';

View file

@ -154,7 +154,7 @@ EOF;
}
}
Theme::plugins('afterPageCreate');
execPluginsByHook('afterPageCreate');
reindexCategories();
reindexTags();
}

View file

@ -21,7 +21,7 @@ class pluginRSS extends Plugin {
$html .= '<div>';
$html .= '<label>'.$L->get('RSS URL').'</label>';
$html .= '<a href="'.Theme::rssUrl().'">'.Theme::rssUrl().'</a>';
$html .= '<a href="'.HTML::rssUrl().'">'.HTML::rssUrl().'</a>';
$html .= '</div>';
$html .= '<div>';
@ -32,7 +32,7 @@ class pluginRSS extends Plugin {
return $html;
}
private function encodeURL($url)
{
return preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url);

View file

@ -21,7 +21,7 @@ class pluginSitemap extends Plugin {
$html .= '<div>';
$html .= '<label>'.$L->get('Sitemap URL').'</label>';
$html .= '<a href="'.Theme::sitemapUrl().'">'.Theme::sitemapUrl().'</a>';
$html .= '<a href="'.HTML::sitemapUrl().'">'.HTML::sitemapUrl().'</a>';
$html .= '</div>';
$html .= '<div>';
@ -85,12 +85,12 @@ class pluginSitemap extends Plugin {
private function ping()
{
if ($this->getValue('pingGoogle')) {
$url = 'https://www.google.com/ping?sitemap='.Theme::sitemapUrl();
$url = 'https://www.google.com/ping?sitemap='.HTML::sitemapUrl();
TCP::http($url, 'GET', true, 3);
}
if ($this->getValue('pingBing')) {
$url = 'https://www.bing.com/ping?sitemap='.Theme::sitemapUrl();
$url = 'https://www.bing.com/ping?sitemap='.HTML::sitemapUrl();
TCP::http($url, 'GET', true, 3);
}
}

View file

@ -1,32 +1,32 @@
<!DOCTYPE html>
<html lang="<?php echo Theme::lang() ?>">
<html lang="<?php echo HTML::lang() ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="generator" content="Bludit">
<!-- Dynamic title tag -->
<?php echo Theme::metaTagTitle(); ?>
<?php echo HTML::metaTagTitle(); ?>
<!-- Dynamic description tag -->
<?php echo Theme::metaTagDescription(); ?>
<?php echo HTML::metaTagDescription(); ?>
<!-- Include Favicon -->
<?php echo Theme::favicon('img/favicon.png'); ?>
<?php echo HTML::favicon('img/favicon.png'); ?>
<!-- Include CSS Bootstrap file from Bludit Core -->
<?php echo Theme::cssBootstrap(); ?>
<?php echo HTML::cssBootstrap(); ?>
<!-- Include CSS Styles from this theme -->
<?php echo Theme::css('css/style.css'); ?>
<?php echo HTML::css('css/style.css'); ?>
<!-- Load Bludit Plugins: Site head -->
<?php Theme::plugins('siteHead'); ?>
<?php execPluginsByHook('siteHead'); ?>
</head>
<body>
<!-- Load Bludit Plugins: Site Body Begin -->
<?php Theme::plugins('siteBodyBegin'); ?>
<?php execPluginsByHook('siteBodyBegin'); ?>
<!-- Navbar -->
<?php include(THEME_DIR_PHP.'navbar.php'); ?>
@ -47,13 +47,13 @@
<?php include(THEME_DIR_PHP.'footer.php'); ?>
<!-- Include Jquery file from Bludit Core -->
<?php echo Theme::jquery(); ?>
<?php echo HTML::jquery(); ?>
<!-- Include javascript Bootstrap file from Bludit Core -->
<?php echo Theme::jsBootstrap(); ?>
<?php echo HTML::jsBootstrap(); ?>
<!-- Load Bludit Plugins: Site Body End -->
<?php Theme::plugins('siteBodyEnd'); ?>
<?php execPluginsByHook('siteBodyEnd'); ?>
</body>
</html>

View file

@ -16,7 +16,7 @@
<button class="btn btn-outline-primary my-2 my-sm-0" type="button" onClick="searchNow()"><?php $language->p('Search') ?></button>
<script>
function searchNow() {
var searchURL = "<?php echo Theme::siteUrl(); ?>search/";
var searchURL = "<?php echo HTML::siteUrl(); ?>search/";
window.open(searchURL + document.getElementById("search-input").value, "_self");
}
document.getElementById("search-input").onkeypress = function(e) {
@ -46,7 +46,7 @@
<div class="row">
<div class="col-lg-8 mx-auto">
<!-- Load Bludit Plugins: Page Begin -->
<?php Theme::plugins('pageBegin'); ?>
<?php execPluginsByHook('pageBegin'); ?>
<!-- Page title -->
<a class="text-dark" href="<?php echo $page->permalink(); ?>">
@ -71,7 +71,7 @@
<?php endif ?>
<!-- Load Bludit Plugins: Page End -->
<?php Theme::plugins('pageEnd'); ?>
<?php execPluginsByHook('pageEnd'); ?>
</div>
</div>
</div>
@ -92,7 +92,7 @@
<!-- Home button -->
<li class="page-item <?php if (Paginator::currentPage()==1) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Theme::siteUrl() ?>"><?php echo $L->get('Home'); ?></a>
<a class="page-link" href="<?php echo HTML::siteUrl() ?>"><?php echo $L->get('Home'); ?></a>
</li>
<!-- Next button -->

View file

@ -1,6 +1,6 @@
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark text-uppercase">
<div class="container">
<a class="navbar-brand" href="<?php echo Theme::siteUrl(); ?>">
<a class="navbar-brand" href="<?php echo HTML::siteUrl(); ?>">
<span class="text-white"><?php echo $site->title(); ?></span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
@ -18,7 +18,7 @@
<?php endforeach ?>
<!-- Social Networks -->
<?php foreach (Theme::socialNetworks() as $key=>$label): ?>
<?php foreach (HTML::socialNetworks() as $key=>$label): ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $site->{$key}(); ?>" target="_blank">
<img class="d-none d-sm-block nav-svg-icon" src="<?php echo DOMAIN_THEME.'img/'.$key.'.svg' ?>" alt="<?php echo $label ?>" />
@ -28,9 +28,9 @@
<?php endforeach; ?>
<!-- RSS -->
<?php if (Theme::rssUrl()): ?>
<?php if (HTML::rssUrl()): ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo Theme::rssUrl() ?>" target="_blank">
<a class="nav-link" href="<?php echo HTML::rssUrl() ?>" target="_blank">
<img class="d-none d-sm-block nav-svg-icon text-primary" src="<?php echo DOMAIN_THEME.'img/rss.svg' ?>" alt="RSS" />
<span class="d-inline d-sm-none">RSS</span>
</a>

View file

@ -3,7 +3,7 @@
<div class="row">
<div class="col-lg-8 mx-auto">
<!-- Load Bludit Plugins: Page Begin -->
<?php Theme::plugins('pageBegin'); ?>
<?php execPluginsByHook('pageBegin'); ?>
<!-- Page title -->
<h1 class="title"><?php echo $page->title(); ?></h1>
@ -26,7 +26,7 @@
</div>
<!-- Load Bludit Plugins: Page End -->
<?php Theme::plugins('pageEnd'); ?>
<?php execPluginsByHook('pageEnd'); ?>
</div>
</div>
</div>

View file

@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="<?php echo Theme::lang() ?>">
<html lang="<?php echo HTML::lang() ?>">
<head>
<?php include(THEME_DIR_PHP.'head.php'); ?>
</head>
<body>
<!-- Load Bludit Plugins: Site Body Begin -->
<?php Theme::plugins('siteBodyBegin'); ?>
<?php execPluginsByHook('siteBodyBegin'); ?>
<!-- Navbar -->
<?php include(THEME_DIR_PHP.'navbar.php'); ?>
@ -52,14 +52,14 @@
<!-- Javascript -->
<?php
// Include Jquery file from Bludit Core
echo Theme::jquery();
echo HTML::jquery();
// Include javascript Bootstrap file from Bludit Core
echo Theme::jsBootstrap();
echo HTML::jsBootstrap();
?>
<!-- Load Bludit Plugins: Site Body End -->
<?php Theme::plugins('siteBodyEnd'); ?>
<?php execPluginsByHook('siteBodyEnd'); ?>
</body>
</html>

View file

@ -3,19 +3,19 @@
<meta name="generator" content="Bludit">
<!-- Dynamic title tag -->
<?php echo Theme::metaTags('title'); ?>
<?php echo HTML::metaTags('title'); ?>
<!-- Dynamic description tag -->
<?php echo Theme::metaTags('description'); ?>
<?php echo HTML::metaTags('description'); ?>
<!-- Include Favicon -->
<?php echo Theme::favicon('img/favicon.png'); ?>
<?php echo HTML::favicon('img/favicon.png'); ?>
<!-- Include Bootstrap CSS file bootstrap.css -->
<?php echo Theme::cssBootstrap(); ?>
<?php echo HTML::cssBootstrap(); ?>
<!-- Include CSS Styles from this theme -->
<?php echo Theme::css('css/style.css'); ?>
<?php echo HTML::css('css/style.css'); ?>
<!-- Load Bludit Plugins: Site head -->
<?php Theme::plugins('siteHead'); ?>
<?php execPluginsByHook('siteHead'); ?>

View file

@ -9,7 +9,7 @@
<div class="card my-5 border-0">
<!-- Load Bludit Plugins: Page Begin -->
<?php Theme::plugins('pageBegin'); ?>
<?php execPluginsByHook('pageBegin'); ?>
<!-- Cover image -->
<?php if ($page->coverImage()): ?>
@ -36,7 +36,7 @@
</div>
<!-- Load Bludit Plugins: Page End -->
<?php Theme::plugins('pageEnd'); ?>
<?php execPluginsByHook('pageEnd'); ?>
</div>
<hr>
@ -56,7 +56,7 @@
<!-- Home button -->
<li class="page-item <?php if (Paginator::currentPage()==1) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Theme::siteUrl() ?>">Home</a>
<a class="page-link" href="<?php echo HTML::siteUrl() ?>">Home</a>
</li>
<!-- Next button -->

View file

@ -1,6 +1,6 @@
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark text-uppercase">
<div class="container">
<a class="navbar-brand" href="<?php echo Theme::siteUrl() ?>">
<a class="navbar-brand" href="<?php echo HTML::siteUrl() ?>">
<span class="text-white"><?php echo $site->title() ?></span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
@ -17,7 +17,7 @@
<?php endforeach ?>
<!-- Social Networks -->
<?php foreach (Theme::socialNetworks() as $key=>$label): ?>
<?php foreach (HTML::socialNetworks() as $key=>$label): ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $site->{$key}(); ?>" target="_blank">
<img class="d-none d-sm-block nav-svg-icon" src="<?php echo DOMAIN_THEME.'img/'.$key.'.svg' ?>" alt="<?php echo $label ?>" />

View file

@ -2,7 +2,7 @@
<div class="card my-5 border-0">
<!-- Load Bludit Plugins: Page Begin -->
<?php Theme::plugins('pageBegin'); ?>
<?php execPluginsByHook('pageBegin'); ?>
<!-- Cover image -->
<?php if ($page->coverImage()): ?>
@ -26,6 +26,6 @@
</div>
<!-- Load Bludit Plugins: Page End -->
<?php Theme::plugins('pageEnd'); ?>
<?php execPluginsByHook('pageEnd'); ?>
</div>

View file

@ -1 +1 @@
<?php Theme::plugins('siteSidebar') ?>
<?php execPluginsByHook('siteSidebar') ?>