I have found that one thing that is slacking in the gallery module is a block that will display the images of the gallery of the user whos profile you are viewing.
Put simply, you have a user page/profile for each user. There should be an option to actvate a block that displays on each userpage and only displays the gallery of that specific user whos user page it is.
Thanks to profix898 there is a code that displays exactly that, using the gallery_get_block() etc...., but you have to create a block for every user, it is not automatic, and in every block you need to manually change a variable. (code shown bellow)
<?php
// Grid block (4 random images in 2 columns from useralbum of Drupal uid 8)
$params = array(
'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
'itemId' => <strong>'user:8'</strong>
);
$block = gallery_get_block($params, 2);
print $block['content'];
?>
In the above code I have made bold the important variable that defines which users gallery it is getting the images from. unfortunately if you have any understanding of php, you will know this means that a new block will have to be manually made for each user that is created, only because that variable needs to be changed.
I then went and played around with the code to try and define the user automatically, and I came up with this:
<?php $testnum = $node->uid; ?>
<?php
// Grid block (4 random images in 2 columns from useralbum of Drupal uid 8)
$params = array(
'itemId' => 'user:'.$testnum,
'blocks' => implode('|', array_fill(0, 4, 'randomImage'))
);
$block = gallery_get_block($params, 2);
print $block['content'];
?>
$node->uid is the most important part because that is the id of the user who owns the user page. but here comes the unfortunate and confusing part. I am not exactly certain where I defined that, you see I built a custom profile not using the profile module. I used the tutorial from http://shellmultimedia.com/node/274
now that there is a sort of base to work off, hopefully, once the coding is completed properly, it will be possible to make this an inbuilt block like the grid block etc, so it will be possible for the administrator to just activate the block and limit it to displaying only on userpages.
on a side note, though probably a very important one, I personally did not place the code into a block for this, I used it in my actual coding for what appears on the user pages.
I have attatched the code for my userpages, most of the code is unrelated, but it might help in some way.
I post this in the hope that userpage gallery displays can be inbuilt into the module in some way or another.
Comment | File | Size | Author |
---|---|---|---|
node-uprofile.tpl_.php_.txt | 11.48 KB | odonja09 |
Comments
Comment #1
profix898 CreditAttribution: profix898 commentedThats it.
$node->uid
is always the profile owner. The tutorial uses$profileuser = user_load(array('uid' => $node->uid));
to actually load the user data and that wouldn't work if$node->uid
changed. So from what I see you can simply replace'itemId' => 'user:'. $user->uid
with'itemId' => 'user:'. $node->uid
(or'itemId' => 'user:'. $profileuser->uid
), not?Actually I'm not sure we will add this to the module. Most certainly the user wants to customize the layout of the gallery on profile pages. For this he/she has to touch the template anyway. So it shouldnt be a problem to add this 5 liner as well!? How many users need this kind of functionality? Isnt it advanced customization of profiles here?
Its not the code to add this functionality to the module, but we would also need a UI to configure the parameters, such as image/grid block, random/recent/... images, number of images, number of columns, ...
Comment #2
profix898 CreditAttribution: profix898 commentedThinking about it, we could add a gallery_profile.module to the package implementing this functionality without bloating the main module. What do you think?
Comment #3
odonja09 CreditAttribution: odonja09 commentedsounds like a good Idea. not even sure if I helped at all except reinforce the fact that something like that is needed/wanted. though I guess that is still something :-).
Comment #4
profix898 CreditAttribution: profix898 commentedFirst version of gallery_profile module added to cvs. Would be great if you could spent a few minutes to review ;) Thanks.
Comment #5
(not verified) CreditAttribution: commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #6
profix898 CreditAttribution: profix898 commentedI have just committed an update to the gallery_get_block() function that introduces a small change in parameters. This is to minimize incompatibility with future versions (Drupal 6) of gallery module. Sorry for inconvenience, but the new syntax will continue to work with newer versions and will therefore save you time/work. (I think its better to change it now during the beta testing than later in the stable release.)
Example code using the new syntax:
Its a simple modification to replace
$block = gallery_get_block($params, 2);
with$block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 2));
. The second argument should be set to 'ImageBlock' and the third argument is an array containing additional parameters (e.g. array('num_cols' => 2, 'class' => 'myclass', ...)).Comment #7
kokoyote CreditAttribution: kokoyote commentedAddressing the orginal purpose of the issue, is there a way to easily translate this code so that it can be used as a separate block? I'd prefer to be able to have a user's gallery page appear as a sidebar on their posts as well as on their profile.
Comment #8
profix898 CreditAttribution: profix898 commentedYou can create a custom block and paste the snippet above using the php input format ... not sure this is what you want!?
Comment #9
kokoyote CreditAttribution: kokoyote commentedYes, that was the idea, but I tried doing exactly that and couldn't get it to work, although it worked fine when inserted into user_profile.tpl.php. I assumed that I needed additional php code to make it work as a block. When I set the input to php, the block simply fails to appear entirely. Switching it to a filtered HTML format allows it to appear (as a bunch of code, obviously) so I assume that there is some php error occurring.
Comment #10
profix898 CreditAttribution: profix898 commentedWhere did you get the uid from? Did you use the global
global $user; ... $user->uid
? If you want to bind the block to a node or user profile, you will need to figure out the uid from the path. For the author of a node that would look like this:For a profile page its simpler:
[both snippets untested ;)]
Not sure this is what was missing? If not, can you please post the code you used?
Comment #11
awolfey CreditAttribution: awolfey commentedHi,
I've tried all of these in my user_profile.tpl.php, and switched randomImage to recentAlbum, but it's just showing me the 4 most recent albums from all users, no matter which user's profile I'm looking at.
I wonder if the problem might be related to my user sync, which looks like this:
ID G2ID Username Status Sync Status Operations
1 14 Aaron active OK edit | edit G2
2 16 wolfey active OK edit | edit G2
3 17 vixen active OK edit | edit G2
4 207 Anthony active OK edit | edit G2
Or maybe I'm just missing something?
Thanks.
Comment #12
risou CreditAttribution: risou commentedI have the same problem! The block does not change the displayed images if the user profile is changed !!
I tested the following snippets:
Comment #13
scarer CreditAttribution: scarer commentedwhen i run the code i use this:
It shows the correct images but when you click on them to view them they don't link to the correct location.
This code shows the link as: http://mysite.com/index.php?q=gallery&g2_itemId=55 when it should really be http://mysite.com/gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=... that should open a lightbox preview. At the moment it just goes to a blank drupal page when you click on the image.
How do I fix this?
Thanks ;)
Comment #14
scarer CreditAttribution: scarer commentedI uninstalled gallerix and it seems to work but the view is not filtered by user.