feat(main): Initial Module

This commit is contained in:
2026-06-23 10:36:51 +02:00
parent d84aa7c701
commit 9ee25402df
26 changed files with 1121 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace Websmid\CustomHtml\Module;
trait AdminHooks
{
public function isUsingNewTranslationSystem(): bool
{
return true;
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Model\CustomHtml;
use Context;
trait FrontHooks
{
public function renderWidget($hookName = null, array $configuration = [])
{
if (empty($hookName)) {
return false;
}
$idLang = (int) Context::getContext()->language->id;
$templateFile = 'module:ws_customhtml/views/templates/hook/customhtml_block.tpl';
$cacheId = $this->getCacheId('ws_customhtml_' . $idLang . '_' . $hookName);
if (!$this->isCached($templateFile, $cacheId)) {
$variables = $this->getWidgetVariables($hookName, $configuration);
if (empty($variables)) {
return false;
}
$this->smarty->assign($variables);
}
return $this->fetch($templateFile, $cacheId);
}
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$blockList = CustomHtml::getActiveByHookName((string) $hookName);
if (empty($blockList)) {
return [];
}
return [
'hookName' => $hookName,
'blockList' => $blockList,
];
}
}
+118
View File
@@ -0,0 +1,118 @@
<?php
namespace Websmid\CustomHtml\Module;
use Websmid\CustomHtml\Config\Config;
use Db;
use Language;
use Tab;
trait Install
{
public function install()
{
if (!parent::install()) {
error_log('[ws_customhtml] parent::install() failed');
return false;
}
if (!$this->createTables()) {
error_log('[ws_customhtml] createTables() failed — DB error: ' . Db::getInstance()->getMsgError());
return false;
}
if (!$this->registerTabs(Config::TABS)) {
error_log('[ws_customhtml] registerTabs() failed');
return false;
}
if (!$this->registerHooks()) {
error_log('[ws_customhtml] registerHooks() failed');
return false;
}
return true;
}
private function createTables(): bool
{
$sqlToExec = [];
$sqlToExec[] = '
CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'ws_customhtml (
`id_ws_customhtml` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`hook_name` VARCHAR(64) NOT NULL,
`title` VARCHAR(256) NOT NULL DEFAULT \'\',
`content` LONGTEXT,
`active` TINYINT(1) NOT NULL DEFAULT 1,
`show_title` TINYINT(1) NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0,
`date_add` DATETIME NOT NULL,
`date_upd` DATETIME NOT NULL
);
';
foreach ($sqlToExec as $sqlBlock) {
Db::getInstance()->execute(trim($sqlBlock));
}
return true;
}
private function registerHooks(): bool
{
foreach (Config::HOOKS as $hook) {
if (!$this->registerHook($hook)) {
return false;
}
}
return true;
}
private function registerTabs(array $moduleTabs): bool
{
$languages = Language::getLanguages(false);
foreach ($moduleTabs as $moduleTab) {
if (Tab::getIdFromClassName($moduleTab['class_name'])) {
continue;
}
$tab = new Tab();
$tab->class_name = $moduleTab['class_name'];
$tab->module = $moduleTab['module'];
$tab->active = 1;
$tab->route_name = $moduleTab['route_name'];
if (isset($moduleTab['icon'])) {
$tab->icon = $moduleTab['icon'];
}
foreach ($languages as $language) {
if (is_array($moduleTab['name'])) {
$tab->name[$language['id_lang']] = $moduleTab['name'][$language['iso_code']]
?? $moduleTab['name']['en'];
} else {
$tab->name[$language['id_lang']] = $moduleTab['name'];
}
}
if (isset($moduleTab['parent_class_name'])) {
$tab->id_parent = (int) Tab::getIdFromClassName($moduleTab['parent_class_name']);
} elseif (isset($moduleTab['id_parent'])) {
$tab->id_parent = (int) $moduleTab['id_parent'];
} else {
$tab->id_parent = -1;
}
$tab->add();
if (!$tab->id) {
return false;
}
}
return true;
}
}