12.include.cache.php 2.5 KB

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