| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /*
- * This file is part of MODX Revolution.
- *
- * Copyright (c) MODX, LLC. All Rights Reserved.
- *
- * For complete copyright and license information, see the COPYRIGHT and LICENSE
- * files found in the top-level directory of this distribution.
- */
- require_once MODX_CORE_PATH . 'model/modx/modmanagerrequest.class.php';
- /**
- * This is the Connector Request handler for MODX.
- *
- * It serves to redirect connector requests to their appropriate processors,
- * while validating for security.
- *
- * @package modx
- */
- class modConnectorRequest extends modManagerRequest {
- /**
- * The base subdirectory location of the requested action.
- * @var string
- * @access public
- */
- public $location;
- /**
- * Initializes the connector request, loading the proper context, culture and lexicon; also loads the action map
- * @return bool
- */
- public function initialize() {
- if ($this->modx && is_object($this->modx->context) && $this->modx->context instanceof modContext) {
- $ctx = $this->modx->context->get('key');
- if (!empty($ctx) && $ctx == 'mgr') {
- $ml = $this->modx->getOption('manager_language',null,$this->modx->getOption('cultureKey',null,'en'));
- if (!empty($ml)) {
- $this->modx->setOption('cultureKey',$ml);
- }
- }
- }
- /* load default core cache file of lexicon strings */
- $this->modx->lexicon->load('core:default');
- if ($this->modx->actionMap === null || !is_array($this->modx->actionMap)) {
- $this->loadActionMap();
- }
- return true;
- }
- /**
- * Handles all requests specified by the action param and prepares for loading.
- *
- * @access public
- * @param array $options An array of request options
- * @return boolean
- */
- public function handleRequest(array $options = array()) {
- if (!isset($options['action'])) {
- $options['action'] = '';
- }
- if (isset($options['action']) && !is_string($options['action'])) return false;
- if ((!isset($options['action']) || $options['action'] == '') && isset($_REQUEST['action'])) {
- $options['action'] = $_REQUEST['action'];
- }
- $options['action'] = strtolower($options['action']);
- $this->loadErrorHandler();
- /* Cleanup action and store. */
- $this->prepareResponse($options);
- return true;
- }
- /**
- * Prepares the output with the specified processor.
- *
- * @param array $options An array of options
- */
- public function prepareResponse(array $options = array()) {
- $procDir = !empty($options['processors_path']) ? $options['processors_path'] : '';
- $this->setDirectory($procDir);
- $this->modx->response->outputContent($options);
- }
- /**
- * Sets the directory to load the processors from
- *
- * @param string $dir The directory to load from
- */
- public function setDirectory($dir = '') {
- if (!$this->modx->getResponse('modConnectorResponse')) {
- $this->modx->log(modX::LOG_LEVEL_FATAL, 'Could not load response class: modConnectorResponse');
- }
- $this->modx->response->setDirectory($dir);
- }
- }
|