handle languages
This commit is contained in:
@@ -16,6 +16,8 @@ return [
|
||||
'name' => 'varchar(255)',
|
||||
'layout' => 'varchar(255)',
|
||||
'data' => 'longtext',
|
||||
'slug' => 'varchar(255)',
|
||||
'parent_id' => 'int',
|
||||
'updated_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
||||
'created_at' => 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||
],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Plugi\Extensions;
|
||||
|
||||
if (! function_exists('phpb_e')) {
|
||||
@@ -10,7 +11,7 @@ if (! function_exists('phpb_e')) {
|
||||
* @param bool $doubleEncode
|
||||
* @return string
|
||||
*/
|
||||
function phpb_e($value, $doubleEncode = true)
|
||||
function phpb_e(string $value, bool $doubleEncode = true): string
|
||||
{
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', $doubleEncode);
|
||||
}
|
||||
@@ -20,11 +21,11 @@ if (! function_exists('phpb_encode_or_null')) {
|
||||
/**
|
||||
* Encode HTML special characters in a string, but preserve a null value if the passed input equals null.
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|null $value
|
||||
* @param bool $doubleEncode
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
function phpb_encode_or_null($value, $doubleEncode = true)
|
||||
function phpb_encode_or_null(?string $value, bool $doubleEncode = true): ?string
|
||||
{
|
||||
return is_null($value) ? null : phpb_e($value, $doubleEncode);
|
||||
}
|
||||
@@ -37,11 +38,11 @@ if (! function_exists('phpb_asset')) {
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function phpb_asset($path)
|
||||
function phpb_asset(string $path): string
|
||||
{
|
||||
$basePath = __DIR__ . '/../../dist/';
|
||||
$distPath = realpath($basePath . $path);
|
||||
$version = ($distPath && strpos($distPath, realpath($basePath)) === 0) ? filemtime($distPath) : '';
|
||||
$version = ($distPath && str_starts_with($distPath, realpath($basePath))) ? filemtime($distPath) : '';
|
||||
return phpb_full_url(phpb_config('general.assets_url') . '/' . $path) . '?v=' . $version;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +54,7 @@ if (! function_exists('phpb_theme_asset')) {
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function phpb_theme_asset($path)
|
||||
function phpb_theme_asset(string $path): string
|
||||
{
|
||||
$themeFolder = phpb_config('theme.folder_url') . '/' . phpb_config('theme.active_theme');
|
||||
return phpb_full_url($themeFolder . '/' . $path);
|
||||
@@ -68,12 +69,12 @@ if (! function_exists('phpb_flash')) {
|
||||
* @param bool $encode
|
||||
* @return bool|mixed
|
||||
*/
|
||||
function phpb_flash($key, $encode = true)
|
||||
function phpb_flash($key, bool $encode = true): mixed
|
||||
{
|
||||
global $phpb_flash;
|
||||
|
||||
// if no dot notation is used, return first dimension value or empty string
|
||||
if (strpos($key, '.') === false) {
|
||||
if (!str_contains($key, '.')) {
|
||||
if (! isset($phpb_flash[$key])) {
|
||||
return false;
|
||||
}
|
||||
@@ -109,12 +110,12 @@ if (! function_exists('phpb_config')) {
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
function phpb_config($key)
|
||||
function phpb_config(string $key): mixed
|
||||
{
|
||||
global $phpb_config;
|
||||
|
||||
// if no dot notation is used, return first dimension value or empty string
|
||||
if (strpos($key, '.') === false) {
|
||||
if (!str_contains($key, '.')) {
|
||||
return $phpb_config[$key] ?? '';
|
||||
}
|
||||
|
||||
@@ -137,16 +138,16 @@ if (! function_exists('phpb_trans')) {
|
||||
/**
|
||||
* Return the translation of the given key (as dot-separated multidimensional array selector).
|
||||
*
|
||||
* @param $key
|
||||
* @param string $key
|
||||
* @param array $parameters
|
||||
* @return string|array
|
||||
*/
|
||||
function phpb_trans($key, $parameters = [])
|
||||
function phpb_trans(string $key, array $parameters = []): array|string
|
||||
{
|
||||
global $phpb_translations;
|
||||
|
||||
// if no dot notation is used, return first dimension value or empty string
|
||||
if (strpos($key, '.') === false) {
|
||||
if (!str_contains($key, '.')) {
|
||||
return phpb_replace_placeholders($phpb_translations[$key] ?? '', $parameters);
|
||||
}
|
||||
|
||||
@@ -176,12 +177,13 @@ if (! function_exists('phpb_replace_placeholders')) {
|
||||
/**
|
||||
* Replace in the given string the given parameter placeholders with corresponding values.
|
||||
*
|
||||
* @param $string
|
||||
* @param string $string
|
||||
* @param array $parameters
|
||||
* @return string
|
||||
*/
|
||||
function phpb_replace_placeholders($string, $parameters = [])
|
||||
function phpb_replace_placeholders($string, array $parameters = [])
|
||||
{
|
||||
// TODO adapt for given array
|
||||
foreach ($parameters as $placeholder => $value) {
|
||||
$string = str_replace(':' . $placeholder, $value, $string);
|
||||
}
|
||||
@@ -193,14 +195,11 @@ if (! function_exists('phpb_replace_placeholders')) {
|
||||
if (! function_exists('phpb_full_url')) {
|
||||
/**
|
||||
* Give the full URL of a given URL which is relative to the base URL.
|
||||
*
|
||||
* @param string $urlRelativeToBaseUrl
|
||||
* @return string
|
||||
*/
|
||||
function phpb_full_url($urlRelativeToBaseUrl)
|
||||
function phpb_full_url(string $urlRelativeToBaseUrl): string
|
||||
{
|
||||
// if the URL is already a full URL, do not alter the URL
|
||||
if (strpos($urlRelativeToBaseUrl, 'http://') === 0 || strpos($urlRelativeToBaseUrl, 'https://') === 0) {
|
||||
if (str_starts_with($urlRelativeToBaseUrl, 'http://') || str_starts_with($urlRelativeToBaseUrl, 'https://')) {
|
||||
return $urlRelativeToBaseUrl;
|
||||
}
|
||||
|
||||
@@ -212,13 +211,8 @@ if (! function_exists('phpb_full_url')) {
|
||||
if (! function_exists('phpb_url')) {
|
||||
/**
|
||||
* Give the full URL of a given public path.
|
||||
*
|
||||
* @param string $module
|
||||
* @param array $parameters
|
||||
* @param bool $fullUrl
|
||||
* @return string
|
||||
*/
|
||||
function phpb_url($module, array $parameters = [], $fullUrl = true)
|
||||
function phpb_url(string $module, array $parameters = [], bool $fullUrl = true): string
|
||||
{
|
||||
$url = $fullUrl ? phpb_full_url('') : '';
|
||||
$url .= phpb_config($module . '.url');
|
||||
@@ -239,10 +233,8 @@ if (! function_exists('phpb_url')) {
|
||||
if (! function_exists('phpb_current_full_url')) {
|
||||
/**
|
||||
* Give the current full URL.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function phpb_current_full_url()
|
||||
function phpb_current_full_url(): ?string
|
||||
{
|
||||
// return null when running form CLI
|
||||
if (! isset($_SERVER['SERVER_NAME']) || ! isset($_SERVER['REQUEST_URI'])) {
|
||||
@@ -256,8 +248,7 @@ if (! function_exists('phpb_current_full_url')) {
|
||||
}
|
||||
|
||||
$currentFullUrl = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . urldecode($_SERVER['REQUEST_URI']);
|
||||
$currentFullUrl = rtrim($currentFullUrl, '/' . DIRECTORY_SEPARATOR);
|
||||
return $currentFullUrl;
|
||||
return rtrim($currentFullUrl, '/' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,10 +256,8 @@ 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.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function phpb_current_relative_url()
|
||||
function phpb_current_relative_url(): string
|
||||
{
|
||||
$baseUrl = phpb_config('general.base_url');
|
||||
$baseUrl = rtrim($baseUrl, '/'. DIRECTORY_SEPARATOR);
|
||||
@@ -283,17 +272,15 @@ if (! function_exists('phpb_current_relative_url')) {
|
||||
if (! function_exists('phpb_current_language')) {
|
||||
/**
|
||||
* Give the current language based on the current URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function phpb_current_language()
|
||||
function phpb_current_language(): string
|
||||
{
|
||||
$urlComponents = explode('/', phpb_current_relative_url());
|
||||
// remove empty values and reset array key numbering
|
||||
$urlComponents = array_values(array_filter($urlComponents));
|
||||
if (! empty($urlComponents)) {
|
||||
foreach (phpb_active_languages() as $languageCode => $languageTranslation) {
|
||||
if ($urlComponents[0] === $languageCode) {
|
||||
if (explode('?', $urlComponents[0])[0] === $languageCode) {
|
||||
return $languageCode;
|
||||
}
|
||||
}
|
||||
@@ -315,11 +302,8 @@ if (! function_exists('phpb_current_language')) {
|
||||
if (! function_exists('phpb_in_module')) {
|
||||
/**
|
||||
* Return whether we are currently accessing the given module.
|
||||
*
|
||||
* @param string $module
|
||||
* @return bool
|
||||
*/
|
||||
function phpb_in_module($module)
|
||||
function phpb_in_module(string $module): bool
|
||||
{
|
||||
$url = phpb_url($module, [], false);
|
||||
$currentUrl = explode('?', phpb_current_relative_url(), 2)[0];
|
||||
@@ -330,10 +314,8 @@ if (! function_exists('phpb_in_module')) {
|
||||
if (! function_exists('phpb_themes')) {
|
||||
/**
|
||||
* Return all theme configs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function phpb_themes()
|
||||
function phpb_themes(): array
|
||||
{
|
||||
$themes = [];
|
||||
|
||||
@@ -356,12 +338,8 @@ if (! function_exists('phpb_themes')) {
|
||||
if (! function_exists('phpb_on_url')) {
|
||||
/**
|
||||
* Return whether we are currently on the given URL.
|
||||
*
|
||||
* @param string $module
|
||||
* @param array $parameters
|
||||
* @return bool
|
||||
*/
|
||||
function phpb_on_url($module, array $parameters = [])
|
||||
function phpb_on_url(string $module, array $parameters = []): bool
|
||||
{
|
||||
$url = phpb_url($module, $parameters, false);
|
||||
return phpb_current_relative_url() === $url;
|
||||
@@ -371,10 +349,8 @@ if (! function_exists('phpb_on_url')) {
|
||||
if (! function_exists('phpb_set_in_editmode')) {
|
||||
/**
|
||||
* Set whether the current page is being load in edit mode (i.e. inside the page builder).
|
||||
*
|
||||
* @param bool $inEditMode
|
||||
*/
|
||||
function phpb_set_in_editmode($inEditMode = true)
|
||||
function phpb_set_in_editmode(bool $inEditMode = true): void
|
||||
{
|
||||
global $phpb_in_editmode;
|
||||
|
||||
@@ -385,10 +361,8 @@ if (! function_exists('phpb_set_in_editmode')) {
|
||||
if (! function_exists('phpb_in_editmode')) {
|
||||
/**
|
||||
* Return whether the current page is load in edit mode (i.e. inside the page builder).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function phpb_in_editmode()
|
||||
function phpb_in_editmode(): bool
|
||||
{
|
||||
global $phpb_in_editmode;
|
||||
|
||||
@@ -399,12 +373,8 @@ if (! function_exists('phpb_in_editmode')) {
|
||||
if (! function_exists('phpb_redirect')) {
|
||||
/**
|
||||
* Redirect to the given URL with optional session flash data.
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $flashData
|
||||
* @param $statusCode
|
||||
*/
|
||||
function phpb_redirect($url, $flashData = [], $statusCode = 302)
|
||||
#[NoReturn] function phpb_redirect(string $url, array $flashData = [], int $statusCode = 302): void
|
||||
{
|
||||
if (! empty($flashData)) {
|
||||
$_SESSION["phpb_flash"] = $flashData;
|
||||
@@ -418,10 +388,8 @@ if (! function_exists('phpb_redirect')) {
|
||||
if (! function_exists('phpb_route_parameters')) {
|
||||
/**
|
||||
* Return the named route parameters resolved from the current URL.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
function phpb_route_parameters()
|
||||
function phpb_route_parameters(): ?array
|
||||
{
|
||||
global $phpb_route_parameters;
|
||||
|
||||
@@ -432,11 +400,8 @@ if (! function_exists('phpb_route_parameters')) {
|
||||
if (! function_exists('phpb_route_parameter')) {
|
||||
/**
|
||||
* Return the value of the given named route parameter resolved from the current URL.
|
||||
*
|
||||
* @param string $parameter
|
||||
* @return string|null
|
||||
*/
|
||||
function phpb_route_parameter($parameter)
|
||||
function phpb_route_parameter(string $parameter): ?string
|
||||
{
|
||||
global $phpb_route_parameters;
|
||||
|
||||
@@ -447,12 +412,8 @@ if (! function_exists('phpb_route_parameter')) {
|
||||
if (! function_exists('phpb_field_value')) {
|
||||
/**
|
||||
* Return the posted value or the attribute value of the given instance, or null if no value was found.
|
||||
*
|
||||
* @param $attribute
|
||||
* @param object $instance
|
||||
* @return string|null
|
||||
*/
|
||||
function phpb_field_value($attribute, $instance = null)
|
||||
function phpb_field_value(string $attribute, object $instance = null): ?string
|
||||
{
|
||||
if (isset($_POST[$attribute])) {
|
||||
return phpb_encode_or_null($_POST[$attribute]);
|
||||
@@ -471,10 +432,8 @@ if (! function_exists('phpb_field_value')) {
|
||||
if (! function_exists('phpb_active_languages')) {
|
||||
/**
|
||||
* Return the list of all active languages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function phpb_active_languages()
|
||||
function phpb_active_languages(): array
|
||||
{
|
||||
$configLanguageCode = phpb_config('general.language');
|
||||
$languages = phpb_instance('setting')::get('languages') ?? [$configLanguageCode];
|
||||
@@ -511,7 +470,7 @@ if (! function_exists('phpb_instance')) {
|
||||
* @param array $params
|
||||
* @return object|null
|
||||
*/
|
||||
function phpb_instance(string $name, $params = [])
|
||||
function phpb_instance(string $name, array $params = []): ?object
|
||||
{
|
||||
if (phpb_config($name . '.class')) {
|
||||
$className = phpb_config($name . '.class');
|
||||
@@ -535,7 +494,7 @@ if (! function_exists('phpb_static')) {
|
||||
* @param string $name the name of the config main section in which the class path is defined
|
||||
* @return object|string|null
|
||||
*/
|
||||
function phpb_static(string $name)
|
||||
function phpb_static(string $name): object|string|null
|
||||
{
|
||||
if (phpb_config($name . '.class')) {
|
||||
return phpb_config($name . '.class');
|
||||
@@ -553,12 +512,8 @@ if (! function_exists('phpb_static')) {
|
||||
if (! function_exists('phpb_slug')) {
|
||||
/**
|
||||
* Create a slug (safe URL or path) of the given string.
|
||||
*
|
||||
* @param string $text
|
||||
* @param false $allowSlashes
|
||||
* @return string
|
||||
*/
|
||||
function phpb_slug(string $text, $allowSlashes = false)
|
||||
function phpb_slug(string $text, bool $allowSlashes = false): string
|
||||
{
|
||||
if ($allowSlashes) {
|
||||
return strtolower(trim(preg_replace('/[^A-Za-z0-9-\/]+/', '-', $text)));
|
||||
@@ -571,10 +526,8 @@ if (! function_exists('phpb_slug')) {
|
||||
if (! function_exists('phpb_autoload')) {
|
||||
/**
|
||||
* Autoload classes from the Plugi package.
|
||||
*
|
||||
* @param string $className
|
||||
*/
|
||||
function phpb_autoload($className)
|
||||
function phpb_autoload(string $className): void
|
||||
{
|
||||
// PSR-0 autoloader
|
||||
$className = ltrim($className, '\\');
|
||||
@@ -598,11 +551,9 @@ if (! function_exists('phpb_autoload')) {
|
||||
if (! function_exists('phpb_registered_assets')) {
|
||||
/**
|
||||
* Render all manually registered assets.
|
||||
*
|
||||
* @param $location
|
||||
* @return void
|
||||
*/
|
||||
function phpb_registered_assets($location = 'header') {
|
||||
function phpb_registered_assets(string $location = 'header'): void
|
||||
{
|
||||
$assets = [];
|
||||
if($location === 'header'){
|
||||
$assets = Extensions::getHeaderAssets();
|
||||
@@ -628,3 +579,27 @@ if (! function_exists('phpb_registered_assets')) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('array_merge_recursive_ex')) {
|
||||
/**
|
||||
* Deep merging
|
||||
*/
|
||||
function array_merge_recursive_ex(array $array1, array $array2): array
|
||||
{
|
||||
$merged = $array1;
|
||||
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
$merged[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>PageBuilder</title>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
@@ -9,7 +9,7 @@ if (isset($_GET['tab'])) {
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
@@ -125,6 +125,17 @@ class Plugi
|
||||
if (file_exists($themeTranslationsFolder . '/' . $language . '.php')) {
|
||||
$phpb_translations = array_merge($phpb_translations, require $themeTranslationsFolder . '/' . $language . '.php');
|
||||
}
|
||||
|
||||
foreach (Extensions::getConfigs() as $ext => $extConfig) {
|
||||
$extLanguageFile = $extConfig['dir'] . '/lang/' . $language . '.php';
|
||||
if (! file_exists($extLanguageFile)) {
|
||||
$extLanguageFile = $extConfig['dir'] . '/lang/en.php';
|
||||
}
|
||||
if (file_exists($extLanguageFile)) {
|
||||
$phpb_translations = array_merge_recursive_ex($phpb_translations, require $extLanguageFile);
|
||||
}
|
||||
}
|
||||
|
||||
return $phpb_translations;
|
||||
}
|
||||
|
||||
@@ -144,6 +155,7 @@ class Plugi
|
||||
if ($entry->isDir() && ! $entry->isDot() && file_exists($extensionFile) && file_exists($configFile)) {
|
||||
require $extensionFile;
|
||||
$extConfig = include($configFile);
|
||||
$extConfig['dir'] = 'extensions/' . $extFolder;
|
||||
$extKey = $extConfig['identifier'];
|
||||
Extensions::registerConfig($extKey, $extConfig);
|
||||
if(array_key_exists('assets', $extConfig) && is_array($extConfig['assets'])){
|
||||
@@ -400,13 +412,13 @@ class Plugi
|
||||
// if we are on the URL of an upload, return uploaded file
|
||||
// (note: this is a fallback option used if .htaccess does not whitelist direct access to the /uploads folder.
|
||||
// allowing direct /uploads access via .htaccess is preferred since it gives faster loading time)
|
||||
if (strpos(phpb_current_relative_url(), phpb_config('general.uploads_url') . '/') === 0) {
|
||||
if (str_starts_with(phpb_current_relative_url(), phpb_config('general.uploads_url') . '/')) {
|
||||
$this->handleUploadedFileRequest();
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit();
|
||||
}
|
||||
// if we are on the URL of a Plugi asset, return the asset
|
||||
if (strpos(phpb_current_relative_url(), phpb_config('general.assets_url') . '/') === 0) {
|
||||
if (str_starts_with(phpb_current_relative_url(), phpb_config('general.assets_url') . '/')) {
|
||||
$this->handlePageBuilderAssetRequest();
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit();
|
||||
@@ -454,8 +466,9 @@ class Plugi
|
||||
}
|
||||
// render page if resolved
|
||||
if ($page) {
|
||||
// TODO add menu etc
|
||||
$renderedContent = $this->pageBuilder->renderPage($page, $pageTranslation->locale);
|
||||
if (strpos($pageTranslation->route, '/*') === false) {
|
||||
if (!str_contains($pageTranslation->route, '/*')) {
|
||||
$this->cacheRenderedPage($renderedContent);
|
||||
}
|
||||
echo $renderedContent;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Plugi\Repositories;
|
||||
|
||||
use Plugi\Contracts\MenuRepositoryContract;
|
||||
use Plugi\Contracts\PageTranslationContract;
|
||||
|
||||
class MenuRepository extends BaseRepository implements MenuRepositoryContract
|
||||
{
|
||||
@@ -33,6 +34,28 @@ class MenuRepository extends BaseRepository implements MenuRepositoryContract
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one language switcher menu
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getLanguageMenu($id)
|
||||
{
|
||||
$menu = [];
|
||||
$pageTranslationsRepo = new PageTranslationRepository();
|
||||
$pageTranslations = $pageTranslationsRepo->findWhere('page_id', $id);
|
||||
foreach ($pageTranslations as $pageTranslation) {
|
||||
$langMenuPage = [
|
||||
'id' => $id,
|
||||
'title' => phpb_trans('languages.'.$pageTranslation->locale),
|
||||
'lang' => $pageTranslation->locale,
|
||||
'route' => $pageTranslation->route
|
||||
];
|
||||
$menu[] = $langMenuPage;
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one hydrated menu with the given name.
|
||||
*
|
||||
@@ -42,6 +65,7 @@ class MenuRepository extends BaseRepository implements MenuRepositoryContract
|
||||
public function getHydratedMenu(string $name)
|
||||
{
|
||||
$pageRepository = new PageRepository;
|
||||
$pageTranslationsRepo = new PageTranslationRepository();
|
||||
$pages = $pageRepository->getAll();
|
||||
$menu = $this->findWhere('name', $name)[0];
|
||||
$menuPages = explode(',',$menu['pages']);
|
||||
@@ -49,11 +73,19 @@ class MenuRepository extends BaseRepository implements MenuRepositoryContract
|
||||
foreach ($pages as $page) {
|
||||
$key = array_search($page->getId(), $menuPages);
|
||||
if($key === false) continue;
|
||||
$hyMenuPages[$key] = [
|
||||
$hyMenuPage = [
|
||||
'id' => $page->getId(),
|
||||
'title' => $page->getName(),
|
||||
'route' => $page->getRoute()
|
||||
];
|
||||
$pageTranslations = $pageTranslationsRepo->findWhere('page_id', $page->getId());
|
||||
foreach ($pageTranslations as $pageTranslation) {
|
||||
if ($pageTranslation->locale !== phpb_current_language()) continue;
|
||||
$hyMenuPage['route'] = $pageTranslation->route;
|
||||
$hyMenuPage['title'] = $pageTranslation->title;
|
||||
}
|
||||
|
||||
$hyMenuPages[$key] = $hyMenuPage;
|
||||
}
|
||||
ksort($hyMenuPages);
|
||||
|
||||
|
||||
+1
-2072
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@ use Plugi\Repositories\MenuRepository;
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
@@ -12,6 +12,9 @@ use Plugi\Repositories\MenuRepository;
|
||||
<title><?= phpb_e($page->getTranslation('meta_title')) ?></title>
|
||||
<meta name="description" content="<?= phpb_e($page->getTranslation('meta_description')) ?>">
|
||||
|
||||
<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">
|
||||
|
||||
<link href="<?= phpb_theme_asset('dist/style.css') ?>" rel="stylesheet">
|
||||
</head>
|
||||
@@ -24,10 +27,10 @@ use Plugi\Repositories\MenuRepository;
|
||||
|
||||
<?php
|
||||
|
||||
foreach ((new MenuRepository)->getHydratedMenu('Main')['pages'] as $page): ?>
|
||||
foreach ((new MenuRepository)->getHydratedMenu('Main')['pages'] as $menuPage): ?>
|
||||
<li>
|
||||
<a href="<?= phpb_e($page['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($page['title']) ?>
|
||||
<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>
|
||||
</li>
|
||||
<?php
|
||||
@@ -46,15 +49,28 @@ use Plugi\Repositories\MenuRepository;
|
||||
<ul class="flex flex-wrap justify-center items-center mb-6 text-gray-900 dark:text-white">
|
||||
<?php
|
||||
|
||||
foreach ((new MenuRepository)->getHydratedMenu('Footer')['pages'] as $page): ?>
|
||||
foreach ((new MenuRepository)->getHydratedMenu('Footer')['pages'] as $menuPage): ?>
|
||||
<li>
|
||||
<a href="<?= phpb_e($page['route']) ?>" class="mr-4 hover:underline md:mr-6 "><?= phpb_e($page['title']) ?></a>
|
||||
<a href="<?= phpb_e($menuPage['route']) ?>" class="mr-4 hover:underline md:mr-6 "><?= phpb_e($menuPage['title']) ?></a>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</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>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
Generated
+78
@@ -9,6 +9,7 @@
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^10.4.14",
|
||||
"daisyui": "^3.0.3",
|
||||
"npm-watch": "^0.11.0",
|
||||
"postcss": "^8.4.24",
|
||||
"tailwindcss": "^3.3.2",
|
||||
@@ -670,6 +671,12 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/colord": {
|
||||
"version": "2.9.3",
|
||||
"resolved": "https://registry.npmjs.org/colord/-/colord-2.9.3.tgz",
|
||||
"integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
|
||||
@@ -685,6 +692,16 @@
|
||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/css-selector-tokenizer": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz",
|
||||
"integrity": "sha512-Jd6Ig3/pe62/qe5SBPTN8h8LeUg/pT4lLgtavPf7updwwHpvFzxvOQBHYj2LZDMjUnBzgvIUSjRcf6oT5HzHFg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"cssesc": "^3.0.0",
|
||||
"fastparse": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"node_modules/cssesc": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
|
||||
@@ -697,6 +714,26 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/daisyui": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-3.2.1.tgz",
|
||||
"integrity": "sha512-gIqE6wiqoJt9G8+n3R/SwLeUnpNCE2eDhT73rP0yZYVaM7o6zVcakBH3aEW5RGpx3UkonPiLuvcgxRcb2lE8TA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"colord": "^2.9",
|
||||
"css-selector-tokenizer": "^0.8",
|
||||
"postcss": "^8",
|
||||
"postcss-js": "^4",
|
||||
"tailwindcss": "^3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.9.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/daisyui"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
|
||||
@@ -798,6 +835,12 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fastparse": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.2.tgz",
|
||||
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/fastq": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
|
||||
@@ -2185,6 +2228,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"colord": {
|
||||
"version": "2.9.3",
|
||||
"resolved": "https://registry.npmjs.org/colord/-/colord-2.9.3.tgz",
|
||||
"integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==",
|
||||
"dev": true
|
||||
},
|
||||
"commander": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
|
||||
@@ -2197,12 +2246,35 @@
|
||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||
"dev": true
|
||||
},
|
||||
"css-selector-tokenizer": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz",
|
||||
"integrity": "sha512-Jd6Ig3/pe62/qe5SBPTN8h8LeUg/pT4lLgtavPf7updwwHpvFzxvOQBHYj2LZDMjUnBzgvIUSjRcf6oT5HzHFg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cssesc": "^3.0.0",
|
||||
"fastparse": "^1.1.2"
|
||||
}
|
||||
},
|
||||
"cssesc": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz",
|
||||
"integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==",
|
||||
"dev": true
|
||||
},
|
||||
"daisyui": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/daisyui/-/daisyui-3.2.1.tgz",
|
||||
"integrity": "sha512-gIqE6wiqoJt9G8+n3R/SwLeUnpNCE2eDhT73rP0yZYVaM7o6zVcakBH3aEW5RGpx3UkonPiLuvcgxRcb2lE8TA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colord": "^2.9",
|
||||
"css-selector-tokenizer": "^0.8",
|
||||
"postcss": "^8",
|
||||
"postcss-js": "^4",
|
||||
"tailwindcss": "^3"
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
|
||||
@@ -2290,6 +2362,12 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"fastparse": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.2.tgz",
|
||||
"integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==",
|
||||
"dev": true
|
||||
},
|
||||
"fastq": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "^10.4.14",
|
||||
"daisyui": "^3.0.3",
|
||||
"npm-watch": "^0.11.0",
|
||||
"postcss": "^8.4.24",
|
||||
"tailwindcss": "^3.3.2",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="<?= phpb_current_language() ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
|
||||
@@ -27,7 +27,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
require('flowbite/plugin'),
|
||||
],
|
||||
require("daisyui")
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user