Skip to content

Instantly share code, notes, and snippets.

@christianseel
Created June 28, 2017 15:35
Show Gist options
  • Save christianseel/122bde54b67941c6e0c5d5ae8a5d820e to your computer and use it in GitHub Desktop.
Save christianseel/122bde54b67941c6e0c5d5ae8a5d820e to your computer and use it in GitHub Desktop.
MODX index.php with XRouting integrated
<?php
/*
* This file is part of MODX Revolution.
*
* Copyright (c) MODX, LLC. All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$tstart= microtime(true);
/* define this as true in another entry file, then include this file to simply access the API
* without executing the MODX request handler */
if (!defined('MODX_API_MODE')) {
define('MODX_API_MODE', false);
}
/* this can be used to disable caching in MODX absolutely */
$modx_cache_disabled= false;
/* include custom core config and define core path */
@include(dirname(__FILE__) . '/config.core.php');
if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', dirname(__FILE__) . '/core/');
/* include the modX class */
if (!@include_once (MODX_CORE_PATH . "model/modx/modx.class.php")) {
$errorMessage = 'Site temporarily unavailable';
@include(MODX_CORE_PATH . 'error/unavailable.include.php');
header('HTTP/1.1 503 Service Unavailable');
echo "<html><title>Error 503: Site temporarily unavailable</title><body><h1>Error 503</h1><p>{$errorMessage}</p></body></html>";
exit();
}
/* start output buffering */
ob_start();
/* Create an instance of the modX class */
$modx= new modX();
if (!is_object($modx) || !($modx instanceof modX)) {
ob_get_level() && @ob_end_flush();
$errorMessage = '<a href="setup/">MODX not installed. Install now?</a>';
@include(MODX_CORE_PATH . 'error/unavailable.include.php');
header('HTTP/1.1 503 Service Unavailable');
echo "<html><title>Error 503: Site temporarily unavailable</title><body><h1>Error 503</h1><p>{$errorMessage}</p></body></html>";
exit();
}
/* Set the actual start time */
$modx->startTime= $tstart;
/* Load XRouting Class */
$xrouting_path = MODX_CORE_PATH . 'components/xrouting/model/';
$modx->getService('xrouting', 'XRouting', $xrouting_path, array(
'xrouting.default_context' => 'antenne-de',
'xrouting.include_www' => false,
'xrouting.allow_debug_info' => false,
'xrouting.show_no_match_error' => false
));
if (!$modx->xrouting instanceof XRouting) {
$modx->log(modX::LOG_LEVEL_ERROR, '[XRouting] Could not load XRouting service from ' . $xrouting_path);
$errorMessage = 'Site temporarily unavailable. Routing Error.';
@include(MODX_CORE_PATH . 'error/unavailable.include.php');
header('HTTP/1.1 503 Service Unavailable');
echo "<html><title>Error 503: Site temporarily unavailable</title><body><h1>Error 503</h1><p>{$errorMessage}</p></body></html>";
exit();
}
/* get the correct context */
$ctxKey = $modx->xrouting->getContext();
/* initialize the requested context */
$modx->initialize($ctxKey, $options);
/* execute the request handler */
if (!MODX_API_MODE) {
$modx->handleRequest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment