From 1c5992477f87583dec8c4c2363d19d10bcb4c841 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Fri, 19 Mar 2021 16:48:04 -0300 Subject: [PATCH] refactor to remove Theme helper --- bl-kernel/admin/themes/booty/login.php | 4 +- bl-kernel/boot/rules/69.pages.php | 2 +- bl-kernel/boot/rules/99.paginator.php | 2 +- bl-kernel/boot/site.php | 8 +- bl-kernel/helpers/html.class.php | 179 +++++++++++++++++++++++++ bl-kernel/site.class.php | 4 +- bl-plugins/remote-content/plugin.php | 2 +- bl-plugins/rss/plugin.php | 4 +- bl-plugins/sitemap/plugin.php | 6 +- bl-themes/alternative/index.php | 22 +-- bl-themes/alternative/php/home.php | 8 +- bl-themes/alternative/php/navbar.php | 8 +- bl-themes/alternative/php/page.php | 4 +- bl-themes/blogx/index.php | 10 +- bl-themes/blogx/php/head.php | 12 +- bl-themes/blogx/php/home.php | 6 +- bl-themes/blogx/php/navbar.php | 4 +- bl-themes/blogx/php/page.php | 4 +- bl-themes/blogx/php/sidebar.php | 2 +- 19 files changed, 235 insertions(+), 56 deletions(-) diff --git a/bl-kernel/admin/themes/booty/login.php b/bl-kernel/admin/themes/booty/login.php index b53f639a..815030eb 100644 --- a/bl-kernel/admin/themes/booty/login.php +++ b/bl-kernel/admin/themes/booty/login.php @@ -22,8 +22,8 @@ diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index 85af105f..aa613ed2 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -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(); diff --git a/bl-kernel/boot/rules/99.paginator.php b/bl-kernel/boot/rules/99.paginator.php index 6324398e..5051c7c3 100644 --- a/bl-kernel/boot/rules/99.paginator.php +++ b/bl-kernel/boot/rules/99.paginator.php @@ -21,7 +21,7 @@ if ($url->whereAmI()=='admin') { } // Execute hook from plugins -Theme::plugins('paginator'); +execPluginsByHook('paginator'); // Items per page Paginator::set('itemsPerPage', $itemsPerPage); diff --git a/bl-kernel/boot/site.php b/bl-kernel/boot/site.php index 7cf997cc..f096f7a7 100644 --- a/bl-kernel/boot/site.php +++ b/bl-kernel/boot/site.php @@ -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'); diff --git a/bl-kernel/helpers/html.class.php b/bl-kernel/helpers/html.class.php index c51190f1..cd921850 100644 --- a/bl-kernel/helpers/html.class.php +++ b/bl-kernel/helpers/html.class.php @@ -82,6 +82,185 @@ class HTML { return ''.PHP_EOL; } + // --- CHECK OLD + + public static function charset($charset) + { + return ''.PHP_EOL; + } + + public static function viewport($content) + { + return ''.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 ''.$format.''.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 ''.PHP_EOL; + } + } ?> \ No newline at end of file diff --git a/bl-kernel/site.class.php b/bl-kernel/site.class.php index ebf8214f..575b0109 100644 --- a/bl-kernel/site.class.php +++ b/bl-kernel/site.class.php @@ -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'; diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php index cbff79ea..8c92534c 100644 --- a/bl-plugins/remote-content/plugin.php +++ b/bl-plugins/remote-content/plugin.php @@ -154,7 +154,7 @@ EOF; } } - Theme::plugins('afterPageCreate'); + execPluginsByHook('afterPageCreate'); reindexCategories(); reindexTags(); } diff --git a/bl-plugins/rss/plugin.php b/bl-plugins/rss/plugin.php index f91ebe0a..848ecce6 100644 --- a/bl-plugins/rss/plugin.php +++ b/bl-plugins/rss/plugin.php @@ -21,7 +21,7 @@ class pluginRSS extends Plugin { $html .= '
'; $html .= ''; - $html .= ''.Theme::rssUrl().''; + $html .= ''.HTML::rssUrl().''; $html .= '
'; $html .= '
'; @@ -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); diff --git a/bl-plugins/sitemap/plugin.php b/bl-plugins/sitemap/plugin.php index dfb1bee8..c0e3c559 100644 --- a/bl-plugins/sitemap/plugin.php +++ b/bl-plugins/sitemap/plugin.php @@ -21,7 +21,7 @@ class pluginSitemap extends Plugin { $html .= '
'; $html .= ''; - $html .= ''.Theme::sitemapUrl().''; + $html .= ''.HTML::sitemapUrl().''; $html .= '
'; $html .= '
'; @@ -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); } } diff --git a/bl-themes/alternative/index.php b/bl-themes/alternative/index.php index 86cfb118..36bdad69 100755 --- a/bl-themes/alternative/index.php +++ b/bl-themes/alternative/index.php @@ -1,32 +1,32 @@ - + - + - + - + - + - + - + - + @@ -47,13 +47,13 @@ - + - + - + \ No newline at end of file diff --git a/bl-themes/alternative/php/home.php b/bl-themes/alternative/php/home.php index babdecb3..6d097d3e 100644 --- a/bl-themes/alternative/php/home.php +++ b/bl-themes/alternative/php/home.php @@ -16,7 +16,7 @@