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
Posts: 8339
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
Posts: 32
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
Posts: 8339
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.
Posts: 243
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?
Posts: 224
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();
Posts: 8339
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.
Posts: 8339
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
Posts: 32
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
Posts: 8339
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 ;)
Posts: 32
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
Posts: 8339
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>";
?>
Posts: 32
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
Posts: 8339
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
Posts: 32
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?
Posts: 8339
well with only a quick look, your g2Uri should have the trailing /
Posts: 32
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
Posts: 8339
try playing around with your embedUri maybe removing the & might help.
I had the same problem when I made my pugin.
Posts: 32
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
Posts: 8339
try taking a look here to see what you are missing
Posts: 1
I added some code to gallery_user.inc of gallery module in line 285. A new function called gallery_view_my_user_album
I call this function from my user_profile.tpl.php via
Posts: 1
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.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.
Posts: 24
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.
Posts: 8339
Something like this:
If they don't already have a userAlbum and you want to create one this returns the url:
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2
Posts: 24
Thanks for your help, that got me going in the right direction.