I am using the following code on a page to call a random image:
Quote:
<?php @readfile('http://www.mywebsite.com/g2gallerymain/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title'); ?>
It works great!
What code could I add to it to show the "Jump to album" block under it?
Posts: 8601
probably use a local template for modules/imageblock/templates/ImageBlock.tpl
Posts: 23
Do you have to do anything to enable the random block to execute outside of gallery?
Here is the code I'm using:
<?php @readfile('http://www.mysite.com/gallery/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title'); ?>
If I go to the gallery page, the image shows. If I execute the URL above in the browser, the image shows. But on my php page, no image shows. I've even removed the @ symbol but I don't get any errors!
Any ideas? Thanks.
Geoffrey
Posts: 32509
djhomeless, you have to install and activate the g2 site admin -> random / popular module (imageblock module).
if it's active, you should get the block with readfile(...). and if it doesn't work, create a php file with just:
<?php readfile('http://www.mysite.com/gallery/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title'); ?>
to see all errors (no further html).
Posts: 23
Could it possibly be something to do with my htaccess file or Apache? I tried creating an empty php file before and I had put just that code inside but nothing showed (even after removing the @ symbol).
Even stranger if I put in an incorrect hostname, I still don't get any errors.
But this code is working inside the gallery app so I'm really confused why it won't execute remotely.
Thanks again,
Geoffrey
Posts: 23
Hmm, the plot thickens.
It turns out my php.ini settings had allow_url_fopen disabled. Once I enabled this, I can at least see the errors now. As before, if I call the file directly the image loads. If I drop the code into a blank php file, it throws the following:
Anyone run into this?
Thanks,
Geoffrey
Posts: 32509
when i enter this url, i get html, i.e. a HTTP 200 success code. But i also get a G2 security violation. you might have to set other image permissions in G2.
Posts: 23
What G2 security violation are you getting? I changed the permissions on my album to allow All Users to view items, but I am still getting the error.
I'm really lost on why this is happening!
Geoffrey
Posts: 32509
djhomeless, just logout from G2 and browse to
http://www.idiotabroad.com/gallery2/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=title
then you should see that the item is NOT viewable by guests.
Posts: 23
Ok, I see where this is going. But I'm still a bit confused.
I've given user guest All Access permissions in the root of Gallery, and the direct URL is now working even when logged off.
Unfortunately, the simple php file is still giving me the same error as before. The file is here:
http://www.idiotabroad.com/foo.php
Thanks again for the help!
Geoffrey
Posts: 23
Does anyone have any ideas? I'm really desperate to get this working!
Thanks in advance.
Geoffrey
Posts: 8601
djhomeless, try other urls with readfile().. you need to get your php working with readfile. looks like your imageblock is ok now.
Posts: 23
I'm pretty sure its environmental, sadly I don't know enough about my OS to work this through.
Basically I can do all kinds of includes in php with no trouble. However, it always has trouble if I try to execute a script via the hostname.
One thing I was able to figure out, if I replace the hostname, with the local IP I was able to get the script to execute.
However, since I'm not local to the machine it obviously won't stream the image.
My server uses SME Linux (www.contribs.org), which is a heavily secured variant of RedHat 9. I've cross posted this there so hopefully someone may have a clue. If you think of anything I'd appreciate some help as well, this is really frustrating to be so close!
Thanks,
Geoffrey
Posts: 8601
try 84.9.63.165
Posts: 1378
I posted this before .. a lot of Hosting firms are turning off php readfile() because of the security concerns..
Try using the Curl Library with something like this.. (I use them embedded calls so this is defunct for me)
Posts: 23
Sadly this code didn't work (thanks for trying!). I tried both using the IP, and your Curl workaround. The curl code didn't execute or stream an exception back to the browser. I've checked the sys_log but theres nothing useful in there either.
Surely this has something to do with some sort of security restriction or dns?
If I use localhost, or the local ip, the script executes but doesn't stream an image.
If I use the external IP or host, I get a 404.
If I use just a relative path, like /gallery2/main.php, it says there is no such file or directory.
*sigh*
Geoffrey
Posts: 1378
Try something like this using the embedded calls in G2. This is from a testing program so it is pretty crude but you should be able to modify it..
Posts: 32509
and don't forget the GalleryEmbed::done(); at the end of the G2 interactions!
same code, added error status checks and >>done(); at the end:
Posts: 3
Valiant, I've modified your code above to produce a number of thumbnails for use in a horizontal Imageblock. Could it be done any better for multiple blocks?
http://skit.id.au
Posts: 4
I'm using your solution, ozgreg. I was able to customize the output without touching any of the templates or classes in Gallery by using regular expressions:
Just replace the "print $buffer;" line with the above code.
This change gives you more flexibility to define your css for this random image output independently of Gallery's css declarations. I changed the <h4> tags to <p> tags because non-css browsers always treat the contents of the "h" tags as headings. I removed empty "longdesc" statements since HTMLTidy is anal about that.
Posts: 6
I managed to get this script to work but I have a problem with multiple images. Randomimages works fine but when I use Recentimages it just prints the same thumbnail repeatedly.
Is there a way that I can put it in a loop?
here is my code:
Posts: 6
Ahhh, found a way!
And since im feeling friendly today :D Heres a horizontal bar solution!
After "?>" add
And you get a very nice looking horizontal bar!
Posts: 8601
Thanks! I added this info at http://codex.gallery2.org/Gallery2:GalleryEmbed:getImageBlock
Posts: 46
..
if thats the case, how do u turn it back ON and where do you looking for it, php.ini ?
TT