[SOLVED] New Module: RandImg - returns a bit of HTML to display a random image on an external site

nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Sun, 2010-01-03 19:53

Creating a new thread per floridave's request on this thread: http://gallery.menalto.com/node/89325

This tiny module just provides a small interface to be able to fetch a small block of HTML containing a random image. The basic idea is that I wanted a random image from my gallery3 install to display on an external site. You can see this in action at the following site. Each time you reload the page a new image should be displayed:

http://natha.nkinka.de

There is a small bit of code on that page:

<?php
$imglink = file_get_contents("http://natha.nkinka.de/photos/index.php/randimg", "r");
echo "$imglink";
?>

Of course, you would need to change the URL in the above code to match the URL of your gallery3 site.

You can view/download the code here:

http://code.nkinka.de/gitweb?p=randimg.git;a=summary

Nathan

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22890
Posted: Mon, 2010-01-04 01:51

I have created a skeletal codex page:
http://codex.gallery2.org/Gallery3:Modules:randimg
please feel free to fix/update.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
MarkRH

Joined: 2007-05-25
Posts: 178
Posted: Mon, 2010-01-04 03:06

Tried this out. Unless I downloaded the wrong thing, I had to modify both /randimg/helpers/randimg.php and /randimg/views/randimg.html.php files.

The SQL statement in /randimg/helpers/randimg.php doesn't take into account table prefixes. I had to add "g3_" in front of the "items" table name. I also modified it so that it would not return albums and requested the other fields that contain the album directory structure within them.

    $query = "
      SELECT i1.name, i1.title, i1.description, i1.relative_url_cache, i1.relative_path_cache, i2.slug
      FROM g3_items i1 JOIN g3_items i2
        ON i1.parent_id = i2.id
      WHERE i1.type != 'album'
      ORDER BY RAND()
      LIMIT 1;
    ";
    $result = $db->query($query)->current();

    $randimg = new View("randimg.html");
    $relpath = "$result->slug/$result->name";
    //$randimg->imgpath = $relpath;
    $randimg->img_url = $result->relative_url_cache;
    $randimg->img_path = $result->relative_path_cache;
    $randimg->img_title = $result->title;

    return $randimg;

Your site's URL was still hard-coded in the /randimg/views/randimg.html.php file as well so I had to change it to match mine. I used the /var/thumbs/ directory instead of the resizes directory.

I'm using Gallery 3 Beta 3 btw.

Hope this helps,
Mark H.

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Mon, 2010-01-04 15:27

floridave & MarkRH, thanks. Regarding views/randimg.html.php, I had made the code non-site specific a while back and had committed the changes locally but had forgot to push the changes back to the repository. Here's the working file:

http://code.nkinka.de/gitweb?p=randimg.git;a=blob;f=views/randimg.html.php;h=6cf0943e74099dfc01b57899f416d61ae2418447;hb=HEAD

Thanks for reminding me about the "type != 'album'". About the table prefix issue, this commit should fix that:

http://code.nkinka.de/gitweb?p=randimg.git;a=commitdiff;h=ea6b892922363aeac1ef7dbf0e17aecd64033071

I really would have liked to use the ORM for this, but the following doesn't work for me:

$result = ORM::factory("item")
  ->viewable()
  ->where("type", "!=", "album")
  ->order_by(NULL, 'RAND()')
  ->find_all(1);

The Kohana docs says that RAND() can be used for order_by like that, but the query ends up looking like:

"SELECT `items`.* FROM `items` WHERE `type` != 'album' ORDER BY `` RAND() LIMIT 1;"

... but the empty backticks before RAND() cause a MySQL error. Anyone have any thoughts or ideas there?

Thanks!

Nathan

 
Aceofspade
Aceofspade's picture

Joined: 2010-01-09
Posts: 3
Posted: Sun, 2010-01-10 00:00

I suppose i work fine with G3, but for G2 ? this modules can work too ?

G2....

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22890
Posted: Sun, 2010-01-10 00:55
 
MarkRH

Joined: 2007-05-25
Posts: 178
Posted: Sun, 2010-01-10 00:59

No. This is only for Gallery 3. For Gallery 2 just use the Gallery 2 Image Block module which has an External access feature. More info can be found here: http://codex.gallery2.org/Gallery2:Modules:imageblock and http://codex.gallery2.org/Gallery2:How_To_Use_The_External_Image_Block_When_url_fopen_Is_Disabled

Hope it helps,
Mark H.

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Sun, 2010-01-10 15:13

Can anyone comment on this commit?:

http://github.com/gallery/gallery3/commit/b8ee6f25bdd9372dccd4552ca29cf6f2857e8164

If there is a REST interface to the G3 imageblock module, it seems like that would obviate the need for the randimg module, no? I looked at the code but it wasn't clear to me how to construct the URL and I couldn't really find docs about the G3 REST implementation.

Nathan

 
Aceofspade
Aceofspade's picture

Joined: 2010-01-09
Posts: 3
Posted: Sun, 2010-01-10 17:50

Thanks all !!! ;-)

 
aamir888

Joined: 2010-01-12
Posts: 1
Posted: Tue, 2010-01-12 14:35

well... i've just installed Gallery3 and enable reCaptcha, but its not showing.
anybody can help?

Aamir
==========
http://www.windows-7-wallpapers.org

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2010-01-12 14:40

What's not showing? If you are talking about the reCaptcha, then this is the wrong thread. Otherwise, would you elaborate?

Nathan

 
Vadim_ru

Joined: 2010-04-30
Posts: 2
Posted: Fri, 2010-04-30 06:57

Soory, but what`s the matter?

http://www.covcheg.org/random.php

The hosting support can`t help.

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Mon, 2010-07-26 19:39

Hi,

I am looking for a simple module for this. This looks just the one I want but it doesn't seems to work for me.

I embedded the code in http://galerie.cindyenguy.be/random.php
Only the title shows. The link is
http://galerie.cindyenguy.be/index.php/De-Efteling/DSC_4096-2 instead of
http://galerie.cindyenguy.be/index.php/2009/De-Efteling/DSC_4096
Image source is
http://galerie.cindyenguy.be//var/resizes/De-Efteling/DSC_4096-2.jpg instead of
http://galerie.cindyenguy.be//var/resizes/2009/De-Efteling/DSC_4096.jpg

It seems that the code can't handle albums within albums.

Any ideas?

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Mon, 2010-07-26 19:48

Take a look at the source HTML that is generated on your page:

<a href="http://galerie.cindyenguy.be/index.php/De-Efteling/DSC_4104-2" title="DSC 4104-2">
<img src="http://galerie.cindyenguy.be//var/resizes/De-Efteling/DSC_4104-2.jpg" style="border: thin solid black;" alt="DSC 4104-2" />
</a>

When I click on the link provided by the alt="" tag I get a login page. Your images need to be publicly accessible in order for any browser to display them using this plugin.

 
Serge D
Serge D's picture

Joined: 2009-06-11
Posts: 2139
Posted: Tue, 2010-07-27 00:29

http://codex.gallery2.org/Gallery3:Modules:rss_extra provides RSS feed with random images
You can then use something like MiniSlideShow to display content on external page

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Tue, 2010-07-27 15:14

@nkinkade: strange, when I go to http://galerie.cindyenguy.be/var/resizes/De-Efteling/DSC_4096-2.jpg I get a 404 not found error because the "2009" isn't in the link.

@Serge D: I know your plugin. Problem with it is that the links don't work when I put it on my blog. And I don't like flash

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2010-07-27 15:44

@GuyVerschuere. Sorry, my comments were related to the target of the link, not the actual src of the <img> tag. I didn't bother to follow that and it is indeed a 404. I'm not sure what it could be. I'm using the module on this page and my generated links include the album in the path. I'm not sure why it wouldn't be in your set up:

http://natha.nkinka.de/

Could it by some chance be a theme issue of some sort? I'm using the latest development code from Gallery3, at least the latest as of maybe 2 weeks ago.

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Tue, 2010-07-27 20:00

I notice that all your pictures are in albums under the root.
All my pictures are in albums within albums because I first want to filter by year.

I'm gonna test to be sure by moving some albums to the root.

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Tue, 2010-07-27 20:17

Yup, that's the problem.
I moved some albums from the 2010 album to the root album.

If you refresh several times http://galerie.cindyenguy.be/random.php you get the image. If one from those albums is chosen that is.

So, the problem is that subalbums don't work.

Can you fix that? Really one to keep my years at the root album.

Thanks!

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2010-07-27 20:52

Thanks for figuring this out. I think this commit corrects the problem:

http://code.nkinka.de/gitweb?p=randimg.git;a=commitdiff;h=8335cc388672614395481d8519276e746fad3248

You should be able to download the latest version at this URL:

http://code.nkinka.de/gitweb?p=randimg.git;a=snapshot;h=HEAD;sf=tgz

Let me know if this does or doesn't work for you.

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Wed, 2010-07-28 05:34

WORKS!!!

THANK YOU!

A minor issue discovered:

<a href="http://galerie.cindyenguy.be/index.php/" title="DSC 6255">
<img src="http://galerie.cindyenguy.be//var/resizes/" style="border: none;" alt="DSC 6255" width="220px" />
</a>

If the random selects a image wich is never been shown on the site there's no relative_path_cache in the database.
Maybe a 'maintenance task' can be written for that?

I also added a witdh specification because the script uses the resize instead of the thumb.

Again, THANK YOU for the fast solution!

 
GuyVerschuere
GuyVerschuere's picture

Joined: 2007-09-16
Posts: 88
Posted: Wed, 2010-07-28 08:08

In 'helpers/randimg.php' I changed:

WHERE i1.type != 'album'

to:

WHERE `i1.relative_path_cache` IS NOT NULL AND `i1.type` != 'album'

In 'viewers/randimg.html.php' I had to hardcode the imagesource, otherwise there was a 404 due to the double slash //

<img src="http://galerie.cindyenguy.be/var/thumbs/$imgpath" style="border: none;" alt="$img_title" width="200px" />

 
xaphod2

Joined: 2006-03-30
Posts: 11
Posted: Mon, 2010-10-04 00:12

If anyone out there wants randimg to grab the FULL size image (not just the resize), then here's how I hacked it: from the modules/randimg folder on the server, edit ./views/randimg.html.php, and change the line
<img src="http://$virtpath/var/resizes/$imgpath"

... to ...

<img src="http://$virtpath/var/albums/$imgpath"

 
Vojtech
Vojtech's picture

Joined: 2009-06-22
Posts: 24
Posted: Tue, 2010-10-26 17:08

I recently upgraded my site from G2 to G3: http://botany.natur.cuni.cz/zeisek/galerie/ I created http://botany.natur.cuni.cz/zeisek/galerie_obr.php containing more or less only HTML head and the code from this module, which is supposed to produce random image, but it does not work... Any idea why and how to get it to work?

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2010-10-26 17:26

Just to be sure, you have followed the directions at the following URL and the module is enabled?

http://codex.gallery2.org/Gallery3:Modules:randimg

Nathan

 
Vojtech
Vojtech's picture

Joined: 2009-06-22
Posts: 24
Posted: Tue, 2010-10-26 19:24

Yes, the page with random image contains
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body bgcolor="e7eaed"><center>
<?php
$imglink = file_get_contents("http://botany.natur.cuni.cz/zeisek/galerie/index.php/randimg", "r");
echo "$imglink";
?>
</center></body></html>
and it sais "No direct script access." so I think I have to edit somehow the randimg.html.php, but I have no idea how... :-(

 
Vojtech
Vojtech's picture

Joined: 2009-06-22
Posts: 24
Posted: Tue, 2010-10-26 19:29

Ah, sorry, I get to work. Nathan, sorry t disturb and thank YOu for Your interest. :-) I had problem with Apache aliases in httpd.conf. Nothing with Your module. It works fine now. :-)

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Wed, 2010-10-27 20:55

i have a modified version on my downloads page here: http://www.danneh.org/downloads/
it's html output was modified from the original version to be a little cleaner/tidier/compact, and there's also a wordpress plugin to put it on your blog if you so wish. the same principle can be applied to any cms that has a widget/modular structure, or just use the methods in the widget on that page to integrate into your own site.

credit goes to the original author though. i just made it a little better :)

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Wed, 2010-10-27 21:03

I'm the original author. Might I suggest that if your changes are generally applicable to everyone that you submit me a patch and I'll be happy to update the sources. :-)

Also the files on your site appear to tarred then gzipped twice. For the following file I had to gunzip it twice, then untar it:

http://www.danneh.org/files/randimg.tar.gz

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Wed, 2010-10-27 21:15

it's a gzipped tarball;

tar -zxf file.tar.gz

will decompress and untar the file at the same time. i rarely use zip on the command line. old habit. i'll grab you a patch if you want and post it here later.

Dan

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Wed, 2010-10-27 21:19

It's not right. It appears you gzipped a tar-gzipped file.

~/tmp$ tar xvzf randimg.tar.gz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
~/tmp$ file randimg.tar.gz
randimg.tar.gz: gzip compressed data, from Unix
~/tmp$ gunzip randimg.tar.gz
~/tmp$ tar xvzf randimg.tar
randimg/
randimg/helpers/
randimg/helpers/randimg.php
randimg/module.info
randimg/views/
randimg/views/randimg.html.php
randimg/controllers/
randimg/controllers/randimg.php

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Wed, 2010-10-27 21:38

haha oops. guess when i made that one up i was having a moment! i wonder how many other gzipped gzipped tarballs i have, in general.. :(

i fixed that one anyway lol

 
inposure
inposure's picture

Joined: 2010-04-23
Posts: 268
Posted: Sat, 2010-11-06 02:30

That JOIN clause is really, really expensive and also superfluous. All that is needed is:

SELECT title, relative_path_cache, relative_url_cache
FROM {items}
WHERE type = 'photo' AND relative_path_cache IS NOT NULL
ORDER BY RAND()
LIMIT 1;

Also note the condition type = 'photo', since movies don't have thumbs and thus generate broken image links.

--
http://inposure.se/

 
inposure
inposure's picture

Joined: 2010-04-23
Posts: 268
Posted: Sat, 2010-11-06 03:07

As for the ORM method, try:

order_by(DB::expr('RAND()'))

--
http://inposure.se/

 
inposure
inposure's picture

Joined: 2010-04-23
Posts: 268
Posted: Sat, 2010-11-06 03:50

Disregard the previous comment. This works fine for me:

class randimg_Core {

static function randimg_link() {

$item = item::random_query()->viewable()->where("type", "=", "photo")->find_all(1)->current();

$randimg = new View("randimg.html");
$randimg->imgpath = $item->relative_path();
$randimg->linkpath = $item->relative_url();
$randimg->img_title = $item->title;

return $randimg;

}

}

--
http://inposure.se/

 
inposure
inposure's picture

Joined: 2010-04-23
Posts: 268
Posted: Sat, 2010-11-06 04:02

I haven't seen any flawed results in my limited tests, but just in case, you could implement the method from ImageBlock:

class randimg_Core {

static function randimg_link() {

$randimg = '';
$attempts = 0;
do {
$item = item::random_query()->viewable()->where("type", "=", "photo")->find_all(1)->current();
} while (!$item && $attempts++ < 3);
if ($item && $item->loaded()) {
$randimg = new View("randimg.html");
$randimg->imgpath = $item->relative_path();
$randimg->linkpath = $item->relative_url();
$randimg->img_title = $item->title;
}
return $randimg;

}

}

--
http://inposure.se/

 
inposure
inposure's picture

Joined: 2010-04-23
Posts: 268
Posted: Sat, 2010-11-06 06:37

Actually, we can keep the !=album condition, provided we use thumb_url() instead of relative_path(), but then we have to slightly modify views/randimg.html.php as well.

Attaching a modified version for those who like to play around.

--
http://inposure.se/

AttachmentSize
randimg_mod.zip3.32 KB
 
jg123

Joined: 2003-06-20
Posts: 23
Posted: Sun, 2011-01-02 21:19

It would be nice if you could pass randimg/t, randimg/r, or randimg/f to get the three different sizes of images. Not sure how to get at the query string to parse off this last value.

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Tue, 2011-08-02 20:41

I have an updated version here which i've modified for my own purposes. The author might consider merging this into the general release, as it improves a bunch of stuff, including loading an item model as opposed to just dragging the relevant data out of the database.

If you use mine, in modules/randimg/views/randimg.html.php (line 16) is a call to $item->thumb_url(true); You could change this to the following:

switch (Input::instance()->get("size")) {
    case "f": $thumb_url = $item->file_url(true); break;
    case "r": $thumb_url = $item->resize_url(true); break;
    case "t":
    default: $thumb_url = $item->thumb_url(true);
}

Then you can construct url's as such:
http://www.mydomain.com/gallery3/randimg?size=f&width=x (fullsize)
http://www.mydomain.com/gallery3/randimg?size=r&width=x (resize)
http://www.mydomain.com/gallery3/randimg?size=t&width=x (thumb)

(set width to number in pixels for the output html). hope this helps.

Dan

danneh.org :: Gallery3

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2011-01-04 01:16

danneh3826,

You're changes look fine to me and I'll be happy to apply your them to the sources. However, before I do that can you clarify one thing for me. In helpers/randimg.php, this following looks wrong:

    $max_iterations_before_fail = 10;

    $iterations = 0;
    do {
      $iterations = 1;
      <snip>
    } while (!access::can("view", $item) && $iterations > $max_iterations_before_fail);

You are manually setting $iterations to 1, then evaluating it against $max_iterations_before_fail, which will always evaluate to false because 1 will never be more than 10. In the while statement do you really mean to increment $iterations?

      $iterations++

And in the while statement conditions, don't you really mean to check whether $iterations is less than (<) $max_iterations_before_fail, instead of greater than?

Also, being ignorant of how to check for access rights. If I logically read the check in the while conditions it would read "while not can view", which seems like the opposite of what we want. My theory is that the only reason your code currently works is because the while conditions aren't checked until after the first iteration, because as far as I can tell both conditions will always evaluate to false so the while loop will never iterate more than once. To verify this, I moved the conditions to the beginning of the while statement and I found the code failed. Am I wrong here?

These are the main problems that stood out to me. Wrapping the returned HTML in a nicely id'd <div> seems like a great idea. And using Gallery3's own item model does make a lot more sense than picking around at individual fields in the db.

Once you can clarify, and possibly address, my above concerns I'll push your changes to the repository.

Thanks,

Nathan

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Tue, 2011-01-04 01:30

hi nathan;

i see where you're coming from, and re-evaluating the code confused myself for a bit. firstly, you are quite correct. it should be $iterations++. that's my bad. the while statement logically reads:

while (unable to view item and number of iterations more than maximum). therefore;

if an item is returned and you can view it, access::can() will return true. the while statement becomes invalid, and breaks. or;
if the number of iterations exceeds the maximum number of iterations and access::can() still hasn't returned a true value (not come across an item which you CAN view), the while statement is invalid, and breaks.

however, re-reading the code after that, $item will be set to the last item before the loop breaks, so if it's unable to find an item which you can view, then exceeds the maximum number of iterations, it'll still spit out the last $item to the browser. i suppose one last if statement can be wrapped around the creation of the view to check if $item is defined, and access::can("view", $item), else return an empty string.

i'll fix them 2 issues, i hope my explanation of the while loop statement makes more sense now?

Dan

danneh.org :: Gallery3

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2011-01-04 01:47

Hey Dan,

Thanks for the explanation. The !access::can() part now makes sense. But I think in addition to changing $iterations = 1 to $iterations++, you also want to change the while condition to a less than. That is, you only want the while to continue as long as $iterations is less than $max_iterations_before_fail. What you may have meant was this:

while (! access::can("view", $item) && ! $iterations > $max_iterations_before_fail);

But it seems easier to me to simply check that $iterations is less than the max. Not only is that easier to understand and read, but your loop will actually iterate 11 times, since you set $iterations to 0.

Thanks for the improvements.

Nathan

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Tue, 2011-01-04 01:47

alright. done some fixes. same url here. your comments on $iterations > $max_iterations_before_fail were also correct. silly me. i fixed that too, $iterations++, and added an if check under the while loop to make sure it doesn't vend a view with an item you're not allowed to see (which would happen if it was unable to find an item you're allowed to see).

thanks for pointing them out. the whole reason i updated the code was so that it would play better with my aws_s3 module, which extends the item model and overloads the thumb_url(), resize_url() and file_url() functions within there to redirect the request off to s3. of course, since the previous version of this code just took the path straight from the database, it didn't work (and took me a while to figure out why lol).

the g- id'd div was put there so i could style it within my wordpress installation, but i guess it gives greater access for styling in various other situations also :)

Dan

danneh.org :: Gallery3

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Tue, 2011-01-04 02:44

Thanks, Dan. Another question. It somehow seems really inefficient to grab an item and then check to see if we have view access, and if not, to select another item, and so on until we reach some arbitrary $max_iterations count. Isn't there some way to select only times which are viewable? And a related question: in which cases will a module not have view permissions for an item? This latter question is mostly my own lack of knowledge about how Gallery3 works.

Thanks.

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Tue, 2011-01-04 03:57

it does, a little, yes. i agree. however, it's the easiest method to check for a permissions for items, since access:can() only takes (and accepts) an item model as it's $item parameter. if i ever find a way of improving it, i'll be one of the first to implement it across the modules i develop/maintain. take a look at modules/gallery/helpers/access.php from line 93 (static function user_can() {} (where access::can() ends up)), and you'll see what i mean!

it's not a case of the module not having permission to view an item, but the requesting client. access::can() checks the currently logged in user against the item's group/individual permissions, etc. in some cases there may be only some items (out of thousands) that are viewable by "everybody" (if not a registered/logged in user), so the chances or it returning a viewable item is quite slim, or in other cases where *no* items are viewable by everybody, so it'll never return anything if the user's not logged in.

hope this helps.

Dan

danneh.org :: Gallery3

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Sun, 2011-01-09 18:03

The module is updated now to reflect some of the changes you proposed, mostly in passing the item model to the view rather than trying to pick fields from the database. For selecting a ramdom image I just borrowed the snippet from the image_block module, which uses a built-in method in modules/gallery/helpers/item.php called random_query(). There is no need to check for viewability because that method used the ORM method of ->viewable() to only select viewable items, which I now understand to be the method I was referring to above to only select viewable items before the fact rather than iterating through results, hoping that one is viewable before $max_iterations is reached.

I removed most of the CSS because I feel that the CSS should be user-configurable via some site-wide CSS include rather that directly coded into the module. I did, however, leave the enclosing <div> with an id="g-randimg" so that the block is selectable by CSS for general purposes.

I also implemented jg123's idea, via your suggested code, for a &size= query parameter, and I also left your &width= paramater.

I updated the wiki page for the module: http://codex.gallery2.org/Gallery3:Modules:randimg

And, per that page, the latest version of the module is here: http://code.nkinka.de/gitweb?p=randimg.git;a=snapshot;h=HEAD;sf=tgz

Thanks!

 
danneh3826
danneh3826's picture

Joined: 2007-08-18
Posts: 274
Posted: Sun, 2011-01-09 19:02

awesome! glad i could help. i'll pull down my copy of the module on my site and re-post it with your official version instead. at least then anyone who has it has any problems with it, we'll all be singing from the same hymn sheet :)

i'll review your code too, as since we're all still learners here, i'll get to learn a thing or 2 as well :)

Dan

danneh.org :: Gallery3

 
jg123

Joined: 2003-06-20
Posts: 23
Posted: Sun, 2011-01-09 21:44

Downloading now. Thanks everyone!

 
burtomov

Joined: 2011-02-23
Posts: 1
Posted: Wed, 2011-02-23 06:21

Hi
1. How can i use more than 1 picture?
2. How can i use last picture?

 
nkinkade

Joined: 2009-12-05
Posts: 37
Posted: Wed, 2011-02-23 14:09

You'd have to change the code in various ways. At the moment, the code uses a Gallery3 built-in function called random_query(), which as far as I know only returns a single item. Same thing for using the most recent photo, the code fetches a random item, so you'd have to modify the code to not use that function. If you look through the git history for this module you should be able to find an iteration of helpers/randimg.php that used raw SQL to pull the item, and that could be a good starting point for pulling multiple photos, and in a certain order.

Nathan

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22890
Posted: Thu, 2011-02-24 02:49

Like nkinkade said the code would have to changed. The image block module has a setting for getting the quantity. I bet this module could be extended to do the same. look in image_block_block.php.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team