optimizing cache reload

This commit is contained in:
Christophe LATOUR 2017-11-28 15:27:10 +01:00
parent e49a9a0206
commit 43530f4b84

View File

@ -31,12 +31,38 @@ trait ImageTrait {
public function getSaleImage($id_sale, $active = true, $reload_cache = true) {
global $cookie;
$filename = _PS_ROOT_DIR_ . '/' . $this->getSaleImgPath($id_sale, $active);
$extension = $this->getImageTime($filename);
$static = 'http://static.bebeboutik.com/';
$extension = $active === true ? 'mobile' : 'mobileoff';
return $static .
__PS_BASE_URI__.'modules/privatesales/img/' . $id_sale . '/' .
$extension . '_' . $cookie->id_lang . '.jpg'.
($reload_cache ? '?rand=' . rand() : '');
__PS_BASE_URI__. '/' . $this->getSaleImgPath($id_sale, $active) .
($reload_cache === true ? '?'.$extension : '');
}
/**
* Returns image timestamp last modified
*
* @return integer
*/
private function getImageTime($filename) {
return file_exists($filename) ? filemtime($filename) : 0;
}
/**
* Return uri to get image
*
* @param $id_sale integer The id sales
* @param $active boolean Whether to return inactive image of the sale
*
* @return string path to image
*/
private function getSaleImgPath($id_sale, $active) {
global $cookie;
$extension = $active === true ? 'mobile' : 'mobileoff';
return 'modules/privatesales/img/' . $id_sale . '/' . $extension .
'_' . $cookie->id_lang . '.jpg';
}
}