tiki-browse_image.php 7.33 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6
// $Id$
changi67's avatar
changi67 committed
7

8
$section = "galleries";
9 10
require_once ('tiki-setup.php');
include_once ("lib/imagegals/imagegallib.php");
11
include_once ('lib/stats/statslib.php');
12 13 14

$access->check_feature('feature_galleries');

15
if ($prefs['feature_categories'] == 'y') {
mose's avatar
mose committed
16 17
	global $categlib;
	if (!is_object($categlib)) {
18
		include_once ('lib/categories/categlib.php');
mose's avatar
mose committed
19 20
	}
}
21

22
if (!isset($_REQUEST['imageId'])) {
23
	$smarty->assign('msg', tra("No image indicated"));
24
	$smarty->display("error.tpl");
25
	die;
26
}
27
$imageId = $_REQUEST['imageId'];
mose's avatar
mose committed
28 29
// always get gallery from image so no user can fake the galleryid
// and get an image that is truly in another (forbidden) gallery
30 31 32
$galleryId = $imagegallib->get_gallery_from_image($imageId);
if (!$galleryId) {
	$smarty->assign('msg', tra("picture not found"));
mose's avatar
mose committed
33 34 35
	$smarty->display("error.tpl");
	die;
}
36 37

$tikilib->get_perm_object( $galleryId, 'image gallery' );
38
$access->check_permission('tiki_p_view_image_gallery');
39

40
$gal_info = $imagegallib->get_gallery($galleryId);
41
$scalesize = 0;
42
if (isset($_REQUEST["scalesize"])) {
43 44 45 46
	if (is_numeric($_REQUEST["scalesize"]) && $_REQUEST["scalesize"] > 0) {
		$scalesize = $_REQUEST["scalesize"];
	}
} elseif ($gal_info['defaultscale'] !== 'o') {
47
	$scalesize = $gal_info['defaultscale'];
redflo's avatar
 
redflo committed
48
}
49 50
$arrscales = $imagegallib->get_gallery_scale_info($galleryId);
// adjust scale size to existing ones
51
if ($scalesize && !$prefs['preset_galleries_info'] == 'y') {
52
	$testscale = 0;
53 54 55
	foreach( $arrscales as $arrscale ) {
		if ($scalesize <= $arrscale['scale']) {
			$testscale = $arrscale['scale'];
56 57 58 59
			break;
		}
	}
	$scalesize = $testscale;
60
}
61
$smarty->assign_by_ref('scalesize', $scalesize);
62
$smarty->assign('same_scale', "&amp;scalesize={$scalesize}");
63
if (!isset($_REQUEST["sort_mode"])) {
64
	$_REQUEST["sort_mode"] = $gal_info['sortorder'] . '_' . $gal_info['sortdirection'];
lrargerich's avatar
lrargerich committed
65 66
}
$sort_mode = $_REQUEST["sort_mode"];
67 68 69
$listImgId = $imagegallib->get_gallery_image($galleryId, 'all', $sort_mode);
$offset = array_search($imageId, $listImgId);
if ($offset) {
70
	$smarty->assign('previmg', $listImgId[$offset - 1]);
71 72 73
} else {
	$smarty->assign('previmg', '');
}
74
if (count($listImgId) > $offset) {
75
	$smarty->assign('nextimg', $listImgId[$offset + 2]);
76 77 78
} else {
	$smarty->assign('nextimg', '');
}
79
$smarty->assign('firstId', $listImgId[0]);
80
$smarty->assign('lastId', $listImgId[count($listImgId) - 1]);
81
$smarty->assign('sort_mode', $_REQUEST["sort_mode"]);
82 83
$smarty->assign('galleryId', $galleryId);
$popup = isset($_REQUEST['popup']) && $_REQUEST['popup'] ? 'y' : '';
84
$foo = parse_url($_SERVER["REQUEST_URI"]);
85
$foo2 = str_replace("tiki-browse_image", "show_image", $foo["path"]);
86 87 88
$smarty->assign('url_browse', $tikilib->httpPrefix() . $foo["path"]);
$smarty->assign('url_base', $foo["path"] . "?galleryId={$galleryId}&amp;sort_mode={$sort_mode}" . ($popup ? '&amp;popup=y' : '') . '&amp;imageId=');
$smarty->assign('url_show', $tikilib->httpPrefix() . $foo2);
89 90 91 92
$imagegallib->add_image_hit($imageId);
$info = $imagegallib->get_image_info($imageId);
$maxgal = $gal_info['maxRows'] * $gal_info['rowImages'];
$smarty->assign('offset', $maxgal ? $offset - ($offset % $maxgal) : 0);
93 94
//$smarty->assign_by_ref('theme',$gal_info["theme"]);
//$smarty->assign('use_theme','y');
95
if ($prefs['feature_gal_slideshow'] != 'n') {
96
	$headerlib->add_jsfile('lib/imagegals/imagegallib.js', 50);
97 98
	$listImgId = implode(',', $listImgId);
	$smarty->assign('listImgId', $listImgId);
99
}
lrargerich's avatar
lrargerich committed
100
// Everybody can browse images
101
if (isset($_REQUEST["move_image"])) {
102
	check_ticket('browse-image');
103
	if ($tiki_p_admin_galleries != 'y' && (!$user || $user != $gal_info["user"])) {
104
		$smarty->assign('errortype', 401);
105
		$smarty->assign('msg', tra("You do not have permission to move images from this gallery"));
106
		$smarty->display("error.tpl");
107 108
		die;
	}
109
	if (isset($_REQUEST["newname"]) and $_REQUEST["newname"] != $info["name"]) {
110
		if ($imagegallib->edit_image($imageId, $_REQUEST['newname'], $info['description'], $info['lat'], $info['lon'])) {
111 112 113
			$info['name'] = $_REQUEST['newname'];
		}
	}
114 115
	$imagegallib->move_image($imageId, $_REQUEST["newgalleryId"]);
	$info['galleryId'] = $_REQUEST["newgalleryId"];
116 117
}
$smarty->assign_by_ref('owner', $gal_info["user"]);
118
$smarty->assign_by_ref('defaultscale', $gal_info["defaultscale"]);
119
$smarty->assign_by_ref('imageId', $imageId);
120
$smarty->assign_by_ref('name', $info["name"]);
121
$smarty->assign_by_ref('title', $info["name"]);
122 123
$smarty->assign_by_ref('galleryId', $info["galleryId"]);
$smarty->assign_by_ref('description', $info["description"]);
124 125
$smarty->assign_by_ref('lat', $info["lat"]);
$smarty->assign_by_ref('lon', $info["lon"]);
126 127
$smarty->assign_by_ref('created', $info["created"]);
$smarty->assign_by_ref('filename', $info["filename"]);
128 129
$smarty->assign('xsize', $info["xsize"]);
$smarty->assign('ysize', $info["ysize"]);
130 131
$smarty->assign_by_ref('hits', $info["hits"]);
$smarty->assign_by_ref('image_user', $info["user"]);
132
$smarty->assign_by_ref('gal_info', $gal_info);
133 134 135
$galleries = $imagegallib->list_visible_galleries(0, -1, 'lastModif_desc', $user, '');
$smarty->assign_by_ref('galleries', $galleries["data"]);
// Init vars
136
$smarty->assign('popup', $popup);
137 138 139
$smarty->assign('popupsize', '');
$winxsize = 0;
$winysize = 0;
140
// Calculate PopUp Window size for the popup link
141 142 143 144 145 146 147 148
$winx = $info['xsize'];
if ($winx < 320) {
	$winx = 320;
}
$winy = $info['ysize'];
if ($winy < 200) {
	$winy = 200;
}
149
// Give it some more pixels for the links and a little margin
150 151
$winx+= 40;
$winy+= 80;
152
// Now get'em to the template
153 154
$smarty->assign('winx', $winx);
$smarty->assign('winy', $winy);
155 156 157 158 159 160 161
// adjust scale size to existing ones according to image if smaller
$maxsize = max($info['xsize'], $info['ysize']);
$resultscale = $scalesize < $maxsize ? $scalesize : 0;
// build previous and next scale according to current and existing ones
$scaleinfo['nextscale'] = 0;
$scaleinfo['prevscale'] = 0;
$testscale = $resultscale ? $resultscale : $maxsize;
162 163
foreach($arrscales as $arrscale) {
	if ($testscale == $arrscale['scale']) {
164 165
		continue;
	}
166 167
	if ($testscale > $arrscale['scale']) {
		$scaleinfo['prevscale'] = $arrscale['scale'];
168 169
		continue;
	}
170 171
	if ($maxsize > $arrscale['scale']) {
		$scaleinfo['nextscale'] = $arrscale['scale'];
172 173
	}
	break;
174
}
175
$scaleinfo['clickscale'] = $scaleinfo['nextscale'] ? $scaleinfo['nextscale'] : ($resultscale ? 0 : ($arrscales ? $arrscales[0]['scale'] : -1));
176 177
$smarty->assign('resultscale', $resultscale);
if ($resultscale) {
178 179 180
	$info = $imagegallib->get_image_info($imageId, 's', $resultscale);
	$smarty->assign('xsize_scaled', $info["xsize"]);
	$smarty->assign('ysize_scaled', $info["ysize"]);
181
}
182 183
$smarty->assign_by_ref('scaleinfo', $scaleinfo);
include_once ('tiki-section_options.php');
184
if ($prefs['feature_theme_control'] == 'y') {
185
	$cat_type = 'image gallery';
186
	$cat_objid = $galleryId;
187
	include ('tiki-tc.php');
188
}
lrargerich's avatar
lrargerich committed
189
// now set it if needed
190
if ($popup) {
191 192
	$prefs['feature_left_column'] = 'n';
	$prefs['feature_right_column'] = 'n';
lrargerich's avatar
lrargerich committed
193
}
194
ask_ticket('browse-image');
195
//add a hit
196
$statslib->stats_hit($info["name"], "image", $imageId);
197
if ($prefs['feature_actionlog'] == 'y') {
toggg's avatar
toggg committed
198 199
	$logslib->add_action('Viewed', $galleryId, 'image gallery');
}
200
// Display the template
201
if ($popup) {
202 203 204 205 206
	$smarty->display("tiki-browse_image.tpl");
} else {
	$smarty->assign('mid', 'tiki-browse_image.tpl');
	$smarty->display("tiki.tpl");
}