7.cache.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php return 'switch ($modx->event->name) {
  2. case \'OnManagerPageBeforeRender\':
  3. if ($modx->hasPermission(\'error_log_view\')) {
  4. $modx->controller->addLexiconTopic(\'controlerrorlog:default\');
  5. $modx->controller->addCss($modx->getOption(\'assets_url\') . \'components/controlerrorlog/css/mgr/main.css\');
  6. $modx->controller->addJavascript($modx->getOption(\'assets_url\') . \'components/controlerrorlog/js/mgr/cel.default.js\');
  7. $response = $modx->runProcessor(\'mgr/errorlog/get\', [\'includeContent\' => false], [\'processors_path\' => $modx->getOption(\'core_path\') . \'components/controlerrorlog/processors/\']);
  8. $resObj = $response->getObject();
  9. $_html = "<script> controlErrorLog.config = " . $modx->toJSON($resObj) . ";</script>";
  10. $modx->controller->addHtml($_html);
  11. }
  12. break;
  13. case \'OnHandleRequest\':
  14. if ($modx->context->get(\'key\') == \'mgr\') {
  15. return \'\';
  16. }
  17. $f = $modx->getOption(xPDO::OPT_CACHE_PATH) . \'logs/error.log\';
  18. if (file_exists($f)) {
  19. $casheHash = $modx->cacheManager->get(\'error_log\');
  20. $hash = md5_file($f);
  21. $email = $modx->getOption(\'controlerrorlog.admin_email\');
  22. if (filesize($f) > 0 && !empty($casheHash) && $casheHash != $hash && $modx->getOption(\'controlerrorlog.control_frontend\') && !empty($email)) {
  23. $modx->lexicon->load(\'controlerrorlog:default\');
  24. /** @var modPHPMailer $mail */
  25. $mail = $modx->getService(\'mail\', \'mail.modPHPMailer\');
  26. $mail->setHTML(true);
  27. $mail->set(modMail::MAIL_SUBJECT, $modx->lexicon(\'errorlog_email_subject\'));
  28. $mail->set(modMail::MAIL_BODY, $modx->lexicon(\'errorlog_email_body\'));
  29. $mail->set(modMail::MAIL_SENDER, $modx->getOption(\'emailsender\'));
  30. $mail->set(modMail::MAIL_FROM, $modx->getOption(\'emailsender\'));
  31. $mail->set(modMail::MAIL_FROM_NAME, $modx->getOption(\'site_name\'));
  32. $mail->address(\'to\', $email);
  33. $mail->address(\'reply-to\', $modx->getOption(\'emailsender\'));
  34. if (!$mail->send()) {
  35. print (\'An error occurred while trying to send the email: \' . $modx->mail->mailer->ErrorInfo);
  36. }
  37. $mail->reset();
  38. }
  39. if ($casheHash != $hash) {
  40. $modx->cacheManager->set(\'error_log\', $hash, 0);
  41. }
  42. }
  43. break;
  44. }
  45. return;
  46. ';