Show file author/uploader in gallery images
Permalink
Hi all!
I wanted to add a block of code in a gallery that will call out the name of the file and show the name of the uploader/author as well, but I think I must be doing something wrong because the name changes depending on who logs in.
So for example, USER1 logs in, and he'll see file1.jpg by user1.
But if USER2 logs in, he'll see file1.jpg by user2 instead.
Can someone tell me what I did wrong?
In /concrete/packages/asmiller_gallery/blocks/asmiller_gallery/view.php, I did this:
I wanted to add a block of code in a gallery that will call out the name of the file and show the name of the uploader/author as well, but I think I must be doing something wrong because the name changes depending on who logs in.
So for example, USER1 logs in, and he'll see file1.jpg by user1.
But if USER2 logs in, he'll see file1.jpg by user2 instead.
Can someone tell me what I did wrong?
In /concrete/packages/asmiller_gallery/blocks/asmiller_gallery/view.php, I did this:
<?php foreach($images as $imgInfo) { $f = File::getByID($imgInfo['fID']); echo $imgInfo['width']; echo '<li><img src="'; echo $f->getRelativePath(); echo '" '; echo 'title="'; echo $imgInfo['description']; $title = $f->getApprovedVersion()->getTitle(); echo $title; echo " by "; echo $u->getUserName(); echo '"/></li>'; ;}; ?>
Thanks so much! It did work! :)
But here's the thing – it seems to work on the asmiller gallery, but not in the Sortable Fancybox gallery (which I am also implementing):
This is very weird!
But here's the thing – it seems to work on the asmiller gallery, but not in the Sortable Fancybox gallery (which I am also implementing):
<div class="sortable_fancybox_gallery_container"> <?php foreach ($images as $img): ?> <div class="sortable_fancybox_gallery_image" style="height: <?php echo $max_row_height; ?>px; width: <?php echo $column_width; ?>;"> <?php if ($enableLightbox): ?> <a href="<?php echo $img['full_src']; ?>" rel="<?php echo $rel; ?>" title="<?php echo $img['title']; ?><?php echo " by "; ?><?php echo $f->getApprovedVersion()->getAuthorName(); ?>"> <?php echo $html->image($img['thumb_src'], $img['thumb_width'], $img['thumb_height'], array('alt' => $img['title'])); ?> </a> <?php else: ?> <?php echo $html->image($img['full_src'], $img['full_width'], $img['full_height'], array('alt' => $img['title'])); ?> <?php endif; ?> </div>
This is very weird!
It looks like the controller of the sortable fancybox returns an array of image properties (url, title, etc), so you really don't have access to the file object as you did in the other block. You would have to modify the controller to also add the author to the returned array. Something like this under line 42:
Then within your view file you could call the following to echo the author name:
That should do the trick.
$image['author'] = htmlspecialchars($fv->getAuthorName(), ENT_QUOTES, 'UTF-8');
Then within your view file you could call the following to echo the author name:
echo $img['author'];
That should do the trick.
Andrew, thanks so much for this -- it works perfectly! :)
Without testing, that should do the trick.