Selaa lähdekoodia

Added a helper function to get an icon stored as an ormDocument: ormDocument::GetDownloadURL

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3191 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 vuotta sitten
vanhempi
commit
ec698e1209
2 muutettua tiedostoa jossa 18 lisäystä ja 1 poistoa
  1. 12 1
      core/ormdocument.class.inc.php
  2. 6 0
      pages/ajax.render.php

+ 12 - 1
core/ormdocument.class.inc.php

@@ -117,7 +117,18 @@ class ormDocument
 	{
 		return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode\">".$this->GetFileName()."</a>\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()
 	{

+ 6 - 0
pages/ajax.render.php

@@ -778,9 +778,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;