12.cache.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php return '/**
  2. * GatewayManager
  3. * The manager for all you gateway domains
  4. *
  5. * @package gatewaymanager
  6. * @author Bert Oost at OostDesign.nl <bert@oostdesign.nl>
  7. *
  8. * @var modX|xPDO $modx
  9. * @var array $scriptProperties
  10. */
  11. if ($modx->context->get(\'key\') == \'mgr\') {
  12. return;
  13. }
  14. $corePath = $modx->getOption(\'gatewaymanager.core_path\', null, $modx->getOption(\'core_path\') . \'components/gatewaymanager/\');
  15. $gateway = $modx->getService(\'gatewaymanager\', \'GatewayManager\', $corePath . \'model/gatewaymanager/\', $scriptProperties);
  16. if (!($gateway instanceof GatewayManager)) {
  17. return \'\';
  18. }
  19. $gateway->initialize($modx->context->get(\'key\'));
  20. // get the hostname
  21. $hostname = parse_url($_SERVER[\'REQUEST_URI\'], PHP_URL_HOST);
  22. if (empty($hostname)) {
  23. $hostname = $modx->getOption(\'http_host\');
  24. }
  25. // and find the GatewayManager record
  26. $domain = $modx->getObject(\'gatewayDomain\', array(\'domain\' => $hostname, \'active\' => true));
  27. if (!empty($domain) && is_object($domain) && $domain instanceof gatewayDomain) {
  28. // the current context
  29. $currContext = $modx->context;
  30. $currContextKey = $currContext->get(\'key\');
  31. // get the context from the setupped domain
  32. $domContext = $domain->getOne(\'Context\');
  33. $domContextKey = $domContext->get(\'key\');
  34. $sameContext = ($currContextKey == $domContextKey) ? true : false;
  35. if (!$sameContext) {
  36. // switch to the new context
  37. $modx->switchContext($domContextKey);
  38. }
  39. // when domain of context is different then a canonical should be created
  40. $sameDomain = ($currContext->getOption(\'http_host\') == $domContext->getOption(\'http_host\')) ? true : false;
  41. if (!$sameDomain) {
  42. $currContext = $domContext;
  43. }
  44. // site start check (only when trying to reach the homepage)
  45. $urlPath = parse_url($_SERVER[\'REQUEST_URI\'], PHP_URL_PATH);
  46. if ($urlPath == \'/\' || empty($urlPath)) {
  47. $currSiteStart = $currContext->getOption(\'site_start\');
  48. $siteStart = $domain->get(\'sitestart\');
  49. $sameSiteStart = ($currSiteStart == $siteStart || empty($siteStart)) ? true : false;
  50. if (!$sameSiteStart) {
  51. // when not in same context, set a canonical placeholder
  52. if ($sameContext || !$sameDomain) {
  53. $url = $modx->makeUrl($sitestart, $currContext, \'\', \'full\');
  54. $modx->setPlaceholder(\'gateway.canonical\', $url);
  55. }
  56. // send to the new startpage
  57. $modx->sendForward($siteStart);
  58. }
  59. }
  60. }
  61. return;
  62. ';