Last active
November 25, 2020 20:30
-
-
Save goldsky/4127105 to your computer and use it in GitHub Desktop.
Ajax's connector file using MODX's main index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Ajax Connector | |
* | |
* @package mypackage | |
*/ | |
$validActions = array( | |
'web/data/delete', | |
'web/data/edit' | |
); | |
if (!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $validActions)) { | |
@session_cache_limiter('public'); | |
define('MODX_REQP', false); | |
} | |
define('MODX_API_MODE', true); | |
// this goes to the www.domain.name/index.php | |
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/index.php'; | |
$mypackageCorePath = $modx->getOption('mypackage.core_path', null, $modx->getOption('core_path') . 'components/mypackage/'); | |
require_once $mypackageCorePath . 'model/mypackage.class.php'; | |
$modx->mypackage = new MyPackage($modx); | |
$modx->lexicon->load('mypackage:web'); | |
if (in_array($_REQUEST['action'], $validActions)) { | |
$version = $modx->getVersionData(); | |
if (version_compare($version['full_version'], '2.1.1-pl') >= 0) { | |
if ($modx->user->hasSessionContext($modx->context->get('key'))) { | |
$_SERVER['HTTP_MODAUTH'] = $_SESSION["modx.{$modx->context->get('key')}.user.token"]; | |
} else { | |
$_SESSION["modx.{$modx->context->get('key')}.user.token"] = 0; | |
$_SERVER['HTTP_MODAUTH'] = 0; | |
} | |
} else { | |
$_SERVER['HTTP_MODAUTH'] = $modx->site_id; | |
} | |
$_REQUEST['HTTP_MODAUTH'] = $_SERVER['HTTP_MODAUTH']; | |
} | |
// try this | |
// echo $modx->user->get('id'); | |
/* handle request */ | |
$connectorRequestClass = $modx->getOption('modConnectorRequest.class',null,'modConnectorRequest'); | |
$modx->config['modRequest.class'] = $connectorRequestClass; | |
$connectorResponseClass = $modx->getOption('modConnectorResponse.class',null,'modConnectorResponse'); | |
$modx->config['modResponse.class'] = $connectorResponseClass; | |
$path = $modx->getOption('processorsPath', $modx->mypackage->config, $mypackageCorePath . 'processors/'); | |
$modx->getRequest(); | |
$modx->request->sanitizeRequest(); | |
$modx->request->handleRequest(array( | |
'processors_path' => $path, | |
'location' => '', | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment