Implement navigation for photo pages.
This commit is contained in:
		
							parent
							
								
									67a182671f
								
							
						
					
					
						commit
						c11c5c2677
					
				@ -22,6 +22,20 @@ class ViewPhoto extends HTMLController
 | 
				
			|||||||
		if ($exif)
 | 
							if ($exif)
 | 
				
			||||||
			$page->setExif($exif);
 | 
								$page->setExif($exif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// What tag are we browsing?
 | 
				
			||||||
 | 
							$tag = isset($_GET['in']) ? Tag::fromId($_GET['in']) : null;
 | 
				
			||||||
 | 
							$id_tag = isset($tag) ? $tag->id_tag : null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Find previous photo in set.
 | 
				
			||||||
 | 
							$previous_url = $photo->getUrlForPreviousInSet($id_tag);
 | 
				
			||||||
 | 
							if ($previous_url)
 | 
				
			||||||
 | 
								$page->setPreviousPhotoUrl($previous_url);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// ... and the next photo, too.
 | 
				
			||||||
 | 
							$next_url = $photo->getUrlForNextInSet($id_tag);
 | 
				
			||||||
 | 
							if ($next_url)
 | 
				
			||||||
 | 
								$page->setNextPhotoUrl($next_url);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->page->adopt($page);
 | 
							$this->page->adopt($page);
 | 
				
			||||||
		$this->page->setCanonicalUrl($photo->getPageUrl());
 | 
							$this->page->setCanonicalUrl($photo->getPageUrl());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -79,7 +79,12 @@ class ViewPhotoAlbum extends HTMLController
 | 
				
			|||||||
		// Load a photo mosaic for the current tag.
 | 
							// Load a photo mosaic for the current tag.
 | 
				
			||||||
		list($mosaic, $total_count) = $this->getPhotoMosaic($id_tag, $page);
 | 
							list($mosaic, $total_count) = $this->getPhotoMosaic($id_tag, $page);
 | 
				
			||||||
		if (isset($mosaic))
 | 
							if (isset($mosaic))
 | 
				
			||||||
			$this->page->adopt(new PhotosIndex($mosaic, Registry::get('user')->isAdmin()));
 | 
							{
 | 
				
			||||||
 | 
								$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
 | 
				
			||||||
 | 
								$this->page->adopt($index);
 | 
				
			||||||
 | 
								if ($id_tag > 1)
 | 
				
			||||||
 | 
									$index->setUrlSuffix('?in=' . $id_tag);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Make a page index as needed, while we're at it.
 | 
							// Make a page index as needed, while we're at it.
 | 
				
			||||||
		if ($total_count > self::PER_PAGE)
 | 
							if ($total_count > self::PER_PAGE)
 | 
				
			||||||
 | 
				
			|||||||
@ -500,4 +500,70 @@ class Asset
 | 
				
			|||||||
			WHERE id_asset = {int:id_asset}',
 | 
								WHERE id_asset = {int:id_asset}',
 | 
				
			||||||
			$params);
 | 
								$params);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function getUrlForPreviousInSet($id_tag = null)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$row = Registry::get('db')->queryAssoc('
 | 
				
			||||||
 | 
								SELECT a.*
 | 
				
			||||||
 | 
								' . (isset($id_tag) ? '
 | 
				
			||||||
 | 
								FROM assets_tags AS t
 | 
				
			||||||
 | 
								INNER JOIN assets AS a ON a.id_asset = t.id_asset
 | 
				
			||||||
 | 
								WHERE t.id_tag = {int:id_tag} AND
 | 
				
			||||||
 | 
									a.date_captured <= {datetime:date_captured} AND
 | 
				
			||||||
 | 
									a.id_asset != {int:id_asset}
 | 
				
			||||||
 | 
								ORDER BY a.date_captured DESC'
 | 
				
			||||||
 | 
								: '
 | 
				
			||||||
 | 
								FROM assets AS a
 | 
				
			||||||
 | 
								WHERE date_captured >= {datetime:date_captured} AND
 | 
				
			||||||
 | 
									a.id_asset != {int:id_asset}
 | 
				
			||||||
 | 
								ORDER BY date_captured ASC')
 | 
				
			||||||
 | 
								 . '
 | 
				
			||||||
 | 
								LIMIT 1',
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									'id_asset' => $this->id_asset,
 | 
				
			||||||
 | 
									'id_tag' => $id_tag,
 | 
				
			||||||
 | 
									'date_captured' => $this->date_captured,
 | 
				
			||||||
 | 
								]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ($row)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								$obj = self::byRow($row, 'object');
 | 
				
			||||||
 | 
								return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function getUrlForNextInSet($id_tag = null)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$row = Registry::get('db')->queryAssoc('
 | 
				
			||||||
 | 
								SELECT a.*
 | 
				
			||||||
 | 
								' . (isset($id_tag) ? '
 | 
				
			||||||
 | 
								FROM assets_tags AS t
 | 
				
			||||||
 | 
								INNER JOIN assets AS a ON a.id_asset = t.id_asset
 | 
				
			||||||
 | 
								WHERE t.id_tag = {int:id_tag} AND
 | 
				
			||||||
 | 
									a.date_captured >= {datetime:date_captured} AND
 | 
				
			||||||
 | 
									a.id_asset != {int:id_asset}
 | 
				
			||||||
 | 
								ORDER BY a.date_captured ASC'
 | 
				
			||||||
 | 
								: '
 | 
				
			||||||
 | 
								FROM assets AS a
 | 
				
			||||||
 | 
								WHERE date_captured <= {datetime:date_captured} AND
 | 
				
			||||||
 | 
									a.id_asset != {int:id_asset}
 | 
				
			||||||
 | 
								ORDER BY date_captured DESC')
 | 
				
			||||||
 | 
								 . '
 | 
				
			||||||
 | 
								LIMIT 1',
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									'id_asset' => $this->id_asset,
 | 
				
			||||||
 | 
									'id_tag' => $id_tag,
 | 
				
			||||||
 | 
									'date_captured' => $this->date_captured,
 | 
				
			||||||
 | 
								]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ($row)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								$obj = self::byRow($row, 'object');
 | 
				
			||||||
 | 
								return $obj->getPageUrl() . ($id_tag ? '?in=' . $id_tag : '');
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,12 +10,24 @@ class PhotoPage extends SubTemplate
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	private $photo;
 | 
						private $photo;
 | 
				
			||||||
	private $exif;
 | 
						private $exif;
 | 
				
			||||||
 | 
						private $previous_photo_url = '';
 | 
				
			||||||
 | 
						private $next_photo_url = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(Image $photo)
 | 
						public function __construct(Image $photo)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		$this->photo = $photo;
 | 
							$this->photo = $photo;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function setPreviousPhotoUrl($url)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$this->previous_photo_url = $url;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function setNextPhotoUrl($url)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$this->next_photo_url = $url;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected function html_content()
 | 
						protected function html_content()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		$this->photoNav();
 | 
							$this->photoNav();
 | 
				
			||||||
@ -57,16 +69,16 @@ class PhotoPage extends SubTemplate
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	private function photoNav()
 | 
						private function photoNav()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (false) // $previous_post = $this->post->getPreviousPostUrl())
 | 
							if ($this->previous_photo_url)
 | 
				
			||||||
			echo '
 | 
								echo '
 | 
				
			||||||
				<a href="', $previous_post, '" id="previous_photo"><em>Previous photo</em></a>';
 | 
									<a href="', $this->previous_photo_url, '" id="previous_photo"><em>Previous photo</em></a>';
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			echo '
 | 
								echo '
 | 
				
			||||||
				<span id="previous_photo"><em>Previous photo</em></span>';
 | 
									<span id="previous_photo"><em>Previous photo</em></span>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (false) //$this->post->getNextPostUrl())
 | 
							if ($this->next_photo_url)
 | 
				
			||||||
			echo '
 | 
								echo '
 | 
				
			||||||
				<a href="', $next_post, '" id="next_photo"><em>Next photo</em></a>';
 | 
									<a href="', $this->next_photo_url, '" id="next_photo"><em>Next photo</em></a>';
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			echo '
 | 
								echo '
 | 
				
			||||||
				<span id="next_photo"><em>Next photo</em></span>';
 | 
									<span id="next_photo"><em>Next photo</em></span>';
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@ class PhotosIndex extends SubTemplate
 | 
				
			|||||||
	protected $show_labels;
 | 
						protected $show_labels;
 | 
				
			||||||
	protected $row_limit = 1000;
 | 
						protected $row_limit = 1000;
 | 
				
			||||||
	protected $previous_header = '';
 | 
						protected $previous_header = '';
 | 
				
			||||||
 | 
						protected $url_suffix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const PANORAMA_WIDTH = 1280;
 | 
						const PANORAMA_WIDTH = 1280;
 | 
				
			||||||
	const PANORAMA_HEIGHT = null;
 | 
						const PANORAMA_HEIGHT = null;
 | 
				
			||||||
@ -95,7 +96,7 @@ class PhotosIndex extends SubTemplate
 | 
				
			|||||||
					<a class="edit" href="', BASEURL, '/editasset/?id=', $image->getId(), '">Edit</a>';
 | 
										<a class="edit" href="', BASEURL, '/editasset/?id=', $image->getId(), '">Edit</a>';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		echo '
 | 
							echo '
 | 
				
			||||||
					<a href="', $image->getPageUrl(), '">
 | 
										<a href="', $image->getPageUrl(), $this->url_suffix, '">
 | 
				
			||||||
						<img src="', $image->getThumbnailUrl($width, $height, $crop, $fit), '" alt="" title="', $image->getTitle(), '">';
 | 
											<img src="', $image->getThumbnailUrl($width, $height, $crop, $fit), '" alt="" title="', $image->getTitle(), '">';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($this->show_labels)
 | 
							if ($this->show_labels)
 | 
				
			||||||
@ -262,4 +263,9 @@ class PhotosIndex extends SubTemplate
 | 
				
			|||||||
		echo '
 | 
							echo '
 | 
				
			||||||
				</div>';
 | 
									</div>';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function setUrlSuffix($suffix)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							$this->url_suffix = $suffix;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user