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.

CommentFileSizeAuthor
node-uprofile.tpl_.php_.txt11.48 KBodonja09
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

profix898’s picture

  1. The above code can be used as is on normal profile pages, because the $user object is available there. All you need to do is to insert this small snippet into your user_profile.tpl.php template.
    <?php
    // Grid block (4 random images in 2 columns from useralbum of the profile's owner)
    $params = array(
      'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
      'itemId' => 'user:'. $user->uid
    );
    $block = gallery_get_block($params, 2);
    print $block['content'];
    ?>

    Thats it.

  2. Its slightly different using nodeprofile module. But it seems that $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?
  3. "I post this in the hope that userpage gallery displays can be inbuilt into the module in some way or another."
    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, ...
profix898’s picture

Thinking about it, we could add a gallery_profile.module to the package implementing this functionality without bloating the main module. What do you think?

odonja09’s picture

sounds 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 :-).

profix898’s picture

Status: Postponed (maintainer needs more info) » Fixed

First version of gallery_profile module added to cvs. Would be great if you could spent a few minutes to review ;) Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

profix898’s picture

Component: User interface / Theming » User Interface / Theming

I 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:

<?php
// Grid block (4 random images in 2 columns from useralbum of the profile's owner)
$params = array(
  'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
  'itemId' => 'user:'. $user->uid
);
$block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 2));
print $block['content'];
?>

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', ...)).

kokoyote’s picture

Addressing 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.

profix898’s picture

You can create a custom block and paste the snippet above using the php input format ... not sure this is what you want!?

kokoyote’s picture

Yes, 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.

profix898’s picture

Where 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:

<?php
if (arg(0) == 'node' && is_numeric($nid = arg(1))) {
  $node = node_load($nid);
  $params = array(
    'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
    'itemId' => 'user:'. $node->uid
  );
  $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 2));
  print $block['content'];
}
?>

For a profile page its simpler:

<?php
if (arg(0) == 'user' && is_numeric($uid = arg(1))) {
  $params = array(
    'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
    'itemId' => 'user:'. $uid
  );
  $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 2));
  print $block['content'];
}
?>

[both snippets untested ;)]

Not sure this is what was missing? If not, can you please post the code you used?

awolfey’s picture

Hi,

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.

risou’s picture

I have the same problem! The block does not change the displayed images if the user profile is changed !!

I tested the following snippets:


<?php
if (arg(0) == 'user' && is_numeric($uid = arg(1))) {
  $params = array(
    'blocks' => implode('|', array_fill(0, 4, 'randomImage')),
    'itemId' => 'user:'. $uid
  );
  $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 2));
  print $block['content'];
}
?>

scarer’s picture

Version: 5.x-2.0-beta4 » 6.x-1.0

when i run the code i use this:

if (arg(0) == 'user' && is_numeric($uid = arg(1))) {
  $params = array(
    'blocks' => implode('|', array_fill(0, 3, 'randomImage')),
    'itemId' => 'user:'. $account->uid
  );
  $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => 3));
  print $block['content'];
}

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 ;)

scarer’s picture

I uninstalled gallerix and it seems to work but the view is not filtered by user.