many updates

This commit is contained in:
Paul Spenke
2023-08-20 23:45:24 +08:00
parent 726d691054
commit 267d8004e0
15 changed files with 173 additions and 39 deletions
+8
View File
@@ -12,6 +12,14 @@ services:
- mysql
networks:
- backend
adminer:
image: adminer
ports:
- 63001:8080
links:
- mysql
networks:
- backend
mysql:
image: "mysql:8.0"
restart: 'always'
+3 -1
View File
@@ -16,7 +16,8 @@ return [
'name' => 'varchar(255)',
'layout' => 'varchar(255)',
'data' => 'longtext',
'slug' => 'varchar(255)',
'type' => 'varchar(63)',
'status' => 'varchar(63)',
'parent_id' => 'int',
'updated_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'created_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
@@ -40,6 +41,7 @@ return [
'meta_title' => 'varchar(255)',
'meta_description' => 'varchar(255)',
'route' => 'varchar(255)',
'target' => 'varchar(255)',
'updated_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'created_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
],
+1 -1
View File
File diff suppressed because one or more lines are too long
+6 -1
View File
@@ -32,7 +32,12 @@ return [
'page-created' => 'Seite erstellt',
'page-updated' => 'Seite aktualisiert',
'page-deleted' => 'Seite gelöscht',
'page-type' => 'Seitentyp',
'page-types' => [
'static' => 'Statische Seite',
'redirect' => 'Weiterleitung',
],
'target-redirect' => 'Ziel der Weiterleitung',
'files' => 'Dateien',
'settings' => 'Einstellungen',
'info' => 'Info',
+6 -1
View File
@@ -32,7 +32,12 @@ return [
'page-created' => 'Page successfully created',
'page-updated' => 'Page successfully updated',
'page-deleted' => 'Page removed',
'page-type' => 'Page type',
'page-types' => [
'static' => 'Static page',
'redirect' => 'Redirect',
],
'target-redirect' => 'Target of redirect',
'files' => 'Files',
'settings' => 'Settings',
'info' => 'Info',
+73 -4
View File
@@ -261,7 +261,7 @@ if (! function_exists('phpb_current_relative_url')) {
* Give the current URL relative to the base directory (the website's index.php entry point).
* This omits any parent directories from the URL in which the project is installed.
*/
function phpb_current_relative_url(): string
function phpb_current_relative_url($removeParameters = false): string
{
$baseUrl = $_ENV['BASE_URL'];
$baseUrl = rtrim($baseUrl, '/'. DIRECTORY_SEPARATOR);
@@ -269,6 +269,9 @@ if (! function_exists('phpb_current_relative_url')) {
$currentFullUrl = phpb_current_full_url();
$relativeUrl = substr($currentFullUrl, strlen($baseUrl));
$relativeUrl = ltrim($relativeUrl, '/'. DIRECTORY_SEPARATOR);
if($removeParameters) {
$relativeUrl = explode('?', $relativeUrl, 2)[0];
}
return '/' . $relativeUrl;
}
}
@@ -537,6 +540,61 @@ if (! function_exists('phpb_remove_non_alpha_numeric')) {
}
}
if (! function_exists('phpb_is_authenticated')) {
/**
* Create a slug (safe URL or path) of the given string.
*/
function phpb_is_authenticated(): bool
{
$auth = new \Plugi\Modules\Auth\Auth();
return $auth->isAuthenticated();
}
}
if (! function_exists('phpb_requires_authenticated')) {
/**
* Create a slug (safe URL or path) of the given string.
*/
function phpb_requires_authenticated(): void
{
if (!phpb_is_authenticated()) phpb_redirect('/', [], 403);
}
}
if (! function_exists('phpb_render_setting')) {
/**
* Create a slug (safe URL or path) of the given string.
*/
function phpb_render_setting(array $setting): void
{
$label = phpb_e($setting['label'] ?: $setting['name']);
$key = phpb_e($setting['key']);
$value = phpb_e($setting['value']);
switch ($setting['type']) {
case 'toggle':
echo <<<EOL
<div class="form-control" x-data="{state: $value}">
<label class="label cursor-pointer">
<span class="label-text">$label</span>
<input type='hidden' :value="state" name="$key">
<input type="checkbox" class="toggle" x-model="state" />
</label>
</div>
EOL;
case 'text':
echo <<<EOL
<div class="form-control w-full">
<label class="label">
<span class="label-text">$label</span>
</label>
<input type="text" name="$key" value="$value" class="input input-bordered w-full" />
</div>
EOL;
}
}
}
if (! function_exists('phpb_autoload')) {
/**
* Autoload classes from the Plugi package.
@@ -545,6 +603,7 @@ if (! function_exists('phpb_autoload')) {
{
// PSR-0 autoloader
$className = ltrim($className, '\\');
$isExtension = str_contains($className, 'Plugi\\Extensions\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
@@ -553,12 +612,22 @@ if (! function_exists('phpb_autoload')) {
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
// remove leading Plugi/ from the class path
$fileName = str_replace('Plugi' . DIRECTORY_SEPARATOR, '', $fileName);
if ($isExtension) {
$fileName = str_replace('Extensions' . DIRECTORY_SEPARATOR, '', $fileName);
$fileFragments = explode(DIRECTORY_SEPARATOR, $fileName, 2);
$extensionName = strtolower($fileFragments[0]);
if (key_exists($extensionName, \Plugi\Extensions::getConfigs())) {
$dir = \Plugi\Extensions::getConfigs()[$extensionName]['dir'];
require $dir . '/admin/Classes/' . $fileFragments[1];
}
} else {
// include class files starting in the src directory
require __DIR__ . '/../' . $fileName;
}
// include class files starting in the src directory
require __DIR__ . '/../' . $fileName;
}
}
+9 -9
View File
@@ -43,10 +43,10 @@ class Extensions
];
protected static $htmlBlocks = [
'head-end' => [],
'head' => [],
'body-start' => [],
'body-end' => [],
'admin-head-end' => [],
'admin-head' => [],
'admin-body-start' => [],
'admin-body-end' => [],
];
@@ -71,10 +71,8 @@ class Extensions
* @param string $html
* @param string $location
*/
public static function registerHtmlBlock(string $html, string $location = 'head-end') {
self::$assets[$location][] = [
'html' => $html,
];
public static function registerHtmlBlock(string $html, string $location = 'head') {
self::$htmlBlocks[$location][] = $html;
}
/**
@@ -181,7 +179,7 @@ class Extensions
continue;
}
$setting['value'] = $settingIns::get($setting['key']) ?: $setting['default'];
$hydrSettings[] = $setting;
$hydrSettings[$setting['name']] = $setting;
}
return $hydrSettings;
}
@@ -245,14 +243,16 @@ class Extensions
/**
* Get all header assets.
*/
public static function getHtmlBlocks(string $location = 'head-end') {
public static function getHtmlBlocks(string $location = 'head'): string
{
return implode('', self::$htmlBlocks[$location]);
}
/**
* Get all header assets.
*/
public static function getHeaderAssets() {
public static function getHeaderAssets(): array
{
return self::$assets['header'];
}
@@ -10,7 +10,7 @@
</head>
<body>
<div class="container">
<div class="container p-4">
<?php
require __DIR__ . '/' . $viewFile . '.php';
?>
@@ -15,15 +15,15 @@ if (isset($_GET['tab'])) {
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title><?= phpb_trans('website-manager.title') ?></title>
<link rel="icon" href="/plugi-core/dist/images/logo-color.png">
<?= phpb_registered_assets('admin-header') ?>
<?php phpb_registered_assets('admin-header') ?>
<link href="<?= phpb_asset('WebsiteManager.css') ?>" rel="stylesheet">
<link href="<?= phpb_asset('icons/duotone/style.css') ?>" rel="stylesheet">
<link href="<?= phpb_asset('icons/regular/style.css') ?>" rel="stylesheet">
<link href="<?= phpb_asset('icons/bold/style.css') ?>" rel="stylesheet">
<?= Extensions::getHtmlBlocks('head-end') ?>
<?= Extensions::getHtmlBlocks('admin-head') ?>
</head>
<body>
<?= Extensions::getHtmlBlocks('body-start') ?>
<?= Extensions::getHtmlBlocks('admin-body-start') ?>
<div class="drawer lg:drawer-open">
<input id="my-drawer-2" type="checkbox" class="drawer-toggle" />
@@ -90,6 +90,6 @@ if (isset($_GET['tab'])) {
</div>
<script src="<?= phpb_asset('WebsiteManager.js') ?>"></script>
<?= Extensions::getHtmlBlocks('body-end') ?>
<?= Extensions::getHtmlBlocks('admin-body-end') ?>
</body>
</html>
@@ -20,7 +20,7 @@ $pageTranslations = $page ? $page->getTranslations() : [];
?>
</div>
<div class="max-w-lg p-4 mx-auto">
<div class="max-w-lg p-4 mx-auto" x-data="{type: '<?= phpb_field_value('type', $page) ?? 'static' ?>'}">
<div class="form-control w-full mb-4">
<label class="label">
<span class="label-text"> <?= phpb_trans('website-manager.name') ?></span>
@@ -33,6 +33,26 @@ $pageTranslations = $page ? $page->getTranslations() : [];
</div>
<div class="form-control w-full mb-4">
<label class="label">
<span class="label-text"><?= phpb_trans('website-manager.page-type') ?></span>
<span class="label-text-alt"><?= phpb_trans('website-manager.required') ?></span> <!-- TODO add to lang -->
</label>
<select class="select select-bordered" x-model="type" id="type" name="type" required>
<?php
$types = ['static', 'redirect'];
$value = phpb_field_value('type', $page);
foreach ($types as $type):
if ($type === $value):
echo '<option value="' . phpb_e($type) . '" selected>' . phpb_trans('website-manager.page-types.'.$type) . '</option>';
else:
echo '<option value="' . phpb_e($type) . '">' . phpb_trans('website-manager.page-types.'.$type) . '</option>';
endif;
endforeach;
?>
</select>
</div>
<div class="form-control w-full mb-4" x-show="type !== 'redirect'">
<label class="label">
<span class="label-text"><?= phpb_trans('website-manager.layout') ?></span>
<span class="label-text-alt"><?= phpb_trans('website-manager.required') ?></span> <!-- TODO add to lang -->
@@ -64,31 +84,38 @@ $pageTranslations = $page ? $page->getTranslations() : [];
<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'] ?? '') ?>" @input="if(empty){route=`${locale}/${slugify($event.target.value)}`}" 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="type==='static'" />
</div>
<div class="form-control w-full mb-2">
<div class="form-control w-full mb-2" x-show="type === 'static'">
<label class="label" for="<?= phpb_e($languageCode) ?>-page-meta-title">
<span class="label-text"><?= phpb_trans('website-manager.page-meta-title') ?></span>
</label>
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-meta-title" name="meta_title[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['meta_title'] ?? '') ?>" />
</div>
<div class="form-control w-full mb-2">
<div class="form-control w-full mb-2" x-show="type === 'static'">
<label class="label" for="<?= phpb_e($languageCode) ?>-page-meta-description">
<span class="label-text"><?= phpb_trans('website-manager.page-meta-description') ?></span>
</label>
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-meta-description" name="meta_description[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['meta_description'] ?? '') ?>" />
</div>
<div class="form-control w-full mb-2" x-show="type === 'redirect'">
<label class="label" for="<?= phpb_e($languageCode) ?>-page-target-redirect">
<span class="label-text"><?= phpb_trans('website-manager.target-redirect') ?></span>
</label>
<input type="text" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-target-redirect" name="target[<?= phpb_e($languageCode) ?>]" value="<?= phpb_e($pageTranslations[$languageCode]['target'] ?? '') ?>" />
</div>
<div class="form-control w-full mb-2">
<label class="label" for="<?= phpb_e($languageCode) ?>-page-route">
<span class="label-text"><?= phpb_trans('website-manager.route') ?></span>
<span class="label-text-alt"><?= phpb_trans('website-manager.required') ?></span>
</label>
<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" >
<input type="text" :class="{'join-item': type !== 'redirect'}" class="input input-bordered w-full" id="<?= phpb_e($languageCode) ?>-page-route" name="route[<?= phpb_e($languageCode) ?>]" :value="route" :disabled="disabled && type !== 'redirect'" required />
<button class="btn join-item btn-outline text-2xl" @click.stop.prevent="disabled=!disabled" type="button" x-show="type !== 'redirect'">
<i class="ph ph-pencil" x-show="disabled"></i>
<i class="ph ph-pencil-slash" x-show="!disabled"></i>
</button>
@@ -68,7 +68,7 @@ use Plugi\Setting;
</tr>
<tr>
<th class="align-top">Installed extensions</th>
<td>
<td x-data="{show: false}">
<ul>
<?php
foreach (\Plugi\Extensions::getConfigs() as $ext) :
@@ -80,6 +80,12 @@ use Plugi\Setting;
endforeach;
?>
</ul>
<div>
<button @click="show = !show" class="btn btn-xs btn-outline" x-text="show ? 'hide' : 'show config'"></button>
</div>
<pre class="mt-4" x-show="show"><?php
print_r(\Plugi\Extensions::getConfigs());
?></pre>
</td>
</tr>
<tr>
@@ -26,10 +26,10 @@
</td>
<td class="actions">
<a href="<?= phpb_e(phpb_full_url($page->getRoute())) ?>" title="<?= phpb_trans('website-manager.view') ?>" target="_blank" class="btn btn-light btn-outline btn-sm btn-circle">
<a href="<?= phpb_e(phpb_full_url($page->getRoute())) ?>" title="<?= phpb_trans('website-manager.view') ?>" target="_blank" class="btn btn-light btn-outline btn-sm btn-circle <?= $page->get('type') === 'redirect' ? 'btn-disabled' : '' ?>">
<i class="text-xl ph-duotone ph-eye"></i>
</a>
<a href="<?= phpb_url('pagebuilder', ['page' => $page->getId()]) ?>" class="btn btn-primary hidden md:inline-flex btn-sm btn-circle" title="<?= phpb_trans('website-manager.edit') ?>">
<a href="<?= phpb_url('pagebuilder', ['page' => $page->getId()]) ?>" class="btn btn-primary hidden md:inline-flex btn-sm btn-circle <?= $page->get('type') === 'redirect' ? 'btn-disabled' : '' ?>" title="<?= phpb_trans('website-manager.edit') ?>">
<i class="text-xl ph-duotone ph-pencil-line"></i>
</a>
<a href="<?= phpb_url('website_manager', ['route' => 'page_settings', 'action' => 'edit', 'page' => $page->getId()]) ?>" title="<?= phpb_trans('website-manager.settings') ?>" class="btn btn-secondary btn-sm btn-circle">
+10 -7
View File
@@ -423,6 +423,13 @@ class Plugi
exit();
}
if(Extensions::getRoute(phpb_current_relative_url(true))){
$ext = include Extensions::getRoutes()[phpb_current_relative_url(true)];
if($ext !== 'continue'){
return true;
}
}
// try to find page in cache
$cache = phpb_instance('cache');
if (phpb_config('cache.enabled') &&
@@ -438,13 +445,6 @@ class Plugi
}
}
if(Extensions::getRoute(phpb_current_relative_url())){
$ext = include Extensions::getRoutes()[phpb_current_relative_url()];
if($ext !== 'continue'){
return true;
}
}
// let the page router resolve the current URL
$page = null;
$pageTranslation = $this->resolvePageLanguageVariantFromUrl(phpb_current_relative_url());
@@ -465,6 +465,9 @@ class Plugi
}
// render page if resolved
if ($page) {
if ($page->get('type') === 'redirect') {
phpb_redirect($pageTranslation->target);
}
// TODO add menu etc
$renderedContent = $this->pageBuilder->renderPage($page, $pageTranslation->locale);
if (!str_contains($pageTranslation->route, '/*')) {
@@ -50,6 +50,7 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
$page = parent::create([
'name' => $data['name'],
'layout' => $data['layout'],
'type' => $data['type'],
]);
if (! ($page instanceof PageContract)) {
throw new Exception("Page not of type PageContract");
@@ -77,6 +78,7 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
$updateResult = parent::update($page, [
'name' => $data['name'],
'layout' => $data['layout'],
'type' => $data['type'],
]);
$page->invalidateCache();
return $updateResult;
@@ -92,7 +94,7 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
protected function replaceTranslations(PageContract $page, array $data)
{
$activeLanguages = phpb_active_languages();
foreach (['title', 'meta_title', 'meta_description', 'route'] as $field) {
foreach (['title', 'meta_title', 'meta_description', 'route', 'target'] as $field) {
foreach ($activeLanguages as $languageCode => $languageTranslation) {
if (! isset($data[$field][$languageCode])) {
return false;
@@ -110,6 +112,7 @@ class PageRepository extends BaseRepository implements PageRepositoryContract
'meta_title' => $data['meta_title'][$languageCode],
'meta_description' => $data['meta_description'][$languageCode],
'route' => $data['route'][$languageCode],
'target' => $data['target'][$languageCode],
]);
}
+6
View File
@@ -1,5 +1,6 @@
<?php
use Plugi\Extensions;
use Plugi\Repositories\MenuRepository;
?>
@@ -17,9 +18,12 @@ use Plugi\Repositories\MenuRepository;
<link href="<?= phpb_asset('icons/bold/style.css') ?>" rel="stylesheet">
<link href="<?= phpb_theme_asset('dist/style.css') ?>" rel="stylesheet">
<?= Extensions::getHtmlBlocks() ?>
</head>
<body>
<?= Extensions::getHtmlBlocks('body-start') ?>
<div class="navbar bg-base-100">
<div class="navbar-start">
@@ -122,5 +126,7 @@ use Plugi\Repositories\MenuRepository;
scriptTag.dispatchEvent(new Event('run-script'));
});
</script>
<?= Extensions::getHtmlBlocks('body-end') ?>
</body>
</html>