summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Auditor2011-11-22 16:27:52 (GMT)
committer Stefan Auditor2011-11-22 16:27:52 (GMT)
commit1656ebcc79b21ebd5afa253716e67155a8ae572b (patch)
tree937c8f1dfff6f0256dfa894c5c141564213a3cc7
parentddd447677b26fb92020bb05512bd6ba384f24460 (diff)
Prevent alread existing public derivatives from being directed through the menu callback7.x-1.1
-rw-r--r--adaptive_image.image.inc33
-rw-r--r--adaptive_image.module63
2 files changed, 60 insertions, 36 deletions
diff --git a/adaptive_image.image.inc b/adaptive_image.image.inc
index 0ba7301..8173d7e 100644
--- a/adaptive_image.image.inc
+++ b/adaptive_image.image.inc
@@ -13,7 +13,6 @@
* Copy of image_style_deliver() for use with adaptive images.
*/
function adaptive_image_style_deliver($style, $scheme) {
- $resolution = '';
$settings = $resolutions = array();
$settings = adaptive_image_effect_settings($style);
@@ -25,24 +24,7 @@ function adaptive_image_style_deliver($style, $scheme) {
$mobile_first = FALSE;
}
- /* Check to see if a valid cookie exists */
- if (count($resolutions) && isset($_COOKIE['adaptive_image'])) {
- if (is_numeric($_COOKIE['adaptive_image'])) {
- $client_width = (int) $_COOKIE['adaptive_image']; // store the cookie value in a variable
-
- /* the client width in the cookie is valid, now fit that number into the correct resolution break point */
- rsort($resolutions); // make sure the supplied break-points are in reverse size order
- $resolution = $resolutions[0]; // by default it's the largest supported break-point
-
- foreach ($resolutions as $break_point) { // filter down
- if ($client_width <= $break_point) {
- $resolution = $break_point;
- }
- }
- } else {
- setcookie("adaptive_image", "", time() -1); // delete the mangled cookie
- }
- }
+ $resolution = adaptive_image_resolution($resolutions);
/* No resolution was found (no cookie or invalid cookie) */
if (!$resolution && count($resolutions)) {
@@ -138,16 +120,3 @@ function adaptive_image_browser_detect() {
return TRUE;
}
}
-
-/**
- * Get adaptive image effect from style settings
- */
-function adaptive_image_effect_settings($style) {
- $settings = array();
- foreach ($style['effects'] as $effect) {
- if ($effect['name'] == 'adaptive_image') {
- $settings = $effect['data'];
- }
- }
- return $settings;
-}
diff --git a/adaptive_image.module b/adaptive_image.module
index ee945ae..06c4171 100644
--- a/adaptive_image.module
+++ b/adaptive_image.module
@@ -141,21 +141,37 @@ function theme_adaptive_image_scale_summary($variables) {
* Adds a class to adaptive images for max-width.
*/
function adaptive_image_preprocess_image(&$variables) {
+ global $base_url;
+
if (isset($variables['style_name'])) {
// Get image style settings
$style = image_style_load($variables['style_name']);
// Check if style contains the adaptive image effect
if ($style && adaptive_image_contains_effect($style)) {
- if (is_numeric($_COOKIE['adaptive_image'])) {
- // Reconstruct the image path to %/%style_name/adaptive-image/%
- $variables['path'] = str_replace('styles/' . $variables['style_name'], 'styles/' . $variables['style_name'] . '/adaptive-image', $variables['path']);
+ $settings = adaptive_image_effect_settings($style);
+ $resolutions = explode(',', $settings['resolutions']);
+ $resolution = adaptive_image_resolution($resolutions);
+
+ // Only construct direct path if not private
+ if (!strpos($variables['path'], '/system/') && is_numeric($resolution)) {
+ $path_parts = pathinfo($variables['path']);
+ $derivative_uri = $path_parts['dirname'] . '/' . $resolution . '/' . $path_parts['basename'];
+ }
+
+ if (isset($derivative_uri) && file_exists(str_replace($base_url, '.', $derivative_uri))) {
+ // Deliver existing path to bypass menu callback
+ $variables['path'] = $derivative_uri;
}
else {
- // Reconstruct the image path to %/%style_name/adaptive-image/%
+ // Reconstruct the image path to %/%style_name/adaptive-image/% to
+ // trigger image generation or file access check
$variables['path'] = str_replace('styles/' . $variables['style_name'], 'styles/' . $variables['style_name'] . '/adaptive-image', $variables['path']);
}
+
+ // Add class for styling
$variables['attributes']['class'] = 'adaptive-image';
+
// Remove fixed image dimensions
unset($variables['height']);
unset($variables['width']);
@@ -176,3 +192,42 @@ function adaptive_image_contains_effect($style) {
}
return $found;
}
+
+/**
+ * Get adaptive image effect from style settings
+ */
+function adaptive_image_effect_settings($style) {
+ $settings = array();
+ foreach ($style['effects'] as $effect) {
+ if ($effect['name'] == 'adaptive_image') {
+ $settings = $effect['data'];
+ }
+ }
+ return $settings;
+}
+
+/**
+ * Determine current resolution
+ */
+function adaptive_image_resolution($resolutions) {
+ $resolution = '';
+ /* Check to see if a valid cookie exists */
+ if (count($resolutions) && isset($_COOKIE['adaptive_image'])) {
+ if (is_numeric($_COOKIE['adaptive_image'])) {
+ $client_width = (int) $_COOKIE['adaptive_image']; // store the cookie value in a variable
+
+ /* the client width in the cookie is valid, now fit that number into the correct resolution break point */
+ rsort($resolutions); // make sure the supplied break-points are in reverse size order
+ $resolution = $resolutions[0]; // by default it's the largest supported break-point
+
+ foreach ($resolutions as $break_point) { // filter down
+ if ($client_width <= $break_point) {
+ $resolution = $break_point;
+ }
+ }
+ } else {
+ setcookie("adaptive_image", "", time() -1); // delete the mangled cookie
+ }
+ }
+ return $resolution;
+} \ No newline at end of file