//set address block defaults
CRM_Contact_Form_Edit_Address::setDefaultValues( $defaults, $this );
- if (CRM_Utils_Array::value('image_URL', $defaults)) {
++
+ if (!empty($defaults['image_URL'])) {
- 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);
return;
}
- if (CRM_Utils_Array::value('image_URL', $this->_defaults)) {
+ if (!empty($this->_defaults['image_URL'])) {
- 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);
/**
* Perform an incremental version update
*
+ * @param CRM_Queue_TaskContext $ctx
* @param $rev string, the target (intermediate) revision e.g '3.2.alpha1'
- * @param $currentVer string, the original revision
+ * @param $originalVer string, the original revision
* @param $latestVer string, the target (final) revision
* @param $postUpgradeMessageFile string, path of a modifiable file which lists the post-upgrade messages
+ *
+ * @return bool
*/
- static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $currentVer, $latestVer, $postUpgradeMessageFile) {
+ static function doIncrementalUpgradeStep(CRM_Queue_TaskContext$ctx, $rev, $originalVer, $latestVer, $postUpgradeMessageFile) {
$upgrade = new CRM_Upgrade_Form();
$phpFunctionName = 'upgrade_' . str_replace('.', '_', $rev);
}
}
+ /**
+ * @param CRM_Queue_TaskContext $ctx
+ * @param $startId
+ * @param $endId
+ *
+ * @return bool
+ */
+ function upgrade_4_4_7($rev, $originalVer, $latestVer) {
+ // For WordPress/Joomla(?), cleanup broken image_URL from 4.4.6 upgrades - https://issues.civicrm.org/jira/browse/CRM-14971
+ $exBackendUrl = CRM_Utils_System::url('civicrm/contact/imagefile', 'photo=XXX', TRUE); // URL formula from 4.4.6 upgrade
+ $exFrontendUrl = CRM_Utils_System::url('civicrm/contact/imagefile', 'photo=XXX', TRUE, NULL, TRUE, TRUE);
+ if ($originalVer == '4.4.6' && $exBackendUrl != $exFrontendUrl) {
+ $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contact WHERE image_URL IS NOT NULL');
+ $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contact WHERE image_URL IS NOT NULL');
+ for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
+ $endId = $startId + self::BATCH_SIZE - 1;
+ $title = ts('Upgrade image_urls (%1 => %2)', array(1 => $startId, 2 => $endId));
+ $this->addTask($title, 'cleanupBackendImageUrls', $startId, $endId);
+ }
+ }
+ $this->addTask(ts('Update saved search information'), 'changeSavedSearch');
+ }
+
static function upgradeImageUrls(CRM_Queue_TaskContext $ctx, $startId, $endId){
- $sql = "
- SELECT id, image_url
- FROM civicrm_contact
- WHERE 1
- AND id BETWEEN %1 AND %2
- AND image_URL IS NOT NULL
- ";
- $params = array(
- 1 => array($startId, 'Integer'),
- 2 => array($endId, 'Integer'),
- );
- $dao = CRM_Core_DAO::executeQuery($sql, $params, TRUE, NULL, FALSE, FALSE);
+ $dao = self::findContactImageUrls($startId, $endId);
$failures = array();
while ($dao->fetch()){
$imageURL = $dao->image_url;
}
}
+ /**
+ * this function will mask part of the the user portion of an Email address (everything before the @)
+ *
+ * @param string $email the email address to be masked
+ * @param string $maskChar the character used for masking
+ * @param integer $percent the percentage of the user portion to be masked
+ *
+ * @return string returns the masked Email address
+ */
+ public static function maskEmail($email, $maskChar= '*', $percent=50) {
+ list($user, $domain) = preg_split("/@/", $email);
+ $len = strlen($user);
+ $maskCount = floor($len * $percent /100);
+ $offset = floor(($len - $maskCount) / 2);
+
+ $masked = substr($user, 0, $offset)
+ .str_repeat($maskChar, $maskCount)
+ .substr($user, $maskCount + $offset);
+
+ return($masked.'@'.$domain);
+ }
+
+ /**
+ * this function compares two strings
+ *
+ * @param string $strOne string one
+ * @param string $strTwo string two
+ * @param boolean $case boolean indicating whether you want the comparison to be case sensitive or not
+ *
+ * @return boolean TRUE (string are identical); FALSE (strings are not identical)
+ */
+ public static function compareStr($strOne, $strTwo, $case) {
+ if ($case == TRUE) {
+ // Convert to lowercase and trim white spaces
+ if (strtolower(trim($strOne)) == strtolower(trim($strTwo))) {
+ // yes - they are identical
+ return TRUE;
+ }
+ else {
+ // not identical
+ return FALSE;
+ }
+ }
+ if ($case == FALSE) {
+ // Trim white spaces
+ if (trim($strOne) == trim($strTwo)) {
+ // yes - they are identical
+ return TRUE;
+ }
+ else {
+ // not identical
+ return FALSE;
+ }
+ }
+ }
+
+ /**
+ * Many parts of the codebase have a convention of internally passing around
+ * HTML-encoded URLs. This effectively means that "&" is replaced by "&"
+ * (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('&', '&', $htmlUrl);
+ }
}