name = $name; if (!file_exists($this->get_path())) { $this->invalidate(); } else { $this->read(); } } private function read() { $content = file_get_contents($this->get_path() . '/data.json'); if ($content == null) { $this->invalidate(); return; } $root = json_decode($content); if ($root == null) { $this->invalidate(); return; } $this->title = $root->{'title'}; $this->thumbnail = $root->{'thumbnail'}; $this->images = $root->{'images'}; if (property_exists($root, 'metadata')) { $this->metadata; } } private function invalidate() { $this->title = null; $this->thumbnail = null; $this->images = null; } function is_valid() { if ($this->title == null || $this->thumbnail == null || $this->images == null) { return false; } if (!is_string($this->title) || !is_string($this->thumbnail) || !is_array($this->images)) { return false; } foreach ($this->images as $image) { if (!is_string($image)) { return false; } } unset($image); return true; } function get_name() { return $this->name; } function get_path() { return AM_OPTIONS['root'] . '/' . $this::PATH_PREFIX . '/' . $this->name; } function get_title() { return $this->title; } function get_thumbnail() { return $this->get_path() . '/' . $this->thumbnail; } function get_small_thumbnail() { return $this::THUMB_PREFIX . '/small/' . $this->get_name() . '/' . $this->thumbnail; } function get_images() { return $this->images; } function get_html() { $out = ''; if (file_exists($this->get_thumbnail())) { $type = mime_content_type($this->get_thumbnail()); } $category = explode('/', $type)[0]; if (!file_exists($this->get_thumbnail())) { $out .= ''; } else if ($category == 'audio') { $out .= ''; } else { $out .= ''; } $album_len = count($this->get_images()); if ($album_len == 1) { $out .= '
' . $album_len . ' Image
'; } else { $out .= '
' . $album_len . ' Images
'; } $out .= '
' . htmlspecialchars($this->get_title(), ENT_QUOTES | ENT_HTML5) . '
'; $out .= '
'; return $out; } function get_metadata($image) { if ($image == null || !in_array($image, $this->images)) { return null; } if ($this->metadata == null || !property_exists($this->metadata, $image)) { return [ 'description' => '', 'date' => '', 'time' => '', 'latitude' => '', 'longitude' => '' ]; } $description = null; $date = null; $time = null; $lat = null; $lon = null; if (property_exists($this->metadata->{$image}, 'description')) { $description = $this->metadata->{$image}?->{'description'}; } if (property_exists($this->metadata->{$image}, 'date')) { $date = $this->metadata->{$image}?->{'date'}; } if (property_exists($this->metadata->{$image}, 'time')) { $time = $this->metadata->{$image}?->{'time'}; } if (property_exists($this->metadata->{$image}, 'latitude')) { $lat= $this->metadata->{$image}?->{'latitude'}; } if (property_exists($this->metadata->{$image}, 'longitude')) { $lon = $this->metadata->{$image}?->{'longitude'}; } if ($lat && $lon && (preg_match($this::NUMBER_REGEX, $lat) === false || preg_match($this::NUMBER_REGEX, $lon) === false)) { $lat = null; $lon = null; } return [ 'description' => $description == null ? '' : htmlspecialchars($description, ENT_QUOTES | ENT_HTML5), 'date' => $date == null ? '' : htmlspecialchars($date, ENT_QUOTES | ENT_HTML5), 'time' => $time == null ? '' : htmlspecialchars($time, ENT_QUOTES | ENT_HTML5), 'latitude' => $lat == null ? '' : htmlspecialchars($lat, ENT_QUOTES | ENT_HTML5), 'longitude' => $lon == null ? '' : htmlspecialchars($lon, ENT_QUOTES | ENT_HTML5) ]; } function get_image_index($image) { for ($i = 0; $i < count($this->images); ++$i) { if ($image == $this->images[$i]) { return $i; } } return -1; } function get_image_entry($image) { if ($image == null || !in_array($image, $this->images)) { return null; } $index = $this->get_image_index($image); $rpath = $this->get_path() . '/' . $image; $path = htmlspecialchars($rpath); if (file_exists($rpath)) { $file_size = number_format(filesize($path)); $rtype = mime_content_type($path); } else { $file_size = 0; $rtype = "Unknown"; } $type = htmlspecialchars($rtype); $category = explode('/', $type)[0]; $name = htmlspecialchars(basename($path)); $metadata = $this->get_metadata($image); $entry = ''; return $entry; } } ?>