From 2db5aa86933c567fe70e77753967a6880cb3de59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Gr=C3=B6nwoldt?= Date: Fri, 25 Sep 2020 21:39:05 +0200 Subject: [PATCH] cherry-picked changes Meta-Generator from engineer-trooper --- composer.json | 3 ++- install/db.sql | 8 ++++++++ src/Venom/Helper/MetaGenerator.php | 29 +++++++++++++++++++++++++++++ src/Venom/Views/VenomRenderer.php | 5 +++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 62992e9..0288075 100755 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ ], "require": { "ext-pdo": "*", - "ext-http": "*" + "ext-http": "*", + "ext-json": "*" }, "autoload": { "psr-4": { diff --git a/install/db.sql b/install/db.sql index 3dfd064..6e0d81d 100755 --- a/install/db.sql +++ b/install/db.sql @@ -7,6 +7,14 @@ create table if not exists seoData ) comment 'seo url mapping'; +create table if not exists metaTagData +( + id int(255) auto_increment not null unique primary key, + content JSON not null, + isActive tinyint(1) default 1 null +) + comment 'Meta Tag File'; + create table if not exists language ( id int(255) auto_increment not null unique primary key, diff --git a/src/Venom/Helper/MetaGenerator.php b/src/Venom/Helper/MetaGenerator.php index e6dd9dd..81020fb 100644 --- a/src/Venom/Helper/MetaGenerator.php +++ b/src/Venom/Helper/MetaGenerator.php @@ -4,11 +4,40 @@ namespace Venom\Helper; +use Venom\Core\ArgumentHandler; +use Venom\Core\DatabaseHandler; + /** * Class MetaGenerator * @package Venom\Helper */ class MetaGenerator { + private array $container = []; + private string $id; + public function __construct() + { + $this->id = (string)ArgumentHandler::get()->getItem('metaId', '-1'); + } + + public function loadById(): void + { + if ($this->id === '-1') { + return; + } + $db = DatabaseHandler::get(); + $data = $db->getOne('select content from metaTagData where id = :id', [':id' => $this->id]); + if ($data !== null) { + $this->container = json_decode($data->content ?? '', true); + $this->container = array_merge([], $this->container); + } + } + + public function render(): void + { + foreach($this->container as $key => $value) { + echo ''; + } + } } \ No newline at end of file diff --git a/src/Venom/Views/VenomRenderer.php b/src/Venom/Views/VenomRenderer.php index b8bad47..3dfb403 100755 --- a/src/Venom/Views/VenomRenderer.php +++ b/src/Venom/Views/VenomRenderer.php @@ -6,12 +6,14 @@ namespace Venom\Views; use Venom\Core\ArgumentHandler; use Venom\Core\Config; +use Venom\Helper\MetaGenerator; use Venom\Venom; class VenomRenderer { private Venom $venom; private ?RenderController $controller; + private ?MetaGenerator $metaGenerator; private string $templateData = ''; private array $vars = []; private string $baseTemplate = ''; @@ -95,9 +97,12 @@ class VenomRenderer $data = Config::getInstance()->getRenderer(); $theme = $data->theme; $base = $data->baseFile ?? 'base'; + $this->metaGenerator = new MetaGenerator(); if (Config::getInstance()->isAdmin()) { $base = 'base'; $theme = 'admin'; + } else { + $this->metaGenerator->loadById(); } $this->baseTemplate = $base . '.php'; $this->templateDir = __DIR__ . '/../../../tpl/' . $theme . '/';