cherry-picked changes Meta-Generator from engineer-trooper
This commit is contained in:
parent
f7fa124535
commit
2db5aa8693
4 changed files with 44 additions and 1 deletions
|
@ -10,7 +10,8 @@
|
|||
],
|
||||
"require": {
|
||||
"ext-pdo": "*",
|
||||
"ext-http": "*"
|
||||
"ext-http": "*",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 '<meta name="'.$key.'" content="'.$value.'">';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 . '/';
|
||||
|
|
Loading…
Reference in a new issue