Skip to content

Commit

Permalink
Move some global functions to ViewHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Feb 11, 2024
1 parent cd4f2fe commit db978e1
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 43 deletions.
16 changes: 16 additions & 0 deletions app/controllers/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ public function dateFormat(mixed $tstamp): string
$formatter->setPattern(\Aurora\App\Setting::get('date_format') ?? '');
return $formatter->format($tstamp);
}

/**
* @see \Aurora\System\Helper::getUrl
*/
public function url(string $path = ''): string
{
return \Aurora\System\Helper::getUrl($path);
}

/**
* @see \Aurora\System\Language::getCode
*/
public function lang(): string
{
return \Aurora\System\Container::get('language')->getCode();
}
}
2 changes: 1 addition & 1 deletion app/views/admin/dashboard.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('dashboard') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/emails/password_restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<body style="display: flex; flex-direction: column; background-color: #f6f8fa; font-size: 14px; font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif; margin: 20px;">
<div style="display: flex; flex-direction: column; background-color: white; border-radius: 8px; padding: 20px; box-shadow: 0px 0px 8px 0px #e7e7e7;">
<p style="margin: 0;"><?= t('someone_requested_password_restore') ?></p>
<a style="background-color: #25292e; align-self: flex-start; color: white; text-decoration: none; padding: 10px 20px; border-radius: 6px; margin-top: 20px;" href="<?= e(url('admin/new_password?hash=' . $hash)) ?>" target="_blank"><?= t('click_to_restore_password') ?></a>
<a style="background-color: #25292e; align-self: flex-start; color: white; text-decoration: none; padding: 10px 20px; border-radius: 6px; margin-top: 20px;" href="<?= e($this->url('admin/new_password?hash=' . $hash)) ?>" target="_blank"><?= t('click_to_restore_password') ?></a>
</div>
<a href="<?= e(url()) ?>" style="align-self: center; margin-top: 20px;"><?= e(url()) ?></a>
<a href="<?= e($this->url()) ?>" style="align-self: center; margin-top: 20px;"><?= e($this->url()) ?></a>
</body>
</html>
2 changes: 1 addition & 1 deletion app/views/admin/link.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('link') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= e("$title - " . setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/login.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('sign_in') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/page.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('page') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand All @@ -18,7 +18,7 @@
<button class="delete" onclick="remove(this);" <?php if (!$can_edit_page): ?> disabled <?php endif ?>>
<?= $this->include('icons/trash.svg') ?>
</button>
<button onclick="window.open(<?= e(js(url($page['slug']))) ?>, '_blank').focus()"><?= $this->include('icons/eye.svg') ?></button>
<button onclick="window.open(<?= e(js($this->url($page['slug']))) ?>, '_blank').focus()"><?= $this->include('icons/eye.svg') ?></button>
<?php endif ?>
<button id="save" onclick="save();" <?php if (!$can_edit_page): ?> disabled <?php endif ?>><?= t('save') ?></button>
</div>
Expand Down Expand Up @@ -85,7 +85,7 @@
</div>
<div class="input-group">
<label for="canonical-url"><?= t('canonical_url') ?></label>
<input id="canonical-url" name="canonical_url" type="text" placeholder="<?= e(url('/about')) ?>" value="<?= e($page['canonical_url'] ?? '') ?>"/>
<input id="canonical-url" name="canonical_url" type="text" placeholder="<?= e($this->url('/about')) ?>" value="<?= e($page['canonical_url'] ?? '') ?>"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -119,7 +119,7 @@ function remove(btn) {
}

function updateUrl() {
let url = <?= js(url()) ?> + '/' + get('#slug').value;
let url = <?= js($this->url()) ?> + '/' + get('#slug').value;
get('#page-link').innerHTML = url;
get('#page-link').setAttribute('href', url);
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/partials/lists/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="three-dots" onclick="return false" dropdown>
<?= $this->include('icons/dots.svg') ?>
<div class="dropdown-menu">
<div onclick="copyPath(<?= e(js(url($file_path))) ?>)"><?= $this->include('icons/clipboard.svg') ?> <?= t('copy_path') ?></div>
<div onclick="copyPath(<?= e(js($this->url($file_path))) ?>)"><?= $this->include('icons/clipboard.svg') ?> <?= t('copy_path') ?></div>
<?php if (\Aurora\App\Permission::can('edit_media')): ?>
<div onclick="openDuplicateDialog(<?= e(js($i)) ?>)"><?= $this->include('icons/duplicate.svg') ?> <?= t('duplicate') ?>…</div>
<div onclick="openMoveDialog(<?= e(js($i)) ?>)"><?= $this->include('icons/move_file.svg') ?> <?= t('move') ?>…</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/partials/lists/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="three-dots" onclick="return false" dropdown>
<?= $this->include('icons/dots.svg') ?>
<div class="dropdown-menu">
<div onclick="window.open(<?= e(js(url($page['slug']))) ?>, '_blank').focus()"><?= $this->include('icons/eye.svg') ?> <?= t('view') ?></div>
<div onclick="window.open(<?= e(js($this->url($page['slug']))) ?>, '_blank').focus()"><?= $this->include('icons/eye.svg') ?> <?= t('view') ?></div>
<?php if (\Aurora\App\Permission::can('edit_pages')): ?>
<div
class="danger"
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/partials/nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a href="/admin/dashboard">
<?= $this->include('icons/home.svg') ?> <?= t('dashboard') ?>
</a>
<a href="<?= e(url()) ?>" target="_blank">
<a href="<?= e($this->url()) ?>" target="_blank">
<?= $this->include('icons/window.svg') ?> <?= t('view_site') ?>
</a>
<a href="/admin/pages" separator>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/password_restore.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('restore_your_password') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('post') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down Expand Up @@ -105,7 +105,7 @@
</div>
<div class="input-group">
<label for="canonical-url"><?= t('canonical_url') ?></label>
<input id="canonical-url" name="canonical_url" type="text" placeholder="<?= e(url(setting('blog_url') . '/lorem-ipsum')) ?>" value="<?= e($post['canonical_url'] ?? '') ?>"/>
<input id="canonical-url" name="canonical_url" type="text" placeholder="<?= e($this->url(setting('blog_url') . '/lorem-ipsum')) ?>" value="<?= e($post['canonical_url'] ?? '') ?>"/>
</div>
</div>
</div>
Expand Down Expand Up @@ -146,7 +146,7 @@ function updateUrl() {
return;
}

let url = <?= js(url(setting('blog_url'))) ?> + '/' + slug;
let url = <?= js($this->url(setting('blog_url'))) ?> + '/' + slug;
get('#post-link').innerHTML = url;
get('#post-link').setAttribute('href', url);
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('settings') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tag.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('tag') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/user.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<?php $current_user = !empty($user) && $user['id'] == $_SESSION['user']['id'] ?>
<?php $can_edit_user = \Aurora\App\Permission::can('edit_users'); ?>
<?php $title = t($current_user ? 'your_user' : 'user'); ?>
Expand Down
4 changes: 2 additions & 2 deletions app/views/themes/default/blog.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= e("$title - " . setting('title')) ?></title>
<?= $this->include('themes/default/partials/head.php') ?>
Expand All @@ -10,7 +10,7 @@
<meta property="og:title" content="<?= e(setting('meta_title')) ?>"/>
<meta property="og:description" content="<?= e(setting('meta_description')) ?>"/>
<?php endif ?>
<link rel="canonical" href="<?= e(url($_SERVER['REQUEST_URI'])) ?>"/>
<link rel="canonical" href="<?= e($this->url($_SERVER['REQUEST_URI'])) ?>"/>
</head>
<body>
<?= $this->include('themes/default/partials/header.php') ?>
Expand Down
4 changes: 2 additions & 2 deletions app/views/themes/default/information.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= e(setting('title')) ?></title>
<?= $this->include('themes/default/partials/head.php') ?>
<link rel="stylesheet" href="<?= e($this->getFileQuery('/public/assets/css/themes/default/information.css')) ?>">
<link rel="canonical" href="<?= e(url($_SERVER['REQUEST_URI'])) ?>"/>
<link rel="canonical" href="<?= e($this->url($_SERVER['REQUEST_URI'])) ?>"/>
</head>
<body>
<?php if (setting('logo')): ?>
Expand Down
4 changes: 2 additions & 2 deletions app/views/themes/default/page.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!doctype html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= e("$title - " . setting('title')) ?></title>
<?= $this->include('themes/default/partials/head.php') ?>
<meta property="og:title" content="<?= e(empty($meta_title) ? $title : $meta_title) ?>"/>
<meta property="og:description" content="<?= e(empty($meta_description) ? setting('meta_description') : $meta_description) ?>"/>
<meta property="og:type" content="website"/>
<link rel="canonical" href="<?= e(empty($canonical_url) ? url($_SERVER['REQUEST_URI']) : $canonical_url) ?>"/>
<link rel="canonical" href="<?= e(empty($canonical_url) ? $this->url($_SERVER['REQUEST_URI']) : $canonical_url) ?>"/>
</head>
<body>
<?= $this->include('themes/default/partials/header.php') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/views/themes/default/partials/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="keywords" content="<?= e(setting('meta_keywords') ?? '') ?>"/>
<meta property="og:image" content="<?= e($this->getContentUrl(empty($post['image']) ? setting('logo') : $post['image'])) ?>"/>
<meta property="og:site_name" content="<?= e(setting('title')) ?>"/>
<meta property="og:url" content="<?= e(url(\Aurora\System\Helper::getCurrentPath())) ?>"/>
<meta property="og:url" content="<?= e($this->url(\Aurora\System\Helper::getCurrentPath())) ?>"/>
<meta name="theme-color" content="#f5f5f5e6">
<link rel="icon" type="image/x-icon" href="/public/assets/favicon.ico">
<link rel="stylesheet" href="<?= e($this->getFileQuery('/public/assets/css/themes/default/main.css')) ?>">
Expand Down
4 changes: 2 additions & 2 deletions app/views/themes/default/post.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<?= e(lang()) ?>">
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= e($post['title'] . ' - ' . setting('title')) ?></title>
<?= $this->include('themes/default/partials/head.php') ?>
Expand All @@ -10,7 +10,7 @@
<?php foreach ($post['tags'] as $tag): ?>
<meta property="article:tag" content="<?= e($tag) ?>"/>
<?php endforeach ?>
<link rel="canonical" href="<?= e(empty($post['canonical_url']) ? url($_SERVER['REQUEST_URI']) : $post['canonical_url']) ?>"/>
<link rel="canonical" href="<?= e(empty($post['canonical_url']) ? $this->url($_SERVER['REQUEST_URI']) : $post['canonical_url']) ?>"/>
</head>
<body>
<?= $this->include('themes/default/partials/header.php') ?>
Expand Down
14 changes: 0 additions & 14 deletions bootstrap/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,13 @@ function js(mixed $val): string|bool
}
}

if (!function_exists('url')) {
function url(string $path = ''): string
{
return \Aurora\System\Helper::getUrl($path);
}
}

if (!function_exists('setting')) {
function setting(?string $key = null): mixed
{
return \Aurora\App\Setting::get($key);
}
}

if (!function_exists('lang')) {
function lang(): string
{
return \Aurora\System\Container::get('language')->getCode();
}
}

return function (\Aurora\System\Kernel $kernel) {
$languages = [];
foreach (glob(\Aurora\System\Helper::getPath('app/languages/*.php')) as $file) {
Expand Down

0 comments on commit db978e1

Please sign in to comment.