Merge branch 'patch-25' into 'dev'
'Last-Modified' and 'Content-Length' HTTP headers added for better image caching See merge request hubzilla/core!1369
This commit is contained in:
		| @@ -33,8 +33,6 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 	 | 	 | ||||||
| 		$observer_xchan = get_observer_hash(); | 		$observer_xchan = get_observer_hash(); | ||||||
|  |  | ||||||
| 		$default = z_root() . '/' . get_default_profile_photo(); |  | ||||||
| 	 |  | ||||||
| 		if(isset($type)) { | 		if(isset($type)) { | ||||||
| 	 | 	 | ||||||
| 			/** | 			/** | ||||||
| @@ -42,16 +40,17 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 			 *  | 			 *  | ||||||
| 			 */ | 			 */ | ||||||
| 			  | 			  | ||||||
|  | 			$default = get_default_profile_photo(); | ||||||
|  | 			  | ||||||
| 			if($type === 'profile') { | 			if($type === 'profile') { | ||||||
| 				switch($res) { | 				switch($res) { | ||||||
| 	 |  | ||||||
| 					case 'm': | 					case 'm': | ||||||
| 						$resolution = 5; | 						$resolution = 5; | ||||||
| 						$default = z_root() . '/' . get_default_profile_photo(80); | 						$default = get_default_profile_photo(80); | ||||||
| 						break; | 						break; | ||||||
| 					case 's': | 					case 's': | ||||||
| 						$resolution = 6; | 						$resolution = 6; | ||||||
| 						$default = z_root() . '/' . get_default_profile_photo(48); | 						$default = get_default_profile_photo(48); | ||||||
| 						break; | 						break; | ||||||
| 					case 'l': | 					case 'l': | ||||||
| 					default: | 					default: | ||||||
| @@ -60,6 +59,8 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 	 | 	 | ||||||
|  | 			$modified = filemtime($default); | ||||||
|  | 			$default = z_root() . '/' . $default; | ||||||
| 			$uid = $person; | 			$uid = $person; | ||||||
|  |  | ||||||
| 			$d = [ 'imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data'  => '', 'mimetype' => '' ]; | 			$d = [ 'imgscale' => $resolution, 'channel_id' => $uid, 'default' => $default, 'data'  => '', 'mimetype' => '' ]; | ||||||
| @@ -78,6 +79,7 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 					intval(PHOTO_PROFILE) | 					intval(PHOTO_PROFILE) | ||||||
| 				); | 				); | ||||||
| 				if($r) { | 				if($r) { | ||||||
|  | 					$modified = strtotime($r[0]['edited']); | ||||||
| 					$data = dbunescbin($r[0]['content']); | 					$data = dbunescbin($r[0]['content']); | ||||||
| 					$mimetype = $r[0]['mimetype']; | 					$mimetype = $r[0]['mimetype']; | ||||||
| 				} | 				} | ||||||
| @@ -164,10 +166,10 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 				if($exists && $allowed) { | 				if($exists && $allowed) { | ||||||
| 					$data = dbunescbin($e[0]['content']); | 					$data = dbunescbin($e[0]['content']); | ||||||
| 					$mimetype = $e[0]['mimetype']; | 					$mimetype = $e[0]['mimetype']; | ||||||
| 					if(intval($e[0]['os_storage'])) { | 					$modified = strtotime($e[0]['edited']); | ||||||
|  | 					if(intval($e[0]['os_storage'])) | ||||||
| 						$streaming = $data; | 						$streaming = $data; | ||||||
| 				} | 				} | ||||||
| 				} |  | ||||||
| 				else { | 				else { | ||||||
| 					if(! $allowed) { | 					if(! $allowed) { | ||||||
| 						http_status_exit(403,'forbidden'); | 						http_status_exit(403,'forbidden'); | ||||||
| @@ -183,7 +185,6 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 		if(! isset($data)) { | 		if(! isset($data)) { | ||||||
| 			if(isset($resolution)) { | 			if(isset($resolution)) { | ||||||
| 				switch($resolution) { | 				switch($resolution) { | ||||||
| 	 |  | ||||||
| 					case 4: | 					case 4: | ||||||
| 						$data = fetch_image_from_url(z_root() . '/' . get_default_profile_photo(),$mimetype); | 						$data = fetch_image_from_url(z_root() . '/' . get_default_profile_photo(),$mimetype); | ||||||
| 						break; | 						break; | ||||||
| @@ -210,9 +211,13 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	 | 	 | ||||||
|  | 		// @FIXME Seems never invoked | ||||||
| 		// Writing in cachefile | 		// Writing in cachefile | ||||||
| 		if (isset($cachefile) && $cachefile != '') | 		if (isset($cachefile) && $cachefile != '') { | ||||||
| 			file_put_contents($cachefile, $data); | 			file_put_contents($cachefile, $data); | ||||||
|  | 			$modified = filemtime($cachefile); | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
| 		if(function_exists('header_remove')) { | 		if(function_exists('header_remove')) { | ||||||
| 			header_remove('Pragma'); | 			header_remove('Pragma'); | ||||||
| @@ -242,11 +247,13 @@ class Photo extends \Zotlabs\Web\Controller { | |||||||
| 	 | 	 | ||||||
| 			$cache = get_config('system','photo_cache_time', 86400);    // 1 day by default | 			$cache = get_config('system','photo_cache_time', 86400);    // 1 day by default | ||||||
| 			 | 			 | ||||||
| 		 	header("Expires: " . gmdate("D, d M Y H:i:s", time() + $cache) . " GMT"); |  | ||||||
| 			header("Cache-Control: max-age=" . $cache); | 			header("Cache-Control: max-age=" . $cache); | ||||||
| 	 | 	 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT"); | ||||||
|  | 		header("Content-Length: " . strlen($data)); | ||||||
|  |  | ||||||
| 		// If it's a file resource, stream it.  | 		// If it's a file resource, stream it.  | ||||||
|  |  | ||||||
| 		if($streaming && $channel) { | 		if($streaming && $channel) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user