7.include.cache.php 2.5 KB

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