Created
January 27, 2017 03:46
-
-
Save webnitros/e0523268b034622c9191b4a05cbd0fb0 to your computer and use it in GitHub Desktop.
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 | |
/** @var modX $modx */ | |
switch ($modx->event->name) { | |
case 'OnHandleRequest': | |
$isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; | |
if (empty($_REQUEST['action']) || (!$isAjax && $modx->event->name != 'OnHandleRequest')) {return;} | |
$action = trim($_REQUEST['action']); | |
$ctx = !empty($_REQUEST['ctx']) ? (string) $_REQUEST['ctx'] : 'web'; | |
if ($ctx != 'web') {$modx->switchContext($ctx);} | |
if (!empty($_REQUEST['pageId']) && $resource = $modx->getObject('modResource', $_REQUEST['pageId'])) { | |
$ctx = $resource->get('context_key'); | |
} | |
else { | |
$ctx = !empty($_REQUEST['ctx']) ? $_REQUEST['ctx'] : 'web'; | |
} | |
if ($ctx != 'web') { | |
$modx->switchContext($ctx); | |
$modx->user = null; | |
$modx->getUser($ctx); | |
} | |
/* @var msOneClick $msOneClick */ | |
$msOneClick = $modx->getService('msoneclick'); | |
if (!($msOneClick instanceof msOneClick)) { | |
@session_write_close(); | |
exit('Could not initialize msOneClick'); | |
} | |
$action = $_REQUEST['action']; | |
unset($_REQUEST['action']); | |
switch ($action){ | |
case 'form/sendform': | |
$response = $msOneClick->loadAction($action, $_REQUEST); | |
break; | |
case 'form/get': | |
$response = $msOneClick->loadAction($action, array('pageId' => @$_POST['pageId'], 'hash' => @$_POST['hash'], 'product_id' => @$_POST['product_id'],'ctx' => @$_POST['ctx'])); | |
break; | |
case 'form/add': | |
$response = $msOneClick->loadAction($action, array('field' => @$_POST['field'], 'value' => @$_POST['value'])); | |
break; | |
default: | |
$response = $modx->toJSON(array( | |
'success' => false | |
,'message' => $modx->lexicon('msoc_err_action_nf') | |
)); | |
break; | |
} | |
if ($isAjax) { | |
if (is_array($response)) { | |
$response = $modx->toJSON($response); | |
} | |
@session_write_close(); | |
exit($response); | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment