wishthis/includes/classes/page.php

219 lines
7.2 KiB
PHP
Raw Normal View History

2021-11-12 15:23:48 +00:00
<?php
/**
* page.php
*/
namespace wishthis;
2022-01-14 07:34:55 +00:00
use wishthis\User;
2021-11-12 15:23:48 +00:00
class Page
{
2022-01-18 12:23:49 +00:00
public string $language = 'en';
2021-11-12 15:23:48 +00:00
/**
* __construct
*
* @param string $filepath The filepath (__FILE__) of the page.
* @param string $title The HTML title of the page.
*/
2022-01-18 12:23:37 +00:00
public function __construct(string $filepath, public string $title = 'wishthis', public int $power = 0)
2021-11-12 15:23:48 +00:00
{
$this->name = pathinfo($filepath, PATHINFO_FILENAME);
2022-01-14 07:24:08 +00:00
/**
* Session
*/
2022-01-18 12:23:37 +00:00
global $user;
2022-01-14 14:59:56 +00:00
$disableRedirect = array(
2022-01-14 15:22:16 +00:00
'home',
2022-01-14 14:59:56 +00:00
'login',
2022-01-14 15:18:54 +00:00
'register',
2022-01-14 14:59:56 +00:00
'install'
);
if (!isset($_SESSION['user']) && isset($_GET['page']) && !in_array($_GET['page'], $disableRedirect)) {
2022-01-14 07:24:08 +00:00
header('Location: /?page=login');
2022-01-14 09:08:11 +00:00
die();
2022-01-14 07:24:08 +00:00
}
2022-01-18 12:23:37 +00:00
/**
* Power
*/
2022-01-18 13:37:35 +00:00
if ($user && $user->power < $this->power) {
2022-01-18 12:23:37 +00:00
header('Location: /?page=power&required=' . $this->power);
die();
}
2021-11-12 15:23:48 +00:00
}
public function header(): void
{
?>
<!DOCTYPE html>
<html lang="<?= $this->language ?>">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<?php
/**
* Stylesheets
*/
2022-01-13 13:00:31 +00:00
/** Fomantic UI */
$stylesheetFomantic = 'semantic/dist/semantic.min.css';
$stylesheetFomanticModified = filemtime($stylesheetFomantic);
echo '<link rel="stylesheet" href="' . $stylesheetFomantic . '?m=' . $stylesheetFomanticModified . '" />';
2021-11-12 15:23:48 +00:00
/** Default */
$stylesheetDefault = 'includes/assets/css/default.css';
$stylesheetDefaultModified = filemtime($stylesheetDefault);
echo '<link rel="stylesheet" href="' . $stylesheetDefault . '?m=' . $stylesheetDefaultModified . '" />';
/** Page */
$stylesheetPage = 'includes/assets/css/' . $this->name . '.css';
if (file_exists($stylesheetPage)) {
$stylesheetPageModified = filemtime($stylesheetPage);
echo '<link rel="stylesheet" href="' . $stylesheetPage . '?m=' . $stylesheetPageModified . '" />';
}
/**
* Scripts
*/
/** jQuery */
$scriptjQuery = 'node_modules/jquery/dist/jquery.min.js';
$scriptjQueryModified = filemtime($scriptjQuery);
echo '<script defer src="' . $scriptjQuery . '?m=' . $scriptjQueryModified . '"></script>';
/** Fomantic */
$scriptFomantic = 'semantic/dist/semantic.min.js';
$scriptFomanticModified = filemtime($scriptFomantic);
echo '<script defer src="' . $scriptFomantic . '?m=' . $scriptFomanticModified . '"></script>';
/** Default */
$scriptDefault = 'includes/assets/js/default.js';
$scriptDefaultModified = filemtime($scriptDefault);
echo '<script defer src="' . $scriptDefault . '?m=' . $scriptDefaultModified . '"></script>';
2022-01-17 11:17:05 +00:00
/** Page */
$scriptPage = 'includes/assets/js/' . $this->name . '.js';
if (file_exists($scriptPage)) {
$scriptPageModified = filemtime($scriptPage);
echo '<script defer src="' . $scriptPage . '?m=' . $scriptPageModified . '"></script>';
}
?>
2022-01-13 13:00:31 +00:00
2021-11-15 11:20:55 +00:00
<title><?= $this->title ?> - wishthis</title>
2021-11-12 15:23:48 +00:00
</head>
<body>
<?php
}
public function navigation(): void
{
2022-01-13 13:15:43 +00:00
?>
<div class="ui attached stackable menu">
<div class="ui container">
2022-01-14 07:34:55 +00:00
<a class="item" href="/?page=home">
<i class="home icon"></i> Home
2022-01-13 13:15:43 +00:00
</a>
<div class="ui simple dropdown item">
2022-01-14 07:34:55 +00:00
Wishlist
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="/?page=wishlist-create">
<i class="list icon"></i>
Create
</a>
2022-01-14 08:28:41 +00:00
<a class="item" href="/?page=wishlist-view">
<i class="list icon"></i>
View
</a>
2022-01-14 07:34:55 +00:00
<a class="item" href="/?page=wishlist-product-add">
<i class="plus square icon"></i>
Add product
</a>
</div>
2022-01-13 13:15:43 +00:00
</div>
2022-01-14 07:34:55 +00:00
<div class="ui simple dropdown item">
Account
<i class="dropdown icon"></i>
<div class="menu">
<?php
2022-01-14 15:18:54 +00:00
$user = isset($_SESSION['user']) ? new User() : null;
2022-01-14 07:34:55 +00:00
2022-01-14 15:18:54 +00:00
if ($user && $user->isLoggedIn()) {
2022-01-14 07:34:55 +00:00
?>
<a class="item" href="/?page=logout">
<i class="sign out alternate icon"></i>
Logout
</a>
<?php
} else {
?>
<a class="item" href="/?page=login">
<i class="sign in alternate icon"></i>
Login
</a>
<a class="item" href="/?page=register">
<i class="user plus icon"></i>
Register
</a>
<?php
}
?>
</div>
2022-01-13 13:15:43 +00:00
</div>
2022-01-14 13:13:07 +00:00
<?php global $options; ?>
2022-01-18 12:23:37 +00:00
<?php if ($options->updateAvailable && $user && 100 === $user->power) { ?>
2022-01-14 13:13:07 +00:00
<a class="item" href="/?page=update">
<i class="upload icon"></i> Update
</a>
<?php } ?>
2022-01-13 13:15:43 +00:00
</div>
</div>
<div class="ui hidden divider"></div>
<?php
}
2021-11-12 15:23:48 +00:00
public function footer(): void
{
?>
2022-01-14 09:13:37 +00:00
<div class="ui hidden divider"></div>
<div class="ui inverted vertical footer segment">
<div class="ui container">
<div class="ui stackable inverted divided equal height stackable grid">
<div class="sixteen wide column">
<h4 class="ui inverted header">wishthis</h4>
2022-01-17 12:22:54 +00:00
<div class="ui inverted link list">
<?php
global $options;
echo 'v' . $options->version;
?>
</div>
2022-01-14 09:13:37 +00:00
<div class="ui inverted link list">
2022-01-18 12:43:12 +00:00
<a class="item" href="https://github.com/grandeljay/wishthis" target="_blank">
<i class="big github icon"></i>
</a>
2022-01-14 09:13:37 +00:00
</div>
</div>
</div>
</div>
</div>
2021-11-12 15:23:48 +00:00
</body>
</html>
<?php
}
}