dpille
Beginner


Joined: Apr 05, 2010 Posts: 1
|
Posted: Thu Dec 02, 2010 5:34 pm Post subject: Image block rewrite |
|
|
So my installation of phpnuke hated the canned image blocks, and I never liked the idea that I had to disable the gallery blocks to use the similar block site-wide. Anyway, I am a complete php newbie, and I'm posting this just in case someone else wants it to just work without having to brute-force program like I did.
The first section handles that "direct call" issue by assuming the file containing the block is block-Random_Image.php. Then, the block gets the direct random image page, strips off the <div...> and </div> tags that phpnuke won't play nice with, and places that in the block output between the <center> tags so it looks prettier.
The key things, I think, are that the @readfile that gallery2 suggests doesn't give you an editable string like flie_get_contents does. Also, I had a huge amount of difficulty remembering that there's a difference between a browser and a server- since my server doesn't recognize its own FQDN, I had to be struck by lightning to think of using localhost or a 192.168... address.
So to do newest image or any of the other out-of-the-box gallery2 image blocks, just get the corresponding link. Then look at the source for the page returned and change the substr($var, start-on-this-number-character-minus-one, stop-this-many-characters-from-the-end) syntax. No guarantees that this will place nice with image titles, etc, but I bet that's a lot easier to figure out than how far I've gotten already.
Hope somebody finds this useful.
<?php
if (eregi("block-Random_Image.php",$_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
$var = file_get_contents("http://path-to-gallery2-consider-'localhost'/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=none");
$content = "<center>";
$content .= substr($var, 23, -7);
$content .= "</center>";
?> |
|