CRM-14971 - Fix resizing of contact images
authorTim Otten <totten@civicrm.org>
Tue, 15 Jul 2014 00:08:19 +0000 (17:08 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 15 Jul 2014 00:17:18 +0000 (17:17 -0700)
----------------------------------------
* CRM-14971: Contact image URLs broken in WordPress after upgrade to 4.4.6
  https://issues.civicrm.org/jira/browse/CRM-14971

CRM/Contact/Form/Contact.php
CRM/Contact/Page/View.php
CRM/Core/BAO/UFGroup.php
CRM/Profile/Form.php
CRM/Utils/String.php

index 000931f50e36e4f7de5fc130106ea312020fadb7..204ea6fe0ab42d0aaf2012c82613268a9f1481b6 100644 (file)
@@ -443,7 +443,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     CRM_Contact_Form_Edit_Address::setDefaultValues( $defaults, $this );
 
     if (CRM_Utils_Array::value('image_URL', $defaults)) {
-      list($imageWidth, $imageHeight) = getimagesize($defaults['image_URL']);
+      list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($defaults['image_URL']));
       list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
       $this->assign('imageWidth', $imageWidth);
       $this->assign('imageHeight', $imageHeight);
index 41bcb0dfc508a3d449dbc8bee26a6cb5e0a73207..3fcbcd9f5f6a4d700f890f052b4b321e874ad1af 100644 (file)
@@ -167,7 +167,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page {
         $image_URL = str_replace('http://', 'https://', $image_URL);
       }
 
-      list($imageWidth, $imageHeight) = getimagesize($image_URL);
+      list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($image_URL));
       list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
       $this->assign("imageWidth", $imageWidth);
       $this->assign("imageHeight", $imageHeight);
index b8a54e652cc7d08c56ee927ec291f1ca0f599668..0baf7f7f49cb85c4b707afbe2bfdfa17661d1c12 100644 (file)
@@ -1111,7 +1111,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
               }
             }
             elseif ($name == 'image_URL') {
-              list($width, $height) = getimagesize($details->$name);
+              list($width, $height) = getimagesize(CRM_Utils_String::unstupifyUrl($details->$name));
               list($thumbWidth, $thumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($width, $height);
 
               $image_URL = '<img src="' . $details->$name . '" height= ' . $thumbHeight . ' width= ' . $thumbWidth . '  />';
index e01d56768e6a0089f9f62388951770fb29152cdd..33e46f5429b171498aad9f3ee2a407468778d099 100644 (file)
@@ -551,7 +551,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
     }
 
     if (CRM_Utils_Array::value('image_URL', $this->_defaults)) {
-      list($imageWidth, $imageHeight) = getimagesize($this->_defaults['image_URL']);
+      list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($this->_defaults['image_URL']));
       list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
       $this->assign("imageWidth", $imageWidth);
       $this->assign("imageHeight", $imageHeight);
index eaae593b46e6551f6696784e259f9266479946e9..4ba11f1942fd812385e4fa4dffb12346d7529dcf 100644 (file)
@@ -652,6 +652,17 @@ class CRM_Utils_String {
     }
   }
 
-
+  /**
+   * Many parts of the codebase have a convention of internally passing around
+   * HTML-encoded URLs. This effectively means that "&" is replaced by "&amp;"
+   * (because most other odd characters are %-escaped in URLs; and %-escaped
+   * strings don't need any extra escaping in HTML).
+   *
+   * @param string $url URL with HTML entities
+   * @return string URL without HTML entities
+   */
+  public static function unstupifyUrl($htmlUrl) {
+    return str_replace('&amp;', '&', $htmlUrl);
+  }
 }