console.class.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. require_once dirname(dirname(__FILE__)) . '/modalConsoleHistory.php';
  3. abstract class modalConsoleProcessor extends modProcessor
  4. {
  5. public $permission = 'console';
  6. public $code;
  7. public $limit;
  8. /** @var modalConsoleHistory $history History repository */
  9. protected $history;
  10. public function checkPermissions()
  11. {
  12. if(!$this->modx->hasPermission($this->permission)){
  13. return false;
  14. }
  15. return true;
  16. }
  17. public function initialize()
  18. {
  19. $this->code = preg_replace('/^\s*<\?(php)?\s*/mi', '', $this->getProperty('code', ''));
  20. $this->code = trim($this->code);
  21. $this->limit = $this->getProperty('limit', $this->modx->getOption('modalconsole_history_limit', null, 20));
  22. if (!class_exists('modalConsoleHistory')) {
  23. $errormsg = 'Class "modalConsoleHistory" is not found!';
  24. $this->modx->log(1, $errormsg);
  25. return $errormsg;
  26. }
  27. $this->history = new modalConsoleHistory($this->modx->getCacheManager(), ['userFolder' => $this->getUserFolder('modal_console/'), 'limit'=> $this->limit]);
  28. return true;
  29. }
  30. public function response($success, $message = '', $data = [])
  31. {
  32. $result = [
  33. 'success' => $success,
  34. 'message' => $message,
  35. ];
  36. return json_encode(array_merge($result, $data));
  37. }
  38. public function getUserFolder($prefix = '', $postfix = DIRECTORY_SEPARATOR)
  39. {
  40. return $prefix . md5('modalconsole' . $this->modx->user->id) . $postfix;
  41. }
  42. }