1: <?php
2:
3: /**
4: * CONTENIDO Chain.
5: * Generate base href for multiple client domains
6: *
7: * Client setting must look like this:
8: * Type: client
9: * Name: frontend_pathX (X any number/character)
10: * Value: base href URL (e.g. http://www.example.org/example/)
11: *
12: * @package Core
13: * @subpackage Chain
14: * @author Andreas Lindner
15: * @copyright four for business AG <www.4fb.de>
16: * @license http://www.contenido.org/license/LIZENZ.txt
17: * @link http://www.4fb.de
18: * @link http://www.contenido.org
19: */
20:
21: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
22:
23: /**
24: *
25: * @param string $currentBaseHref
26: *
27: * @return string
28: *
29: * @throws cDbException
30: * @throws cException
31: * @throws cInvalidArgumentException
32: */
33: function cecCreateBaseHref($currentBaseHref) {
34:
35: // get props of current client
36: $props = cRegistry::getClient()->getProperties();
37: //$props = cRegistry::getClient()->getPropertiesByType('client');
38:
39: // return rootdir as defined in AMR if client has no props
40: if (!is_array($props)) {
41: return $currentBaseHref;
42: }
43:
44: foreach ($props as $prop) {
45:
46: // skip props that are not of type 'client'
47: if ($prop['type'] != 'client') {
48: continue;
49: }
50:
51: // skip props whose name does not contain 'frontend_path'
52: if (false === strstr($prop['name'], 'frontend_path')) {
53: continue;
54: }
55:
56: // current host & path (HTTP_HOST & REQUEST_URI)
57: $httpHost = $_SERVER['HTTP_HOST'];
58: $httpPath = $_SERVER['REQUEST_URI'];
59:
60: // host & path of configured alternative URL
61: $propHost = parse_url($prop['value'], PHP_URL_HOST);
62: $propPath = parse_url($prop['value'], PHP_URL_PATH);
63:
64: // skip if http host does not equal configured host (allowing for optional www)
65: if ($propHost != $httpHost && ('www.' . $propHost) != $httpHost && $propHost != 'www.' . $httpHost) {
66: continue;
67: }
68:
69: // skip if http path does not start with configured path
70: if (0 !== cString::findFirstPos($httpPath, $propPath)) {
71: continue;
72: }
73:
74: // return URL as specified in client settings
75: $currentBaseHref = $prop['value'];
76:
77: }
78:
79: // return default
80: return $currentBaseHref;
81:
82: }
83:
84: ?>