public function outputContent(array $options = array()) {
/* variable pointer for easier access */
/*if($options['location'] == 'resource'){
var_dump($options);
die('-317-');
}*/
$modx =& $this->modx;
/* backwards compat */
$error =& $this->modx->error;
/* prevent browsing of subdirectories for security */
$target = str_replace('../','',$options['action']);
$siteId = $this->modx->user->getUserToken($this->modx->context->get('key'));
$isLogin = $target == 'login';
/* ensure headers are sent for proper authentication */
if (!$isLogin && !isset($_SERVER['HTTP_MODAUTH']) && !isset($_REQUEST['HTTP_MODAUTH'])) {
$this->responseCode = 401;
$this->body = $modx->error->failure($modx->lexicon('access_denied'),array('code' => 401));
} else if (!$isLogin && isset($_SERVER['HTTP_MODAUTH']) && $_SERVER['HTTP_MODAUTH'] != $siteId) {
$this->responseCode = 401;
$this->body = $modx->error->failure($modx->lexicon('access_denied'),array('code' => 401));
} else if (!$isLogin && isset($_REQUEST['HTTP_MODAUTH']) && $_REQUEST['HTTP_MODAUTH'] != $siteId) {
$this->responseCode = 401;
$this->body = $modx->error->failure($modx->lexicon('access_denied'),array('code' => 401));
/* verify the location and action */
} else if (!isset($options['location']) || !isset($options['action'])) {
$this->responseCode = 404;
$this->body = $this->modx->error->failure($modx->lexicon('action_err_ns'),array('code' => 404));
} else if (empty($options['action'])) {
$this->responseCode = 404;
$this->body = $this->modx->error->failure($modx->lexicon('action_err_ns'),array('code' => 404));
/* execute a processor and format the response */
} else {
/* create scriptProperties array from HTTP GPC vars */
if (!isset($_POST)) $_POST = array();
if (!isset($_GET)) $_GET = array();
$scriptProperties = array_merge($_GET,$_POST);
if (isset($_FILES) && !empty($_FILES)) {
$scriptProperties = array_merge($scriptProperties,$_FILES);
}
/* run processor */
$this->response = $this->modx->runProcessor($target,$scriptProperties,$options); // Тут остановился Petja 777
if (!$this->response) {
$this->responseCode = 404;
$this->body = $this->modx->error->failure($this->modx->lexicon('processor_err_nf',array(
'target' => $target,
)));
} else {
$this->body = $this->response->getResponse();
}
}
/* if files sent, this means that the browser needs it in text/plain,
* so ignore text/json header type
*/
if (!isset($_FILES)) {
header("Content-Type: application/json; charset=UTF-8");
$message = 'OK';
if (array_key_exists($this->responseCode,$this->_responseCodes)) {
$message = $this->_responseCodes[$this->responseCode];
}
header('Status: HTTP/1.1 '.$this->responseCode.' '.$message);
}
if (is_array($this->header)) {
foreach ($this->header as $header) header($header);
}
if (is_array($this->body)) {
@session_write_close();
die($this->modx->toJSON(array(
'success' => isset($this->body['success']) ? $this->body['success'] : 0,
'message' => isset($this->body['message']) ? $this->body['message'] : $this->modx->lexicon('error'),
'total' => (isset($this->body['total']) && $this->body['total'] > 0)
? intval($this->body['total'])
: (isset($this->body['errors'])
? count($this->body['errors'])
: 1),
'data' => isset($this->body['errors']) ? $this->body['errors'] : array(),
'object' => isset($this->body['object']) ? $this->body['object'] : array(),
)));
} else {
@session_write_close();
die($this->body);
}
}