Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8.0 Fix type error passing in NULL when it expects an array #19

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions civihoneypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ function civihoneypot_civicrm_buildForm($formName, &$form) {
$settings = _getHoneypotValues();
$protect = FALSE;
if ($formName == 'CRM_Contribute_Form_Contribution_Main' &&
($settings['honeypot_protect_all'] == "1" || (in_array($form->getVar('_id'), CRM_Utils_Array::value('honeypot_form_ids', $settings, []))))
($settings['honeypot_protect_all'] == "1" || (in_array($form->getVar('_id'), $settings['honeypot_form_ids'] ?? [])))
) {
$protect = TRUE;
}
if ($formName == 'CRM_Event_Form_Registration_Register' &&
($settings['honeypot_protect_all_events'] == "1" || (in_array($form->getVar('_id'), CRM_Utils_Array::value('honeypot_event_ids', $settings, []))))
($settings['honeypot_protect_all_events'] == "1" || (in_array($form->getVar('_id'), $settings['honeypot_event_ids'] ?? [])))
) {
$protect = TRUE;
}
if ($protect) {
$deny = CRM_Utils_Array::value('honeypot_ipban', $settings, []);
$deny = $settings['honeypot_ipban'] ?? [];
if ($deny) {
$remote = $_SERVER['REMOTE_ADDR'];
$parts = explode(".", $remote);
Expand All @@ -63,13 +63,13 @@ function civihoneypot_civicrm_buildForm($formName, &$form) {
}
}
$timestamp = $_SERVER['REQUEST_TIME'];
$fieldname = CRM_Utils_Array::value('honeypot_field_names', $settings);
$fieldname = $settings['honeypot_field_names'] ?? NULL;
if (!empty($fieldname)) {
$max = count($fieldname) - 1;
$randfieldname = $fieldname[rand(0, $max)];

// Assumes templates are in a templates folder relative to this file
$templatePath = realpath(dirname(__FILE__)."/templates");
$templatePath = realpath(dirname(__FILE__) . "/templates");
$template = CRM_Core_Smarty::singleton();
$template->assign_by_ref('fieldname', $randfieldname);
$template->assign_by_ref('timestamp', $timestamp);
Expand All @@ -80,13 +80,13 @@ function civihoneypot_civicrm_buildForm($formName, &$form) {

// dynamically insert a template block in the page
CRM_Core_Region::instance('page-body')->add(array(
'template' => "civihoneypot.tpl"
'template' => "civihoneypot.tpl",
));
}
}
}

/*
/**
* Implements hook_civicrm_validateForm().
*
*/
Expand All @@ -95,24 +95,24 @@ function civihoneypot_civicrm_validateForm($formName, &$fields, &$files, &$form,
//check for honeypot field values from randomized fields
$protect = FALSE;
if ($formName == 'CRM_Contribute_Form_Contribution_Main' &&
($settings['honeypot_protect_all'] == "1" || (in_array($form->getVar('_id'), CRM_Utils_Array::value('honeypot_form_ids', $settings, []))))
($settings['honeypot_protect_all'] == "1" || (in_array($form->getVar('_id'), $settings['honeypot_form_ids'] ?? [])))
) {
$protect = TRUE;
}
if ($formName == 'CRM_Event_Form_Registration_Register' &&
($settings['honeypot_protect_all_events'] == "1" || (in_array($form->getVar('_id'), CRM_Utils_Array::value('honeypot_event_ids', $settings, []))))
($settings['honeypot_protect_all_events'] == "1" || (in_array($form->getVar('_id'), $settings['honeypot_event_ids'] ?? [])))
) {
$protect = TRUE;
}
if ($protect) {
if ($limit = CRM_Utils_Array::value('honeypot_limit', $settings)) {
if ($limit = ($settings['honeypot_limit'] ?? NULL)) {
$delay = ($_SERVER['REQUEST_TIME'] - $fields['timestamp']);
if ($delay < $limit) {
$errors['_qf_default'] = ts('User submitted a CiviCRM form too quickly');
}
}

$fieldnames = CRM_Utils_Array::value('honeypot_field_names', $settings, array());
$fieldnames = $settings['honeypot_field_names'] ?? [];
foreach ($fields as $key => $value) {
if (in_array($key, $fieldnames) && $value) {
$errors['_qf_default'] = ts('User filled in hidden field');
Expand Down Expand Up @@ -191,8 +191,7 @@ function civihoneypot_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*

// */
*/

/**
* Implements hook_civicrm_navigationMenu().
Expand All @@ -210,4 +209,4 @@ function civihoneypot_civicrm_navigationMenu(&$menu) {
'separator' => 1,
]);
_civihoneypot_civix_navigationMenu($menu);
}
}