diff options
author | RedMatrix <info@friendica.com> | 2014-05-11 07:36:59 +1000 |
---|---|---|
committer | RedMatrix <info@friendica.com> | 2014-05-11 07:36:59 +1000 |
commit | 1ed210ef0ad38f687d0136e571b87c2ebb4aae9c (patch) | |
tree | 878ee3657b539cef409fb8b71d3263605aa26455 /mod | |
parent | 481b4c21c9ab6e7e6df8f65ef97135fb5807d7fd (diff) | |
parent | d1e0479f58e32c63160c7ad9dbd0c1c2363a1b6c (diff) | |
download | volse-hubzilla-1ed210ef0ad38f687d0136e571b87c2ebb4aae9c.tar.gz volse-hubzilla-1ed210ef0ad38f687d0136e571b87c2ebb4aae9c.tar.bz2 volse-hubzilla-1ed210ef0ad38f687d0136e571b87c2ebb4aae9c.zip |
Merge pull request #454 from chriswinstead/master
Detect high-resolution displays (like retina) and serve higher resolution photo thumbnails
Diffstat (limited to 'mod')
-rw-r--r-- | mod/photo.php | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/mod/photo.php b/mod/photo.php index 1319f9569..9302278b6 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -80,6 +80,22 @@ function photo_init(&$a) { * Other photos */ + /* Check for a cookie to indicate display pixel density, in order to detect high-resolution + displays. This procedure was derived from the "Retina Images" by Jeremey Worboys, + used in accordance with the Creative Commons Attribution 3.0 Unported License. + Project link: https://github.com/Retina-Images/Retina-Images + License link: http://creativecommons.org/licenses/by/3.0/ + */ + $cookie_value = false; + if (isset($_COOKIE['devicePixelRatio'])) { + $cookie_value = intval($_COOKIE['devicePixelRatio']); + } + else { + // Force revalidation of cache on next request + $cache_directive = 'no-cache'; + $status = 'no cookie'; + } + $resolution = 0; if(strpos($photo,'.') !== false) @@ -88,7 +104,23 @@ function photo_init(&$a) { if(substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); + // If viewing on a high-res screen, attempt to serve a higher resolution image: + if ($resolution == 2 && ($cookie_value > 1)) + { + $resolution = 1; + } } + + // If using resolution 1, make sure it exists before proceeding: + if ($resolution == 1) + { + $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", + dbesc($photo), + intval($resolution) + ); + if (!($r)) + $resolution = 2; + } $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", dbesc($photo), @@ -125,7 +157,7 @@ function photo_init(&$a) { dbesc($photo), intval($resolution) ); - + if($r) { logger('mod_photo: forbidden. ' . $a->query_string); $observer = $a->get_observer(); |