From dca383705a4fdd81f452790467ecb77b3bf7a83b Mon Sep 17 00:00:00 2001 From: Lorenz Schori Date: Sun, 20 Jan 2013 13:35:30 +0100 Subject: [PATCH] Replace monster regex copied from the blocks module in ancient times with drupal_match_path --- authcache.helpers.inc | 17 +++++++++++------ authcache.module | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/authcache.helpers.inc b/authcache.helpers.inc index 7e205d7..6bcd12e 100644 --- a/authcache.helpers.inc +++ b/authcache.helpers.inc @@ -103,9 +103,8 @@ function _authcache_is_cacheable() { switch ($page_rules['option']) { case '0': // Cache every page except the listed pages. case '1': // Cache only the listed pages. - $regexp = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote($page_rules['pages'], '/')) . ')$/'; - if (!(!($page_rules['option'] xor preg_match($regexp, $alias)))) { - //TODO: find a clearer way to refactor the above expression + $page_listed = drupal_match_path($alias, $page_rules['pages']); + if (!(!($page_rules['option'] xor $page_listed))) { $_authcache_info['no_cache_reason'] = 'Caching disabled by Page Ruleset ' . $i; $is_cacheable = FALSE; } @@ -187,10 +186,9 @@ function _authcache_shutdown_save_page() { // Find user-specified non-html pages. $alias = drupal_get_path_alias($_GET['q']); - $regexp = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote(variable_get('authcache_nonhtml', AUTHCACHE_NONHTML_DEFAULT), '/')) . ')$/'; $is_cached_nonhtml = ( - (preg_match($regexp, $alias) - || (in_array($content_type, array('text/javascript', 'text/plain', 'application/xml', 'application/atom+xml'))) // Dynamic JS, text, XML + (drupal_match_path($alias, variable_get('authcache_nonhtml', AUTHCACHE_NONHTML_DEFAULT)) + || (in_array($content_type, _authcache_get_nonhtml_content_types())) // Dynamic JS, text, XML || (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) // Ajax ); @@ -433,6 +431,13 @@ function _authcache_get_content_type($default = NULL) { } /** + * Retrun an array of cachable non-html content-types. + */ +function _authcache_get_nonhtml_content_types() { + return preg_split('/(\r\n?|\n)/', AUTHCACHE_NONHTML_CONTENTTYPES, -1, PREG_SPLIT_NO_EMPTY); +} + +/** * Determines the HTTP response code that the current page request will be * returning by examining the HTTP headers that have been output so far. */ diff --git a/authcache.module b/authcache.module index 4028dcc..c42b9b5 100644 --- a/authcache.module +++ b/authcache.module @@ -32,6 +32,13 @@ system/temporary* define('AUTHCACHE_NONHTML_DEFAULT', ' robots.txt '); +// Default non-HTML cachable content-types +define('AUTHCACHE_NONHTML_CONTENTTYPES', ' +text/javascript +text/plain +application/xml +application/atom+xml +'); define('CACHE_DISABLED', FALSE); -- 1.7.10.4