From 2f1b8d2e71b319677ce7de9de8081ed36b25c7a7 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Wed, 4 Jun 2014 13:12:41 +0000 Subject: [PATCH] Added a helper function to get an icon stored as an ormDocument: ormDocument::GetDownloadURL -reintegrated from trunk SVN:2.0.2[3192] --- core/ormdocument.class.inc.php | 13 ++++++++++++- pages/ajax.render.php | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/ormdocument.class.inc.php b/core/ormdocument.class.inc.php index 94625b175..72a897f05 100644 --- a/core/ormdocument.class.inc.php +++ b/core/ormdocument.class.inc.php @@ -117,7 +117,18 @@ class ormDocument { return "".$this->GetFileName()."\n"; } - + + /** + * Returns an URL to download a document like an image (uses HTTP caching) + * @return string + */ + public function GetDownloadURL($sClass, $Id, $sAttCode) + { + // Compute a signature to reset the cache anytime the data changes (this is acceptable if used only with icon files) + $sSignature = md5($this->GetData()); + return utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode&s=$sSignature&cache=86400"; + } + public function IsPreviewAvailable() { diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 1e05db352..b3235ed4c 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -770,9 +770,15 @@ try case 'download_document': $id = utils::ReadParam('id', ''); $sField = utils::ReadParam('field', ''); + $iCacheSec = (int) utils::ReadParam('cache', 0); if (!empty($sClass) && !empty($id) && !empty($sField)) { DownloadDocument($oPage, $sClass, $id, $sField, 'attachment'); + if ($iCacheSec > 0) + { + $oPage->add_header("Expires: "); // Reset the value set in ajax_page + $oPage->add_header("Cache-Control: no-transform,public,max-age=$iCacheSec,s-maxage=$iCacheSec"); + } } break;