Skip to content

Commit

Permalink
Merge branch 'release/150403'
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Apr 9, 2015
2 parents 72d3666 + 0c036e9 commit cc95f77
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 178 deletions.
9 changes: 8 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Server config files.
*.admins text
*.cfg text
*.cnf text
*.conf text
*.htaccess text
*.htaccess-apache text
Expand All @@ -31,8 +32,14 @@
# CSS/JavaScript files.
*.css text
*.js text
*.css.map text
*.js.map text
*.json text

# Applescript files.
*.applescript text
*.scpt binary

# PHP scripts/files.
*.inc text
*.php text
Expand Down Expand Up @@ -140,4 +147,4 @@
*.dll binary
*.exe binary
*.sh text
*.so binary
*.so binary
19 changes: 14 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
*~
*.bak

# Node
node_modules/
npm-debug.log

# SASS
.sass-cache/

# IntelliJ
.idea/
*.iml
*.ipr
*.iws

Expand Down Expand Up @@ -49,10 +55,13 @@ Icon?
# Amazon Web Services
.elasticbeanstalk/

# For shell glob patterns. This includes GIT files too. We simply maintain this list together with `.gitignore`.
# .~*;*~;*.bak;.idea;*.iml;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;.gitignore;.gitattributes;CVS;.cvsignore;.svn;_svn;.bzr;.bzrignore;.hg;.hgignore;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;.elasticbeanstalk
# Vagrant
.vagrant/

# For shell glob patterns. This includes Git files too. We simply maintain this list together with `.gitignore`.
# .~*;*~;*.bak;node_modules;npm-debug.log;.idea;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;.gitignore;.gitattributes;CVS;.cvsignore;.svn;_svn;.bzr;.bzrignore;.hg;.hgignore;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*;.elasticbeanstalk;.vagrant

# This list is for IntelliJ IDEA / PhpStorm `File Types` configuration. Some files we actually WANT to work with as part of a project.
# .idea;*.iml;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;CVS;.svn;_svn;.bzr;.hg;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*
# .sass-cache;.idea;*.ipr;*.iws;*.sublime-workspace;*.sublime-project;.git;CVS;.svn;_svn;.bzr;.hg;SCCS;RCS;$RECYCLE.BIN;Desktop.ini;Thumbs.db;ehthumbs.db;.Spotlight-V100;.AppleDouble;.LSOverride;.DS_Store;.Trashes;._*;.vagrant

# We also need to update the WebSharks™ Core `dirs_files::ignore()` method if this changes.
# We also need to update the WebSharks™ Core `dirs_files::ignore()` method if this changes.
7 changes: 4 additions & 3 deletions zencache/includes/advanced-cache.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,9 @@ public function maybe_start_output_buffering()
if($this->is_uncacheable_request_method())
return $this->maybe_set_debug_info($this::NC_DEBUG_UNCACHEABLE_REQUEST);

if(isset($_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_ADDR']) && $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'])
if(!$this->is_localhost()) return $this->maybe_set_debug_info($this::NC_DEBUG_SELF_SERVE_REQUEST);
if(isset($_SERVER['SERVER_ADDR']) && $this->current_ip() === $_SERVER['SERVER_ADDR'])
if(!$this->is_localhost()) // Allow for a localhost scenario; i.e., a developer testing.
return $this->maybe_set_debug_info($this::NC_DEBUG_SELF_SERVE_REQUEST);

if(!ZENCACHE_FEEDS_ENABLE && $this->is_feed())
return $this->maybe_set_debug_info($this::NC_DEBUG_FEED_REQUEST);
Expand Down Expand Up @@ -1053,7 +1054,7 @@ public function maybe_get_nc_debug_info($reason_code = '', $reason = '')
break; // Break switch handler.

case $this::NC_DEBUG_SELF_SERVE_REQUEST:
$reason = __('because `$_SERVER[\'REMOTE_ADDR\']` === `$_SERVER[\'SERVER_ADDR\']`; i.e. a self-serve request. DEVELOPER TIP: if you are testing on a localhost installation, please add `define(\'LOCALHOST\', TRUE);` to your `/wp-config.php` file while you run tests :-) Remove it (or set it to a `FALSE` value) once you go live on the web.', $this->text_domain);
$reason = __('because `[current IP address]` === `$_SERVER[\'SERVER_ADDR\']`; i.e. a self-serve request. DEVELOPER TIP: if you are testing on a localhost installation, please add `define(\'LOCALHOST\', TRUE);` to your `/wp-config.php` file while you run tests :-) Remove it (or set it to a `FALSE` value) once you go live on the web.', $this->text_domain);
break; // Break switch handler.

case $this::NC_DEBUG_FEED_REQUEST:
Expand Down
2 changes: 1 addition & 1 deletion zencache/includes/menu-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public function options()
echo ' <option value="0">'.__('No, do NOT compress HTML/CSS/JS code at runtime.', $this->plugin->text_domain).'</option>'."\n";
echo ' <option value="1" selected="selected">'.__('Yes, I want to compress HTML/CSS/JS for blazing fast speeds.', $this->plugin->text_domain).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info" style="display:block;">'.__('<strong>Note:</strong> This is experimental. Please <a href="https://github.com/websharks/quick-cache/issues" target="_blank">report issues here</a>.', $this->plugin->text_domain).'</p>'."\n";
echo ' <p class="info" style="display:block;">'.__('<strong>Note:</strong> This is experimental. Please <a href="https://github.com/websharks/zencache/issues" target="_blank">report issues here</a>.', $this->plugin->text_domain).'</p>'."\n";
echo ' <hr />'."\n";
echo ' <div class="plugin-menu-page-panel-if-enabled">'."\n";
echo ' <h3>'.__('HTML Compression Options', $this->plugin->text_domain).'</h3>'."\n";
Expand Down
81 changes: 79 additions & 2 deletions zencache/includes/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract class share // Shared between {@link advanced_cache} and {@link plugin}
*
* @var string Current version of the software.
*/
public $version = '150314';
public $version = '150409';

/**
* Plugin slug; based on `__NAMESPACE__`.
Expand Down Expand Up @@ -979,6 +979,83 @@ public function has_a_cacheable_status()
return (static::$static[__FUNCTION__] = TRUE); // Assume that it is by default.
}

/* --------------------------------------------------------------------------------------
* IP address utilities.
-------------------------------------------------------------------------------------- */

/**
* Get the current visitor's real IP address.
*
* @return string Real IP address, else `unknown` on failure.
*
* @note This supports both IPv4 and IPv6 addresses.
* @note See my tests against this here: http://3v4l.org/fVWUp
*/
public function current_ip()
{
if(isset(static::$static[__FUNCTION__]))
return static::$static[__FUNCTION__];

static::$static[__FUNCTION__] = ''; // Initialize.
$ip = &static::$static[__FUNCTION__];

if(!empty($_SERVER['REMOTE_ADDR']) && $this->apply_filters(__METHOD__.'_prioritize_remote_addr', FALSE))
if(($_valid_public_ip = $this->valid_public_ip($_SERVER['REMOTE_ADDR'])))
return ($ip = $_valid_public_ip);

$sources = array(
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'REMOTE_ADDR',
);
$sources = $this->apply_filters(__METHOD__.'_sources', $sources);

foreach($sources as $_source) // Try each of these; in order.
{
if(!empty($_SERVER[$_source])) // Does the source key exist at all?
if(($_valid_public_ip = $this->valid_public_ip($_SERVER[$_source])))
return ($ip = $_valid_public_ip); // A valid public IPv4 or IPv6 address.
}
unset($_source, $_valid_public_ip); // Housekeeping.

if(!empty($_SERVER['REMOTE_ADDR']) && is_string($_SERVER['REMOTE_ADDR']))
return ($ip = strtolower($_SERVER['REMOTE_ADDR']));

return ($ip = 'unknown'); // Not possible.
}

/**
* Gets a valid/public IP address.
*
* @param string $list_of_possible_ips A single IP, or a comma-delimited list of IPs.
*
* @return string A valid/public IP address (if one is found), else an empty string.
*
* @note This supports both IPv4 and IPv6 addresses.
* @note See my tests against this here: http://3v4l.org/fVWUp
*/
public function valid_public_ip($list_of_possible_ips)
{
if(!$list_of_possible_ips || !is_string($list_of_possible_ips))
return ''; // Empty or invalid data.

if(!($list_of_possible_ips = trim($list_of_possible_ips)))
return ''; // Not possible; i.e., empty string.

foreach(preg_split('/[\s;,]+/', $list_of_possible_ips, NULL, PREG_SPLIT_NO_EMPTY) as $_possible_ip)
if(($_valid_public_ip = filter_var(strtolower($_possible_ip), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)))
return $_valid_public_ip; // A valid public IPv4 or IPv6 address.
unset($_possible_ip, $_valid_public_ip); // Housekeeping.

return ''; // Default return value.
}

/* --------------------------------------------------------------------------------------
* Function/extension utilities.
-------------------------------------------------------------------------------------- */
Expand Down Expand Up @@ -1369,7 +1446,7 @@ public function get_tmp_dir()
$possible_tmp_dirs[] = WP_CONTENT_DIR;

if(!empty($possible_tmp_dirs)) foreach($possible_tmp_dirs as $_tmp_dir)
if(($_tmp_dir = trim((string)$_tmp_dir)) && is_dir($_tmp_dir) && is_writable($_tmp_dir))
if(($_tmp_dir = trim((string)$_tmp_dir)) && @is_dir($_tmp_dir) && @is_writable($_tmp_dir))
return ($tmp_dir = $this->n_dir_seps($_tmp_dir));
unset($_tmp_dir); // Housekeeping.

Expand Down
Loading

0 comments on commit cc95f77

Please sign in to comment.