Rev 1068 | Rev 1115 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
596 | daniel-mar | 1 | <?php |
2 | daniel-mar | 2 | |
3 | /* |
||
4 | * OIDplus 2.0 |
||
1086 | daniel-mar | 5 | * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft |
2 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
1050 | daniel-mar | 20 | namespace ViaThinkSoft\OIDplus; |
511 | daniel-mar | 21 | |
1086 | daniel-mar | 22 | // phpcs:disable PSR1.Files.SideEffects |
23 | \defined('INSIDE_OIDPLUS') or die; |
||
24 | // phpcs:enable PSR1.Files.SideEffects |
||
25 | |||
730 | daniel-mar | 26 | class OIDplusGui extends OIDplusBaseClass { |
2 | daniel-mar | 27 | |
28 | public static function generateContentPage($id) { |
||
29 | $out = array(); |
||
30 | |||
31 | $handled = false; |
||
32 | $out['title'] = ''; |
||
32 | daniel-mar | 33 | $out['icon'] = ''; |
2 | daniel-mar | 34 | $out['text'] = ''; |
35 | |||
281 | daniel-mar | 36 | foreach (OIDplus::getPagePlugins() as $plugin) { |
348 | daniel-mar | 37 | try { |
38 | $plugin->gui($id, $out, $handled); |
||
1050 | daniel-mar | 39 | } catch (\Exception $e) { |
360 | daniel-mar | 40 | $out['title'] = _L('Error'); |
800 | daniel-mar | 41 | $out['icon'] = 'img/error.png'; |
348 | daniel-mar | 42 | $out['text'] = $e->getMessage(); |
43 | } |
||
281 | daniel-mar | 44 | if ($handled) break; |
61 | daniel-mar | 45 | } |
2 | daniel-mar | 46 | |
47 | if (!$handled) { |
||
936 | daniel-mar | 48 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
1068 | daniel-mar | 49 | if (PHP_SAPI != 'cli') @http_response_code(404); |
936 | daniel-mar | 50 | } |
360 | daniel-mar | 51 | $out['title'] = _L('Error'); |
800 | daniel-mar | 52 | $out['icon'] = 'img/error.png'; |
360 | daniel-mar | 53 | $out['text'] = _L('The resource cannot be found.'); |
2 | daniel-mar | 54 | } |
55 | |||
56 | return $out; |
||
57 | } |
||
250 | daniel-mar | 58 | |
595 | daniel-mar | 59 | public static function link($goto, $new_window=false): string { |
327 | daniel-mar | 60 | if ($new_window) { |
61 | return 'href="?goto='.urlencode($goto).'" target="_blank"'; |
||
250 | daniel-mar | 62 | } else { |
327 | daniel-mar | 63 | if (strpos($goto, '#') !== false) { |
64 | list($goto, $anchor) = explode('#', $goto, 2); |
||
65 | return 'href="?goto='.urlencode($goto).'#'.htmlentities($anchor).'" onclick="openOidInPanel('.js_escape($goto).', true, '.js_escape($anchor).'); return false;"'; |
||
66 | } else { |
||
67 | return 'href="?goto='.urlencode($goto).'" onclick="openOidInPanel('.js_escape($goto).', true); return false;"'; |
||
68 | } |
||
250 | daniel-mar | 69 | } |
70 | } |
||
362 | daniel-mar | 71 | |
72 | public static function getLanguageBox($goto, $useJs) { |
||
1056 | daniel-mar | 73 | $out = ''; |
74 | $out .= '<div id="languageBox">'; |
||
362 | daniel-mar | 75 | $langbox_entries = array(); |
76 | $non_default_languages = 0; |
||
77 | foreach (OIDplus::getAllPluginManifests('language') as $pluginManifest) { |
||
389 | daniel-mar | 78 | $flag = $pluginManifest->getLanguageFlag(); |
79 | $code = $pluginManifest->getLanguageCode(); |
||
1041 | daniel-mar | 80 | if ($code != OIDplus::getDefaultLang()) $non_default_languages++; |
362 | daniel-mar | 81 | if ($code == OIDplus::getCurrentLang()) { |
82 | $class = 'lng_flag'; |
||
83 | } else { |
||
84 | $class = 'lng_flag picture_ghost'; |
||
85 | } |
||
86 | $add = (!is_null($goto)) ? '&goto='.urlencode($goto) : ''; |
||
632 | daniel-mar | 87 | |
635 | daniel-mar | 88 | $dirs = glob(OIDplus::localpath().'plugins/'.'*'.'/language/'.$code.'/'); |
632 | daniel-mar | 89 | |
90 | if (count($dirs) > 0) { |
||
91 | $dir = substr($dirs[0], strlen(OIDplus::localpath())); |
||
1060 | daniel-mar | 92 | $langbox_entries[$code] = '<span class="lang_flag_bg"><a '.($useJs ? 'onclick="return !setLanguage(\''.$code.'\')" ' : '').'href="?lang='.$code.$add.'"><img src="'.OIDplus::webpath(null,OIDplus::PATH_RELATIVE).$dir.$flag.'" alt="'.$pluginManifest->getName().'" title="'.$pluginManifest->getName().'" class="'.$class.'" id="lng_flag_'.$code.'" height="20"></a></span> '; |
632 | daniel-mar | 93 | } |
362 | daniel-mar | 94 | } |
95 | if ($non_default_languages > 0) { |
||
426 | daniel-mar | 96 | foreach ($langbox_entries as $ent) { |
1056 | daniel-mar | 97 | $out .= "$ent\n\t\t"; |
426 | daniel-mar | 98 | } |
362 | daniel-mar | 99 | } |
1056 | daniel-mar | 100 | $out .= '</div>'; |
101 | return $out; |
||
362 | daniel-mar | 102 | } |
366 | daniel-mar | 103 | |
104 | public static function html_exception_handler($exception) { |
||
105 | if ($exception instanceof OIDplusConfigInitializationException) { |
||
463 | daniel-mar | 106 | echo '<!DOCTYPE HTML>'; |
1056 | daniel-mar | 107 | echo '<html><head><title>'.htmlentities(_L('OIDplus initialization error')).'</title></head><body>'; |
108 | echo '<h1>'.htmlentities(_L('OIDplus initialization error')).'</h1>'; |
||
366 | daniel-mar | 109 | echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>'; |
1056 | daniel-mar | 110 | $msg = _L('Please check the file %1','<b>userdata/baseconfig/config.inc.php</b>'); |
366 | daniel-mar | 111 | if (is_dir(__DIR__ . '/../../setup')) { |
1056 | daniel-mar | 112 | $msg .= ' '._L('or run <a href="%1">setup</a> again',OIDplus::webpath(null,OIDplus::PATH_RELATIVE).'setup/'); |
366 | daniel-mar | 113 | } |
1056 | daniel-mar | 114 | echo '<p>'.htmlentities($msg).'</p>'; |
780 | daniel-mar | 115 | echo self::getExceptionTechInfo($exception); |
463 | daniel-mar | 116 | echo '</body></html>'; |
366 | daniel-mar | 117 | } else { |
463 | daniel-mar | 118 | echo '<!DOCTYPE HTML>'; |
1056 | daniel-mar | 119 | echo '<html><head><title>'.htmlentities(_L('OIDplus error')).'</title></head><body>'; |
120 | echo '<h1>'.htmlentities(_L('OIDplus error')).'</h1>'; |
||
366 | daniel-mar | 121 | // ENT_SUBSTITUTE because ODBC drivers might return ANSI instead of UTF-8 stuff |
122 | echo '<p>'.htmlentities($exception->getMessage(), ENT_SUBSTITUTE).'</p>'; |
||
780 | daniel-mar | 123 | echo self::getExceptionTechInfo($exception); |
463 | daniel-mar | 124 | echo '</body></html>'; |
366 | daniel-mar | 125 | } |
126 | } |
||
420 | daniel-mar | 127 | |
780 | daniel-mar | 128 | private static function getExceptionTechInfo($exception) { |
129 | $out = ''; |
||
1056 | daniel-mar | 130 | $out .= '<p><b>'.htmlentities(_L('Technical information about the problem')).':</b></p>'; |
780 | daniel-mar | 131 | $out .= '<pre>'; |
132 | $out .= get_class($exception)."\n"; |
||
133 | $out .= _L('at file %1 (line %2)',$exception->getFile(),"".$exception->getLine())."\n\n"; |
||
134 | $out .= _L('Stacktrace').":\n"; |
||
922 | daniel-mar | 135 | $out .= htmlentities($exception->getTraceAsString()); |
780 | daniel-mar | 136 | $out .= '</pre>'; |
137 | return $out; |
||
138 | } |
||
139 | |||
420 | daniel-mar | 140 | public function tabBarStart() { |
141 | return '<ul class="nav nav-tabs" id="myTab" role="tablist">'; |
||
142 | } |
||
143 | |||
144 | public function tabBarEnd() { |
||
145 | return '</ul>'; |
||
146 | } |
||
147 | |||
148 | public function tabBarElement($id, $title, $active) { |
||
641 | daniel-mar | 149 | // data-bs-toggle is for Bootstrap 5 |
150 | // data-toggle is for Bootstrap 4 (InternetExplorer compatibility) |
||
151 | return '<li class="nav-item"><a class="nav-link'.($active ? ' active' : '').'" id="'.$id.'-tab" data-bs-toggle="tab" data-toggle="tab" href="#'.$id.'" role="tab" aria-controls="'.$id.'" aria-selected="'.($active ? 'true' : 'false').'">'.$title.'</a></li>'; |
||
420 | daniel-mar | 152 | } |
153 | |||
154 | public function tabContentStart() { |
||
155 | return '<div class="tab-content" id="myTabContent">'; |
||
156 | } |
||
157 | |||
158 | public function tabContentEnd() { |
||
159 | return '</div>'; |
||
160 | } |
||
161 | |||
162 | public function tabContentPage($id, $content, $active) { |
||
163 | return '<div class="tab-pane fade'.($active ? ' show active' : '').'" id="'.$id.'" role="tabpanel" aria-labelledby="'.$id.'-tab">'.$content.'</div>'; |
||
164 | } |
||
165 | |||
1066 | daniel-mar | 166 | public function combine_systemtitle_and_pagetitle($systemtitle, $pagetitle) { |
167 | // Please also change the function in oidplus_base.js |
||
168 | if ($systemtitle == $pagetitle) { |
||
169 | return $systemtitle; |
||
170 | } else { |
||
171 | return $pagetitle . ' - ' . $systemtitle; |
||
172 | } |
||
173 | } |
||
174 | |||
175 | private function getCommonHeadElems($title) { |
||
1065 | daniel-mar | 176 | // Get theme color (color of title bar) |
177 | $design_plugin = OIDplus::getActiveDesignPlugin(); |
||
178 | $theme_color = is_null($design_plugin) ? '' : $design_plugin->getThemeColor(); |
||
1055 | daniel-mar | 179 | |
1065 | daniel-mar | 180 | $head_elems = array(); |
181 | $head_elems[] = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; |
||
182 | if (OIDplus::baseConfig()->getValue('DATABASE_PLUGIN','') !== '') { |
||
183 | $head_elems[] = '<meta name="OIDplus-SystemTitle" content="'.htmlentities(OIDplus::config()->getValue('system_title')).'">'; // Do not remove. This meta tag is acessed by oidplus_base.js |
||
184 | } |
||
185 | if ($theme_color != '') { |
||
186 | $head_elems[] = '<meta name="theme-color" content="'.htmlentities($theme_color).'">'; |
||
187 | } |
||
188 | $head_elems[] = '<meta name="viewport" content="width=device-width, initial-scale=1.0">'; |
||
1066 | daniel-mar | 189 | $head_elems[] = '<title>'.htmlentities($title).'</title>'; |
1065 | daniel-mar | 190 | $head_elems[] = '<script src="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'polyfill.min.js.php"></script>'; |
191 | $head_elems[] = '<script src="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'oidplus.min.js.php?noBaseConfig=1" type="text/javascript"></script>'; |
||
192 | $head_elems[] = '<link rel="stylesheet" href="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'oidplus.min.css.php?noBaseConfig=1">'; |
||
193 | $head_elems[] = '<link rel="shortcut icon" type="image/x-icon" href="'.OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'favicon.ico.php">'; |
||
194 | if (OIDplus::baseConfig()->exists('CANONICAL_SYSTEM_URL')) { |
||
1066 | daniel-mar | 195 | $head_elems[] = '<link rel="canonical" href="'.htmlentities(OIDplus::canonicalURL()).OIDplus::webpath(null, OIDplus::PATH_RELATIVE).'">'; |
1065 | daniel-mar | 196 | } |
1066 | daniel-mar | 197 | |
198 | return $head_elems; |
||
199 | } |
||
200 | |||
201 | public function showMainPage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags=array(), $static_node_id='') { |
||
202 | $head_elems = $this->getCommonHeadElems($page_title_1); |
||
1065 | daniel-mar | 203 | $head_elems = array_merge($head_elems, $extra_head_tags); |
1055 | daniel-mar | 204 | |
1066 | daniel-mar | 205 | $plugins = OIDplus::getPagePlugins(); |
206 | foreach ($plugins as $plugin) { |
||
207 | $plugin->htmlHeaderUpdate($head_elems); |
||
208 | } |
||
209 | |||
1065 | daniel-mar | 210 | # --- |
1055 | daniel-mar | 211 | |
1065 | daniel-mar | 212 | $out = "<!DOCTYPE html>\n"; |
213 | |||
214 | $out .= "<html lang=\"".substr(OIDplus::getCurrentLang(),0,2)."\">\n"; |
||
215 | $out .= "<head>\n"; |
||
216 | $out .= "\t".implode("\n\t",$head_elems)."\n"; |
||
217 | $out .= "</head>\n"; |
||
218 | |||
219 | $out .= "<body>\n"; |
||
220 | |||
1056 | daniel-mar | 221 | $out .= '<div id="loading" style="display:none">Loading…</div>'; |
1055 | daniel-mar | 222 | |
1056 | daniel-mar | 223 | $out .= '<div id="frames">'; |
224 | $out .= '<div id="content_window" class="borderbox">'; |
||
1055 | daniel-mar | 225 | |
1056 | daniel-mar | 226 | $out .= '<h1 id="real_title">'; |
227 | if ($static_icon != '') $out .= '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> '; |
||
228 | $out .= htmlentities($page_title_2).'</h1>'; |
||
229 | $out .= '<div id="real_content">'.$static_content.'</div>'; |
||
1066 | daniel-mar | 230 | if ((!isset($_SERVER['REQUEST_METHOD'])) || ($_SERVER['REQUEST_METHOD'] == 'GET')) { |
231 | $out .= '<br><p><img src="img/share.png" width="15" height="15" alt="'._L('Share').'"> <a href="?goto='.htmlentities($static_node_id).'" id="static_link" class="gray_footer_font">'._L('Static link to this page').'</a>'; |
||
232 | $out .= '</p>'; |
||
233 | } |
||
1056 | daniel-mar | 234 | $out .= '<br>'; |
1055 | daniel-mar | 235 | |
1056 | daniel-mar | 236 | $out .= '</div>'; |
1055 | daniel-mar | 237 | |
1056 | daniel-mar | 238 | $out .= '<div id="system_title_bar">'; |
1055 | daniel-mar | 239 | |
1066 | daniel-mar | 240 | $out .= '<div id="system_title_menu" onclick="mobileNavButtonClick(this)" onmouseenter="mobileNavButtonHover(this)" onmouseleave="mobileNavButtonHover(this)">'; |
241 | $out .= ' <div id="bar1"></div>'; |
||
242 | $out .= ' <div id="bar2"></div>'; |
||
243 | $out .= ' <div id="bar3"></div>'; |
||
244 | $out .= '</div>'; |
||
245 | |||
1056 | daniel-mar | 246 | $out .= '<div id="system_title_text">'; |
1066 | daniel-mar | 247 | $out .= ' <a '.OIDplus::gui()->link('oidplus:system').' id="system_title_a">'; |
248 | $out .= ' <span id="system_title_logo"></span>'; |
||
249 | $out .= ' <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>'; |
||
250 | $out .= ' <span id="system_title_2">'.htmlentities(OIDplus::config()->getValue('system_title')).'</span>'; |
||
251 | $out .= ' </a>'; |
||
252 | $out .= '</div>'; |
||
253 | |||
254 | $out .= '</div>'; |
||
255 | |||
256 | $out .= OIDplus::gui()->getLanguageBox($static_node_id, true); |
||
257 | |||
258 | $out .= '<div id="gotobox">'; |
||
259 | $out .= '<input type="text" name="goto" id="gotoedit" value="'.htmlentities($static_node_id).'">'; |
||
260 | $out .= '<input type="button" value="'._L('Go').'" onclick="gotoButtonClicked()" id="gotobutton">'; |
||
261 | $out .= '</div>'; |
||
262 | |||
263 | $out .= '<div id="oidtree" class="borderbox">'; |
||
264 | //$out .= '<noscript>'; |
||
265 | //$out .= '<p><b>'._L('Please enable JavaScript to use all features').'</b></p>'; |
||
266 | //$out .= '</noscript>'; |
||
267 | $out .= OIDplus::menuUtils()->nonjs_menu(); |
||
268 | $out .= '</div>'; |
||
269 | |||
270 | $out .= '</div>'; |
||
271 | |||
272 | $out .= "\n</body>\n"; |
||
273 | $out .= "</html>\n"; |
||
274 | |||
275 | # --- |
||
276 | |||
277 | $plugins = OIDplus::getPagePlugins(); |
||
278 | foreach ($plugins as $plugin) { |
||
279 | $plugin->htmlPostprocess($out); |
||
280 | } |
||
281 | |||
282 | return $out; |
||
283 | } |
||
284 | |||
285 | public function showSimplePage($page_title_1, $page_title_2, $static_icon, $static_content, $extra_head_tags=array()) { |
||
286 | $head_elems = $this->getCommonHeadElems($page_title_1); |
||
287 | $head_elems = array_merge($head_elems, $extra_head_tags); |
||
288 | |||
289 | # --- |
||
290 | |||
291 | $out = "<!DOCTYPE html>\n"; |
||
292 | |||
293 | $out .= "<html lang=\"".substr(OIDplus::getCurrentLang(),0,2)."\">\n"; |
||
294 | $out .= "<head>\n"; |
||
295 | $out .= "\t".implode("\n\t",$head_elems)."\n"; |
||
296 | $out .= "</head>\n"; |
||
297 | |||
298 | $out .= "<body>\n"; |
||
299 | |||
300 | $out .= '<div id="loading" style="display:none">Loading…</div>'; |
||
301 | |||
302 | $out .= '<div id="frames">'; |
||
303 | $out .= '<div id="content_window" class="borderbox">'; |
||
304 | |||
305 | $out .= '<h1 id="real_title">'; |
||
306 | if ($static_icon != '') $out .= '<img src="'.htmlentities($static_icon).'" width="48" height="48" alt=""> '; |
||
307 | $out .= htmlentities($page_title_2).'</h1>'; |
||
308 | $out .= '<div id="real_content">'.$static_content.'</div>'; |
||
309 | $out .= '<br>'; |
||
310 | |||
311 | $out .= '</div>'; |
||
312 | |||
313 | $out .= '<div id="system_title_bar">'; |
||
314 | |||
315 | $out .= '<div id="system_title_text">'; |
||
1056 | daniel-mar | 316 | $out .= ' <span id="system_title_logo"></span>'; |
317 | $out .= ' <span id="system_title_1">'.htmlentities(OIDplus::getEditionInfo()['vendor'].' OIDplus 2.0').'</span><br>'; |
||
318 | $out .= ' <span id="system_title_2">'.htmlentities($page_title_1).'</span>'; |
||
319 | $out .= '</div>'; |
||
1055 | daniel-mar | 320 | |
1056 | daniel-mar | 321 | $out .= '</div>'; |
1055 | daniel-mar | 322 | |
1056 | daniel-mar | 323 | $out .= OIDplus::gui()->getLanguageBox(null, true); |
1055 | daniel-mar | 324 | |
1056 | daniel-mar | 325 | $out .= '</div>'; |
326 | |||
1065 | daniel-mar | 327 | $out .= "\n</body>\n"; |
328 | $out .= "</html>\n"; |
||
1056 | daniel-mar | 329 | |
1065 | daniel-mar | 330 | # --- |
331 | |||
1056 | daniel-mar | 332 | return $out; |
1055 | daniel-mar | 333 | } |
334 | |||
366 | daniel-mar | 335 | } |