many updates

This commit is contained in:
Paul Spenke
2023-07-10 21:27:43 +08:00
parent 249f6b06b5
commit cd9dc85420
29 changed files with 3164 additions and 962 deletions
+10
View File
@@ -0,0 +1,10 @@
STAGE = production
BASE_URL = http://localhost:63000
database_driver = mysql
database_host = mysql
database_database = plugi
database_username = plugi
database_password = plugi
database_charset = utf8
database_collation = utf8_unicode_ci
database_prefix =
+2
View File
@@ -11,6 +11,8 @@ node_modules
dist-ssr
*.local
.env
cache
uploads
extensions/dev_*
+1 -13
View File
@@ -10,9 +10,7 @@ return [
|
*/
'general' => [
// 'base_url' => 'http://localhost:63000',
'base_url' => 'https://pagebuilder.dev.onlineer.de',
'language' => 'de',
'language' => 'en',
'assets_url' => '/plugi-core/dist',
'uploads_url' => '/uploads'
],
@@ -27,16 +25,6 @@ return [
*/
'storage' => [
'use_database' => true,
'database' => [
'driver' => 'mysql',
'host' => 'mysql',
'database' => 'plugi',
'username' => 'plugi',
'password' => 'plugi',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
'uploads_folder' => __DIR__ . '/uploads'
],
+8 -4
View File
@@ -1,9 +1,13 @@
<?php
// Uncomment to disable error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once __DIR__.'/plugi-core/src/Core/EnvLoader.php';
(new Plugi\Core\EnvLoader())->load();
if ($_ENV['STAGE'] !== 'production') {
ini_set('display_errors', 1);
error_reporting(E_ALL);
}
// Uncomment if you downloaded Plugi
require_once __DIR__ . '/plugi-core/src/Core/helpers.php';
spl_autoload_register('phpb_autoload');
-180
View File
@@ -1,180 +0,0 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| General settings
|--------------------------------------------------------------------------
|
| General settings for configuring the PageBuilder.
| If you install phpb with Composer, general.assets_url line must be:
| 'assets_url' => '/vendor/hansschouten/plugi/dist',
|
*/
'general' => [
'base_url' => 'http://localhost',
'language' => 'en',
'assets_url' => '/assets',
'uploads_url' => '/uploads'
],
/*
|--------------------------------------------------------------------------
| Storage settings
|--------------------------------------------------------------------------
|
| Database and file storage settings.
|
*/
'storage' => [
'use_database' => true,
'database' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
'uploads_folder' => __DIR__ . '/uploads'
],
/*
|--------------------------------------------------------------------------
| Auth settings
|--------------------------------------------------------------------------
|
| By default an authentication class is provided which checks for the
| credentials configured in this setting block.
|
*/
'auth' => [
'use_login' => true,
'class' => Plugi\Modules\Auth\Auth::class,
'url' => '/admin/auth',
'username' => 'admin',
'password' => 'changethispassword'
],
/*
|--------------------------------------------------------------------------
| WebsiteManager settings
|--------------------------------------------------------------------------
|
| By default a basic WebsiteManager is provided for creating/editing pages.
|
*/
'website_manager' => [
'use_website_manager' => true,
'class' => Plugi\Modules\WebsiteManager\WebsiteManager::class,
'url' => '/admin'
],
/*
|--------------------------------------------------------------------------
| Website settings
|--------------------------------------------------------------------------
|
| By default a setting class is provided for accessing website settings.
|
*/
'setting' => [
'class' => Plugi\Setting::class
],
/*
|--------------------------------------------------------------------------
| PageBuilder settings
|--------------------------------------------------------------------------
|
| By default a PageBuilder is provided based on GrapesJS.
|
*/
'pagebuilder' => [
'class' => Plugi\Modules\GrapesJS\PageBuilder::class,
'url' => '/admin/pagebuilder',
'actions' => [
'back' => '/admin'
]
],
/*
|--------------------------------------------------------------------------
| Page settings
|--------------------------------------------------------------------------
|
| By default a Page class is provided with knowledge about its layout and URL.
|
*/
'page' => [
'class' => Plugi\Page::class,
'table' => 'pages',
'translation' => [
'class' => Plugi\PageTranslation::class,
'table' => 'page_translations',
'foreign_key' => 'page_id',
]
],
/*
|--------------------------------------------------------------------------
| Cache settings
|--------------------------------------------------------------------------
|
| Faster load time by skipping block parsing if the page has been requested before.
| A page will be cached, except if it contains a block with caching set to false.
| This can be used to prevent caching pages with content that varies per page load.
| The cached html is removed if the page is saved again in the page builder.
|
*/
'cache' => [
'enabled' => false,
'folder' => __DIR__ . '/cache',
'class' => Plugi\Cache::class
],
/*
|--------------------------------------------------------------------------
| Theme settings
|--------------------------------------------------------------------------
|
| PageBuilder requires a themes folder in which for each theme the individual
| theme blocks are defined. A theme block is a sub folder in the themes folder
| containing a view, model (optional) and controller (optional).
|
*/
'theme' => [
'class' => Plugi\Theme::class,
'folder' => __DIR__ . '/themes',
'folder_url' => '/themes',
'active_theme' => 'demo'
],
/*
|--------------------------------------------------------------------------
| Routing settings
|--------------------------------------------------------------------------
|
| Settings for resolving pages based on the current URI.
|
*/
'router' => [
'class' => Plugi\Modules\Router\DatabasePageRouter::class
],
/*
|--------------------------------------------------------------------------
| Class replacements
|--------------------------------------------------------------------------
|
| Allows mapping a class namespace to an alternative namespace,
| useful for replacing implementations of specific pagebuilder classes.
| Example: Plugi\UploadedFile::class => Alternative\UploadedFile::class
| Important: when overriding a class always extend the original class.
|
*/
'class_replacements' => [
],
];
+1
View File
@@ -196,6 +196,7 @@ ALTER TABLE `uploads`
--
-- Constraints der Tabelle `page_translations`
-- TODO implement in sql loader
--
ALTER TABLE `page_translations`
ADD CONSTRAINT `page_translations_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `pages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+1 -1
View File
File diff suppressed because one or more lines are too long
+709 -681
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+15 -1
View File
@@ -7,7 +7,8 @@
"name": "plugi-core",
"dependencies": {
"alpinejs": "^3.12.2",
"grapesjs": "^0.21.2"
"grapesjs": "^0.21.2",
"slugify": "^1.6.6"
},
"devDependencies": {
"autoprefixer": "^10.4.14",
@@ -1686,6 +1687,14 @@
"semver": "bin/semver.js"
}
},
"node_modules/slugify": {
"version": "1.6.6",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz",
"integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
@@ -3048,6 +3057,11 @@
}
}
},
"slugify": {
"version": "1.6.6",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz",
"integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw=="
},
"source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
+2 -1
View File
@@ -25,6 +25,7 @@
},
"dependencies": {
"alpinejs": "^3.12.2",
"grapesjs": "^0.21.2"
"grapesjs": "^0.21.2",
"slugify": "^1.6.6"
}
}
+27 -23
View File
@@ -4,9 +4,9 @@ namespace Plugi\Core;
use Exception;
use PDO;
use PDOException;
use Plugi\Extensions;
use Plugi\Repositories\SettingRepository;
use Plugi\Setting;
/**
* Class DB
@@ -20,22 +20,21 @@ class DB
/**
* @var PDO $pdo
*/
protected $pdo;
protected PDO $pdo;
/**
* DB constructor.
*
* @param array $config
*/
public function __construct(array $config)
public function __construct()
{
$this->pdo = new PDO(
$config['driver'] . ':host=' . $config['host'] . ';dbname=' . $config['database'] . ";options='--client_encoding=" . $config['charset'] . "'",
$config['username'],
$config['password'],
$_ENV['DATABASE_DRIVER'] . ':host=' . $_ENV['DATABASE_HOST'] . ';dbname=' . $_ENV['DATABASE_DATABASE'] . ";options='--client_encoding=" . $_ENV['DATABASE_CHARSET'] . "'",
$_ENV['DATABASE_USERNAME'],
$_ENV['DATABASE_PASSWORD'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$this->pdo->exec("set names " . $config['charset']);
$this->pdo->exec("set names " . $_ENV['DATABASE_CHARSET']);
}
/**
@@ -43,7 +42,7 @@ class DB
*
* @return string
*/
public function lastInsertId()
public function lastInsertId(): string
{
return $this->pdo->lastInsertId();
}
@@ -55,7 +54,7 @@ class DB
* @param string $table
* @return array
*/
public function all(string $table, $columns = '*')
public function all(string $table, array|string $columns = '*'): array
{
try {
if (is_array($columns)) {
@@ -63,13 +62,13 @@ class DB
$column = preg_replace('/[^a-zA-Z_]*/', '', $column);
}
$columns = implode(',', $columns);
$stmt = $this->pdo->prepare("SELECT {$columns} FROM {$table}");
$stmt = $this->pdo->prepare("SELECT $columns FROM $table");
} else {
$stmt = $this->pdo->prepare("SELECT * FROM {$table}");
$stmt = $this->pdo->prepare("SELECT * FROM $table");
}
$stmt->execute();
return $stmt->fetchAll();
} catch (\PDOException $e) {
} catch (PDOException $e) {
$_SESSION["phpb_flash"] = [
'message-type' => 'error',
'message' => phpb_trans('website-manager.check-database')
@@ -119,20 +118,23 @@ class DB
return $stmt->execute($parameters);
}
function tableExists($table) {
function tableExists(string $table): bool
{
$tableName = $_ENV['DATABASE_PREFIX'] . phpb_remove_non_alpha_numeric($table);
try {
$this->pdo->query("SELECT 1 FROM {$table} LIMIT 1");
$this->pdo->query("SELECT 1 FROM {$tableName} LIMIT 1");
return true;
} catch (Exception $e) {
return false;
}
}
public function columnExists(string $table, string $column)
public function columnExists(string $table, string $column): bool
{
$tableName = $_ENV['DATABASE_PREFIX'] . phpb_remove_non_alpha_numeric($table);
// check if table with the name $table exists. if not, execute $query.'
try {
$rs = $this->pdo->query("SELECT * FROM {$table} LIMIT 0");
$rs = $this->pdo->query("SELECT * FROM {$tableName} LIMIT 0");
for ($i = 0; $i < $rs->columnCount(); $i++) {
$col = $rs->getColumnMeta($i);
$columns[] = $col['name'];
@@ -146,11 +148,12 @@ class DB
public function uniqueKeyExists(string $table, string $key)
{
$tableName = $_ENV['DATABASE_PREFIX'] . phpb_remove_non_alpha_numeric($table);
// check if table with the name $table exists. if not, execute $query.'
try {
$keys = $this->select(
"SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = ? AND TABLE_SCHEMA = 'plugi' AND TABLE_NAME = ? AND CONSTRAINT_TYPE = 'UNIQUE'",
[$key, $table]
[$key, $tableName]
);
if (count($keys) === 1) return true;
return false;
@@ -202,16 +205,17 @@ class DB
public function resolveDiffDB() {
$diff = $this->diffDB();
foreach ($diff as $table => $tableDiff) {
$tableName = $_ENV['DATABASE_PREFIX'] . phpb_remove_non_alpha_numeric($table);
if($tableDiff === false){
$this->query("CREATE TABLE {$table} (`id` int NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3");
$this->query("ALTER TABLE {$table} ADD PRIMARY KEY (`id`)");
$this->query("ALTER TABLE {$table} MODIFY `id` int NOT NULL AUTO_INCREMENT");
$this->query("CREATE TABLE {$tableName} (`id` int NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3");
$this->query("ALTER TABLE {$tableName} ADD PRIMARY KEY (`id`)");
$this->query("ALTER TABLE {$tableName} MODIFY `id` int NOT NULL AUTO_INCREMENT");
} elseif (is_array($tableDiff)) {
foreach ($tableDiff['columns'] as $column => $columnDefinition) {
$this->query("ALTER TABLE {$table} ADD {$column} {$columnDefinition}");
$this->query("ALTER TABLE {$tableName} ADD {$column} {$columnDefinition}");
}
foreach ($tableDiff['uniqueKeys'] as $key => $keyDefinition) {
$this->query("ALTER TABLE {$table} ADD UNIQUE KEY {$key} ($keyDefinition)");
$this->query("ALTER TABLE {$tableName} ADD UNIQUE KEY {$key} ($keyDefinition)");
}
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Plugi\Core;
class EnvLoader
{
/**
* The directory where the .env file can be located.
*
* @var string
*/
protected string $path;
public function __construct(string $path = '.env')
{
if(!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('%s does not exist', $path));
}
$this->path = $path;
}
public function load() :void
{
if (!is_readable($this->path)) {
throw new \RuntimeException(sprintf('%s file is not readable', $this->path));
}
$lines = file($this->path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue;
}
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
}
+37 -17
View File
@@ -110,10 +110,14 @@ if (! function_exists('phpb_config')) {
* @param string $key
* @return mixed
*/
function phpb_config(string $key): mixed
function phpb_config(?string $key = null): mixed
{
global $phpb_config;
if (!isset($key)) {
return $phpb_config;
}
// if no dot notation is used, return first dimension value or empty string
if (!str_contains($key, '.')) {
return $phpb_config[$key] ?? '';
@@ -203,7 +207,7 @@ if (! function_exists('phpb_full_url')) {
return $urlRelativeToBaseUrl;
}
$baseUrl = phpb_config('general.base_url');
$baseUrl = $_ENV['BASE_URL'];
return rtrim($baseUrl, '/') . $urlRelativeToBaseUrl;
}
}
@@ -259,7 +263,7 @@ if (! function_exists('phpb_current_relative_url')) {
*/
function phpb_current_relative_url(): string
{
$baseUrl = phpb_config('general.base_url');
$baseUrl = $_ENV['BASE_URL'];
$baseUrl = rtrim($baseUrl, '/'. DIRECTORY_SEPARATOR);
$currentFullUrl = phpb_current_full_url();
@@ -523,6 +527,16 @@ if (! function_exists('phpb_slug')) {
}
}
if (! function_exists('phpb_remove_non_alpha_numeric')) {
/**
* Create a slug (safe URL or path) of the given string.
*/
function phpb_remove_non_alpha_numeric(string $string): array|string|null
{
return preg_replace('/\W*/', '', $string);
}
}
if (! function_exists('phpb_autoload')) {
/**
* Autoload classes from the Plugi package.
@@ -580,26 +594,32 @@ if (! function_exists('phpb_registered_assets')) {
}
}
if (! function_exists('array_merge_recursive_ex')) {
if (! function_exists('phpb_array_merge_deep_array')) {
/**
* Deep merging
*/
function array_merge_recursive_ex(array $array1, array $array2): array
{
$merged = $array1;
function phpb_array_merge_deep_array($arrays) {
$result = array();
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = array_merge_recursive_ex($merged[$key], $value);
} else if (is_numeric($key)) {
if (!in_array($value, $merged)) {
$merged[] = $value;
// Renumber integer keys as array_merge_recursive() does. Note that PHP
// automatically converts array keys that are integer strings (e.g., '1')
// to integers.
if (is_integer($key)) {
$result[] = $value;
}
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = phpb_array_merge_deep_array(array(
$result[$key],
$value,
));
}
else {
$result[$key] = $value;
}
} else {
$merged[$key] = $value;
}
}
return $merged;
return $result;
}
}
@@ -1,5 +1,8 @@
import Alpine from "alpinejs"
import './sass/app.scss'
import './js/app.js'
import slugify from "slugify";
window.slugify = slugify
Alpine.start()
@@ -55,16 +55,16 @@ $pageTranslations = $page ? $page->getTranslations() : [];
$firstLang = true;
foreach (phpb_active_languages() as $languageCode => $languageTranslation):
?>
<details class="collapse collapse-plus bg-base-200 mt-6" <?= phpb_e($firstLang ? 'open' : '') ?>>
<details class="collapse collapse-plus bg-white mt-6" <?= phpb_e($firstLang ? 'open' : '') ?>>
<summary class="collapse-title text-xl font-medium"><?= phpb_trans('languages.' . $languageCode) ?></summary>
<div class="collapse-content">
<div class="">
<div x-data="{route: '<?= phpb_e($pageTranslations[$languageCode]['route'] ?? '') ?>', empty: true, locale: '<?= $firstLang ? '' : '/'.phpb_e($languageCode) ?>'}" x-init="empty = route.length === 0">
<div class="form-control w-full mb-2">
<label class="label" for="<?= phpb_e($languageCode) ?>-page-title">
<span class="label-text"><?= phpb_trans('website-manager.page-title') ?></span>
<span class="label-text-alt"><?= phpb_trans('website-manager.required') ?></span>
</label>
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-title" name="title[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['title'] ?? '') ?>" required />
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-title" name="title[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['title'] ?? '') ?>" @input="if(empty){route=`${locale}/${slugify($event.target.value)}`}" required />
</div>
<div class="form-control w-full mb-2">
@@ -86,7 +86,13 @@ $pageTranslations = $page ? $page->getTranslations() : [];
<span class="label-text"><?= phpb_trans('website-manager.route') ?></span>
<span class="label-text-alt"><?= phpb_trans('website-manager.required') ?></span>
</label>
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-route" name="route[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['route'] ?? '') ?>" required />
<div class="join" x-data="{disabled: true}">
<input type="text" class="input input-bordered join-item w-full" id="<?= phpb_e($languageCode) ?>-page-route" name="route[<?= phpb_e($languageCode) ?>]" :value="route" :disabled="disabled" required />
<button class="btn join-item btn-outline text-2xl" @click.stop.prevent="disabled=!disabled" type="button" >
<i class="ph ph-pencil" x-show="disabled"></i>
<i class="ph ph-pencil-slash" x-show="!disabled"></i>
</button>
</div>
</div>
</div>
@@ -82,6 +82,31 @@ use Plugi\Setting;
</ul>
</td>
</tr>
<tr>
<th class="align-top">Config</th>
<td x-data="{show: false}">
<div>
<button @click="show = !show" class="btn btn-xs btn-outline" x-text="show ? 'hide' : 'show'"></button>
</div>
<pre class="mt-4" x-show="show"><?php
print_r(phpb_config());
?></pre>
</td>
</tr>
<tr>
<th class="align-top">Environment</th>
<td x-data="{show: false}">
<div class="">
<button @click="show = !show" class="btn btn-xs btn-outline" x-text="show ? 'hide' : 'show'"></button>
</div>
<pre class="mt-4" x-show="show"><?php
print_r([
'STAGE'=>$_ENV['STAGE'],
'BASE_URL'=>$_ENV['BASE_URL']
]);
?></pre>
</td>
</tr>
</tbody>
</table>
</div>
+5 -6
View File
@@ -45,7 +45,7 @@ class Plugi
/**
* Plugi constructor.
*
* @param array|null $config configuration in the format defined in config/config.example.php
* @param array|null $config configuration in the format defined in config
*/
public function __construct($config = [])
{
@@ -72,7 +72,7 @@ class Plugi
// create database connection, if enabled
if (phpb_config('storage.use_database')) {
$this->setDatabaseConnection(phpb_config('storage.database'));
$this->setDatabaseConnection();
$this->checkDatabaseDefinition();
$this->hydrateConfig();
}
@@ -132,7 +132,7 @@ class Plugi
$extLanguageFile = $extConfig['dir'] . '/lang/en.php';
}
if (file_exists($extLanguageFile)) {
$phpb_translations = array_merge_recursive_ex($phpb_translations, require $extLanguageFile);
$phpb_translations = phpb_array_merge_deep_array([$phpb_translations, require $extLanguageFile]);
}
}
@@ -194,13 +194,12 @@ class Plugi
/**
* Set the Plugi database connection using the given array.
*
* @param array $config
*/
public function setDatabaseConnection(array $config)
public function setDatabaseConnection()
{
global $phpb_db;
global $phpb_config;
$phpb_db = new DB($config);
$phpb_db = new DB();
$theme = Setting::get('selected_theme');
if ($theme) $phpb_config['theme']['active_theme'] = $theme;
$language = Setting::get('admin_language');
@@ -42,7 +42,7 @@ class BaseRepository
$this->db = $phpb_db;
// apply the configured prefix to the table set in the superclass and remove non-alphanumeric characters
$this->table = phpb_config('storage.database.prefix') . $this->removeNonAlphaNumeric($this->table);
$this->table = $_ENV['DATABASE_PREFIX'] . $this->removeNonAlphaNumeric($this->table);
}
/**
@@ -48,9 +48,11 @@ class MenuRepository extends BaseRepository implements MenuRepositoryContract
$langMenuPage = [
'id' => $id,
'title' => phpb_trans('languages.'.$pageTranslation->locale),
'lang' => $pageTranslation->locale,
'route' => $pageTranslation->route
'locale' => $pageTranslation->locale,
'route' => $pageTranslation->route,
'selected' => false,
];
if (phpb_current_language() === $pageTranslation->locale) $langMenuPage['selected'] = true;
$menu[] = $langMenuPage;
}
return $menu;
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+64 -24
View File
@@ -21,31 +21,66 @@ use Plugi\Repositories\MenuRepository;
<body>
<header>
<nav class="">
<ul class="flex flex-col">
<div class="navbar bg-base-100">
<div class="navbar-start">
<div class="dropdown">
<label tabindex="0" class="btn btn-ghost lg:hidden">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16" /></svg>
</label>
<ul tabindex="0" class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52">
<?php
foreach ((new MenuRepository)->getHydratedMenu('Main')['pages'] as $menuPage): ?>
<li>
<a href="<?= phpb_e($menuPage['route']) ?>"><?= phpb_e($menuPage['title']) ?></a>
</li>
<?php
endforeach;
?>
<!-- <li>-->
<!-- <a>Parent</a>-->
<!-- <ul class="p-2">-->
<!-- <li><a>Submenu 1</a></li>-->
<!-- <li><a>Submenu 2</a></li>-->
<!-- </ul>-->
<!-- </li>-->
</ul>
</div>
<a class="btn btn-ghost normal-case text-xl">daisyUI</a>
</div>
<div class="navbar-center hidden lg:flex">
<ul class="menu menu-horizontal px-1">
<?php
foreach ((new MenuRepository)->getHydratedMenu('Main')['pages'] as $menuPage): ?>
<li>
<a href="<?= phpb_e($menuPage['route']) ?>" class="block py-2 pr-4 pl-3 text-gray-700 border-b border-gray-100 hover:bg-gray-50 lg:hover:bg-transparent lg:border-0 lg:hover:text-primary-700 lg:p-0 dark:text-gray-400 lg:dark:hover:text-white dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent dark:border-gray-700">
<?= phpb_e($menuPage['title']) ?>
</a>
<a href="<?= phpb_e($menuPage['route']) ?>"><?= phpb_e($menuPage['title']) ?></a>
</li>
<?php
endforeach;
?>
<!-- <li tabindex="0">-->
<!-- <details>-->
<!-- <summary>Parent</summary>-->
<!-- <ul class="p-2">-->
<!-- <li><a>Submenu 1</a></li>-->
<!-- <li><a>Submenu 2</a></li>-->
<!-- </ul>-->
<!-- </details>-->
<!-- </li>-->
</ul>
</nav>
</header>
</div>
<div class="navbar-end">
<a class="btn">Button</a>
</div>
</div>
<main class="#main-content">
<?= $body ?>
</main>
<footer class="">
<div class="mx-auto max-w-screen-xl text-center">
<footer class="footer footer-center p-4 bg-base-300 text-base-content">
<div>
<ul class="flex flex-wrap justify-center items-center mb-6 text-gray-900 dark:text-white">
<?php
@@ -56,21 +91,26 @@ use Plugi\Repositories\MenuRepository;
<?php
endforeach;
?>
<li>
<div class="dropdown dropdown-hover dropdown-top">
<label tabindex="0" class="btn m-1 btn-xs"><i class="ph ph-translate"></i></label>
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
<?php
foreach ((new MenuRepository)->getLanguageMenu($page->getTranslation('page_id')) as $lang): ?>
<li x-data="{emoji: ''}" x-init="emoji = plugi.getFlagEmoji('<?= phpb_e($lang['locale']) ?>')">
<a href="<?= phpb_e($lang['route']) ?>">
<span x-text="emoji"></span>
<?= phpb_e($lang['title']) ?>
</a>
</li>
<?php
endforeach;
?>
</ul>
</div>
</li>
</ul>
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400">© <?= phpb_e(date("Y"))?></span>
<div class="dropdown dropdown-hover">
<label tabindex="0" class="btn m-1 btn-xs"><i class="ph ph-translate"></i></label>
<ul tabindex="0" class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52">
<?php
foreach ((new MenuRepository)->getLanguageMenu($page->getTranslation('page_id')) as $lang): ?>
<li>
<a href="<?= phpb_e($lang['route']) ?>"><?= phpb_e($lang['title']) ?></a>
</li>
<?php
endforeach;
?>
</ul>
</div>
<p>Copyright © <?= phpb_e(date("Y"))?></p>
</div>
</footer>
+247
View File
@@ -7,6 +7,10 @@
"": {
"name": "phpb-demo-template",
"version": "0.0.0",
"dependencies": {
"@types/alpinejs": "^3.7.2",
"alpinejs": "^3.12.2"
},
"devDependencies": {
"autoprefixer": "^10.4.14",
"daisyui": "^3.0.3",
@@ -413,6 +417,18 @@
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/source-map": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz",
"integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==",
"dev": true,
"optional": true,
"peer": true,
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.0",
"@jridgewell/trace-mapping": "^0.3.9"
}
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
@@ -470,12 +486,68 @@
"node": ">= 8"
}
},
"node_modules/@types/alpinejs": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/@types/alpinejs/-/alpinejs-3.7.2.tgz",
"integrity": "sha512-M/PAVysvGxOlhifP/6XmO8bj5HW9w+Ygr03PdryM3tCb1KuQEaAAvVcyeZc5T75PbjH3dCzy/M/w/nJEE0FTSg==",
"dependencies": {
"@vue/reactivity": "^3.2.26"
}
},
"node_modules/@types/alpinejs/node_modules/@vue/reactivity": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.3.4.tgz",
"integrity": "sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==",
"dependencies": {
"@vue/shared": "3.3.4"
}
},
"node_modules/@types/alpinejs/node_modules/@vue/shared": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.3.4.tgz",
"integrity": "sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ=="
},
"node_modules/@vue/reactivity": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.1.5.tgz",
"integrity": "sha512-1tdfLmNjWG6t/CsPldh+foumYFo3cpyCHgBYQ34ylaMsJ+SNHQ1kApMIa8jN+i593zQuaw3AdWH0nJTARzCFhg==",
"dependencies": {
"@vue/shared": "3.1.5"
}
},
"node_modules/@vue/shared": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.1.5.tgz",
"integrity": "sha512-oJ4F3TnvpXaQwZJNF3ZK+kLPHKarDmJjJ6jyzVNDKH9md1dptjC7lWR//jrGuLdek/U6iltWxqAnYOu8gCiOvA=="
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"dev": true
},
"node_modules/acorn": {
"version": "8.10.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz",
"integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==",
"dev": true,
"optional": true,
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/alpinejs": {
"version": "3.12.3",
"resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-3.12.3.tgz",
"integrity": "sha512-fLz2dfYQ3xCk7Ip8LiIpV2W+9brUyex2TAE7Z0BCvZdUDklJE+n+a8gCgLWzfZ0GzZNZu7HUP8Z0z6Xbm6fsSA==",
"dependencies": {
"@vue/reactivity": "~3.1.1"
}
},
"node_modules/any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
@@ -603,6 +675,14 @@
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
}
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true,
"optional": true,
"peer": true
},
"node_modules/camelcase-css": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
@@ -1589,6 +1669,17 @@
"semver": "bin/semver.js"
}
},
"node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true,
"optional": true,
"peer": true,
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
@@ -1598,6 +1689,18 @@
"node": ">=0.10.0"
}
},
"node_modules/source-map-support": {
"version": "0.5.21",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"dev": true,
"optional": true,
"peer": true,
"dependencies": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
@@ -1691,6 +1794,34 @@
"node": ">=14.0.0"
}
},
"node_modules/terser": {
"version": "5.18.2",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.18.2.tgz",
"integrity": "sha512-Ah19JS86ypbJzTzvUCX7KOsEIhDaRONungA4aYBjEP3JZRf4ocuDzTg4QWZnPn9DEMiMYGJPiSOy7aykoCc70w==",
"dev": true,
"optional": true,
"peer": true,
"dependencies": {
"@jridgewell/source-map": "^0.3.3",
"acorn": "^8.8.2",
"commander": "^2.20.0",
"source-map-support": "~0.5.20"
},
"bin": {
"terser": "bin/terser"
},
"engines": {
"node": ">=10"
}
},
"node_modules/terser/node_modules/commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true,
"optional": true,
"peer": true
},
"node_modules/thenify": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
@@ -2054,6 +2185,18 @@
"integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
"dev": true
},
"@jridgewell/source-map": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz",
"integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==",
"dev": true,
"optional": true,
"peer": true,
"requires": {
"@jridgewell/gen-mapping": "^0.3.0",
"@jridgewell/trace-mapping": "^0.3.9"
}
},
"@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
@@ -2104,12 +2247,64 @@
"fastq": "^1.6.0"
}
},
"@types/alpinejs": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/@types/alpinejs/-/alpinejs-3.7.2.tgz",
"integrity": "sha512-M/PAVysvGxOlhifP/6XmO8bj5HW9w+Ygr03PdryM3tCb1KuQEaAAvVcyeZc5T75PbjH3dCzy/M/w/nJEE0FTSg==",
"requires": {
"@vue/reactivity": "^3.2.26"
},
"dependencies": {
"@vue/reactivity": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.3.4.tgz",
"integrity": "sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==",
"requires": {
"@vue/shared": "3.3.4"
}
},
"@vue/shared": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.3.4.tgz",
"integrity": "sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ=="
}
}
},
"@vue/reactivity": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.1.5.tgz",
"integrity": "sha512-1tdfLmNjWG6t/CsPldh+foumYFo3cpyCHgBYQ34ylaMsJ+SNHQ1kApMIa8jN+i593zQuaw3AdWH0nJTARzCFhg==",
"requires": {
"@vue/shared": "3.1.5"
}
},
"@vue/shared": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.1.5.tgz",
"integrity": "sha512-oJ4F3TnvpXaQwZJNF3ZK+kLPHKarDmJjJ6jyzVNDKH9md1dptjC7lWR//jrGuLdek/U6iltWxqAnYOu8gCiOvA=="
},
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"dev": true
},
"acorn": {
"version": "8.10.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz",
"integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==",
"dev": true,
"optional": true,
"peer": true
},
"alpinejs": {
"version": "3.12.3",
"resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-3.12.3.tgz",
"integrity": "sha512-fLz2dfYQ3xCk7Ip8LiIpV2W+9brUyex2TAE7Z0BCvZdUDklJE+n+a8gCgLWzfZ0GzZNZu7HUP8Z0z6Xbm6fsSA==",
"requires": {
"@vue/reactivity": "~3.1.1"
}
},
"any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
@@ -2189,6 +2384,14 @@
"update-browserslist-db": "^1.0.11"
}
},
"buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true,
"optional": true,
"peer": true
},
"camelcase-css": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
@@ -2859,12 +3062,32 @@
}
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true,
"optional": true,
"peer": true
},
"source-map-js": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz",
"integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==",
"dev": true
},
"source-map-support": {
"version": "0.5.21",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"dev": true,
"optional": true,
"peer": true,
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
}
},
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
@@ -2935,6 +3158,30 @@
"sucrase": "^3.32.0"
}
},
"terser": {
"version": "5.18.2",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.18.2.tgz",
"integrity": "sha512-Ah19JS86ypbJzTzvUCX7KOsEIhDaRONungA4aYBjEP3JZRf4ocuDzTg4QWZnPn9DEMiMYGJPiSOy7aykoCc70w==",
"dev": true,
"optional": true,
"peer": true,
"requires": {
"@jridgewell/source-map": "^0.3.3",
"acorn": "^8.8.2",
"commander": "^2.20.0",
"source-map-support": "~0.5.20"
},
"dependencies": {
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true,
"optional": true,
"peer": true
}
}
},
"thenify": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
+4
View File
@@ -27,5 +27,9 @@
"tailwindcss": "^3.3.2",
"typescript": "^5.1.6",
"vite": "^4.3.9"
},
"dependencies": {
"@types/alpinejs": "^3.7.2",
"alpinejs": "^3.12.2"
}
}
@@ -0,0 +1,11 @@
const map: Record<string, string> = {
'en': 'us',
}
const localeMapper = (locale: string) => {
return Object.keys(map).includes(locale) ? map[locale] : locale
}
export {
localeMapper
}
+7
View File
@@ -0,0 +1,7 @@
export {};
declare global {
interface Window {
plugi: Record<string, unknown>;
}
}
+13
View File
@@ -1,2 +1,15 @@
import './style.css'
// import typescriptLogo from './typescript.svg'
import Alpine from 'alpinejs'
import {localeMapper} from "./helpers/localemapper.ts";
const getFlagEmoji = (locale: string)=> {
const countryCode = localeMapper(locale)
return String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt(0)))
}
window.plugi = {}
window.plugi.getFlagEmoji = getFlagEmoji
Alpine.start()