forked from Public/pics
Add single photo pages, navigateable by arrow keys and touch gestures.
This commit is contained in:
@@ -32,9 +32,7 @@ class Asset
|
||||
|
||||
public static function fromId($id_asset, $return_format = 'object')
|
||||
{
|
||||
$db = Registry::get('db');
|
||||
|
||||
$row = $db->queryAssoc('
|
||||
$row = Registry::get('db')->queryAssoc('
|
||||
SELECT *
|
||||
FROM assets
|
||||
WHERE id_asset = {int:id_asset}',
|
||||
@@ -42,16 +40,31 @@ class Asset
|
||||
'id_asset' => $id_asset,
|
||||
]);
|
||||
|
||||
// Asset not found?
|
||||
if (empty($row))
|
||||
return false;
|
||||
return empty($row) ? false : self::byRow($row, $return_format);
|
||||
}
|
||||
|
||||
$row['meta'] = $db->queryPair('
|
||||
public static function fromSlug($slug, $return_format = 'object')
|
||||
{
|
||||
$row = Registry::get('db')->queryAssoc('
|
||||
SELECT *
|
||||
FROM assets
|
||||
WHERE slug = {string:slug}',
|
||||
[
|
||||
'slug' => $slug,
|
||||
]);
|
||||
|
||||
return empty($row) ? false : self::byRow($row, $return_format);
|
||||
}
|
||||
|
||||
public static function byRow(array $row, $return_format = 'object')
|
||||
{
|
||||
// Supplement with metadata.
|
||||
$row['meta'] = Registry::get('db')->queryPair('
|
||||
SELECT variable, value
|
||||
FROM assets_meta
|
||||
WHERE id_asset = {int:id_asset}',
|
||||
[
|
||||
'id_asset' => $id_asset,
|
||||
'id_asset' => $row['id_asset'],
|
||||
]);
|
||||
|
||||
return $return_format == 'object' ? new Asset($row) : $row;
|
||||
@@ -254,6 +267,11 @@ class Asset
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
public function getFullPath()
|
||||
{
|
||||
return ASSETSDIR . '/' . $this->subdir . '/' . $this->filename;
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->subdir;
|
||||
@@ -282,6 +300,11 @@ class Asset
|
||||
return BASEURL . '/assets/' . $this->subdir . '/' . $this->filename;
|
||||
}
|
||||
|
||||
public function getPageUrl()
|
||||
{
|
||||
return BASEURL . '/' . $this->slug . '/';
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return substr($this->mimetype, 0, strpos($this->mimetype, '/'));
|
||||
|
||||
@@ -53,6 +53,12 @@ class Dispatcher
|
||||
$_GET = array_merge($_GET, $path);
|
||||
return new ViewPhotoAlbum();
|
||||
}
|
||||
// A photo for sure, then, right?
|
||||
elseif (preg_match('~^/(?<slug>.+?)/?$~', $_SERVER['PATH_INFO'], $path))
|
||||
{
|
||||
$_GET = array_merge($_GET, $path);
|
||||
return new ViewPhoto();
|
||||
}
|
||||
// No idea, then?
|
||||
else
|
||||
throw new NotFoundException();
|
||||
|
||||
@@ -246,7 +246,7 @@ class Tag
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return BASEURL . '/tag/' . $this->slug . '/';
|
||||
return BASEURL . '/' . $this->slug . '/';
|
||||
}
|
||||
|
||||
public function save()
|
||||
|
||||
Reference in New Issue
Block a user