If you wanna know how I got it to work, read on
Summary
The goal is to be able to simply php-include the ImgBrowz0r's index.php file in a WordPress page-template but set the path to something else.
By default imgbrowz0r extracts the path from the "q"-variable in the URL.
For example:
- Code: Select all
http://example.com/imgbrowz0r/index.php?q=path/1
The way the script get's that path into a variable, by default, is the following snippet from imgbrowz0r.php from line 87 and beyond:
- Code: Select all
public function init()
{
// Get current url
$protocol = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off' ? 'http://' : 'https://';
$port = $this->config['ignore_port'] === false && (isset($_SERVER['SERVER_PORT']) && (($_SERVER['SERVER_PORT'] != '80'
&& $protocol == 'http://') || ($_SERVER['SERVER_PORT'] != '443' && $protocol == 'https://'))
&& strpos($_SERVER['HTTP_HOST'], ':') === false) ? ':'.$_SERVER['SERVER_PORT'] : '';
$current_url = urldecode($protocol.$_SERVER['HTTP_HOST'].$port.$_SERVER['REQUEST_URI']);
// Regex
preg_match('/^'.str_replace(
array('{', '}', '[', ']', '?', '(', ')', '-', '.', '/', '=', '%PATH%'),
array('\{', '\}', '\[', '\]', '\?', '\(', '\)', '\-', '\.', '\/', '\=', '(.*?)'),
$this->config['main_url']).'$/i', $current_url, $matches);
// Set current path/directory and page
$raw_path = isset($matches[1]) ? trim($matches[1], " /\n\t") : false;
1) Switching variable (ifelse)
So basicly, the url get's decomposed into several pieces. Of which the the "matched" array is one.
Then the $raw_path is set to the path extracted from the URL.
So, we're gonna bring in a new variable that's ultimatly being set in a custom-field of the page.
However, we're gonna work our way back to that custom-field from the very same spot in the snipped above.
- Code: Select all
public function init()
{
// Get current url
$protocol = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off' ? 'http://' : 'https://';
$port = $this->config['ignore_port'] === false && (isset($_SERVER['SERVER_PORT']) && (($_SERVER['SERVER_PORT'] != '80'
&& $protocol == 'http://') || ($_SERVER['SERVER_PORT'] != '443' && $protocol == 'https://'))
&& strpos($_SERVER['HTTP_HOST'], ':') === false) ? ':'.$_SERVER['SERVER_PORT'] : '';
$current_url = urldecode($protocol.$_SERVER['HTTP_HOST'].$port.$_SERVER['REQUEST_URI']);
// Regex
//
// ExternalFilePath-hack by Krinkle
//
if( is_null( $this->my_raw_path ) )
{
preg_match('/^'.str_replace(
array('{', '}', '[', ']', '?', '(', ')', '-', '.', '/', '=', '%PATH%'),
array('\{', '\}', '\[', '\]', '\?', '\(', '\)', '\-', '\.', '\/', '\=', '(.*?)'),
$this->config['main_url']).'$/i', $current_url, $matches);
// Set current path/directory and page
$raw_path = isset($matches[1]) ? trim($matches[1], " /\n\t") : false;
}
else
$raw_path = $this->my_raw_path;
if our new variable in $this ("my_raw_path") is empty, then just do the regular thing and extract the q-variable from the URL.
However, if our variable is not null (meaning it's set to something) then set the $raw_path to our new variable.
2) Adding a few extra lines
Now that the hard part is done, we still have to make it valid since this new variable isn't completely covered overall yet.
In the first few lines of imgbrowz0r.php, find the following code:
- Code: Select all
public $status=200;
// Check if GD is loaded and set configuration
public function __construct($config)
And replace it with this :
- Code: Select all
private $my_raw_path = null;
public $status=200;
// Check if GD is loaded and set configuration
public function __construct($config, $my_raw_path = null )
Then find this:
- Code: Select all
// Set configuration
And replace it with this:
- Code: Select all
# set my raw path
$this->my_raw_path = $my_raw_path;
// Set configuration
3) Transferring the variable from index.php to imgbrowz0r.php
In imgbrowz0r's folder open up index.php and tweak a tiny bit.
Find this:
- Code: Select all
// Start the class
$gallery = new imgbrowz0r($config);
And replace with:
- Code: Select all
// Start the class
$gallery = !isset( $mypath ) ? new imgbrowz0r($config) : new imgbrowz0r( $config, $mypath );
What this does is, again. Check if the variable actually is set. And if not, just do the regular thing.
This will also ensure that you can still access all your galleries by browsing imgbrowz0r's folder directly.
4) Including in page-template and using custom-field
Now comes the WordPress-part of the story.
In your page-template (for example page-gallery.php in your Theme's folder) we're going to set $mypath to the value of our custom-field.
Place the following code anywhere within the loop on the place where you want it to show.
I have placed it directly after the main-content of the page but you can place it anywhere as long as it's within the loop.
- Code: Select all
<?php the_content(''); ?>
<div class="gallery-include">
<?php
$mypath = get_post_meta($post->ID, 'galleryPath', true);
$mypath .= "/1";
include $_SERVER['DOCUMENT_ROOT']."/imgbrowz0r/index.php";
?>
</div>
Now all you have left to do is make/edit a page in your backend of Wordpress,
pick the right Template and make/fill in a custom field called galleriePath.
Also, be sure to check the XHTML and CSS in index.php.
I've stripped out a lot (like the fixed-width css code, it now fits perfectly in the width of your blog-post), I also stripped out the html, header and body tags since it's going to be included inside your file. And lastly I've also stripped out the title, breadcrumbs, navigation and statistics.
However, there is an if-else statement that will show all above mentioned when mypath is empty.
Meaning, when you're not including it but accessing /imgbrowz0r/index.php directly.
So but included and not included, you'll still be presented a fully valid page.
5) Conclusion
So, download the attachment to this forumpost and have fun with my ExternalFilePath V2 + imgbrowz0r 0.3.3.
* Don't forget to fill in your relative paths in index.php just like you have to do with the usual imgbrowz0r
* Don't forget to put the above code in your page-template as stated in step 4
* Remember that the custom-field does not have to include " /1 ".
The code-snippet in the page-template already takes care of this