A "Your Album" link elsewhere

chamb1

Joined: 2004-12-27
Posts: 32
Posted: Fri, 2006-03-17 01:15

Hi,

I was wondering if anyone can walk me through what it would take to add a link to "Your Album" to the sidebar of Drupal. I am sure this has been done, but I just can't seem to figure it out. What (and how) do I need to call in order to allow users who are logged into the Drupal site to be able to click on just one link to get to their photo album and not have to go to gallery and then click "Your Album". Hope my question makes sense! ;)

Thanks in advance!

Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Fri, 2006-03-17 03:05

This is the code I use in my geeklog plugin:

function plugin_getuseroption_G2Bridge()
{
global $_CONF, $_G2B_CONF, $_USER;

$ret = G2B_G2_init();

$username = $_USER['username'];
list ($ret, $user) = GalleryCoreApi::fetchUserByUserName($username);
if ( !$ret)
{
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $user->getId());

return array( 'Your Gallery', $_CONF['site_url'] . '/G2Bridge/index.php?g2_itemId='.$albumId , 0 );
}
}

this is for 2.1

for 2.0.x try:

function plugin_getuseroption_GL_Gallery2()
{
global $_CONF,$_USER;

$ret = GLG_G2_init();

$username = $_USER['username'];
list ($ret, $user) = GalleryCoreApi::fetchUserByUserName($username);
if ( !$ret->isError() )
{
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $user->getId());

if ( SEC_hasRights( 'GL_Gallery2.view' ) )
return array( 'Your Gallery', $_CONF['site_url'] . '/GL_Gallery2/index.php?g2_view=core.ShowItem&g2_itemId='.$albumId , 0 );
}
}
Hope this helps :)

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Fri, 2006-03-17 15:29

suprsidr - Thanks a lot for the info! and really appreciate the fast response....

However, i am still having a problem...I guess I just haven't figured out what else needs to go in the block (i am not a programmer at all, so the logic of this is quite difficult! ;) So, is it really as simple as just cutting and pasting your code into a block in my CMS? for instance, are all of those variables and "active" or is there more code i need to include, such as some PHP includes? I have tried cutting and pasting your 2.1 code into a Drupal block item and i get nothing :( I assume i need more info about the embedding code....is there an EASY tutorial out there that anyone knows about?

Thanks!

Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2006-03-18 01:23

I'm not a drupal user, so I could not tell you what your cms variables are. For me $_CONF['site_url'] is the base url for my site. and geeklogs active user is $_USER['username'].

the if ( SEC_hasRights( 'GL_Gallery2.view' ) ) is just a little geeklog security, so you would not need it.

you can find most of what you need in the G2 documentation, start here.

Drupal probably already has an embed package, in which you could probably find what you need.

 
Continental

Joined: 2004-06-14
Posts: 243
Posted: Sat, 2006-03-18 13:10
chamb1 wrote:
Hope my question makes sense! ;)

The same I wanted to raise just before found this topic. Currently, I inserted a link in Drupal to menu using "gallery?g2_controller=useralbum.UserAlbum" url and hide all navigation block from anonymous with special block by role module (i don't remember the name and lost the link, but there it is), so registered users see "Their Albums" link, anonymous don't see. Of course, if they go to "g2controller=" and not "/user/myalbum" that is ridiculious, I don't know if any other drawback but it's working.

The thing I need more and more now to insert this link to /user/xxx page with profile. So, other users WILL BE ALBE to visit not only thier album, but others!
There is a good (hope so) implementation of Drupal API in "OG" module (they insert groups to this page), but I still can't understand how to write simple php code for getting >a href=/gallery/user/hisalbum"<Name of the User's Albums>/a< just to try to paste if somewhere in the text, of in the hand-made block.

Please, help. I tried 2.0 code above with $ret for Drupal, but it shows nothing (and I disabled register_globals=off, I'm not sure that's connected).

The real thing I would like to do (plase, help! I'm also not programmer):
- to insert link to user Albums on Profile Page
- to insert link FROM user Albums to Profile Page
- to insert list of Albums (root may be only) to profile page
- to insert "normal" link in the nagigation menu (sidebar)
- many more...

other ideas I wrote in http://drupal.org/node/51275 here, but ZERO answers.

I will hire sometime a programmer to do it all, if nobody will implement this somewhere in new module. Currently, I'm on 2.0* * 4.6, but I will be easily to rewrite everything if it's done.

btw, if 2.1 is working with Drupal? Which version? Will 4.6 work with 2.1?

 
dotnature
dotnature's picture

Joined: 2005-10-26
Posts: 224
Posted: Sat, 2006-03-18 18:36

If you get anywhere can you post here I'm also trying to get the "user album" to show up in joomla.
Also whats the $ret = G2B_G2_init();

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2006-03-18 22:17

Sorry, the $ret = G2B_G2_init(); is the geeklog version of the GalleryEmbed::init function.
You must call gallery's init function before most other gallery calls.

More info on the GalleryEmbed::init function can be found here.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2006-03-18 22:44

Actually after a little experimentation it seems you only have to link to g2_controller=useralbum.UserAlbum and the module will figure out the rest.

so my new function looks like this:

function plugin_getuseroption_G2Bridge()
{
global $_CONF, $_G2B_CONF;

if ( $_G2B_CONF['user_albums'] == true){
return array( 'Your Gallery', 'http://mysite.com/gallery_embed_directory/index.php?g2_controller=useralbum.UserAlbum' , 0 );
}else{
return array( 'Gallery 2', 'http://mysite.com/gallery_embed_directory/index.php', 0 );
}
}

So then you don't even have to have the init function.

So for your cms you might be able to just use simple html like this:
<a href="http://yoursite.com/index.php?module=gallery2&g2_controller=useralbum.UserAlbum">Your Gallery</a>

Hope this helps :)

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Mon, 2006-03-27 16:16

Well, I am at a loss - I am clearly missing something (maybe more than just one thing! ;)

So, i have tried the above suggestions as well as various permutations of them in an effort to get just a simple Gallery (2.1) "Your Album" link in the Drupal (4.6) sidebar so when a registered user is logged into the drupal system, they are presented with a block on the left that contains a "Your Album" link (this way they don't need to first go to the gallery and then find the "Your Album" link in the top right. Alas, no luck. I am pretty sure i am missing something on how to do the "require_once" code. In an effort to just see if i can get ANYTHING embedded to work, I am trying to just show a random image (so at least i will know i am getting warm and then I will work on generating the users' "Your Album" link). Here is what i am currently working with that is giving me an error (code first, then a sample of the error):

______code for a Drupal Block______
<?php
require_once('../gallery2/embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true, 'embedPath' => '/gallery2/'));
if ($ret->isError()) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
'show' => 'title|date'));
if ($ret->isError()) {
print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
print $bodyHtml;
?>

______error that results in phperror log______
[26-Mar-2006 22:26:15] PHP Fatal error: Unknown: Failed opening required 'K:\bzb\see-my-pictures\includes../gallery2/embed.php' (include_path='.;C:\PHP\PEAR\pear;C:\PHP\PEAR\pear;c:\php') in K:\bzb\see-my-pictures\includes\common.inc(1857) : eval()'d code on line 2
______________

Seems to me that the relative path is just appending it to the "working" path....but, i am sure my misunderstanding is bigger than just that! ;)

ANyway, if anyone could just guide me through this with a snippet of PHP code (including everything), that would be great - i have tried and tried to read and understand the tutorials suggested, but i have found them very hard to understand - I will understand best if i can see a real-world example....

Thanks in advance!

Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2006-03-28 01:14

that code is for gallery 2.0.x, try this:
<?php
require_once('full_path_to/gallery2/embed.php'); // full system path to your gallery2 embed.php
$ret = GalleryEmbed::init(array('fullInit' => true, 'embeduri' => 'full URI to access G2 via CMS application', 'g2Uri' => 'full URI of the G2 standalone location'));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
'show' => 'title|date'));
if ($ret) {
print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
print $bodyHtml;
?>

try using full system paths and URIs.

for more thorough info on GalleryEmbed::init try here.

If that works for you, we will try the My Gallery Link. Since I've never used Drupal ;)

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Tue, 2006-03-28 01:29

Woo hoo! with the following code, i am able to see a random image! :)

_____code for a drupal block______
<?php
require_once('K:\bzb\see-my-pictures\gallery2\embed.php'); // full system path to your gallery2 embed.php
$ret = GalleryEmbed::init(array('fullInit' => true, 'embeduri' => '/gallery2/', 'g2Uri' => '/gallery2/'));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
'show' => 'title|date'));
if ($ret) {
print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
print $bodyHtml;
?>
___________

Now, to get the "your album" link! ;)

Your help is MUCH appreciated, suprsidr!

Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2006-03-28 01:56

not sure if this will work, you need to know Drupal's current user variable. In geeklog we use $_USER['uid']. And of coarse they would have to be pre-mapped to gallery.
<?php
require_once('K:\bzb\see-my-pictures\gallery2\embed.php'); // full system path to your gallery2 embed.php
$ret = GalleryEmbed::init(array('fullInit' => true, 'embeduri' => '/gallery2/', 'g2Uri' => '/gallery2/', 'activeUserId' => your CMS current user variable ));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
print "<a href='http://yoursite.com/your cms gallery/index.php?g2_controller=useralbum.UserAlbum'>Your Album</a>";
?>

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Wed, 2006-03-29 06:56

Hi - well, still haven't figured this one out...i tried the following code (much like you suggested), and it ALMOST works - it puts out a link, but the link is exactly from the "print" statement - useralbum.UserAlbum is passed as just text :( the other thing is that the link "should" look like this: http://www.see-my-pictures.com/index.php?q=gallery&g2_itemId=114 with just the itemId...so how can i get that info into a variable that i can place in the link-making print statement?
______here's da code_____________
<?php
require_once('K:\bzb\see-my-pictures\gallery2\embed.php'); // full system path to your gallery2 embed.php
$ret = GalleryEmbed::init(array('fullInit' => true, 'embeduri' => '/gallery2/', 'g2Uri' => '/gallery2/', 'activeUserId' => $user->uid ));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
print "<a href='http://www.see-my-pictures.com/index.php?g2_controller=useralbum.UserAlbum'>Your Album</a>";
?>
___________end code________________
Any help or suggestions are much appreciated!
Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2006-03-29 22:24

try this:

<?php
// not sure if you need to include a common lib for Drupal usually includes common functions and variables like $user.
require_once('path_to_your_cms_common_lib.php');
global $user;

require_once('K:\bzb\see-my-pictures\gallery2\embed.php'); // full system path to your gallery2 embed.php
$ret = GalleryEmbed::init(array('fullInit' => true, 'embeduri' => '/gallery2/', 'g2Uri' => '/gallery2/', 'activeUserId' => $user->uid ));
if ($ret){
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUserName($user->username);
if ( !$ret){
list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum', 'albumId', $g2_user->getId());
print "<a href='http://www.see-my-pictures.com/index.php?g2_itemId=".$albumId. "'>Your Album</a>";
}

?>

you could put the two code segments together and have a random image with a link to your gallery under it :)

Hope this helps

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Mon, 2006-04-03 15:58

Thanks for all the help and suggestions! I got the "your album" link working! The one issue i am still having is that the random image part of the drupal block is returning the picture fine, but the wrong hyperlink...interestingly, however, it returns the correct link when viewing the embedded gallery, but the wrong one when not viewing the embedded gallery. I assume that there is some file i am not calling that is being loaded into memory when viewing the embedded gallery. A "wrong" link looks like:

http://www.see-my-pictures.com/main.php?g2_itemId=3818

And a "correct" link looks like:

http://www.see-my-pictures.com/index.php?q=gallery&g2_itemId=8124

Here is the code i am using:

_________________________
<?php

// here is the random image generator
print "<br>";
print "Random User Photo";
print "<br>";
print "<br>";

global $user, $base_url;

require_once('K:\bzb\see-my-pictures\gallery2\embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true, 'g2Uri' => '/gallery2', 'embedUri' => 'http://www.see-my-pictures.com/index.php?q=gallery&'));

list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage', 'maxSize' => 130));

if ($ret) {
print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
exit;
}

print $bodyHtml;

?>
__________________

any suggestions?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2006-04-03 23:48

well with only a quick look, your g2Uri should have the trailing /

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Tue, 2006-04-04 00:06

Hummmmmm....I put in the trailing "/" on the g2uri and, alas, still the wrong link.... hummmmm....
I wonder if the gallery.module is loading something that I, in my little php snippet, am not?
Thanks,
Jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Tue, 2006-04-04 22:29

try playing around with your embedUri maybe removing the & might help.
I had the same problem when I made my pugin.

 
chamb1

Joined: 2004-12-27
Posts: 32
Posted: Thu, 2006-04-06 00:39

no luck....i tried all kinds of options with no change in the fact that it is giving me a link that has "main.php" in it versus "index.php" in it....i am SO close to finishing this little project....all i need is the link to work right! ;)

Thanks!
jim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Thu, 2006-04-06 11:24

try taking a look here to see what you are missing

 
info@plinko.biz

Joined: 2007-10-07
Posts: 1
Posted: Sun, 2007-10-07 17:38

I added some code to gallery_user.inc of gallery module in line 285. A new function called gallery_view_my_user_album


if (!empty($albumId)) {
    global $gallery;
    $urlGenerator =&amp; $gallery-&gt;getUrlGenerator();
    $link = $urlGenerator-&gt;generateUrl(
      array('view' =&gt; 'core.ShowItem',
        'itemId' =&gt; $albumId),
      array('forceFullUrl' =&gt; 1, 
            'htmlEntities' =&gt; false));

    $form['gallery_view_myuser_album'] = array(
      'value' =&gt; l(t('My Album'), $link),
      'class' =&gt; 'send-message');
  } else {
    $form['gallery_view_my_user_album'] = array(
      'value' =&gt; t('No Album'),
      'class' =&gt; 'send-message');
  }




I call this function from my user_profile.tpl.php via


$galleryprofile=gallery_view_user($GLOBALS['user']);
print $galleryprofile['Gallery2']['gallery_view_my_user_album']['value'];


 
qufighter

Joined: 2008-01-28
Posts: 1
Posted: Mon, 2008-01-28 04:15

I'm using community builder and came up with my own solution. The problem I was having was that new users don't have an album created yet, so g2 needs their g2_authToken to set up their account for the first time. If you are in a function when using this you probably need to declare global $database, $my; at the top of the function.

$query = "SELECT i.g_id FROM jos_g2_externalidmap as m, jos_g2_item as i WHERE m.g_externalId='".$my->id."' AND i.g_canContainChildren=1 AND i.g_ownerId=m.g_entityId";
$database->setQuery($query);
$g2AccountData = $database->loadObjectList();
			
if( count($g2AccountData) < 1 ){
	//USER has not set up their ALBUM yet, so we need to get their auth token
	$query = "SELECT ma.g_data FROM jos_g2_externalidmap AS m, jos_g2_sessionmap AS ma WHERE m.g_externalId='".$my->id."' AND ma.g_userId=m.g_entityId";
	$database->setQuery($query);
	$g2AccountData = $database->loadObjectList();
	$acntData = unserialize($g2AccountData[0]->g_data);
	if( strlen( $acntData['core.authToken'] ) > 0 ){
		$uploadPhotosV = 'index.php?option=com_gallery2&Itemid=221&g2_controller=useralbum.UserAlbum&g2_authToken='.$acntData['core.authToken'];
	}else{
		$uploadPhotosV = 'index.php?option=com_gallery2&Itemid=221';
	}
}else{
	$Yourg2ProfileURL = 'index.php?option=com_gallery2&Itemid=221&g2_itemId='.$g2AccountData[0]->g_id;
}

then you can create a link: echo '<a href="'.$Yourg2ProfileURL.'">Your Album</a>';
Unfortunately I realized that the auth token won't exist until the user visits the main galleria page for the first time, so if there is no auth-token yet, just redirect them there.

 
insomnix

Joined: 2009-04-19
Posts: 24
Posted: Mon, 2009-04-20 05:45

I am trying to do the same thing, I need a link for the user's album, but I am not using any of the above web programs. Is there a way to get the user album with just the users external id? I tried several solutions, but not much luck.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2009-04-20 11:28

Something like this:

    function getUserAlbumUrl($uid) {
	global $gallery;
	list ($ret, $user) = GalleryCoreApi::loadEntityByExternalId($uid, 'GalleryUser');
	if ($ret) {
	    print "error loading user: ".$ret->getAsHtml();
	}
	list ($ret, $albumId) = GalleryCoreApi::getPluginParameter('module', 'useralbum',
	    'albumId', $user->getId());
	if ($ret || $albumId == '') {
	    print "error getting userAlbumId: ".$ret->getAsHtml();
	}
	$urlGenerator = & $gallery->getUrlGenerator();
	return $urlGenerator->generateUrl(array ('view'=>'core.ShowItem', 'itemId'=>$albumId),
	    array ('forceFullUrl'=>true, 'forceSessionId'=>true));
    }

If they don't already have a userAlbum and you want to create one this returns the url:

    function getUserAlbumCreateUrl() {
	global $gallery;
	$urlGenerator =& $gallery->getUrlGenerator();
	return $urlGenerator->generateUrl(
	array('controller' => 'useralbum.UserAlbum'),
	array('forceFullUrl' => true, 'forceSessionId' => true));
    }

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
insomnix

Joined: 2009-04-19
Posts: 24
Posted: Fri, 2009-04-24 05:00

Thanks for your help, that got me going in the right direction.