Add locale, en_US, DJ and Database functions.
This commit is contained in:
parent
67066287fc
commit
5fe1a21b8e
7 changed files with 440 additions and 8 deletions
128
classes/DJ.php
Normal file
128
classes/DJ.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
class DJ
|
||||
{
|
||||
|
||||
private int $id = -1;
|
||||
private string $name = "";
|
||||
private string $bio = "";
|
||||
private string $slug = "";
|
||||
private string $img = "";
|
||||
private bool $active = false;
|
||||
private string $email = "";
|
||||
private array $socials = [];
|
||||
|
||||
private string $created = "";
|
||||
private string $updated = "";
|
||||
private $db = null;
|
||||
|
||||
|
||||
public function __construct($slug, $db)
|
||||
{
|
||||
$this->slug = $slug;
|
||||
$this->db = $db;
|
||||
if (!$this->load_from_slug()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function load_from_slug(): bool
|
||||
{
|
||||
$dj = $this->get_dj_by_slug($this->slug);
|
||||
if ($dj) {
|
||||
if (isset($dj['id'])) {
|
||||
$this->id = $dj['id'];
|
||||
}
|
||||
if (isset($dj['name'])) {
|
||||
$this->name = $dj['name'];
|
||||
}
|
||||
if (isset($dj['bio'])) {
|
||||
$this->bio = $dj['bio'];
|
||||
}
|
||||
if (isset($dj['img'])) {
|
||||
$this->img = $dj['img'];
|
||||
}
|
||||
if (isset($dj['email'])) {
|
||||
$this->email = $dj['email'];
|
||||
}
|
||||
if (isset($dj['socials'])) {
|
||||
$this->socials = json_decode($dj['socials'], true) ?? [];
|
||||
}
|
||||
if (isset($dj['created'])) {
|
||||
$this->created = $dj['created'];
|
||||
}
|
||||
if (isset($dj['updated'])) {
|
||||
$this->updated = $dj['updated'];
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_dj_by_slug($slug)
|
||||
{
|
||||
$stmt = $this->db->prepare("SELECT * FROM djs WHERE slug = ?");
|
||||
$stmt->bind_param("s", $slug);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$dj = $result->fetch_assoc();
|
||||
$stmt->close();
|
||||
return $dj;
|
||||
}
|
||||
|
||||
public function get_slug(): string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function get_id(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_name(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function get_bio(): string
|
||||
{
|
||||
return $this->bio;
|
||||
}
|
||||
|
||||
public function get_img(): string
|
||||
{
|
||||
return $this->img;
|
||||
}
|
||||
|
||||
public function get_active(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function get_email(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function get_socials(): array
|
||||
{
|
||||
return $this->socials;
|
||||
}
|
||||
|
||||
public function get_created(): string
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function get_updated(): string
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -7,6 +7,6 @@ class Database extends mysqli
|
|||
public function __construct($config)
|
||||
{
|
||||
// call the parent constructor with the config file
|
||||
parent::__construct($config['database']['host'], $config['database']['username'], $config['database']['password'], $config['database']['database'], $config['database']['port'] ?? 3306);
|
||||
parent::__construct($config['database']['host'], $config['database']['user'], $config['database']['pass'], $config['database']['db'], $config['database']['port'] ?? 3306);
|
||||
}
|
||||
}
|
246
dj.php
Normal file
246
dj.php
Normal file
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
|
||||
// read toml config file
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'functions/i18n.php';
|
||||
require_once 'classes/Database.php';
|
||||
require_once 'classes/DJ.php';
|
||||
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
$config = Toml::ParseFile('includes/config.toml');
|
||||
$lang = $_SESSION['lang'] ?? $config['app']['locale'];
|
||||
$locale = loadLocale($lang);
|
||||
// if there's a query parameter named 'dj', load the DJ class
|
||||
$db = new Database($config);
|
||||
$djFound = false;
|
||||
if (isset($_GET['dj'])) {
|
||||
$dj = new DJ($_GET['dj'], $db);
|
||||
if ($dj->get_name() != "") {
|
||||
$djFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!doctype html >
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?php echo $config['app']['name']; ?></title>
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<?php require 'navbar.php'; ?>
|
||||
<section style="background-color: #eee;">
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
|
||||
<ol class="breadcrumb mb-0">
|
||||
<li class="breadcrumb-item"><a href="#"><?php echo $locale['home']; ?></a></li>
|
||||
<li class="breadcrumb-item"><a href="#"><?php echo $locale['djs']; ?></a></li>
|
||||
<li class="breadcrumb-item active"
|
||||
aria-current="page"><?php echo $dj->get_name(); ?></li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($djFound): ?>
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body text-center">
|
||||
<img src="<?php echo $dj->get_img(); ?>"
|
||||
alt="avatar"
|
||||
class="rounded-circle img-fluid" style="width: 150px;">
|
||||
<h5 class="my-3"><?php echo $dj->get_name(); ?></h5>
|
||||
<p class="text-muted mb-1">$desc1</p>
|
||||
<p class="text-muted mb-4">$location1</p>
|
||||
<div class="d-flex justify-content-center mb-2">
|
||||
<button type="button" data-mdb-button-init data-mdb-ripple-init class="btn btn-primary">
|
||||
<?php echo $locale['follow']; ?>
|
||||
</button>
|
||||
<button type="button" data-mdb-button-init data-mdb-ripple-init
|
||||
class="btn btn-outline-primary ms-1"><?php echo $locale['message']; ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-4 mb-lg-0">
|
||||
<div class="card-body p-0">
|
||||
<ul class="list-group list-group-flush rounded-3">
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center p-3">
|
||||
<i class="fas fa-globe fa-lg text-warning"></i>
|
||||
<p class="mb-0">https://mdbootstrap.com</p>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center p-3">
|
||||
<i class="fab fa-github fa-lg" style="color: #333333;"></i>
|
||||
<p class="mb-0">mdbootstrap</p>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center p-3">
|
||||
<i class="fab fa-twitter fa-lg" style="color: #55acee;"></i>
|
||||
<p class="mb-0">@mdbootstrap</p>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center p-3">
|
||||
<i class="fab fa-instagram fa-lg" style="color: #ac2bac;"></i>
|
||||
<p class="mb-0">mdbootstrap</p>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center p-3">
|
||||
<i class="fab fa-facebook-f fa-lg" style="color: #3b5998;"></i>
|
||||
<p class="mb-0">mdbootstrap</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<p class="mb-0">Full Name</p>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<p class="text-muted mb-0">Johnatan Smith</p>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<p class="mb-0">Email</p>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<p class="text-muted mb-0">example@example.com</p>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<p class="mb-0">Phone</p>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<p class="text-muted mb-0">(097) 234-5678</p>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<p class="mb-0">Mobile</p>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<p class="text-muted mb-0">(098) 765-4321</p>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<p class="mb-0">Address</p>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<p class="text-muted mb-0">Bay Area, San Francisco, CA</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4 mb-md-0">
|
||||
<div class="card-body">
|
||||
<p class="mb-4"><span class="text-primary font-italic me-1">assigment</span> Project
|
||||
Status
|
||||
</p>
|
||||
<p class="mb-1" style="font-size: .77rem;">Web Design</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 80%"
|
||||
aria-valuenow="80"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Website Markup</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 72%"
|
||||
aria-valuenow="72"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">One Page</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 89%"
|
||||
aria-valuenow="89"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Mobile Template</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 55%"
|
||||
aria-valuenow="55"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Backend API</p>
|
||||
<div class="progress rounded mb-2" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 66%"
|
||||
aria-valuenow="66"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card mb-4 mb-md-0">
|
||||
<div class="card-body">
|
||||
<p class="mb-4"><span class="text-primary font-italic me-1">assigment</span> Project
|
||||
Status
|
||||
</p>
|
||||
<p class="mb-1" style="font-size: .77rem;">Web Design</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 80%"
|
||||
aria-valuenow="80"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Website Markup</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 72%"
|
||||
aria-valuenow="72"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">One Page</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 89%"
|
||||
aria-valuenow="89"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Mobile Template</p>
|
||||
<div class="progress rounded" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 55%"
|
||||
aria-valuenow="55"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
<p class="mt-4 mb-1" style="font-size: .77rem;">Backend API</p>
|
||||
<div class="progress rounded mb-2" style="height: 5px;">
|
||||
<div class="progress-bar" role="progressbar" style="width: 66%"
|
||||
aria-valuenow="66"
|
||||
aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php echo $locale['djNotFound']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif;
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -8,4 +8,6 @@ function loadLocale($lang = 'en_US') {
|
|||
// Fallback to English if the specified language file does not exist
|
||||
return require __DIR__ . '/../locale/en_US/messages.php';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
27
index.php
27
index.php
|
@ -1,14 +1,29 @@
|
|||
<?php
|
||||
|
||||
// read toml config file
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'functions/i18n.php';
|
||||
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
require 'functions/i18n.php';
|
||||
use Yosymfony\Toml\Toml;
|
||||
|
||||
$config = Toml::ParseFile('includes/config.toml');
|
||||
// $config['app']['name']
|
||||
$lang = $_SESSION['lang'] ?? $config['app']['locale'];
|
||||
$locale = loadLocale($lang);
|
||||
|
||||
// load locale
|
||||
$locale = loadLocale($config['app']['locale']);
|
||||
// $locale['string']
|
||||
?>
|
||||
<!doctype html >
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?php echo $config['app']['name']; ?></title>
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<?php require 'navbar.php'; ?>
|
||||
|
||||
<script src="js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,5 +1,18 @@
|
|||
<?php
|
||||
return [
|
||||
'welcome' => 'Welcome to our Website!',
|
||||
'description' => 'This is a description in English.'
|
||||
'description' => 'This is a description in English.',
|
||||
'userProfile' => "User Profile",
|
||||
'user' => 'User',
|
||||
'home' => 'Home',
|
||||
'djName' => 'DJ Name',
|
||||
'email' => 'Email',
|
||||
'location' => 'Location',
|
||||
'bio' => 'Bio',
|
||||
'submit' => 'Submit',
|
||||
'login' => 'Login',
|
||||
'message' => 'Message',
|
||||
'follow' => 'Follow',
|
||||
'djs' => 'DJs',
|
||||
"djNotFound" => "Could not load DJ; either the DJ wasn't found or this DJ is private.",
|
||||
];
|
28
navbar.php
Normal file
28
navbar.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<header class="navbar sticky-top bg-dark flex-md-nowrap p-0 shadow" data-bs-theme="dark">
|
||||
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3 fs-6 text-white" href="#"><?php echo $config['app']['name'];?></a>
|
||||
|
||||
<ul class="navbar-nav flex-row d-md-none">
|
||||
<li class="nav-item text-nowrap">
|
||||
<button class="nav-link px-3 text-white" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#navbarSearch" aria-controls="navbarSearch" aria-expanded="false"
|
||||
aria-label="Toggle search">
|
||||
<svg class="bi">
|
||||
<use xlink:href="#search"/>
|
||||
</svg>
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item text-nowrap">
|
||||
<button class="nav-link px-3 text-white" type="button" data-bs-toggle="offcanvas"
|
||||
data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<svg class="bi">
|
||||
<use xlink:href="#list"/>
|
||||
</svg>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div id="navbarSearch" class="navbar-search w-100 collapse">
|
||||
<input class="form-control w-100 rounded-0 border-0" type="text" placeholder="Search" aria-label="Search">
|
||||
</div>
|
||||
</header>
|
Loading…
Add table
Add a link
Reference in a new issue