I getting stuck with trying to write a simple module to add a link to the top menu which is based on the owner of the gallery album/item being viewed. I'm using the phpBB3 integration, and while this works perfectly and adds links to user profiles in phpBB to their own root album in Gallery2 it doesn't add anything links going back to the forum. It does put a mapping of gallery user id to phpBB user id into the ExternalIdMap table, so what I want to do is just add a single link to the top navigation that links to "memberlist.php?mode=viewprofile&u=<phpbbuserid>", where phpbbuserid is the value of externalId from the ExternalIdMap table for entityType "GalleryUser" where entityId is the userid of the album/item owner.
This is as far as I got, I just can't figure out what to do next:
class BBUserLinkModule extends GalleryModule {
function BBUserLinkModule() {
global $gallery;
$this->setId('bbuserlink');
$this->setName('BB User Link');
$this->setDescription($gallery->i18n('Add link for album/item to the owner profile in phpBB3.'));
$this->setVersion('0.0.1');
$this->setGroup('data', $gallery->i18n('Extra Data'));
$this->setCallbacks('getSystemLinks');
$this->setRequiredCoreApi(array(7, 10));
$this->setRequiredModuleApi(array(3, 0));
}
/**
* @see GalleryModule::getSystemLinks
*/
function getSystemLinks()
{
global $item;
$links = array();
list ($ret, $g2_results) = GalleryCoreApi::getMapEntry('ExternalIdMap', array('externalId'), array('entityId' => $item->owner_id, 'entityType' => 'GalleryUser'));
if ($ret) {return array($ret->wrap(__FILE__, __LINE__), null); }
foreach ($g2_results as $externalId )
{
$links['bbuserlink'] = array(
'text' => $this->translate('Owner profile'),
'params' => array('href' => '/memberlist.php?mode=viewprofile&u='.$externalId));
}
return array(null, $links);
}
}
While it adds the link to the view album/item pages fine, the link has mapinfo in it rather than the externalId value which is I assume do the foreach part (I'm still learning PHP, associative arrays cause me a few problems as I'm used to array handling in VB6 and ASP which is very simplistic), and also I get errors in the site admin - which I assume is because $item isn't valid at that point but I can't figure out how to verify that $item is valid (I tried isset and testing it's value and this just caused other errors).
Can anyone help me with this?
Posts: 32
I've realised that it might be better if I can modify the Owner: <Name> text in the album/item header at the upper right to link to the owner profile page as that will save adding a link to the top nav and instead use existing text that should be more intuitive. I can't however figure out what I need to write in my module in order to override the standard showowner handling - I don't even know where to start on this. If someone can give me a hint of where to look that would be handy, I'm happy enough to tinker and willing to learn but this is beyond me at the moment.
Posts: 8339
Try http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryEmbed.html#methodgetExternalIdMap
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 32
I'd already seen that page - it wasn't much use without an example showing to actually use it. I already had the calling code for that method, what I needed was how to use the result. I've now figured it out.
However, I did manage to figure out how to get the data I needed (rather than writing a module I simply added the code to the theme.inc I'm using and pass the value back in the theme data) and am now successfully returning the phpBB user ID to my template in the ItemInfo block, now I'm figuring out how to adjust the owner name display to link to the right place in phpBB. I should have it all finished in a few minutes
Posts: 8339
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 32
In case anyone else is trying to do this and searches the forum, here's what I did.
In theme.inc, in functions showAlbumPage and showPhotoPage, added the following:
(if $theme is already set in the theme code don't include the first line).
The I copied modules/core/templates/blocks/ItemInfo.tpl to themes/mytheme/templates/core_1/blocks/ItemInfo.tpl , and then made the showowner block to be
And this works perfectly on my site :D
Posts: 32
Thanks for that, but doesn't that end up returning an array of all the user mappings? I've got over 800 users at the moment and surely it's more efficient to query for just the single id that is required isn't it?
Posts: 8339
$user[$item->owner_id][externalId] is just your specified user
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 32
But $user is an array containing all the externalmapid table data, isn't it? That will have, at present, over 800 array elements, each with 3 values (entityId, externalId, and entityType). Assuming 8 bit ints for the Ids, that's 27 bits of data per map entry plus array overheads, which is at least 21kB of data (and will increase as I get more users signing up) to be read into and released from memory at every hit to a page. Requesting just the single entityId should be significantly less than this. While 21kb isn't much right now I think I'll stick to the code I've figured out myself. Thanks for the suggestion though, if I hadn't managed to work out how to use the results from getMapEntry it would have been a useful temporary solution.
Posts: 1
On my site that code works good on image page (theme.inc: showPhotoPage). But on album view - all users have link to phpbb profile of album owner (theme.inc: showAlbumPage).
How do fix?
Sorry for my bad English.