modconnectorrequest.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. require_once MODX_CORE_PATH . 'model/modx/modmanagerrequest.class.php';
  11. /**
  12. * This is the Connector Request handler for MODX.
  13. *
  14. * It serves to redirect connector requests to their appropriate processors,
  15. * while validating for security.
  16. *
  17. * @package modx
  18. */
  19. class modConnectorRequest extends modManagerRequest {
  20. /**
  21. * The base subdirectory location of the requested action.
  22. * @var string
  23. * @access public
  24. */
  25. public $location;
  26. /**
  27. * Initializes the connector request, loading the proper context, culture and lexicon; also loads the action map
  28. * @return bool
  29. */
  30. public function initialize() {
  31. if ($this->modx && is_object($this->modx->context) && $this->modx->context instanceof modContext) {
  32. $ctx = $this->modx->context->get('key');
  33. if (!empty($ctx) && $ctx == 'mgr') {
  34. $ml = $this->modx->getOption('manager_language',null,$this->modx->getOption('cultureKey',null,'en'));
  35. if (!empty($ml)) {
  36. $this->modx->setOption('cultureKey',$ml);
  37. }
  38. }
  39. }
  40. /* load default core cache file of lexicon strings */
  41. $this->modx->lexicon->load('core:default');
  42. if ($this->modx->actionMap === null || !is_array($this->modx->actionMap)) {
  43. $this->loadActionMap();
  44. }
  45. return true;
  46. }
  47. /**
  48. * Handles all requests specified by the action param and prepares for loading.
  49. *
  50. * @access public
  51. * @param array $options An array of request options
  52. * @return boolean
  53. */
  54. public function handleRequest(array $options = array()) {
  55. if (!isset($options['action'])) {
  56. $options['action'] = '';
  57. }
  58. if (isset($options['action']) && !is_string($options['action'])) return false;
  59. if ((!isset($options['action']) || $options['action'] == '') && isset($_REQUEST['action'])) {
  60. $options['action'] = $_REQUEST['action'];
  61. }
  62. $options['action'] = strtolower($options['action']);
  63. $this->loadErrorHandler();
  64. /* Cleanup action and store. */
  65. $this->prepareResponse($options);
  66. return true;
  67. }
  68. /**
  69. * Prepares the output with the specified processor.
  70. *
  71. * @param array $options An array of options
  72. */
  73. public function prepareResponse(array $options = array()) {
  74. $procDir = !empty($options['processors_path']) ? $options['processors_path'] : '';
  75. $this->setDirectory($procDir);
  76. $this->modx->response->outputContent($options);
  77. }
  78. /**
  79. * Sets the directory to load the processors from
  80. *
  81. * @param string $dir The directory to load from
  82. */
  83. public function setDirectory($dir = '') {
  84. if (!$this->modx->getResponse('modConnectorResponse')) {
  85. $this->modx->log(modX::LOG_LEVEL_FATAL, 'Could not load response class: modConnectorResponse');
  86. }
  87. $this->modx->response->setDirectory($dir);
  88. }
  89. }