-
Notifications
You must be signed in to change notification settings - Fork 5
/
domain.blocks.inc
167 lines (160 loc) · 3.8 KB
/
domain.blocks.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* @file
* Block view functions for Domain Access.
*/
/**
* A nifty little domain-switcher block, useful during debugging.
*
* @see domain_block_view()
*/
function domain_block_view_switcher() {
$output = '';
$list = [];
$domains = domain_domains();
$msg = FALSE;
foreach ($domains as $domain) {
if ($domain['valid']) {
$title = $domain['sitename'];
$allow = TRUE;
}
else {
$title = $domain['sitename'] . ' *';
$allow = FALSE;
if (user_access('access inactive domains')) {
$msg = TRUE;
$allow = TRUE;
}
}
if ($allow) {
$list[] = l($title, domain_get_uri($domain), ['absolute' => TRUE]);
}
}
$items = ['items' => $list];
$output = theme('item_list', $items);
$block = [
'subject' => t('Domain switcher'),
'content' => [
'#markup' => $output,
],
];
return $block;
}
/**
* Prints information about the current node.
*
* @see domain_block_view()
*/
function domain_block_view_information() {
$output = '';
$node = menu_get_object();
if (empty($node->nid)) {
return;
}
// Print the assigned domains.
if (!empty($node->subdomains)) {
$output .= theme('item_list', [
'items' => $node->subdomains,
'title' => t('Assigned domains'),
]);
}
// Print the link source domain.
$this_domain = domain_get_node_match($node->nid);
$output .= theme('item_list', [
'items' => [check_plain($this_domain['sitename'])],
'title' => t('Source domain'),
]);
if (empty($output)) {
$output = t('This node is not assigned to a domain.');
}
else {
$output = '<p>' . t('%node is published with the following Domain Access rules:', ['%node' => $node->title]) . '</p>' . $output;
}
$block = [
'subject' => t('Domain access information'),
'content' => [
'#markup' => $output,
],
];
return $block;
}
/**
* Prints information about the current HTTP request.
*
* @see domain_block_view()
*/
function domain_block_view_server() {
$_domain = domain_get_domain();
$output = '';
$header = [t('Property'), t('Value')];
$rows = [];
$rows[] = [
t('HTTP_HOST request'),
check_plain($_SERVER['HTTP_HOST']),
];
$check = domain_lookup(NULL, $_SERVER['HTTP_HOST']);
$match = t('TRUE');
if ($check == -1) {
// Specific check for Domain Alias.
if (isset($_domain['active_alias_id'])) {
$match = t('ALIAS: Using alias %id', ['%id' => $_domain['active_alias_id']]);
}
else {
$match = t('FALSE: Using default domain.');
}
}
$rows[] = [
t('Domain match'),
$match,
];
foreach ($_domain as $key => $value) {
if (is_null($value)) {
$value = t('NULL');
}
elseif ($value === TRUE) {
$value = t('TRUE');
}
elseif ($value === FALSE) {
$value = t('FALSE');
}
$rows[] = [
check_plain($key),
!is_array($value) ? check_plain($value) : _domain_block_print_array($value),
];
}
$output = theme('table', ['header' => $header, 'rows' => $rows]);
$block = [
'subject' => t('Domain server information'),
'content' => [
'#markup' => $output,
],
];
return $block;
}
/**
* Prints array data for the server block.
*
* @param $array
* An array of data. Note that we support two levels of nesting.
*
* @return
* A suitable output string.
*/
function _domain_block_print_array($array) {
$items = [];
foreach ($array as $key => $val) {
$value = 'array';
if (!is_array($val)) {
$value = check_plain($val);
}
else {
$list = [];
foreach ($val as $k => $v) {
$list[] = t('@key : @value', ['@key' => $k, '@value' => $v]);
}
$value = implode('<br />', $list);
}
$items[] = t('@key : !value', ['@key' => $key, '!value' => $value]);
}
return theme('item_list', ['items' => $items]);
}