index.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  11. * @package modx
  12. * @subpackage connectors
  13. */
  14. $included = defined('MODX_CONNECTOR_INCLUDED') || defined('MODX_CORE_PATH');
  15. /* retrieve or define MODX_CORE_PATH */
  16. if (!defined('MODX_CORE_PATH')) {
  17. if (file_exists(dirname(__FILE__) . '/config.core.php')) {
  18. include dirname(__FILE__) . '/config.core.php';
  19. } else {
  20. define('MODX_CORE_PATH', dirname(__DIR__) . '/core/');
  21. }
  22. /* anonymous access for security/login action */
  23. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'security/login') {
  24. define('MODX_REQP', false);
  25. }
  26. }
  27. /* include modX class - return error on failure */
  28. if (!include_once(MODX_CORE_PATH . 'model/modx/modx.class.php')) {
  29. header("Content-Type: application/json; charset=UTF-8");
  30. header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
  31. echo json_encode(array(
  32. 'success' => false,
  33. 'code' => 404,
  34. ));
  35. die();
  36. }
  37. /* load modX instance */
  38. $modx = new modX('', array(xPDO::OPT_CONN_INIT => array(xPDO::OPT_CONN_MUTABLE => true)));
  39. /* initialize the proper context */
  40. $ctx = isset($_REQUEST['ctx']) && !empty($_REQUEST['ctx']) && is_string($_REQUEST['ctx']) ? $_REQUEST['ctx'] : 'mgr';
  41. $modx->initialize($ctx);
  42. /* check for anonymous access or for a context access policy - return error on failure */
  43. if (defined('MODX_REQP') && MODX_REQP === false) {
  44. } else if (!is_object($modx->context) || !$modx->context->checkPolicy('load')) {
  45. header("Content-Type: application/json; charset=UTF-8");
  46. header($_SERVER['SERVER_PROTOCOL'] . ' 401 Not Authorized');
  47. echo json_encode(array(
  48. 'success' => false,
  49. 'code' => 401,
  50. ));
  51. @session_write_close();
  52. die();
  53. }
  54. /* set manager language in manager context */
  55. if ($ctx == 'mgr') {
  56. $ml = $modx->getOption('manager_language',null,'en');
  57. if ($ml != 'en') {
  58. $modx->lexicon->load($ml.':core:default');
  59. $modx->setOption('cultureKey',$ml);
  60. }
  61. }
  62. /* handle the request */
  63. $connectorRequestClass = $modx->getOption('modConnectorRequest.class', null, 'modConnectorRequest');
  64. $modx->config['modRequest.class'] = $connectorRequestClass;
  65. $modx->getRequest();
  66. $modx->request->sanitizeRequest();
  67. if (!$included) {
  68. $modx->request->handleRequest();
  69. }