PageRenderTime 98ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/civicrm/custom/ext/reporterror/CRM/ReportError/Handler/IgnoreBots.php

https://github.com/nysenate/Bluebird-CRM
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
  1. <?php
  2. use CRM_ReportError_ExtensionUtil as E;
  3. class CRM_ReportError_Handler_IgnoreBots {
  4. /**
  5. * Identify and possibly ignore bots.
  6. */
  7. static public function handler($vars, $options_overrides) {
  8. $sendreport = TRUE;
  9. $is_bot = FALSE;
  10. $bots_regexp = reporterror_setting_get('reporterror_bots_regexp', $options_overrides);
  11. if ($bots_regexp && preg_match('/' . $bots_regexp . '/', $_SERVER['HTTP_USER_AGENT'])) {
  12. $is_bot = TRUE;
  13. $bots_sendreport = reporterror_setting_get('reporterror_bots_sendreport', $options_overrides);
  14. $bots_404 = reporterror_setting_get('reporterror_bots_404', $options_overrides);
  15. $vars['reporterror_subject'] = E::ts('reporterror_bot');
  16. if ($bots_sendreport) {
  17. CRM_ReportError_Utils::sendReport($vars, $options_overrides);
  18. }
  19. if ($bots_404) {
  20. CRM_ReportError_Utils::generate404();
  21. return TRUE;
  22. }
  23. // FIXME: should we continue going through other handlers?
  24. // For example, we might want to redirect a bot.
  25. }
  26. return FALSE;
  27. }
  28. }