Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Imgbrowz0r vs. WordPress Re: [Solved] Imgbrowz0r vs. WordPress

#59739
TeMc
Member

Okay, after a session on #wordpress on irc.freenode.org I got it fixed !

If you just want to know what to fix, scroll all the way down to Conclusion. If you wanna know how it got to work, read on :)

Summary
The goal is to be able to simply php-include the imgbrowz0r’s index.php file in a page-template but set the path to something else.
By default imgbrowz0r extracts the path from the "q"-variable in the URL.

For example:

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:
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], ” /nt”) : 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:
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], ” /nt”) : 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:
public $status=200;

// Check if GD is loaded and set configuration
public function __construct($config)

And replace it with this :

Code:
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:
// Set configuration

And replace it with this:

Code:
# 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:
// Start the class
$gallery = new imgbrowz0r($config);

And replace with:

Code:
// 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:

Now all you have left to do is make/edit a page in your backend of WordPress, pick the right Template and fill in the galleryPath custom-field.

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.

5) Conclusion

So, download attachment to this post and get my customized imgbrowz0r.php and index.php files based on imgbrowz0r 0.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

[attachment=0]imgbrowz0r-ExternalFilePath-1.0.zip[/attachment]