=$gallery->label?>
+-
+images as $image): ?>
+
- + + + + + +
diff --git a/config.php b/config.php new file mode 100644 index 0000000..da3e1ae --- /dev/null +++ b/config.php @@ -0,0 +1,16 @@ + [ + "label" => "label", + "url" => "https://example.com", + "self" => false + ] +]; diff --git a/css/portfolio.css b/css/portfolio.css new file mode 100644 index 0000000..bc4b834 --- /dev/null +++ b/css/portfolio.css @@ -0,0 +1,3 @@ +@charset "utf-8"; + +* { box-sizing: border-box; } diff --git a/index.php b/index.php new file mode 100644 index 0000000..dc191b8 --- /dev/null +++ b/index.php @@ -0,0 +1,10 @@ +run(); diff --git a/lib/Gallery.php b/lib/Gallery.php new file mode 100644 index 0000000..814c48d --- /dev/null +++ b/lib/Gallery.php @@ -0,0 +1,17 @@ +label = $label; + } + + public function add(Image $image) + { + $this->images[] = $image; + } +} diff --git a/lib/Image.php b/lib/Image.php new file mode 100644 index 0000000..bb16a80 --- /dev/null +++ b/lib/Image.php @@ -0,0 +1,21 @@ +full = $full; + $this->thumbnail = $thumbnail; + $this->title = $title; + $this->alt = $alt; + $this->width = $width; + $this->height = $height; + } +} diff --git a/lib/Link.php b/lib/Link.php new file mode 100644 index 0000000..36fde26 --- /dev/null +++ b/lib/Link.php @@ -0,0 +1,17 @@ +id = $id; + $this->label = $label; + $this->url = $url; + $this->self = $self; + } +} diff --git a/lib/Portfolio.php b/lib/Portfolio.php new file mode 100644 index 0000000..39b8d6b --- /dev/null +++ b/lib/Portfolio.php @@ -0,0 +1,81 @@ +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 + ); + } +} diff --git a/views/index.phtml b/views/index.phtml new file mode 100644 index 0000000..09898a5 --- /dev/null +++ b/views/index.phtml @@ -0,0 +1,40 @@ + + +
+ +