First commit with actual files.
parent
84acf37f18
commit
82e74fe9f7
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
define("PORTFOLIO_TITLE", "portfolio title");
|
||||
define("PORTFOLIO_URL", "portfolio URL");
|
||||
define("PORTFOLIO_LANGUAGE", "country code");
|
||||
define("PORTFOLIO_CREATION_YEAR", 2023);
|
||||
define("AUTHOR_NICKNAME", "portfolio author's nickname");
|
||||
define("AUTHOR_REALNAME", "portfolio author's realname - optional, leave blank if none");
|
||||
|
||||
$links = [
|
||||
"link id" => [
|
||||
"label" => "label",
|
||||
"url" => "https://example.com",
|
||||
"self" => false
|
||||
]
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
@charset "utf-8";
|
||||
|
||||
* { box-sizing: border-box; }
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
spl_autoload_register(
|
||||
function ($class_name) {
|
||||
require_once "lib/$class_name.php";
|
||||
}
|
||||
);
|
||||
|
||||
$portfolio = new Portfolio();
|
||||
$portfolio->run();
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
final class Gallery
|
||||
{
|
||||
public string $label;
|
||||
public array $images = [];
|
||||
|
||||
public function __construct(string $label)
|
||||
{
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function add(Image $image)
|
||||
{
|
||||
$this->images[] = $image;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
final class Image
|
||||
{
|
||||
public string $full;
|
||||
public string $thumbnail;
|
||||
public string $title;
|
||||
public string $alt;
|
||||
public int $width;
|
||||
public int $height;
|
||||
|
||||
public function __construct(string $full, string $thumbnail, string $title, string $alt, int $width, int $height)
|
||||
{
|
||||
$this->full = $full;
|
||||
$this->thumbnail = $thumbnail;
|
||||
$this->title = $title;
|
||||
$this->alt = $alt;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
final class Link
|
||||
{
|
||||
public string $id;
|
||||
public string $label;
|
||||
public string $url;
|
||||
public bool $self;
|
||||
|
||||
public function __construct(string $id, string $label, string $url, bool $self)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->label = $label;
|
||||
$this->url = $url;
|
||||
$this->self = $self;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
final class Portfolio
|
||||
{
|
||||
|
||||
private array $links = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->loadConfig();
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->render();
|
||||
}
|
||||
|
||||
private function loadConfig()
|
||||
{
|
||||
require_once "config.php";
|
||||
foreach ($links as $id => $link) {
|
||||
$this->links[] = new Link($id, $link["label"], $link["url"], $link["self"]);
|
||||
}
|
||||
}
|
||||
|
||||
private function render()
|
||||
{
|
||||
$title = PORTFOLIO_TITLE;
|
||||
$url = PORTFOLIO_URL;
|
||||
$galleries = $this->loadGalleries();
|
||||
$links = $this->links;
|
||||
$footer = PORTFOLIO_CREATION_YEAR .
|
||||
". " . AUTHOR_NICKNAME .
|
||||
(AUTHOR_REALNAME !== "" ? " (" . AUTHOR_REALNAME . ")" : "");
|
||||
include "views/index.phtml";
|
||||
}
|
||||
|
||||
private function loadGalleries(): array
|
||||
{
|
||||
$galleries = [];
|
||||
foreach (array_diff(scandir("./galleries"), [".", ".."]) as $dir) {
|
||||
$path = "./galleries/$dir";
|
||||
$meta = "$gallery_path/metadata.txt";
|
||||
if (!is_file($meta)) {
|
||||
continue;
|
||||
}
|
||||
$galleries[] = $this->loadGallery($path, trim(file_get_contents($meta)));
|
||||
}
|
||||
return $galleries;
|
||||
}
|
||||
|
||||
private function loadGallery(string $dir, string $title): Gallery
|
||||
{
|
||||
$gallery = new Gallery($title);
|
||||
foreach (array_diff(scandir($dir, SCANDIR_SORT_DESCENDING), [".", ".."]) as $file) {
|
||||
$path = "$dir/$file";
|
||||
$meta = "$path.meta.txt";
|
||||
if (!is_file($meta)) {
|
||||
continue;
|
||||
}
|
||||
$gallery->add($this->loadImage($dir, $file, $meta));
|
||||
}
|
||||
return $gallery;
|
||||
}
|
||||
|
||||
private function loadImage(string $dir, string $file, string $meta): Image
|
||||
{
|
||||
$path = "$dir/" . rawurlencode($file);
|
||||
$thumbnail = str_replace(".jpg", "_thb.jpg", $image_path);
|
||||
list($title, $alt) = file($image_meta);
|
||||
list($width, $height) = getimagesize("$dir/$file");
|
||||
return new Image(
|
||||
$path,
|
||||
$thumbnail,
|
||||
trim($title),
|
||||
trim($alt),
|
||||
(int) $width,
|
||||
(int) $height
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?=$title?></title>
|
||||
<link href="css/portfolio.css" rel="stylesheet" title="Portfolio" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="<?=$url?>"><?=$title?></a></h1>
|
||||
</header>
|
||||
<main>
|
||||
<?php foreach ($galleries as $gallery): ?>
|
||||
<h2><?=$gallery->label?></h2>
|
||||
<ul class="gallery">
|
||||
<?php foreach ($gallery->images as $image): ?>
|
||||
<li>
|
||||
<a class="thumbnail" href="<?=$image->full?>">
|
||||
<figure>
|
||||
<img src="<?=$image->thumbnail?>" alt="<?=$image->alt?>" data-width="<?=$image->width?>" data-height="<?=$image->height?>">
|
||||
<figcaption><?=$image->title?></figcaption>
|
||||
</figure>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endforeach ?>
|
||||
</main>
|
||||
<aside>
|
||||
<ul class="links">
|
||||
<?php foreach ($links as $link): ?>
|
||||
<li class="icon">
|
||||
<a class="icon <?=$link->id?>" href="<?=$link->url?>"<?=$link->self ? " rel=\"me\"" : ""?>><?=$link->label?></a>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</aside>
|
||||
<footer><p><?=$footer?></p></footer>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue