Skip to content

Commit

Permalink
Use template inheritance when possible in views
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Feb 12, 2024
1 parent 887fdb8 commit e807e26
Show file tree
Hide file tree
Showing 17 changed files with 991 additions and 992 deletions.
8 changes: 0 additions & 8 deletions app/controllers/ViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,4 @@ 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();
}
}
89 changes: 89 additions & 0 deletions app/views/admin/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html lang="<?= e(\Aurora\System\Container::get('language')->getCode()) ?>">
<head>
<title>
<?php $this->sectionStart('title') ?>
<?php $this->sectionEnd() ?>
</title>
<?= $this->include('admin/partials/head.php') ?>
</head>
<body class="admin">
<nav>
<header>
<img src="/public/assets/logo.svg"/>
<h1>Aurora</h1>
</header>
<div class="admin-options">
<a href="/admin/dashboard">
<?= $this->include('icons/home.svg') ?> <?= t('dashboard') ?>
</a>
<a href="<?= e($this->url()) ?>" target="_blank">
<?= $this->include('icons/window.svg') ?> <?= t('view_site') ?>
</a>
<a href="/admin/pages" separator>
<?= $this->include('icons/book.svg') ?> <?= t('pages') ?>
</a>
<a href="/admin/posts">
<?= $this->include('icons/pencil.svg') ?> <?= t('posts') ?>
</a>
<a href="/admin/tags">
<?= $this->include('icons/tag.svg') ?> <?= t('tags') ?>
</a>
<a href="/admin/media">
<?= $this->include('icons/image.svg') ?> <?= t('media') ?>
</a>
<a href="/admin/users">
<?= $this->include('icons/user.svg') ?> <?= t('users') ?>
</a>
<a href="/admin/links">
<?= $this->include('icons/link.svg') ?> <?= t('links') ?>
</a>
<a href="/admin/settings">
<?= $this->include('icons/settings.svg') ?> <?= t('settings') ?>
</a>
</div>
<div class="current-user">
<a href="/admin/users/edit?id=<?= e($_SESSION['user']['id']) ?>" title="<?= e($_SESSION['user']['name']) ?>">
<?php if (!empty($_SESSION['user']['image'])): ?>
<img src="<?= e($this->getContentUrl($_SESSION['user']['image'])) ?>"/>
<?php else: ?>
<img src="/public/assets/no-image.svg" class="empty-img"/>
<?php endif ?>
</a>
<div id="toggle-theme" class="pointer" title="<?= t('switch_theme') ?>" data-theme="<?php if (($_COOKIE['theme'] ?? '') !== 'dark'): ?>light<?php else: ?>dark<?php endif ?>">
<?= $this->include('icons/moon.svg') ?>
<?= $this->include('icons/sun.svg') ?>
</div>
<a href="/admin/logout" class="pointer" title="<?= t('logout') ?>">
<?= $this->include('icons/logout.svg') ?>
</a>
</div>
</nav>
<noscript class="warning">Looks like JavaScript is disabled or your browser does not support it. JavaScript is required for the site to work properly.</noscript>
<div class="nav-background" onclick="document.body.toggleAttribute('nav-open')"></div>
<?= $this->include('admin/partials/snackbar.php') ?>
<div class="content">
<?php $this->sectionStart('content') ?>
<?php $this->sectionEnd() ?>
</div>
</body>
</html>
<script>
window.addEventListener('load', () => {
document.querySelectorAll('.admin-options > a').forEach(el => {
if (location.pathname.startsWith(el.getAttribute('href'))) {
el.dataset.checked = true;
}
});

Dropdown.init();
});

document.getElementById('toggle-theme').addEventListener('click', () => {
let theme = get('#css-dark').toggleAttribute('disabled') ? 'light' : 'dark';
get('#toggle-theme').dataset.theme = theme;
document.cookie = 'theme=' + theme + ';path=/';
});
</script>
<?php $this->sectionStart('script') ?>
<?php $this->sectionEnd() ?>
162 changes: 79 additions & 83 deletions app/views/admin/dashboard.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,93 @@
<!DOCTYPE html>
<html lang="<?= e($this->lang()) ?>">
<head>
<title><?= t('dashboard') . ' - ' . e(setting('title')) ?></title>
<?= $this->include('admin/partials/head.php') ?>
</head>
<body class="admin">
<?= $this->include('admin/partials/nav.php') ?>
<div class="content">
<div>
<div class="page-title">
<?= $this->include('admin/partials/menu_btn.php') ?>
<h2><?= t('dashboard') ?></h2>
</div>
<?php $this->extend('admin/base.php') ?>

<?php $this->sectionStart('title') ?>
<?= t('dashboard') . ' - ' . e(setting('title')) ?>
<?php $this->sectionEnd() ?>

<?php $this->sectionStart('content') ?>
<div>
<div class="page-title">
<?= $this->include('admin/partials/menu_btn.php') ?>
<h2><?= t('dashboard') ?></h2>
</div>
<div class="grid">
<div class="grid grid-two-columns">
<div class="grid">
<?php if (!empty($links)): ?>
<div class="card dashboard v-spacing">
<h3><?= t('links') ?></h3>
<div class="dashboard-card-rows links">
<?php foreach ($links as $link): ?>
<a href="<?= e($link['url']) ?>" target="_blank">
<?= e($link['title']) ?>
</a>
<?php endforeach ?>
</div>
</div>
<?php endif ?>
</div>
<div class="grid">
<div class="grid grid-two-columns">
<div class="grid">
<?php if (!empty($links)): ?>
<div class="card dashboard v-spacing">
<h3><?= t('latest_published_posts') ?></h3>
<div class="dashboard-card-rows">
<?php foreach ($posts as $post): ?>
<a href="<?= e('/' . setting('blog_url') . '/' . $post['slug']) ?>" target="_blank">
<img src="<?= e($this->getContentUrl($post['image'] ?? '')) ?>" alt="<?= e($post['title']) ?>" <?php if (empty($post['image'])): ?> style="visibility: hidden;" <?php endif ?>/>
<div>
<b><?= e($post['title']) ?></b>
<span class="subtitle">
<?php if ($post['user_id']): ?>
<?= t('by') . ' ' . e($post['user_name']) ?>
<?php else: ?>
&nbsp;
<?php endif ?>
</span>
</div>
<h3><?= t('links') ?></h3>
<div class="dashboard-card-rows links">
<?php foreach ($links as $link): ?>
<a href="<?= e($link['url']) ?>" target="_blank">
<?= e($link['title']) ?>
</a>
<?php endforeach ?>
<?php if (empty($posts)): ?>
<span class="empty"><?= t('no_results') ?></span>
<?php endif ?>
</div>
</div>
<?php endif ?>
<div class="card dashboard v-spacing">
<h3><?= t('latest_published_posts') ?></h3>
<div class="dashboard-card-rows">
<?php foreach ($posts as $post): ?>
<a href="<?= e('/' . setting('blog_url') . '/' . $post['slug']) ?>" target="_blank">
<img src="<?= e($this->getContentUrl($post['image'] ?? '')) ?>" alt="<?= e($post['title']) ?>" <?php if (empty($post['image'])): ?> style="visibility: hidden;" <?php endif ?>/>
<div>
<b><?= e($post['title']) ?></b>
<span class="subtitle">
<?php if ($post['user_id']): ?>
<?= t('by') . ' ' . e($post['user_name']) ?>
<?php else: ?>
&nbsp;
<?php endif ?>
</span>
</div>
</a>
<?php endforeach ?>
<?php if (empty($posts)): ?>
<span class="empty"><?= t('no_results') ?></span>
<?php endif ?>
</div>
</div>
<div class="grid">
<div class="card dashboard v-spacing">
<h3><?= t('start_creating') ?></h3>
<div class="start-creating">
<a href="/admin/pages/edit"><?= $this->include('icons/book.svg') ?> <span><?= t('create_page') ?></span></a>
<a href="/admin/posts/edit"><?= $this->include('icons/pencil.svg') ?> <span><?= t('write_post') ?></span></a>
<a href="/admin/users/edit"><?= $this->include('icons/user.svg') ?> <span><?= t('add_user') ?></span></a>
<a href="/admin/tags/edit"><?= $this->include('icons/tag.svg') ?> <span><?= t('add_tag') ?></span></a>
</div>
</div>
<div class="grid">
<div class="card dashboard v-spacing">
<h3><?= t('start_creating') ?></h3>
<div class="start-creating">
<a href="/admin/pages/edit"><?= $this->include('icons/book.svg') ?> <span><?= t('create_page') ?></span></a>
<a href="/admin/posts/edit"><?= $this->include('icons/pencil.svg') ?> <span><?= t('write_post') ?></span></a>
<a href="/admin/users/edit"><?= $this->include('icons/user.svg') ?> <span><?= t('add_user') ?></span></a>
<a href="/admin/tags/edit"><?= $this->include('icons/tag.svg') ?> <span><?= t('add_tag') ?></span></a>
</div>
<div class="card dashboard v-spacing">
<h3><?= t('statistics') ?></h3>
<div>
<div class="input-group">
<b><?= t('posts') ?></b>
<span>
<?= e($total_posts) ?> <?= t('published') ?>,
<?= e($total_scheduled_posts) ?> <?= t('scheduled') ?>,
<?= e($total_draft_posts) ?> <?= t('draft') ?>
</span>
</div>
<div class="input-group">
<b><?= t('pages') ?></b>
<span>
<?= e($total_pages) ?> <?= t('published') ?>,
<?= e($total_draft_pages) ?> <?= t('draft') ?>
</span>
</div>
<div class="input-group">
<b><?= t('users') ?></b>
<span>
<?= e($total_users) ?> <?= t('active') ?>,
<?= e($total_inactive_users) ?> <?= t('inactive') ?>
</span>
</div>
</div>
<div class="card dashboard v-spacing">
<h3><?= t('statistics') ?></h3>
<div>
<div class="input-group">
<b><?= t('posts') ?></b>
<span>
<?= e($total_posts) ?> <?= t('published') ?>,
<?= e($total_scheduled_posts) ?> <?= t('scheduled') ?>,
<?= e($total_draft_posts) ?> <?= t('draft') ?>
</span>
</div>
<div class="input-group">
<b><?= t('pages') ?></b>
<span>
<?= e($total_pages) ?> <?= t('published') ?>,
<?= e($total_draft_pages) ?> <?= t('draft') ?>
</span>
</div>
<div class="input-group">
<b><?= t('users') ?></b>
<span>
<?= e($total_users) ?> <?= t('active') ?>,
<?= e($total_inactive_users) ?> <?= t('inactive') ?>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<?php $this->sectionEnd() ?>
Loading

0 comments on commit e807e26

Please sign in to comment.