event.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. class SystemEventManagerController extends modManagerController {
  11. public $logArray = array();
  12. /**
  13. * Check for any permissions or requirements to load page
  14. * @return bool
  15. */
  16. public function checkPermissions() {
  17. return $this->modx->hasPermission('error_log_view');
  18. }
  19. /**
  20. * Register custom CSS/JS for the page
  21. * @return void
  22. */
  23. public function loadCustomCssJs() {
  24. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  25. $this->addJavascript($mgrUrl.'assets/modext/widgets/system/modx.panel.error.log.js');
  26. $this->addJavascript($mgrUrl.'assets/modext/sections/system/error.log.js');
  27. $this->addHtml('<script type="text/javascript">
  28. MODx.hasEraseErrorLog = "'.($this->modx->hasPermission('error_log_erase') ? 1 : 0).'"
  29. Ext.onReady(function() {
  30. MODx.load({
  31. xtype: "modx-page-error-log"
  32. ,record: '.$this->modx->toJSON($this->logArray).'
  33. });
  34. });
  35. </script>');
  36. }
  37. /**
  38. * Custom logic code here for setting placeholders, etc
  39. * @param array $scriptProperties
  40. * @return mixed
  41. */
  42. public function process(array $scriptProperties = array()) {
  43. $logTarget = $this->modx->getLogTarget();
  44. if (!is_array($logTarget)) {
  45. $logTarget = array('options' => array());
  46. }
  47. $filename = $this->modx->getOption('filename', $logTarget['options'], 'error.log', true);
  48. $filepath = $this->modx->getOption('filepath', $logTarget['options'], $this->modx->getCachePath() . xPDOCacheManager::LOG_DIR, true);
  49. $f = $filepath.$filename;
  50. $this->logArray['name'] = $f;
  51. if (file_exists($f)) {
  52. $this->logArray['size'] = round(@filesize($f) / 1000 / 1000, 2);
  53. $this->logArray['log'] = '';
  54. if ($this->logArray['size'] > 1) {
  55. $this->logArray['tooLarge'] = true;
  56. $this->logArray['size'] .= ' MiB';
  57. } else {
  58. $this->logArray['tooLarge'] = false;
  59. }
  60. }
  61. }
  62. /**
  63. * Return the pagetitle
  64. *
  65. * @return string
  66. */
  67. public function getPageTitle() {
  68. return $this->modx->lexicon('error_log');
  69. }
  70. /**
  71. * Return the location of the template file
  72. * @return string
  73. */
  74. public function getTemplateFile() {
  75. return '';
  76. }
  77. /**
  78. * Specify the language topics to load
  79. * @return array
  80. */
  81. public function getLanguageTopics() {
  82. return array('system_events');
  83. }
  84. }