summaryrefslogtreecommitdiff
path: root/includes/image_lookup_inc.php
blob: 9c9823b216e6c4ecc5024a1ed17522eec59463bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
 * @version $Header$
 * @package fisheye
 * @subpackage functions
 */

global $gContent, $gGallery;
use \Bitweaver\Fisheye\FisheyeImage;
use \Bitweaver\Fisheye\FisheyeGallery;
;
if( $gContent = FisheyeImage::lookup( $_REQUEST ) ) {
	// nothing to do. ::lookup will do a full load
} else {
	$gContent = new FisheyeImage();
	$imageId = null;
}

if( !empty( $_REQUEST['gallery_path'] ) ) {
	$_REQUEST['gallery_path'] = rtrim( $_REQUEST['gallery_path'], '/' );
	$gContent->setGalleryPath( $_REQUEST['gallery_path'] );
	$matches = [];
	$tail = strrpos( $_REQUEST['gallery_path'], '/' );
	$_REQUEST['gallery_id'] = substr( $_REQUEST['gallery_path'], $tail + 1 );
}
if( empty( $_REQUEST['gallery_id'] ) ) {
	if( $parents = $gContent->getParentGalleries() ) {
		$gal = current( $parents );
		$gContent->setGalleryPath( '/'.$gal['gallery_id'] );
		$_REQUEST['gallery_id'] = $gal['gallery_id'];
	}
}
// the image is considered the primary content, however the gallery is useful
if( !empty($_REQUEST['gallery_id']) && is_numeric($_REQUEST['gallery_id']) ) {
	$gGallery = FisheyeGallery::lookup( $_REQUEST );
	if( is_object( $gGallery ) && $gGallery->isValid() ) {
		$gGallery->loadCurrentImage( $gContent->mImageId );
	}
	$gBitSmarty->assign('gGallery', $gGallery);
	$gBitSmarty->assign('galleryId', $_REQUEST['gallery_id']);
}

// This user does not own this gallery and they have not been granted the permission to edit this gallery
$gContent->verifyViewPermission();

$gBitSmarty->assign('gContent', $gContent);
$gBitSmarty->assign('imageId', $gContent->mImageId );