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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
<?php
// Include translation file
require_once __DIR__ . '/l10n.php';
// Base file to handle each page request
require get_template_directory().'/config.php';
require get_template_directory().'/strings.php';
$html = '';
// If news then include nothing
if(is_page('oc-news') || is_page('blogfeed')) {
ob_clean();
ob_start();
include roots_template_path();
$html .= ob_get_contents();
ob_end_clean();
} else {
/**
* Pages that still use the old layout and haven't been migrated
*/
$oldPages = [
'404',
'5years',
'about',
'advisories',
'advisory',
'agreement',
'android',
'appform',
'appform-submit',
'apply',
'apply2',
'changelog',
'code-of-conduct',
'collaboraonline',
'community',
'conf',
'conference-program',
'confinfo',
'confsubscribe',
'connect',
'consulting',
'contact',
'contactform',
'contactsubmit',
// 'contribute',
'contributors',
'design',
'desktop',
'devices',
'events',
'faq',
'features',
'federation',
'hackathon',
'history',
'impressum',
'install',
'install-backup',
'meetups',
// 'migration',
'news',
'newsletter',
'nine',
'pidrive',
'policy',
'pr20160602',
'pr20160614',
'pr20160705',
'pr20160719',
'pr20160721',
'pr20160725',
'pr20160812',
'pr20160825',
'pr20160901',
'pr20160916',
'pr20160929',
'pr20161027',
'pr20161213',
'press',
'privacy',
'promote',
'providers',
'providersubmit',
'release-channels',
'salessubmit',
'securesharesubmit',
'securesharing',
'security',
'sharing',
'speaking',
'spreedbox',
// 'support',
'team',
'thanks',
'thankyou',
'theming',
'threat-model',
'trademarks',
'translation',
'user',
'webrtc',
'workflow'
];
function is_blog()
{
global $post;
$posttype = get_post_type($post);
return (((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ($posttype == 'post')) ? true : false;
}
$currentPage = strtolower(get_post()->post_name);
$oldPage = true;
if (in_array($currentPage, $oldPages) || is_blog()) {
// It's an old page, use the old template
ob_clean();
ob_start();
get_template_part('templates/head-old');
$html .= ob_get_contents();
ob_end_clean();
} else {
// It's a new page, use the new template
ob_clean();
ob_start();
get_template_part('templates/head');
$html .= ob_get_contents();
ob_end_clean();
$oldPage = false;
}
$html .= '<body ';
ob_clean();
ob_start();
body_class();
$html .= ob_get_contents() . '>';
ob_end_clean();
ob_clean();
ob_start();
get_template_part('templates/header-top-navbar');
$html .= ob_get_contents();
ob_end_clean();
// The basic translation for the files
$l = new L10N(get_post()->post_name);
if ($oldPage === true) {
$html .= '<div class="wrap container" role="document"><div class="content row">';
$html .= '<main class="main ' . roots_main_class() . '; ?>" role="main">';
ob_clean();
ob_start();
include roots_template_path();
$html .= ob_get_contents();
ob_end_clean();
$html .= '</main></div></div>';
} else {
ob_clean();
ob_start();
include roots_template_path();
$html .= ob_get_contents();
ob_end_clean();
}
ob_clean();
ob_start();
require get_template_directory() . '/templates/footer.php';
$html .= ob_get_contents();
ob_end_clean();
if (PIWIKTRACKING) {
ob_clean();
ob_start();
get_template_part('templates/piwik-tracking');
$html .= ob_get_contents();
ob_end_clean();
}
$html .= '</body>';
$html .= '</html>';
}
// Check if the page is completely translated, if so use the translated one. If not default to the cached value.
$storeToCache = false;
$echoed = false;
$hl = '';
$path = parse_url(site_url())['path'];
$language = explode('/', substr($_SERVER['REQUEST_URI'], strlen($path)));
if(isset($language[1]) && $language[1] === 'de') {
$hl = strtolower((string)$language[1]);
if (ctype_alnum($hl) && strlen($hl) === 2) {
$l10nFiles = [
get_post()->post_name,
'header-navbar',
'footer',
];
$storeToCache = true;
foreach($l10nFiles as $file) {
$translatedPath = __DIR__ . '/l10n/' . $hl . '/' . $file . '.json';
$originalPath = __DIR__ . '/l10n/base/' . $file . '.json';
if(file_exists($translatedPath) && file_exists($originalPath)) {
$translatedFile = json_decode(file_get_contents($translatedPath), true);
$originalFile = json_decode(file_get_contents($originalPath), true);
} else {
$translatedFile = null;
$originalFile = null;
}
if(!is_array($translatedFile) || !is_array($originalFile)) {
$storeToCache = false;
}
if (array_keys($translatedFile) !== array_keys($originalFile)) {
$storeToCache = false;
}
}
$cacheFile = __DIR__ . '/l10n/cache/' . md5($_SERVER['REQUEST_URI']);
if(file_exists($cacheFile) && $storeToCache === false) {
echo file_get_contents($cacheFile);
$echoed = true;
}
if($storeToCache === true) {
file_put_contents($cacheFile, $html);
if(file_exists($cacheFile)) {
echo file_get_contents($cacheFile);
$echoed = true;
}
}
}
}
if($echoed === false) {
echo $html;
}
|