forked from opencaching/opencaching-pl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gallery_cache.php
64 lines (55 loc) · 2.36 KB
/
gallery_cache.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use src\Utils\Uri\Uri;
use src\Controllers\PictureController;
use src\Models\ApplicationContainer;
use src\Models\GeoCache\GeoCache;
use src\Models\Pictures\Thumbnail;
use src\Utils\Uri\SimpleRouter;
use src\Utils\Database\OcDb;
use src\Models\OcConfig\OcConfig;
require_once (__DIR__.'/lib/common.inc.php');
$view = tpl_getView();
if (!isset($_REQUEST['cacheid']) || ($cache = GeoCache::fromCacheIdFactory($_REQUEST['cacheid'])) === null) {
$view->redirect('/');
exit();
}
$user = ApplicationContainer::GetAuthorizedUser();
// Chceck if gallery should be visible
if (($cache->getStatus() == GeoCache::STATUS_WAITAPPROVERS
|| $cache->getStatus() == GeoCache::STATUS_NOTYETAVAILABLE
|| $cache->getStatus() == GeoCache::STATUS_BLOCKED)
&& ($user === null || ($user->getUserId() != $cache->getOwnerId() && ! $user->hasOcTeamRole()))) {
$view->redirect('/');
exit();
}
// Prepare array of log pictures
$params = [];
$query = 'SELECT `pictures`.`url`, `pictures`.`title`, `pictures`.`uuid`, `pictures`.`spoiler`, `pictures`.`object_id`
FROM `pictures`,`cache_logs`
WHERE `pictures`.`object_id`=`cache_logs`.`id` AND `cache_logs`.`deleted` = 0
AND `pictures`.`object_type`= 1
AND `cache_logs`.`cache_id`= :cacheid
ORDER BY `pictures`.`date_created` DESC';
$params['cacheid']['value'] = $cache->getCacheId();
$params['cacheid']['data_type'] = 'integer';
$db = OcDb::instance();
$stmt = $db->paramQuery($query, $params);
$logpictures = [];
while ($row = $db->dbResultFetch($stmt)) {
$row['url'] = str_replace("images/uploads", "upload", $row['url']);
if ($row['spoiler'] == '1') {
$row['thumbUrl'] = Thumbnail::placeholderUri(Thumbnail::PHD_SPOILER);
} else {
$row['thumbUrl'] = SimpleRouter::getLink(PictureController::class, 'thumbSizeMedium', [$row['uuid']]);
}
$logpictures[] = $row;
}
$view->setVar('logpictures', $logpictures);
$view->setVar('cachepictures', $cache->getPicturesList(false));
$view->setVar('hidespoilers', ($user === null && OcConfig::coordsHiddenForNonLogged()));
$view->setVar('cache', $cache);
$view->setVar('cacheicon', $cache->getCacheIcon($user));
$view->addLocalCss(Uri::getLinkWithModificationTime('/views/viewcache/viewcache.css'));
$view->loadFancyBox();
$view->setTemplate('gallery_cache');
$view->buildView();