/civicrm/custom/ext/reporterror/CRM/ReportError/Handler/IgnoreBots.php
PHP | 39 lines | 23 code | 11 blank | 5 comment | 4 complexity | 5cff7cd43c7aea4a36000c50a649f6e0 MD5 | raw file
Possible License(s): JSON, BSD-3-Clause, MPL-2.0-no-copyleft-exception, AGPL-1.0, GPL-2.0, AGPL-3.0, Apache-2.0, MIT, GPL-3.0, CC-BY-4.0, LGPL-2.1, BSD-2-Clause, LGPL-3.0
- <?php
- use CRM_ReportError_ExtensionUtil as E;
- class CRM_ReportError_Handler_IgnoreBots {
- /**
- * Identify and possibly ignore bots.
- */
- static public function handler($vars, $options_overrides) {
- $sendreport = TRUE;
- $is_bot = FALSE;
- $bots_regexp = reporterror_setting_get('reporterror_bots_regexp', $options_overrides);
- if ($bots_regexp && preg_match('/' . $bots_regexp . '/', $_SERVER['HTTP_USER_AGENT'])) {
- $is_bot = TRUE;
- $bots_sendreport = reporterror_setting_get('reporterror_bots_sendreport', $options_overrides);
- $bots_404 = reporterror_setting_get('reporterror_bots_404', $options_overrides);
- $vars['reporterror_subject'] = E::ts('reporterror_bot');
- if ($bots_sendreport) {
- CRM_ReportError_Utils::sendReport($vars, $options_overrides);
- }
- if ($bots_404) {
- CRM_ReportError_Utils::generate404();
- return TRUE;
- }
- // FIXME: should we continue going through other handlers?
- // For example, we might want to redirect a bot.
- }
- return FALSE;
- }
- }