]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/php/read-hosts.php
Merge branch '3.6-release'
[friendica-addons.git] / jappixmini / jappix / php / read-hosts.php
1 <?php
2
3 /*
4
5 Jappix - An open social platform
6 This is the hosts configuration reader
7
8 -------------------------------------------------
9
10 License: AGPL
11 Author: Vanaryon
12 Last revision: 29/05/11
13
14 */
15
16 // Someone is trying to hack us?
17 if(!defined('JAPPIX_BASE'))
18         exit;
19
20 // Get the protocol we use
21 if(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on'))
22         $protocol = 'https';
23 else
24         $protocol = 'http';
25
26 // Get the HTTP host
27 $http_host = 'jappix.com';
28
29 if($_SERVER['HTTP_HOST']) {
30         $http_host_split = str_replace('www.', '', $_SERVER['HTTP_HOST']);
31         $http_host_split = preg_replace('/:[0-9]+$/i', '', $http_host_split);
32         
33         if($http_host_split)
34                 $http_host = $http_host_split;
35 }
36
37 // Define the default hosts configuration values
38 $hosts_conf = array(
39                 'main'          => $http_host,
40                 'muc'           => 'muc.'.$http_host,
41                 'pubsub'        => 'pubsub.'.$http_host,
42                 'vjud'          => 'vjud.'.$http_host,
43                 'anonymous'     => 'anonymous.'.$http_host,
44                 'bosh'          => 'http://'.$http_host.':5280/http-bind',
45                 'bosh_main'     => '',
46                 'bosh_mini'     => '',
47                 'static'        => '',
48                 'upload'        => ''
49               );
50
51 // Define a default values array
52 $hosts_default = $hosts_conf;
53
54 // Read the hosts configuration file
55 $hosts_data = readXML('conf', 'hosts');
56
57 // Read the hosts configuration file
58 if($hosts_data) {
59         // Initialize the hosts configuration XML data
60         $hosts_xml = new SimpleXMLElement($hosts_data);
61         
62         // Loop the hosts configuration elements
63         foreach($hosts_xml->children() as $hosts_child) {
64                 $hosts_value = $hosts_child->getName();
65                 
66                 // Only push this to the array if it exists
67                 if(isset($hosts_conf[$hosts_value]) && $hosts_child)
68                         $hosts_conf[$hosts_value] = str_replace('{PROTOCOL}', $protocol, $hosts_child);
69         }
70 }
71
72 // Finally, define the hosts configuration globals
73 define('HOST_MAIN', $hosts_conf['main']);
74 define('HOST_MUC', $hosts_conf['muc']);
75 define('HOST_PUBSUB', $hosts_conf['pubsub']);
76 define('HOST_VJUD', $hosts_conf['vjud']);
77 define('HOST_ANONYMOUS', $hosts_conf['anonymous']);
78 define('HOST_BOSH', $hosts_conf['bosh']);
79 define('HOST_BOSH_MAIN', $hosts_conf['bosh_main']);
80 define('HOST_BOSH_MINI', $hosts_conf['bosh_mini']);
81 define('HOST_STATIC', $hosts_conf['static']);
82 define('HOST_UPLOAD', $hosts_conf['upload']);
83
84 ?>