cherry-picked changes Meta-Generator from engineer-trooper

This commit is contained in:
Maurice Grönwoldt 2020-09-25 21:39:05 +02:00
parent f7fa124535
commit 2db5aa8693
4 changed files with 44 additions and 1 deletions

View file

@ -10,7 +10,8 @@
], ],
"require": { "require": {
"ext-pdo": "*", "ext-pdo": "*",
"ext-http": "*" "ext-http": "*",
"ext-json": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View file

@ -7,6 +7,14 @@ create table if not exists seoData
) )
comment 'seo url mapping'; 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 create table if not exists language
( (
id int(255) auto_increment not null unique primary key, id int(255) auto_increment not null unique primary key,

View file

@ -4,11 +4,40 @@
namespace Venom\Helper; namespace Venom\Helper;
use Venom\Core\ArgumentHandler;
use Venom\Core\DatabaseHandler;
/** /**
* Class MetaGenerator * Class MetaGenerator
* @package Venom\Helper * @package Venom\Helper
*/ */
class MetaGenerator 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 '<meta name="'.$key.'" content="'.$value.'">';
}
}
} }

View file

@ -6,12 +6,14 @@ namespace Venom\Views;
use Venom\Core\ArgumentHandler; use Venom\Core\ArgumentHandler;
use Venom\Core\Config; use Venom\Core\Config;
use Venom\Helper\MetaGenerator;
use Venom\Venom; use Venom\Venom;
class VenomRenderer class VenomRenderer
{ {
private Venom $venom; private Venom $venom;
private ?RenderController $controller; private ?RenderController $controller;
private ?MetaGenerator $metaGenerator;
private string $templateData = ''; private string $templateData = '';
private array $vars = []; private array $vars = [];
private string $baseTemplate = ''; private string $baseTemplate = '';
@ -95,9 +97,12 @@ class VenomRenderer
$data = Config::getInstance()->getRenderer(); $data = Config::getInstance()->getRenderer();
$theme = $data->theme; $theme = $data->theme;
$base = $data->baseFile ?? 'base'; $base = $data->baseFile ?? 'base';
$this->metaGenerator = new MetaGenerator();
if (Config::getInstance()->isAdmin()) { if (Config::getInstance()->isAdmin()) {
$base = 'base'; $base = 'base';
$theme = 'admin'; $theme = 'admin';
} else {
$this->metaGenerator->loadById();
} }
$this->baseTemplate = $base . '.php'; $this->baseTemplate = $base . '.php';
$this->templateDir = __DIR__ . '/../../../tpl/' . $theme . '/'; $this->templateDir = __DIR__ . '/../../../tpl/' . $theme . '/';