$this->set('contactType', $contactType);
// note: there could still be multiple subtypes. We just trimming the outer separator.
- $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO::VALUE_SEPARATOR));
+ $this->set('contactSubtype', trim(($contactSubtype ?? ''), CRM_Core_DAO::VALUE_SEPARATOR));
// add to recently viewed block
$isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted');
$ufJoinDAO->module = $module;
$ufJoinDAO->entity_id = $params['id'];
$ufJoinDAO->find(TRUE);
- $jsonData = json_decode($ufJoinDAO->module_data);
+ $jsonData = json_decode($ufJoinDAO->module_data ?? '');
if ($jsonData) {
$json[$module] = array_merge((array) $jsonData->$module, $json[$module]);
}
// we filter out null, '' and FALSE but not zero - I'm on the fence about zero.
$overrides = array_filter([
'is_test' => $inputOverrides['is_test'] ?? $recurringContribution['is_test'],
- 'financial_type_id' => $inputOverrides['financial_type_id'] ?? $recurringContribution['financial_type_id'],
- 'campaign_id' => $inputOverrides['campaign_id'] ?? ($recurringContribution['campaign_id'] ?? NULL),
+ 'financial_type_id' => $inputOverrides['financial_type_id'] ?? ($recurringContribution['financial_type_id'] ?? ''),
+ 'campaign_id' => $inputOverrides['campaign_id'] ?? ($recurringContribution['campaign_id'] ?? ''),
'total_amount' => $inputOverrides['total_amount'] ?? $recurringContribution['amount'],
], 'strlen');
$this->_paymentProcessorIDs = array_filter(explode(
CRM_Core_DAO::VALUE_SEPARATOR,
- CRM_Utils_Array::value('payment_processor', $this->_values)
+ ($this->_values['payment_processor'] ?? '')
));
$this->assignPaymentProcessor($isPayLater);
$ids = $this->getSelectedIDs($this->getSearchFormValues());
if (!$ids) {
$result = $this->getSearchQueryResults();
+ $ids = [];
while ($result->fetch()) {
$ids[] = $result->contribution_id;
}
'sid' => CRM_Utils_System::getSiteID(),
'baseUrl' => $config->userFrameworkBaseURL,
'lang' => $config->lcMessages,
- 'co' => $config->defaultContactCountry,
+ 'co' => $config->defaultContactCountry ?? '',
];
$vars = [];
foreach ($vals as $k => $v) {
public static function valid($key) {
// ensure that key is an alphanumeric string of at least HASH_LENGTH with
// an optional underscore+digits at the end.
- return preg_match('#^[0-9a-zA-Z]{' . self::HASH_LENGTH . ',}+(_\d+)?$#', $key) ? TRUE : FALSE;
+ return preg_match('#^[0-9a-zA-Z]{' . self::HASH_LENGTH . ',}+(_\d+)?$#', ($key ?? '')) ? TRUE : FALSE;
}
/**
$key = 'name';
}
- if (trim($sort)) {
+ if (trim($sort ?? '')) {
$object->orderBy($sort);
}
elseif ($key) {
*/
protected function getTrxnID() {
$string = $this->_mode;
- $trxn_id = CRM_Core_DAO::singleValueQuery("SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE '{$string}_%'");
+ $trxn_id = CRM_Core_DAO::singleValueQuery("SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE '{$string}_%'") ?? '';
$trxn_id = str_replace($string, '', $trxn_id);
$trxn_id = (int) $trxn_id + 1;
return $string . '_' . $trxn_id . '_' . uniqid();
$args['state'] = $params['state_province'];
$args['countryCode'] = $params['country'];
$args['zip'] = $params['postal_code'];
- $args['desc'] = substr(CRM_Utils_Array::value('description', $params), 0, 127);
+ $args['desc'] = substr(($params['description'] ?? ''), 0, 127);
$args['custom'] = $params['accountingCode'] ?? NULL;
// add CiviCRM BN code
$p = [];
foreach ($args as $n => $v) {
- $p[] = "$n=" . urlencode($v);
+ $p[] = "$n=" . urlencode($v ?? '');
}
//NVPRequest for submitting to server
$query['casContactIdField'] = 'e.contact_id';
$query['casEntityIdField'] = 'e.id';
$query['casContactTableAlias'] = NULL;
- $query['casDateField'] = str_replace('event_', 'r.', $schedule->start_action_date);
+ $query['casDateField'] = str_replace('event_', 'r.', ($schedule->start_action_date ?? ''));
if (empty($query['casDateField']) && $schedule->absolute_date) {
$query['casDateField'] = "'" . CRM_Utils_Type::escape($schedule->absolute_date, 'String') . "'";
}
$details['eligible'] = TRUE;
$details['status'] = $dao->status;
$details['role'] = $dao->role;
- $details['fee_level'] = trim($dao->fee_level, CRM_Core_DAO::VALUE_SEPARATOR);
+ $details['fee_level'] = trim(($dao->fee_level ?? ''), CRM_Core_DAO::VALUE_SEPARATOR);
$details['fee_amount'] = $dao->fee_amount;
$details['register_date'] = $dao->register_date;
$details['event_start_date'] = $dao->start_date;
$dao->name = trim($info->name);
$dao->description = trim($info->description);
- $dao->user_name_label = trim($info->typeInfo['userNameLabel']);
- $dao->password_label = trim($info->typeInfo['passwordLabel']);
- $dao->signature_label = trim($info->typeInfo['signatureLabel']);
- $dao->subject_label = trim($info->typeInfo['subjectLabel']);
- $dao->url_site_default = trim($info->typeInfo['urlSiteDefault']);
- $dao->url_api_default = trim($info->typeInfo['urlApiDefault']);
- $dao->url_recur_default = trim($info->typeInfo['urlRecurDefault']);
- $dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault']);
- $dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault']);
- $dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault']);
- $dao->url_button_default = trim($info->typeInfo['urlButtonDefault']);
- $dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault']);
+ $dao->user_name_label = trim($info->typeInfo['userNameLabel'] ?? '');
+ $dao->password_label = trim($info->typeInfo['passwordLabel'] ?? '');
+ $dao->signature_label = trim($info->typeInfo['signatureLabel'] ?? '');
+ $dao->subject_label = trim($info->typeInfo['subjectLabel'] ?? '');
+ $dao->url_site_default = trim($info->typeInfo['urlSiteDefault'] ?? '');
+ $dao->url_api_default = trim($info->typeInfo['urlApiDefault'] ?? '');
+ $dao->url_recur_default = trim($info->typeInfo['urlRecurDefault'] ?? '');
+ $dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault'] ?? '');
+ $dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault'] ?? '');
+ $dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault'] ?? '');
+ $dao->url_button_default = trim($info->typeInfo['urlButtonDefault'] ?? '');
+ $dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault'] ?? '');
switch (trim($info->typeInfo['billingMode'])) {
case 'form':
throw new CRM_Core_Exception(ts('Billing mode in info file has wrong value.'));
}
- $dao->is_recur = trim($info->typeInfo['isRecur']);
- $dao->payment_type = trim($info->typeInfo['paymentType']);
+ $dao->is_recur = trim($info->typeInfo['isRecur'] ?? '');
+ $dao->payment_type = trim($info->typeInfo['paymentType'] ?? '');
$dao->save();
}
if (empty($defaults['from_email'])) {
$defaultAddress = CRM_Core_BAO_Domain::getNameAndEmail(TRUE, TRUE);
foreach ($defaultAddress as $id => $value) {
- if (preg_match('/"(.*)" <(.*)>/', $value, $match)) {
+ if (preg_match('/"(.*)" <(.*)>/', ($value ?? ''), $match)) {
$defaults['from_email'] = $match[2];
$defaults['from_name'] = $match[1];
}
$query['casContactTableAlias'] = NULL;
// Leaving this in case of legacy databases
- $query['casDateField'] = str_replace('membership_', 'e.', $schedule->start_action_date);
+ $query['casDateField'] = str_replace('membership_', 'e.', ($schedule->start_action_date ?? ''));
// Options currently are just 'join_date', 'start_date', and 'end_date':
// they need an alias
// allow for 0 value.
if (!empty($fields['option_amount'][$index]) ||
- strlen($fields['option_amount'][$index]) > 0
+ strlen($fields['option_amount'][$index] ?? '') > 0
) {
$noAmount = 0;
}
}
$this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate');
- $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0));
+ $gids = explode(',', (CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0) ?? ''));
if ((count($gids) > 1) && !$this->_profileIds && empty($this->_profileIds)) {
if (!empty($gids)) {
}
// we do this gross hack since qf also does entity replacement
- $this->_postURL = str_replace('&', '&', $this->_postURL);
- $this->_cancelURL = str_replace('&', '&', $this->_cancelURL);
+ $this->_postURL = str_replace('&', '&', ($this->_postURL ?? ''));
+ $this->_cancelURL = str_replace('&', '&', ($this->_cancelURL ?? ''));
// also retain error URL if set
$this->_errorURL = $_POST['errorURL'] ?? NULL;
* is that we might print a bar chart as a pdf.
*/
protected function setOutputMode() {
- $this->_outputMode = str_replace('report_instance.', '', CRM_Utils_Request::retrieve(
+ $this->_outputMode = str_replace('report_instance.', '', (CRM_Utils_Request::retrieve(
'output',
'String',
CRM_Core_DAO::$_nullObject,
FALSE,
CRM_Utils_Array::value('task', $this->_params)
- ));
+ ) ?? ''));
// if contacts are added to group
if (!empty($this->_params['groups']) && empty($this->_outputMode)) {
$this->_outputMode = 'group';
}
// replacements in case of Custom Token
- if (stristr($formatted, 'custom_')) {
+ if (stristr(($formatted ?? ''), 'custom_')) {
$customToken = array_keys($fields);
foreach ($customToken as $value) {
if (substr($value, 0, 7) == 'custom_') {
// the value is not empty, otherwise drop the whole {fooTOKENbar}
foreach ($replacements as $token => $value) {
if ($value && is_string($value) || is_numeric($value)) {
- $formatted = preg_replace("/{([^{}]*)\b{$token}\b([^{}]*)}/u", "\${1}{$value}\${2}", $formatted);
+ $formatted = preg_replace("/{([^{}]*)\b{$token}\b([^{}]*)}/u", "\${1}{$value}\${2}", ($formatted ?? ''));
}
else {
- $formatted = preg_replace("/{[^{}]*\b{$token}\b[^{}]*}/u", '', $formatted);
+ $formatted = preg_replace("/{[^{}]*\b{$token}\b[^{}]*}/u", '', ($formatted ?? ''));
}
}
$fullWeekdayNames = self::getFullWeekdayNames();
$abbrWeekdayNames = self::getAbbrWeekdayNames();
- // backwards compatability with %D being the equivilant of %m/%d/%y
- $format = str_replace('%D', '%m/%d/%y', $format);
+ // backwards compatibility with %D being the equivalent of %m/%d/%y
+ $format = str_replace('%D', '%m/%d/%y', ($format ?? ''));
if (!$format) {
$config = CRM_Core_Config::singleton();
public function requireCiviModules(&$moduleList) {
$civiModules = CRM_Core_PseudoConstant::getModuleExtensions();
foreach ($civiModules as $civiModule) {
- if (!file_exists($civiModule['filePath'])) {
+ if (!file_exists($civiModule['filePath'] ?? '')) {
CRM_Core_Session::setStatus(
ts('Error loading module file (%1). Please restore the file or disable the module.',
[1 => $civiModule['filePath']]),
}
return $obj;
}
- $result = json_decode($js);
+ $result = json_decode($js ?? '');
if ($throwException && $result === NULL && $js !== 'null') {
throw new CRM_Core_Exception(json_last_error_msg());
}
// CRM-7130 --lets addslashes to only double quotes,
// since we are using it to quote the field value.
// str_replace helps to provide a break for new-line
- $sOutput .= '"' . addcslashes(str_replace(["\r\n", "\n", "\r"], '<br />', $value[$element]), '"\\') . '"';
+ $sOutput .= '"' . addcslashes(str_replace(["\r\n", "\n", "\r"], '<br />', ($value[$element] ?? '')), '"\\') . '"';
// remove extra spaces and tab character that breaks dataTable CRM-12551
$sOutput = preg_replace("/\s+/", " ", $sOutput);
}
$config = CRM_Core_Config::singleton();
- $verpSeparator = preg_quote($config->verpSeparator);
+ $verpSeparator = preg_quote($config->verpSeparator ?? '');
$twoDigitStringMin = $verpSeparator . '(\d+)' . $verpSeparator . '(\d+)';
$twoDigitString = $twoDigitStringMin . $verpSeparator;
$threeDigitString = $twoDigitString . '(\d+)' . $verpSeparator;
// FIXME: legacy regexen to handle CiviCRM 2.1 address patterns, with domain id and possible VERP part
- $commonRegex = '/^' . preg_quote($dao->localpart) . '(b|bounce|c|confirm|o|optOut|r|reply|re|e|resubscribe|u|unsubscribe)' . $threeDigitString . '([0-9a-f]{16})(-.*)?@' . preg_quote($dao->domain) . '$/';
- $subscrRegex = '/^' . preg_quote($dao->localpart) . '(s|subscribe)' . $twoDigitStringMin . '@' . preg_quote($dao->domain) . '$/';
+ $commonRegex = '/^' . preg_quote($dao->localpart ?? '') . '(b|bounce|c|confirm|o|optOut|r|reply|re|e|resubscribe|u|unsubscribe)' . $threeDigitString . '([0-9a-f]{16})(-.*)?@' . preg_quote($dao->domain ?? '') . '$/';
+ $subscrRegex = '/^' . preg_quote($dao->localpart ?? '') . '(s|subscribe)' . $twoDigitStringMin . '@' . preg_quote($dao->domain ?? '') . '$/';
// a common-for-all-actions regex to handle CiviCRM 2.2 address patterns
- $regex = '/^' . preg_quote($dao->localpart) . '(b|c|e|o|r|u)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '$/';
+ $regex = '/^' . preg_quote($dao->localpart ?? '') . '(b|c|e|o|r|u)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '$/';
// a tighter regex for finding bounce info in soft bounces’ mail bodies
- $rpRegex = '/Return-Path:\s*' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/';
+ $rpRegex = '/Return-Path:\s*' . preg_quote($dao->localpart ?? '') . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '/';
// a regex for finding bound info X-Header
- $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/i';
+ $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart ?? '') . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '/i';
// CiviMail in regex and Civimail in header !!!
// retrieve the emails
if ($usedfor == 1) {
foreach ($mail->to as $address) {
- if (preg_match($regex, $address->email, $matches)) {
+ if (preg_match($regex, ($address->email ?? ''), $matches)) {
list($match, $action, $job, $queue, $hash) = $matches;
break;
// FIXME: the below elseifs should be dropped when we drop legacy support
}
- elseif (preg_match($commonRegex, $address->email, $matches)) {
+ elseif (preg_match($commonRegex, ($address->email ?? ''), $matches)) {
list($match, $action, $_, $job, $queue, $hash) = $matches;
break;
}
- elseif (preg_match($subscrRegex, $address->email, $matches)) {
+ elseif (preg_match($subscrRegex, ($address->email ?? ''), $matches)) {
list($match, $action, $_, $job) = $matches;
break;
}
// CRM-5471: if $matches is empty, it still might be a soft bounce sent
// to another address, so scan the body for ‘Return-Path: …bounce-pattern…’
- if (!$matches and preg_match($rpRegex, $mail->generateBody(), $matches)) {
+ if (!$matches and preg_match($rpRegex, ($mail->generateBody() ?? ''), $matches)) {
list($match, $action, $job, $queue, $hash) = $matches;
}
// if $matches is still empty, look for the X-CiviMail-Bounce header
// CRM-9855
- if (!$matches and preg_match($rpXheaderRegex, $mail->generateBody(), $matches)) {
+ if (!$matches and preg_match($rpXheaderRegex, ($mail->generateBody() ?? ''), $matches)) {
list($match, $action, $job, $queue, $hash) = $matches;
}
// With Mandrilla, the X-CiviMail-Bounce header is produced by generateBody
if ($v_part instanceof ezcMailFile) {
$p_file = $v_part->__get('fileName');
$c_file = file_get_contents($p_file);
- if (preg_match($rpXheaderRegex, $c_file, $matches)) {
+ if (preg_match($rpXheaderRegex, ($c_file ?? ''), $matches)) {
list($match, $action, $job, $queue, $hash) = $matches;
}
}
}
// if all else fails, check Delivered-To for possible pattern
- if (!$matches and preg_match($regex, $mail->getHeader('Delivered-To'), $matches)) {
+ if (!$matches and preg_match($regex, ($mail->getHeader('Delivered-To') ?? ''), $matches)) {
list($match, $action, $job, $queue, $hash) = $matches;
}
}
*/
public function loadCMSBootstrap() {
$requestParams = CRM_Utils_Request::exportValues();
- $q = $requestParams['q'] ?? NULL;
+ $q = $requestParams['q'] ?? '';
$args = explode('/', $q);
// Proceed with bootstrap for "?entity=X&action=Y"
*/
public static function cleanMoney($value) {
// first remove all white space
- $value = str_replace([' ', "\t", "\n"], '', $value);
+ $value = str_replace([' ', "\t", "\n"], '', ($value ?? ''));
$config = CRM_Core_Config::singleton();
* @return string[]
*/
public static function explode($separator, $string, $limit) {
- $result = explode($separator, $string, $limit);
+ $result = explode($separator, ($string ?? ''), $limit);
for ($i = count($result); $i < $limit; $i++) {
$result[$i] = NULL;
}
case 'Date':
case 'Timestamp':
// a null timestamp is valid
- if (strlen(trim($data)) == 0) {
- return trim($data);
+ if (strlen(trim($data ?? '')) == 0) {
+ return trim($data ?? '');
}
if ((preg_match('/^\d{14}$/', $data) ||
$sdomain = $match[2];
preg_match('/(.+)\@([^\@]+)$/', $recipient, $match);
- $rlocal = $match[1] ?? NULL;
- $rdomain = $match[2] ?? NULL;
+ $rlocal = $match[1] ?? '';
+ $rdomain = $match[2] ?? '';
foreach (self::$encodeMap as $char => $code) {
$rlocal = preg_replace('/' . preg_quote($char) . '/i', "+$code", $rlocal);
array_column(\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'filePath')
);
foreach ($locations as $location) {
- $dir = \CRM_Utils_File::addTrailingSlash(dirname($location)) . 'Civi/Api4';
+ $dir = \CRM_Utils_File::addTrailingSlash(dirname($location ?? '')) . 'Civi/Api4';
if (is_dir($dir)) {
foreach (glob("$dir/*.php") as $file) {
$className = 'Civi\Api4\\' . basename($file, '.php');
$expectedValue, $message
) {
$value = \CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE);
- $this->assertEquals(trim($expectedValue), trim($value), $message);
+ $this->assertEquals(trim($expectedValue), trim($value ?? ''), $message);
}
/**