savefile.class.php 968 B

123456789101112131415161718192021222324252627
  1. <?php
  2. require_once __DIR__ . '/console.class.php';
  3. class modalConsoleSaveFileProcessor extends modalConsoleProcessor
  4. {
  5. public function process()
  6. {
  7. $code = trim($this->getProperty('code',''));
  8. $fileName = basename(trim($this->getProperty('filename','')), '.php');
  9. if (empty($fileName)) {
  10. return $this->response(false, $this->modx->lexicon('modalconsole_err_file_ns'));
  11. }
  12. $path = realpath($this->modx->getOption('modalconsole_files_path', NULL, $this->modx->getOption('core_path') . 'components/modalconsole/files/'));
  13. $file = $path . DIRECTORY_SEPARATOR . $fileName . '.php';
  14. if ($code) {
  15. if (!file_put_contents($file, $code)) {
  16. return $this->response(false, $this->modx->lexicon('modalconsole_err_save_file'));
  17. }
  18. }
  19. return $this->response(true, '', ['filename' => $fileName]);
  20. }
  21. }
  22. return 'modalConsoleSaveFileProcessor';