Random album cover
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Hi, It will be nice to have random album covers (thumbs). Is there any option for this? I tryed to code it by myself. Greets Kees. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
There is no option for this at this time. Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Is there any update about this request? Or does anyone knows how to code it by myself (the sql query). Greets Kees. |
|
rWatcher
![]()
Joined: 2005-09-06
Posts: 722 |
![]() |
Untested, but maybe something like this: $item = ORM::factory("item", $album_id) ->viewable() ->where("type", "!=", "album") ->where("rand_key", "<", random::percent()) ->order_by("rand_key", "DESC"); ->descendants(1); $album_id would be the id# of the parent album. |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
This is the original code, how i have to place the above code?
Greets Kees. |
|
rWatcher
![]()
Joined: 2005-09-06
Posts: 722 |
![]() |
I would do something like: if ($child->is_album()) { $rnd = ORM::factory("item", $child->id) ->viewable() ->where("type", "!=", "album") ->where("rand_key", "<", random::percent()) ->order_by("rand_key", "DESC"); ->descendants(1); if ($rnd->loaded()) { // Your code goes here. } } |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
It don't works. Here is the whole code maybe it will help: <?php defined("SYSPATH") or die("No direct script access.") ?> <? // @todo Set hover on AlbumGrid list items for guest users ?> <div id="g-info"> <?= $theme->album_top() ?> <h1><?= html::purify($item->title) ?></h1> <div class="g-description"><?= nl2br(html::purify($item->description)) ?></div> </div> <ul id="g-album-grid" class="ui-helper-clearfix"> <? if (count($children)): ?> <? foreach ($children as $i => $child): ?> <? $item_class = "g-photo"; ?> <? if ($child->is_album()): ?> <? $item_class = "g-album"; ?> <? endif ?> <li id="g-item-id-<?= $child->id ?>" class="g-item <?= $item_class ?>"> <?= $theme->thumb_top($child) ?> <? if ($child->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $child->id)->find()) && $rnd->loaded()): ?> <a href="<?= $child->url() ?>"> <? if ($rnd->has_thumb()): ?> <? if ($rnd->thumb_height >= $rnd->thumb_width): ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> </a> <? else: ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <? if ($child->thumb_height >= $child->thumb_width): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> <? endif ?> </a> <?= $theme->thumb_bottom($child) ?> <?= $theme->context_menu($child, "#g-item-id-{$child->id} .g-thumbnail") ?> <h2><span class="<?= $item_class ?>"></span> <a href="<?= $child->url() ?>"><?= html::purify($child->title) ?></a></h2> <ul class="g-metadata"> <?= $theme->thumb_info($child) ?> </ul> </li> <? endforeach ?> <? else: ?> <? if ($user->admin || access::can("add", $item)): ?> <? $addurl = url::site("uploader/index/$item->id") ?> <li><?= t("There aren't any photos here yet! <a %attrs>Add some</a>.", array("attrs" => html::mark_clean("href=\"$addurl\" class=\"g-dialog-link\""))) ?></li> <? else: ?> <li><?= t("There aren't any photos here yet!") ?></li> <? endif; ?> <? endif; ?> </ul> <?= $theme->album_bottom() ?> <?= $theme->paginator() ?> |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Is there any news about this? |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
This seems to work but has some lag. Perhaps I can make it a bit better moving the code up a bit but this is a proof of concept first.... <? if ($child->is_album()): ?> <? $rnd = item::random_query()->where("parent_id", "=", $child->id)->find(); ?> <script> $("#g-item-id-<?= $child->id ?> img.g-thumbnail").attr("src", "<?= $rnd->thumb_url(); ?>"); </script> <? endif ?> just after Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
How about the attached module? Dave |
|
shug17
Joined: 2009-01-10
Posts: 76 |
![]() |
Dave, excellent work - love it! Installed it and tested on one gallery so far. Is there a setting option - so that some albums will be exempted? Many Thanks |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Many thanks for trying It works a little bit but not correctly. See it on www.mydigitalworld.nl Second problem is that when a album has sub albums (as example the album vakantie) it don't work. When you have only pics in the album (without subs) it works ok. This is the code: <?php defined("SYSPATH") or die("No direct script access.") ?> <? // @todo Set hover on AlbumGrid list items for guest users ?> <div id="g-info"> <?= $theme->album_top() ?> <h1><?= html::purify($item->title) ?></h1> <div class="g-description"><?= nl2br(html::purify($item->description)) ?></div> </div> <ul id="g-album-grid" class="ui-helper-clearfix"> <? if (count($children)): ?> <? foreach ($children as $i => $child): ?> <? $item_class = "g-photo"; ?> <? if ($child->is_album()): ?> <? $item_class = "g-album"; ?> <? endif ?> <li id="g-item-id-<?= $child->id ?>" class="g-item <?= $item_class ?>"> <?= $theme->thumb_top($child) ?> <? if ($child->is_album()): ?> <? $rnd = item::random_query()->where("parent_id", "=", $child->id)->find(); ?> <script> $("#g-item-id-<?= $child->id ?> img.g-thumbnail").attr("src", "<?= $rnd->thumb_url(); ?>"); </script> <? endif ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? endif ?> </a> <?= $theme->thumb_bottom($child) ?> <?= $theme->context_menu($child, "#g-item-id-{$child->id} .g-thumbnail") ?> <h2><span class="<?= $item_class ?>"></span> <a href="<?= $child->url() ?>"><?= html::purify($child->title) ?></a></h2> <ul class="g-metadata"> <?= $theme->thumb_info($child) ?> </ul> </li> <? endforeach ?> <? else: ?> <? if ($user->admin || access::can("add", $item)): ?> <? $addurl = url::site("uploader/index/$item->id") ?> <li><?= t("There aren't any photos here yet! <a %attrs>Add some</a>.", array("attrs" => html::mark_clean("href=\"$addurl\" class=\"g-dialog-link\""))) ?></li> <? else: ?> <li><?= t("There aren't any photos here yet!") ?></li> <? endif; ?> <? endif; ?> </ul> <?= $theme->album_bottom() ?> <?= $theme->paginator() ?> Greets Kees. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
Is there a setting option - so that some albums will be exempted? Not yet. How do you want this setting? Number of items in an album? or album specific? How do you propose the UI to work & look like? Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Knorde, Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
Second problem is that when a album has sub albums (as example the album vakantie) it don't work. So we don't want to randomize the cover if there is only sub-albums in the album? Dave |
|
shug17
Joined: 2009-01-10
Posts: 76 |
![]() |
Dave, my own personal thought is that each album can opt in or out of the random image - just like we had in G2. So that if you have an album with 2 sub albums. one album can have the random item from an image inside it and the other album can have a fixed non random image. Then the top album will pick from the two album covers and use that as it's cover. as for how to do it - I dunno - my coding skills are non-existent, sorry. Could the UI be in the album option menu for each album? |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Ok now i used the module only (and not the code) but i see the same effect as i described above |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
floridave wrote:
Ok i understand but in that case the parent album has always the same thumb and will never be another one. As example: Parentalbum "Vacation" - Subalbum "2012" - Subalbum "Italy" It will be nice if the thumb of Vacation will be random from the subs or newest one or something. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
If it is a fixed one, it will always be the same after years Choose your own at any time. Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
Ok now i used the module only (and not the code) but i see the same effect as i described above The two albums with no highlight only have one item it it. Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
floridave wrote:
Now i have placed extra pics in (as example) Auto. But same problem (maybe you have to refresh some times |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Added some code to check in $rnd is set. More upgrades to come....later Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Ok tnx, where can i download it? |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Updated to version 2. Still thinking about the best way to eliminate some albums from randomization. Dave _____________________________________________ |
|
shug17
Joined: 2009-01-10
Posts: 76 |
![]() |
I get an error occurred while installing for version 2. I tried to upgrade first and got the error. Then I un-installed the module deleted it with ftp and uploaded v2. installed it and still getting the error. It hasn't effected the thumbnails as far as I can see they are the ones I picked before trying this module. Thanks |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
I get an error while installing the module. "Er is een fout opgetreden bij het installeren van de module Random album cover - highlight". It means it will not be installed because there is an error |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Not sure why you got an error but have attached version 3 that now includes 2 new features: Later this week I will create a codex page. Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Hi Dave, This is exactly what I wanted, perfect! I only have one more little thing (but this is not something to the module). If I use the original album.html.php the random module works fine but with the custom album.html.php it does not work correctly. <?= $theme->thumb_top($child) ?> <? if ($child->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $child->id)->find()) && $rnd->loaded()): ?> <a href="<?= $child->url() ?>"> <? if ($rnd->has_thumb()): ?> <? if ($rnd->thumb_height >= $rnd->thumb_width): ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> </a> <? else: ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <? if ($child->thumb_height >= $child->thumb_width): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> <? endif ?> </a> |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
If I use the original album.html.php the random module works fine but with the custom album.html.php it does not work correctly. What do you mean by not working? I'm assuming that the image is distorted as different images are used? Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
I don't use other pics. You can test it to refresh some times When i use the original album.html.php the random module works perfect only in that case i have not the right ration (portrait or landscape). Below is the whole code from my custom album.html.php <?php defined("SYSPATH") or die("No direct script access.") ?> <? // @todo Set hover on AlbumGrid list items for guest users ?> <div id="g-info"> <?= $theme->album_top() ?> <h1><?= html::purify($item->title) ?></h1> <div class="g-description"><?= nl2br(html::purify($item->description)) ?></div> </div> <ul id="g-album-grid" class="ui-helper-clearfix"> <? if (count($children)): ?> <? foreach ($children as $i => $child): ?> <? $item_class = "g-photo"; ?> <? if ($child->is_album()): ?> <? $item_class = "g-album"; ?> <? endif ?> <li id="g-item-id-<?= $child->id ?>" class="g-item <?= $item_class ?>"> <?= $theme->thumb_top($child) ?> <? if ($child->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $child->id)->find()) && $rnd->loaded()): ?> <a href="<?= $child->url() ?>"> <? if ($rnd->has_thumb()): ?> <? if ($rnd->thumb_height >= $rnd->thumb_width): ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> </a> <? else: ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <? if ($child->thumb_height >= $child->thumb_width): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> <? endif ?> </a> <?= $theme->thumb_bottom($child) ?> <?= $theme->context_menu($child, "#g-item-id-{$child->id} .g-thumbnail") ?> <h2><span class="<?= $item_class ?>"></span> <a href="<?= $child->url() ?>"><?= html::purify($child->title) ?></a></h2> <ul class="g-metadata"> <?= $theme->thumb_info($child) ?> </ul> </li> <? endforeach ?> <? else: ?> <? if ($user->admin || access::can("add", $item)): ?> <? $addurl = url::site("uploader/index/$item->id") ?> <li><?= t("There aren't any photos here yet! <a %attrs>Add some</a>.", array("attrs" => html::mark_clean("href=\"$addurl\" class=\"g-dialog-link\""))) ?></li> <? else: ?> <li><?= t("There aren't any photos here yet!") ?></li> <? endif; ?> <? endif; ?> </ul> <?= $theme->album_bottom() ?> <?= $theme->paginator() ?> |
|
shug17
Joined: 2009-01-10
Posts: 76 |
![]() |
Dave, looking great - working on one install already - 3 more to go when I get time. Thanks You so much! Shug17 |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
When i use the custom album.html.php the ration (portrait or landscape) isn't everytime correct. Is this customization for random album highlights? You cson't need a new album.html.php to accomlish this as the module will do it for you. Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Also viwing the source of your page the Vakantie thumbnail never changes as the class to the image changes for some reason. Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Is this: <? if ($rnd->has_thumb()): ?> <? if ($rnd->thumb_height >= $rnd->thumb_width): ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> part of the original theme? Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Your theme or your customization need some work <? endif ?> </a> <? else: ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <? if ($child->thumb_height >= $child->thumb_width): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> <? endif ?> </a> I would suggest using the original theme code and report back your findings. Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
The theme is browny_wind. For every different screen resolution i use a different css file. .g-thumbnail { border: 1px solid #000000; margin-top: 3px; margin-bottom: 3px; max-height: 120px; max-width: 90px; } .g-thumbnail2 { border: 1px solid #000000; margin-top: 3px; margin-bottom: 3px; max-height: 120px; max-width: 160px; } The result is that every screen resolution has a nice site resolution. g-thumbnail and g-thumbnail2 is portrait or landscape. <? if ($rnd->has_thumb()): ?> <? if ($rnd->thumb_height >= $rnd->thumb_width): ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $rnd->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> The above code is not a part of the original browny_wind theme. I have made it by myself. This is the original album.html.php <?php defined("SYSPATH") or die("No direct script access.") ?> <? // @todo Set hover on AlbumGrid list items for guest users ?> <div id="g-info"> <?= $theme->album_top() ?> <h1><?= html::purify($item->title) ?></h1> <div class="g-description"><?= nl2br(html::purify($item->description)) ?></div> </div> <ul id="g-album-grid" class="ui-helper-clearfix"> <? if (count($children)): ?> <? foreach ($children as $i => $child): ?> <? $item_class = "g-photo"; ?> <? if ($child->is_album()): ?> <? $item_class = "g-album"; ?> <? endif ?> <li id="g-item-id-<?= $child->id ?>" class="g-item <?= $item_class ?>"> <?= $theme->thumb_top($child) ?> <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? endif ?> </a> <?= $theme->thumb_bottom($child) ?> <?= $theme->context_menu($child, "#g-item-id-{$child->id} .g-thumbnail") ?> <h2><span class="<?= $item_class ?>"></span> <a href="<?= $child->url() ?>"><?= html::purify($child->title) ?></a></h2> <ul class="g-metadata"> <?= $theme->thumb_info($child) ?> </ul> </li> <? endforeach ?> <? else: ?> <? if ($user->admin || access::can("add", $item)): ?> <? $addurl = url::site("uploader/index/$item->id") ?> <li><?= t("There aren't any photos here yet! <a %attrs>Add some</a>.", array("attrs" => html::mark_clean("href=\"$addurl\" class=\"g-dialog-link\""))) ?></li> <? else: ?> <li><?= t("There aren't any photos here yet!") ?></li> <? endif; ?> <? endif; ?> </ul> <?= $theme->album_bottom() ?> <?= $theme->paginator() ?> |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
floridave wrote:
Your theme or your customization need some work Above that is the <a> look: <a href="<?= $child->url() ?>"> <? if ($child->has_thumb()): ?> <? if ($child->thumb_height >= $child->thumb_width): ?> <?= $child->thumb_img(array("class" => "g-thumbnail")) ?> <? else: ?> <?= $child->thumb_img(array("class" => "g-thumbnail2")) ?> <? endif ?> <? endif ?> <? endif ?> </a> |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
The code works perfect without the random module. I works just fine without your customization's as well i bet. Quote:
Above that is the <a> look: I'm not going to debug your theme in this thread. I just saw two closing </a> tags when viewing the source. OK for your custom theme see if this helps: <script type="text/javascript"> $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("src", "<?= $rnd->thumb_url(); ?>"); $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("height", "<?= $rnd->thumb_height; ?>"); $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("width", "<?= $rnd->thumb_width; ?>"); </script> Replace the code_thumb_top.html.php in my modules view folder with the above code. Perhaps a better JS jquery expert can chime in if getting the selector above to work with g-thumbnail and g-thumbnail2 to work without selecting too much or too little. Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Hi, The random module works but the pics are in incorrect resolution sometimes now (portrait or landscape). I think the problem is that in the random module code i only see g-thumbnail and not g-thumbnail2. No idea :P <script type="text/javascript"> $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("src", "<?= $rnd->thumb_url(); ?>"); $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("height", "<?= $rnd->thumb_height; ?>"); $("#g-item-id-<?= $child->id ?> img[class^=g-thumbnail]").attr("width", "<?= $rnd->thumb_width; ?>"); </script> |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Your site is down now so it is hard to diagnose your theme issue. Anybody else have a issue? or is it just this customized theme? Dave |
|
shug17
Joined: 2009-01-10
Posts: 76 |
![]() |
The module works really well and is so easy to use. Huge Thanks |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
I think the problem is that in the random module code i only see g-thumbnail and not g-thumbnail2. The jquery selector: So any image in a <div> with the id of g-item-id-$child->id that has a class of g-thumbnail or g-thumbnail1 or g-thumbnail2 should be swapped. I hope that helps in understand how it gets swapped. Dave |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
@knorde, your site is still down to diagnose. @shug17, Glad it is working. Got some suggestions to flesh out the docs> http://codex.gallery2.org/Gallery3:Modules:random_album_highlight Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
floridave wrote:
@knorde, your site is still down to diagnose. Don't know the reasson but the error log says: Premature end of script headers: index.php I have nothing changed... I think this is the problem, my host has upgraded the php version. EDIT Don't know now what to do Greets Kees. |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Ok now i have re-installed the whole site. I hope you can diagnose now Greets Kees. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
knorde, Dave |
|
knorde
Joined: 2010-02-02
Posts: 64 |
![]() |
Finally it works now, it is difficult to say how the code is now (i had to change more files) but it works now perfect! Many thanks! Greets Kees. |
|
chrisgaines717
Joined: 2012-10-19
Posts: 1 |
![]() |
Hey Dave, Thanks for sharing, |
|