[SOLVED] map module - modifications
|
eliz82
Joined: 2009-11-06
Posts: 71 |
Posted: Sun, 2014-08-03 10:05
|
|
few years ago i made that sidebar links "View in Google Earth" & "View Album on a Map" to appear only to users logged on. i made some modifications to "modules/map/module.inc"
/**
* @see GalleryModule::getItemLinks()
*/
function getItemLinks($items, $wantsDetailedLinks, $permissions) {
GalleryCoreApi::requireOnce('modules/map/classes/mapHelper.class');
$links = array();
list ($ret, $user['isGuest']) = GalleryCoreApi::isAnonymousUser();
if ($ret) {
return $ret;
}
list ($ret, $linktype) = GalleryCoreApi::getPluginParameter('module', 'map', 'linktype');
if (empty($linktype)) {
$linktype = 0;
}
list ($ret, $ExportGELink) =
GalleryCoreApi::getPluginParameter('module', 'map', 'ShowExportGELink');
foreach ($items as $item) {
$itemId = $item->getId();
$type = $item->getEntityType();
if ($linktype != 3) {
if ($type == 'GalleryPhotoItem') {
$NitemId = $item->getParentId();
} else {
$NitemId = $itemId;
}
list ($ret, $item) = GalleryCoreApi::loadEntitiesById($NitemId);
$name = $item->getTitle();
$goodalbum = false;
if ($linktype == 2) {
$goodalbum = true; /* Always filter on current album */
}
if ($linktype == 1) {
/* Dynamic link -> search for item in the album/subalbum with GPS coords */
list ($ret, $count) = mapHelper::getCountItemWithCoords($item->getId());
if ($ret) {
return array($ret, null);
}
if ($count != 0){
$goodalbum = true;
}
}
if (isset($wantsDetailedLinks[$itemId])) {
/* The View in Google Earth Link (only if enabled in the Panel) */
if ($ExportGELink && !$user['isGuest']) {
$links[$itemId][] =
array('text' => $this->_translate('View in Google Earth'),
'params' => array('view' => 'map.GoogleEarth',
'itemId' => $itemId));
}
/* The Google Map link */
if ($goodalbum && !$user['isGuest']) {
$links[$itemId][] =
array('text' => $this->_translate('View Album on a Map'),
'params' => array('view' => 'map.ShowMap',
'Mode' => 'Normal',
'Group' => '',
'album' => $name));
} else {
/*
* The current album (or parent of the current photo) does not have any
* GPS item, check from the root
*/
list ($ret, $count) = mapHelper::getCountItemWithCoords();
if ($ret) {
return array($ret, null);
}
if ($count && !$user['isGuest']) {
/* There are some items to show in the Gallery Display the Map Link */
$links[$itemId][] = array('text' => $this->_translate('Show a Google Map'),
'params' => array('view' => 'map.ShowMap'));
}
}
}
}
}
return array(null, $links);
}
the code above is working correctly. now i want that those link to appear only to a specific group . and i have replaced code with this:
/**
* @see GalleryModule::getItemLinks()
*/
function getItemLinks($items, $wantsDetailedLinks, $permissions) {
GalleryCoreApi::requireOnce('modules/map/classes/mapHelper.class');
$links = array();
list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($user['id'], '120');
if ($ret) {
return $ret;
}
list ($ret, $linktype) = GalleryCoreApi::getPluginParameter('module', 'map', 'linktype');
if (empty($linktype)) {
$linktype = 0;
}
list ($ret, $ExportGELink) =
GalleryCoreApi::getPluginParameter('module', 'map', 'ShowExportGELink');
foreach ($items as $item) {
$itemId = $item->getId();
$type = $item->getEntityType();
if ($linktype != 3) {
if ($type == 'GalleryPhotoItem') {
$NitemId = $item->getParentId();
} else {
$NitemId = $itemId;
}
list ($ret, $item) = GalleryCoreApi::loadEntitiesById($NitemId);
$name = $item->getTitle();
$goodalbum = false;
if ($linktype == 2) {
$goodalbum = true; /* Always filter on current album */
}
if ($linktype == 1) {
/* Dynamic link -> search for item in the album/subalbum with GPS coords */
list ($ret, $count) = mapHelper::getCountItemWithCoords($item->getId());
if ($ret) {
return array($ret, null);
}
if ($count != 0){
$goodalbum = true;
}
}
if (isset($wantsDetailedLinks[$itemId])) {
/* The View in Google Earth Link (only if enabled in the Panel) */
if ($ExportGELink && $user['isPosters']) {
$links[$itemId][] =
array('text' => $this->_translate('View in Google Earth'),
'params' => array('view' => 'map.GoogleEarth',
'itemId' => $itemId));
}
/* The Google Map link */
if ($goodalbum && $user['isPosters']) {
$links[$itemId][] =
array('text' => $this->_translate('View Album on a Map'),
'params' => array('view' => 'map.ShowMap',
'Mode' => 'Normal',
'Group' => '',
'album' => $name));
} else {
/*
* The current album (or parent of the current photo) does not have any
* GPS item, check from the root
*/
list ($ret, $count) = mapHelper::getCountItemWithCoords();
if ($ret) {
return array($ret, null);
}
if ($count && $user['isPosters']) {
/* There are some items to show in the Gallery Display the Map Link */
$links[$itemId][] = array('text' => $this->_translate('Show a Google Map'),
'params' => array('view' => 'map.ShowMap'));
}
}
}
}
}
return array(null, $links);
}
it's not seem to work. now the links are not show to anyone. any idea what am i doing wrong? the group number is correct because i made the same modification in modules/core/classes/GalleryView.class . i use that function in template files to check if a user is in that group with {if $user.isPosters} {/if} , and it's working correctly. --- |
|

Posts: 71
ok, i manage to do it by myself. i've replaced this
list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($user['id'], '120'); if ($ret) { return $ret; }with this
global $gallery; $session =& $gallery->getSession(); $user = (array)$gallery->getActiveUser(); list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($user['id'], '120'); if ($ret) { return $ret; }.
_____________
my G2 site
Posts: 1642
In your new modification, you have "$user['id']" in ...
list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($user['id'], '120'); if ($ret) { return $ret; }... but it is not initialised earlier in the function and will have a "null" value.
You can try amending that section to something along the lines of ...
global $gallery; $activeUserId = $gallery->getActiveUserId(); list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($activeUserId, 120); if ($ret) { return $ret; }--
dakanji.com
Posts: 71
not working. but this work
global $gallery; $user = (array)$gallery->getActiveUser(); list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($activeUserId, 120); if ($ret) { return $ret; }@later edit. i only now i observe that you changed $user to $activeUserId. so your version should work too
_____________
my G2 site
Posts: 1642
I think you mean this works ...
global $gallery; $user = (array)$gallery->getActiveUser(); list ($ret, $user['isPosters']) = GalleryCoreApi::isUserInGroup($user['id'], 120); if ($ret) { return $ret; }--
dakanji.com
Posts: 71
i only now i observe that you changed $user to $activeUserId. so your version should work to. i will test later
.
_____________
my G2 site
Posts: 1642
Your version is better as it creates the "$user" array and will avoid problems with "$user['isPosters']".
--
dakanji.com