Skip to content

Commit

Permalink
Updated example config file
Browse files Browse the repository at this point in the history
Added better support for WP installs using Apache mod_userdir URLs
  • Loading branch information
Damian committed Mar 24, 2015
1 parent 4bc2d60 commit ee0a6b2
Showing 1 changed file with 84 additions and 7 deletions.
91 changes: 84 additions & 7 deletions mthumb-config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,98 @@
*
* @created 4/2/14 11:52 AM
* @author Mindshare Studios, Inc.
* @copyright Copyright (c) 2014
* @link http://www.mindsharelabs.com/documentation/
* @copyright Copyright (c) 2006-2015
* @link http://www.mindsharelabs.com/
*
*/

// tilde support for mthumb, in default WP install this should result in the same value as ABSPATH
$_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__).'/../../../../../');
//var_dump($_SERVER['DOCUMENT_ROOT']); die;
// Max sizes
if(!defined('MAX_WIDTH')) {
define('MAX_WIDTH', 3600);
}
if(!defined('MAX_HEIGHT')) {
define('MAX_HEIGHT', 3600);
}
if(!defined('MAX_FILE_SIZE')) {
define ('MAX_FILE_SIZE', 20971520); // 20MB
}

/*
* External Sites
*/
global $ALLOWED_SITES;

// External Sites
$ALLOWED_SITES = array(
'flickr.com',
'staticflickr.com',
'picasa.com',
'img.youtube.com',
'upload.wikimedia.org',
'photobucket.com',
'imgur.com',
'imageshack.us',
'tinypic.com',
'mind.sh',
'mindsharelabs.com',
'mindsharestudios.com'
);

// The rest of the code in this config only applies to Apache mod_userdir (URIs like /~username)

if(mthumb_in_url('~')) {
$_SERVER['DOCUMENT_ROOT'] = mthumb_find_wp_root();
}

/**
* We need to set DOCUMENT_ROOT in cases where /~username URLs are being used.
* In a default WordPress install this should result in the same value as ABSPATH
* but ABSPATH and all WP functions are not accessible in the current scope.
*
* This code should work in 99% of cases.
*
* @param int $levels
*
* @return bool|string
*/
function mthumb_find_wp_root($levels = 9) {

$dir_name = dirname(__FILE__).'/';

for($i = 0; $i <= $levels; $i++) {
$path = realpath($dir_name.str_repeat('../', $i));
if(file_exists($path.'/wp-config.php')) {
return $path;
}
}

return FALSE;
}

/**
*
* Gets the current URL.
*
* @return string
*/
function mthumb_get_url() {
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")).$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);

return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}

/**
*
* Checks to see if $text is in the current URL.
*
* @param $text
*
* @return bool
*/
function mthumb_in_url($text) {
if(stristr(mthumb_get_url(), $text)) {
return TRUE;
} else {
return FALSE;
}
}

0 comments on commit ee0a6b2

Please sign in to comment.