Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-01-26-14-28-00
authorkurund <kurund@civicrm.org>
Mon, 26 Jan 2015 09:07:58 +0000 (14:37 +0530)
committerkurund <kurund@civicrm.org>
Mon, 26 Jan 2015 09:07:58 +0000 (14:37 +0530)
Conflicts:
CRM/Contact/Page/ImageFile.php
CRM/Contribute/Form/SoftCredit.php
CRM/Event/Form/ManageEvent/Registration.php

CRM/Contact/Page/ImageFile.php
CRM/Event/Form/ManageEvent/Registration.php

index 9c82b100a46ff6643826c5fabe9d1e53ae34a372..86f3608c57ec07b0a76e766efa9a5fff7d93ebdf 100644 (file)
  *
  */
 class CRM_Contact_Page_ImageFile extends CRM_Core_Page {
+  /**
+   * @var int Time to live (seconds).
+   *
+   * 12 hours: 12 * 60 * 60 = 43200
+   */
+  private $ttl = 43200;
+
   public function run() {
     if (!preg_match('/^[^\/]+\.(jpg|jpeg|png|gif)$/i', $_GET['photo'])) {
       CRM_Core_Error::fatal('Malformed photo name');
@@ -49,12 +56,10 @@ class CRM_Contact_Page_ImageFile extends CRM_Core_Page {
     }
     if ($cid) {
       $config = CRM_Core_Config::singleton();
-      $buffer = file_get_contents($config->customFileUploadDir . $_GET['photo']);
-      $mimeType = 'image/' . pathinfo($_GET['photo'], PATHINFO_EXTENSION);
-      CRM_Utils_System::download($_GET['photo'], $mimeType, $buffer,
-        NULL,
-        TRUE,
-        'inline'
+      $this->download(
+        $config->customFileUploadDir . $_GET['photo'],
+        'image/' . pathinfo($_GET['photo'], PATHINFO_EXTENSION),
+        $this->ttl
       );
       CRM_Utils_System::civiExit();
     }
@@ -63,4 +68,27 @@ class CRM_Contact_Page_ImageFile extends CRM_Core_Page {
     }
   }
 
+  /**
+   * @param string $file
+   *   Local file path.
+   * @param string $mimeType
+   * @param int $ttl
+   *   Time to live (seconds).
+   */
+  protected function download($file, $mimeType, $ttl) {
+    if (!file_exists($file)) {
+      header("HTTP/1.0 404 Not Found");
+      return;
+    } elseif (!is_readable($file)) {
+      header('HTTP/1.0 403 Forbidden');
+      return;
+    }
+    header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', CRM_Utils_Time::getTimeRaw() + $ttl));
+    header("Content-Type: $mimeType");
+    header("Content-Disposition: inline; filename=\"" . basename($file) . "\"");
+    header("Cache-Control: max-age=$ttl, public");
+    header('Pragma: public');
+    readfile($file);
+  }
+
 }
index 38e53be47eb13255e1bfb29b9ae392e46d63c08c..bd434e9a050581c20397dae0a0064a4ce3de9daa 100644 (file)
@@ -725,9 +725,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
    * @return bool
    */
   public static function canProfilesDedupe($profileIds, $rgId = 0) {
-
     // find the unsupervised rule
-
     $rgParams = array(
       'used' => 'Unsupervised',
       'contact_type' => 'Individual',