When cast to boolean by a conditional, these 2 functions behave identically, but str_contains is more readable
$order = NULL;
if (!empty($params['sortBy'])) {
- if (strstr($params['sortBy'], 'date ')) {
+ if (str_contains($params['sortBy'], 'date ')) {
$params['sortBy'] = str_replace('date', 'activity_date_time', $params['sortBy']);
}
$order = "ORDER BY " . $params['sortBy'];
if ($value) {
// Note: this is already taken care in getDisplayValue above, but sometimes
// strings like '^A^A' creates problem. So to fix this special case -
- if (strstr($value, CRM_Core_DAO::VALUE_SEPARATOR)) {
+ if (str_contains($value, CRM_Core_DAO::VALUE_SEPARATOR)) {
$value = trim($value, CRM_Core_DAO::VALUE_SEPARATOR);
}
if (($typeValue['type'] ?? NULL) == 'String' ||
elseif ($op == '!=') {
$this->_where[$grouping][] = "{$etTable}.entity_id NOT IN (SELECT entity_id FROM civicrm_entity_tag cet WHERE cet.entity_table = 'civicrm_contact' AND " . self::buildClause("cet.tag_id", '=', $value, 'Int') . ")";
}
- elseif ($op == '=' || strstr($op, 'IN')) {
+ elseif ($op == '=' || str_contains($op, 'IN')) {
$op = ($op == '=') ? 'IN' : $op;
$this->_where[$grouping][] = "{$etTable}.tag_id $op ( $value )";
}
if (self::caseImportant($op)) {
$value = implode("[[:cntrl:]]|[[:cntrl:]]", (array) $value);
- $op = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT RLIKE' : 'RLIKE';
+ $op = (str_contains($op, '!') || str_contains($op, 'NOT')) ? 'NOT RLIKE' : 'RLIKE';
$value = "[[:cntrl:]]" . $value . "[[:cntrl:]]";
}
}
$date = $format = NULL;
- if (strstr($op, 'IN')) {
+ if (str_contains($op, 'IN')) {
$format = [];
foreach ($value as &$date) {
$date = CRM_Utils_Date::processDate($date, NULL, FALSE, $dateFormat);
if (count($groupSelect) > 1) {
$session = CRM_Core_Session::singleton();
// user dashboard
- if (strstr($session->readUserContext(), 'user')) {
+ if (str_contains($session->readUserContext(), 'user')) {
$msg = ts('Join a Group');
}
else {
$fldType = $fldValue['type'] ?? NULL;
$type = CRM_Utils_Type::typeToString($fldType);
- if (strstr($v[1], 'IN')) {
+ if (str_contains($v[1], 'IN')) {
if (empty($v[2])) {
$errorMsg["value[$v[3]][$v[4]]"] = ts("Please enter a value.");
}
if ($type && empty($errorMsg)) {
// check for valid format while using IN Operator
- if (strstr($v[1], 'IN')) {
+ if (str_contains($v[1], 'IN')) {
if (!is_array($v[2])) {
$inVal = trim($v[2]);
//checking for format to avoid db errors
$blocks = ['email', 'phone', 'im', 'url', 'openid'];
foreach ($this->_params['onbehalf'] as $loc => $value) {
$field = $typeId = NULL;
- if (strstr($loc, '-')) {
+ if (str_contains($loc, '-')) {
[$field, $locType] = explode('-', $loc);
}
}
}
}
- elseif (strstr($loc, 'custom')) {
+ elseif (str_contains($loc, 'custom')) {
if ($value && isset($this->_params['onbehalf']["{$loc}_id"])) {
$value = $this->_params['onbehalf']["{$loc}_id"];
}
$value = str_replace(",", "$sp|$sp", $value);
$value = str_replace(['[:comma:]', '(', ')'], [',', '[(]', '[)]'], $value);
- $op = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT RLIKE' : 'RLIKE';
+ $op = (str_contains($op, '!') || str_contains($op, 'NOT')) ? 'NOT RLIKE' : 'RLIKE';
$value = $sp . $value . $sp;
if (!$wildcard) {
foreach (explode("|", $value) as $val) {
}
elseif (($htmlType == 'TextArea' ||
($htmlType == 'Text' && $dataType == 'String')
- ) && strstr($formValues[$key], '%')
+ ) && str_contains($formValues[$key], '%')
) {
$formValues[$key] = ['LIKE' => $formValues[$key]];
}
}
// CRM-14983: verify if values are comma separated convert to array
- if (!is_array($value) && strstr($params['operator'][$key][$k], 'IN')) {
+ if (!is_array($value) && str_contains($params['operator'][$key][$k], 'IN')) {
$value = explode(',', $value);
$value = [$params['operator'][$key][$k] => $value];
}
$el['html'] = $date . '<input type="hidden" value="' . $element->getValue() . '" name="' . $element->getAttribute('name') . '">';
}
// Render html for wysiwyg textareas
- if ($el['type'] == 'textarea' && isset($element->_attributes['class']) && strstr($element->_attributes['class'], 'wysiwyg')) {
+ if ($el['type'] == 'textarea' && isset($element->_attributes['class']) && str_contains($element->_attributes['class'], 'wysiwyg')) {
$el['html'] = '<span class="crm-frozen-field">' . $el['value'] . '</span>';
}
else {
unset($pageArgs['mode']);
}
$title = $item['title'] ?? NULL;
- if (strstr($item['page_callback'], '_Page') || strstr($item['page_callback'], '\\Page\\')) {
+ if (str_contains($item['page_callback'], '_Page') || str_contains($item['page_callback'], '\\Page\\')) {
$object = new $item['page_callback']($title, $mode);
$object->urlPath = explode('/', $_GET[$config->userFrameworkURLVar]);
}
- elseif (strstr($item['page_callback'], '_Controller') || strstr($item['page_callback'], '\\Controller\\')) {
+ elseif (str_contains($item['page_callback'], '_Controller') || str_contains($item['page_callback'], '\\Controller\\')) {
$addSequence = 'false';
if (isset($pageArgs['addSequence'])) {
$addSequence = $pageArgs['addSequence'];
}
}
- if (strstr($path, 'report/instance')) {
+ if (str_contains($path, 'report/instance')) {
$args = explode('/', $path);
if (is_numeric(end($args))) {
$menuPath['path'] .= '/' . end($args);
$elements["onbehalf_{$key}"]['value'][$k] = $v;
}
}
- elseif (strstr($htmlType, 'Multi-Select')) {
+ elseif (str_contains($htmlType, 'Multi-Select')) {
$elements["onbehalf_{$key}"]['type'] = 'Multi-Select';
$elements["onbehalf_{$key}"]['value'] = array_values($defaults[$key]);
}
$gid = (isset($form->_groupID)) ? $form->_groupID : NULL;
$getCachedTree = $form->_getCachedTree ?? TRUE;
- if (!is_array($subType) && strstr(($subType ?? ''), CRM_Core_DAO::VALUE_SEPARATOR)) {
+ if (!is_array($subType) && str_contains(($subType ?? ''), CRM_Core_DAO::VALUE_SEPARATOR)) {
CRM_Core_Error::deprecatedWarning('Using a CRM_Core_DAO::VALUE_SEPARATOR separated subType deprecated, use a comma-separated string instead.');
$subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR));
}
$exEventId = '';
if ($query->_where[$grouping]) {
foreach ($query->_where[$grouping] as $key => $val) {
- if (strstr($val, 'civicrm_event.id =')) {
+ if (str_contains($val, 'civicrm_event.id =')) {
$exEventId = $val;
$extractEventId = explode(" ", $val);
$value = $extractEventId[2];
$where = $query->_where[$grouping][$key];
}
- elseif (strstr($val, 'civicrm_event.id IN')) {
+ elseif (str_contains($val, 'civicrm_event.id IN')) {
//extract the first event id if multiple events are selected
preg_match('/civicrm_event.id IN \(\"(\d+)/', $val, $matches);
$value = $matches[1];
$op = key($value);
$value = $value[$op];
}
- if (!strstr($op, 'NULL') && !strstr($op, 'EMPTY') && !strstr($op, 'LIKE')) {
- $regexOp = (strstr($op, '!') || strstr($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP';
+ if (!str_contains($op, 'NULL') && !str_contains($op, 'EMPTY') && !str_contains($op, 'LIKE')) {
+ $regexOp = (str_contains($op, '!') || str_contains($op, 'NOT')) ? 'NOT REGEXP' : 'REGEXP';
$regexp = "([[:cntrl:]]|^)" . implode('([[:cntrl:]]|$)|([[:cntrl:]]|^)', (array) $value) . "([[:cntrl:]]|$)";
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.$name", $regexOp, $regexp, 'String');
}
if ($field == 'provider_id' || $field == 'im_provider') {
$fieldValue = $imProviders[$fieldValue] ?? NULL;
}
- elseif (strstr($field, 'master_id')) {
+ elseif (str_contains($field, 'master_id')) {
// @todo - why not just $field === 'master_id' - what else would it be?
$masterAddressId = $iterationDAO->$field ?? NULL;
// get display name of contact that address is shared.
$this->_matchingContacts = FALSE;
if (($values['radio_ts'] ?? NULL) == 'ts_sel') {
foreach ($values as $key => $value) {
- if (strstr($key, 'mark_x')) {
+ if (str_contains($key, 'mark_x')) {
$count++;
}
if ($count > 2) {
if ($recordType == 'target') {
// @todo - fix up the way the tables are declared in construct & remove this.
foreach ($this->_selectClauses as $key => $clause) {
- if (strstr($clause, 'civicrm_contact_assignee.') ||
- strstr($clause, 'civicrm_contact_source.') ||
- strstr($clause, 'civicrm_email_assignee.') ||
- strstr($clause, 'civicrm_email_source.') ||
- strstr($clause, 'civicrm_phone_assignee.') ||
- strstr($clause, 'civicrm_phone_source.')
+ if (str_contains($clause, 'civicrm_contact_assignee.') ||
+ str_contains($clause, 'civicrm_contact_source.') ||
+ str_contains($clause, 'civicrm_email_assignee.') ||
+ str_contains($clause, 'civicrm_email_source.') ||
+ str_contains($clause, 'civicrm_phone_assignee.') ||
+ str_contains($clause, 'civicrm_phone_source.')
) {
$removeKeys[] = $key;
unset($this->_selectClauses[$key]);
elseif ($recordType == 'assignee') {
// @todo - fix up the way the tables are declared in construct & remove this.
foreach ($this->_selectClauses as $key => $clause) {
- if (strstr($clause, 'civicrm_contact_target.') ||
- strstr($clause, 'civicrm_contact_source.') ||
- strstr($clause, 'civicrm_email_target.') ||
- strstr($clause, 'civicrm_email_source.') ||
- strstr($clause, 'civicrm_phone_target.') ||
- strstr($clause, 'civicrm_phone_source.') ||
- strstr($clause, 'civicrm_address_')
+ if (str_contains($clause, 'civicrm_contact_target.') ||
+ str_contains($clause, 'civicrm_contact_source.') ||
+ str_contains($clause, 'civicrm_email_target.') ||
+ str_contains($clause, 'civicrm_email_source.') ||
+ str_contains($clause, 'civicrm_phone_target.') ||
+ str_contains($clause, 'civicrm_phone_source.') ||
+ str_contains($clause, 'civicrm_address_')
) {
$removeKeys[] = $key;
unset($this->_selectClauses[$key]);
elseif ($recordType == 'source') {
// @todo - fix up the way the tables are declared in construct & remove this.
foreach ($this->_selectClauses as $key => $clause) {
- if (strstr($clause, 'civicrm_contact_target.') ||
- strstr($clause, 'civicrm_contact_assignee.') ||
- strstr($clause, 'civicrm_email_target.') ||
- strstr($clause, 'civicrm_email_assignee.') ||
- strstr($clause, 'civicrm_phone_target.') ||
- strstr($clause, 'civicrm_phone_assignee.') ||
- strstr($clause, 'civicrm_address_')
+ if (str_contains($clause, 'civicrm_contact_target.') ||
+ str_contains($clause, 'civicrm_contact_assignee.') ||
+ str_contains($clause, 'civicrm_email_target.') ||
+ str_contains($clause, 'civicrm_email_assignee.') ||
+ str_contains($clause, 'civicrm_phone_target.') ||
+ str_contains($clause, 'civicrm_phone_assignee.') ||
+ str_contains($clause, 'civicrm_address_')
) {
$removeKeys[] = $key;
unset($this->_selectClauses[$key]);
$this->_selectClauses = $this->_selectAliasesTotal;
foreach ($this->_selectClauses as $key => $clause) {
// @todo - fix up the way the tables are declared in construct & remove this.
- if (strstr($clause, 'civicrm_contact_contact_target') ||
- strstr($clause, 'civicrm_contact_contact_assignee') ||
- strstr($clause, 'civicrm_contact_contact_source') ||
- strstr($clause, 'civicrm_phone_contact_source_phone') ||
- strstr($clause, 'civicrm_phone_contact_assignee_phone') ||
- strstr($clause, 'civicrm_email_contact_source_email') ||
- strstr($clause, 'civicrm_email_contact_assignee_email') ||
- strstr($clause, 'civicrm_email_contact_target_email') ||
- strstr($clause, 'civicrm_phone_contact_target_phone') ||
- strstr($clause, 'civicrm_address_')
+ if (str_contains($clause, 'civicrm_contact_contact_target') ||
+ str_contains($clause, 'civicrm_contact_contact_assignee') ||
+ str_contains($clause, 'civicrm_contact_contact_source') ||
+ str_contains($clause, 'civicrm_phone_contact_source_phone') ||
+ str_contains($clause, 'civicrm_phone_contact_assignee_phone') ||
+ str_contains($clause, 'civicrm_email_contact_source_email') ||
+ str_contains($clause, 'civicrm_email_contact_assignee_email') ||
+ str_contains($clause, 'civicrm_email_contact_target_email') ||
+ str_contains($clause, 'civicrm_phone_contact_target_phone') ||
+ str_contains($clause, 'civicrm_address_')
) {
$this->_selectClauses[$key] = "GROUP_CONCAT(DISTINCT $clause SEPARATOR ';') as $clause";
}
$templateInfo['name'] = $reportClass;
}
- if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) {
+ if (str_contains($templateInfo['name'], '_Form') || !is_null($reportClass)) {
$instanceInfo = [];
CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo);
$templateInfo['name'] = $reportClass;
}
- if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) {
+ if (str_contains($templateInfo['name'] ?? '', '_Form') || !is_null($reportClass)) {
CRM_Utils_System::setTitle(ts('%1 - Template', [1 => $templateInfo['label']]));
$this->assign('reportTitle', $templateInfo['label']);
$templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', $optionVal, 'value');
$obj = new CRM_Report_Page_Instance();
$is_error = 0;
- if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form')) {
+ if (str_contains($templateInfo['name'] ?? '', '_Form')) {
$instanceInfo = [];
CRM_Report_BAO_ReportInstance::retrieve(['id' => $instanceId], $instanceInfo);
$qs = explode('&', str_replace('&', '&', $_SERVER['QUERY_STRING']));
for ($i = 0, $cnt = count($qs); $i < $cnt; $i++) {
// check first if exist a pair
- if (strstr($qs[$i], '=') !== FALSE) {
+ if (str_contains($qs[$i], '=')) {
[$name, $value] = explode('=', $qs[$i]);
if ($name != $urlVar) {
$name = rawurldecode($name);
$query = self::makeQueryString($query);
// Legacy handling for when the system passes around html escaped strings
- if (strstr($query, '&')) {
+ if (str_contains($query, '&')) {
$query = html_entity_decode($query);
}
// Extract fragment from path or query if munged together
- if ($query && strstr($query, '#')) {
+ if ($query && str_contains($query, '#')) {
[$path, $fragment] = explode('#', $query);
}
- if ($path && strstr($path, '#')) {
+ if ($path && str_contains($path, '#')) {
[$path, $fragment] = explode('#', $path);
}
// Extract query from path if munged together
- if ($path && strstr($path, '?')) {
+ if ($path && str_contains($path, '?')) {
[$path, $extraQuery] = explode('?', $path);
$query = $extraQuery . ($query ? "&$query" : '');
}
if ($referer && !empty($names)) {
foreach ($names as $name) {
- if (strstr($referer, $name)) {
+ if (str_contains($referer, $name)) {
$url = $referer;
break;
}
// convert ipV6 to ipV4
if ($strictIPV4) {
// this converts 'IPV4 mapped IPV6 address' to IPV4
- if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && strstr($address, '::ffff:')) {
+ if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && str_contains($address, '::ffff:')) {
$address = ltrim($address, '::ffff:');
}
}
'entityID' => $params['entity_id'],
'entityType' => $params['entity_table'] ?? '',
];
- if (strstr($getParams['entityType'], 'civicrm_')) {
+ if (str_contains($getParams['entityType'], 'civicrm_')) {
$getParams['entityType'] = ucfirst(substr($getParams['entityType'], 8));
}
unset($params['entity_id'], $params['entity_table']);
//accept filters like filter.activity_date_time_high
// std is now 'filters' => ..
- if (strstr(implode(',', array_keys($params)), 'filter')) {
+ if (str_contains(implode(',', array_keys($params)), 'filter')) {
if (isset($params['filters']) && is_array($params['filters'])) {
foreach ($params['filters'] as $paramkey => $paramvalue) {
_civicrm_api3_apply_filters_to_dao($paramkey, $paramvalue, $dao);
}
else {
foreach ($params as $paramkey => $paramvalue) {
- if (strstr($paramkey, 'filter')) {
+ if (str_contains($paramkey, 'filter')) {
_civicrm_api3_apply_filters_to_dao(substr($paramkey, 7), $paramvalue, $dao);
}
}
* DAO object.
*/
function _civicrm_api3_apply_filters_to_dao($filterField, $filterValue, &$dao) {
- if (strstr($filterField, 'high')) {
+ if (str_contains($filterField, 'high')) {
$fieldName = substr($filterField, 0, -5);
$dao->whereAdd("($fieldName <= $filterValue )");
}
- if (strstr($filterField, 'low')) {
+ if (str_contains($filterField, 'low')) {
$fieldName = substr($filterField, 0, -4);
$dao->whereAdd("($fieldName >= $filterValue )");
}
if (!empty($fieldValue) && is_array($fieldValue) &&
(array_search(key($fieldValue), CRM_Core_DAO::acceptedSQLOperators()) ||
- $type == 'String' && strstr(key($fieldValue), 'EMPTY'))
+ $type == 'String' && str_contains(key($fieldValue), 'EMPTY'))
) {
$op = key($fieldValue);
$fieldValue = $fieldValue[$op] ?? NULL;
case 'grant_status_id':
case 'grant_status':
- if (strstr($name, 'type')) {
+ if (str_contains($name, 'type')) {
$name = 'grant_type_id';
$label = E::ts('Grant Type(s)');
}
}
foreach ($values as $customField => $customValue) {
- if (strstr($customField, 'civicrm_value_')) {
+ if (str_contains($customField, 'civicrm_value_')) {
$customFieldTitle = $this->_columnHeaders[$customField]['title'] ?? NULL;
$customGroupTitle = explode('_custom', strstr($customField, 'civicrm_value_'));
$customGroupTitle = $this->_columns[$customGroupTitle[0]]['group_title'];
foreach ($savedSearches as $savedSearch) {
$newAliases = [];
foreach ($savedSearch['api_params']['select'] ?? [] as $i => $select) {
- if (strstr($select, '(') && !strstr($select, ' AS ')) {
+ if (str_contains($select, '(') && !str_contains($select, ' AS ')) {
$alias = CRM_Utils_String::munge(str_replace(')', '', $select), '_', 256);
$newAliases[$select] = $alias;
$savedSearch['api_params']['select'][$i] = $select . ' AS ' . $alias;
];
foreach ($apiParams['select'] ?? [] as $select) {
- if (strstr($select, ' AS ')) {
+ if (str_contains($select, ' AS ')) {
$expr = SqlExpression::convert($select, TRUE);
$label = $expr::getTitle();
foreach ($expr->getFields() as $num => $fieldName) {