source: trunk/Application/View.php

Last change on this file was 894, checked in by chronos, 14 months ago
  • Fixed: Export error due to PHP 8.1 deprecated code.
  • Modified: Code cleanup.
File size: 7.2 KB
Line 
1<?php
2
3class BaseView extends View
4{
5 public string $Title = '';
6
7 function ShowLocaleSelector()
8 {
9 $Output = ' <select onchange="window.location=this.value">';
10 foreach (Core::Cast($this->System)->LocaleManager->Available as $Locale)
11 {
12 $Remaining = substr($_SERVER["REQUEST_URI"], strlen(Core::Cast($this->System)->BaseURL));
13 if (substr($Remaining, 1, strlen($Locale['Code'].'/')) == Core::Cast($this->System)->LocaleManager->LangCode.'/')
14 $Remaining = substr($Remaining, strlen('/'.$Locale['Code']));
15 if ($Locale['Code'] == Core::Cast($this->System)->LocaleManager->CurrentLocale->Texts->Code) $Selected = ' selected="selected"';
16 else $Selected = '';
17 $Remaining = Core::Cast($this->System)->TranslateReverseURL($Remaining, Core::Cast($this->System)->LocaleManager->LangCode);
18
19 $URL = Core::Cast($this->System)->LinkLocale($Remaining, $Locale['Code']);
20 $Output .= '<option title="" value="'.$URL.'"'.$Selected.' onchange="this.form.submit()">'.$Locale['Title'].'</option>';
21 }
22 $Output .= '</select><noscript><span><input type="submit" value="Submit"/></span></noscript>';
23
24 return $Output;
25 }
26
27 function ShowTopBar()
28 {
29 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
30 $Output = '<div class="Menu">';
31 if (isset($User))
32 {
33 if (!$User->Licence(LICENCE_USER))
34 $Output .= '<div class="advert">'.Core::Cast($this->System)->Config['Web']['Advertisement'].'</div>';
35 }
36 $Output .= '<span class="MenuItem"></span><span class="MenuItem2">';
37
38 // Show bars items
39 $Bar = '';
40 foreach (Core::Cast($this->System)->Bars['Top'] as $BarItem)
41 $Bar .= call_user_func($BarItem);
42 if (trim($Bar) != '') $Output .= $Bar;
43 else $Output .= '&nbsp;';
44
45 $Output .= $this->ShowLocaleSelector();
46 $Output .= '</span></div>';
47 return $Output;
48 }
49
50 function ShowMainMenu()
51 {
52 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
53 $Output = '<strong>'.T('Menu').':</strong>'.
54 '<div class="verticalmenu"><ul>';
55 foreach (Core::Cast($this->System)->Menu as $MenuItem)
56 {
57 if (!isset($User) or $User->Licence($MenuItem['Permission']))
58 {
59 if (isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"';
60 else $OnClick = '';
61 if ($MenuItem['Icon'] != '') $Icon = '<img src="'.$this->System->Link('/images/menu/'.$MenuItem['Icon']).'"/>';
62 else $Icon = '';
63 $Output .= '<li>'.$Icon.'<a class="verticalmenua" title="'.$MenuItem['Hint'].'" href="'.
64 $MenuItem['Link'].'"'.$OnClick.'>'.$MenuItem['Title'].'</a></li>';
65 }
66 }
67 $Output .= '</ul></div>';
68 return $Output;
69 }
70
71 function ShowHeader()
72 {
73 $Output = ''.
74 '<!DOCTYPE html>'.
75 '<html>'.
76 '<head>'.
77 '<meta http-equiv="content-type" content="text/html; charset='.Core::Cast($this->System)->Config['Web']['Charset'].'" />'.
78 '<meta name="keywords" content="'.Core::Cast($this->System)->Config['Web']['Keywords'].'" />'.
79 '<meta name="description" content="'.Core::Cast($this->System)->Config['Web']['Description'].'" />'.
80 '<meta name="robots" content="all" />'.
81 '<meta name="viewport" content="width=device-width, initial-scale=1">'.
82 '<link rel="stylesheet" href="'.$this->System->Link('/style/style.css').'" type="text/css" media="all" />'.
83 '<script type="text/javascript" src="'.$this->System->Link('/style/global.js').'"></script>'.
84 '<link rel="shortcut icon" href="'.$this->System->Link('/images/favicon.ico').'" />';
85
86 // Show page headers
87 $Bar = '';
88 foreach (Core::Cast($this->System)->PageHeaders as $Item)
89 {
90 $Output .= call_user_func($Item);
91 }
92
93 $Title = Core::Cast($this->System)->Config['Web']['Title'];
94 if ($this->Title != '') $Title = $this->Title.' - '.$Title;
95 $Output .= '<title>'.$Title.'</title>'.
96 '<script src="'.$this->System->Link('/style/respond.js').'"></script>'.
97 '</head><body>';
98
99 $Output .= $this->ShowTopBar();
100 $Output .= '<table class="page"><tr><td class="menu">';
101 $Output .= $this->ShowMainMenu();
102
103 // Show bars items
104 $Bar = '';
105 foreach (Core::Cast($this->System)->Bars['Left'] as $BarItem)
106 $Bar .= call_user_func($BarItem);
107 if (trim($Bar) != '') $Output .= $Bar;
108 else $Output .= '&nbsp;';
109
110 $Output .= '</td><td id="border-left"></td><td class="content">';
111 return $Output;
112 }
113
114 function ShowFooter()
115 {
116 global $ScriptStartTime, $Revision, $ReleaseDate, $Version;
117
118 $ScriptGenerateDuration = round(GetMicrotime() - $ScriptStartTime, 2);
119
120 $Output = '</td>';
121 $Output .= '<td class="menu2">';
122 // Show bars items
123 $Bar = '';
124 foreach (Core::Cast($this->System)->Bars['Right'] as $BarItem)
125 $Bar .= call_user_func($BarItem);
126 if (trim($Bar) != '') $Output .= $Bar;
127 else $Output .= '&nbsp;';
128 $Output .= '</td>';
129 $Output .= '</tr><tr>'.
130 '<td colspan="4" class="page-bottom">'.T('Version').': '.$Version.' '.T('Revision').': '.$Revision.' ('.Core::Cast($this->System)->HumanDate($ReleaseDate).')'.
131 ' &nbsp; <a href="https://app.zdechov.net/wowpreklad/browser/trunk">'.T('Source code').'</a> &nbsp; '.
132 '<a href="https://app.zdechov.net/wowpreklad/log/trunk?verbose=on">'.T('Changelog').'</a> &nbsp; '.
133 Core::Cast($this->System)->Config['Web']['WebCounter'];
134
135 $Output .= '</td></tr>';
136 if (Core::Cast($this->System)->Config['Web']['ShowRuntimeInfo'] == true)
137 $Output .= '<tr><td colspan="3" style="text-align: center;">'.T('Generating duration').': '.
138 $ScriptGenerateDuration.' s / '.ini_get('max_execution_time').' s &nbsp;&nbsp; '.T('Used memory').': '.
139 HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B &nbsp;&nbsp; <a href="http://validator.w3.org/check?uri='.
140 htmlentities('http://'.$_SERVER['HTTP_HOST'].GetRequestURI().'?'.$_SERVER['QUERY_STRING']).'">HTML validator</a></td></tr>';
141 $Output .= '</table>'.
142 '</body>'.
143 '</html>';
144 return $Output;
145 }
146
147 function ShowPage($Content)
148 {
149 $Output = $this->ShowHeader().$Content.$this->ShowFooter();
150 if (Core::Cast($this->System)->Config['Web']['FormatOutput'])
151 $Output = $this->FormatOutput($Output);
152 return $Output;
153 }
154
155 function FormatOutput($s)
156 {
157 $out = '';
158 $nn = 0;
159 $n = 0;
160 while ($s != '')
161 {
162 $start = strpos($s, '<');
163 $end = strpos($s, '>');
164 if ($start != 0)
165 {
166 $end = $start - 1;
167 $start = 0;
168 }
169 $line = trim(substr($s, $start, $end + 1));
170 if (strlen($line) > 0)
171 if ($line[0] == '<')
172 {
173 if ($s[$start + 1] == '/')
174 {
175 $n = $n - 2;
176 $nn = $n;
177 } else
178 {
179 if (strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
180 else $cmd = substr($line, 1, strlen($line) - 2);
181 //echo('['.$cmd.']');
182 if (strpos($s, '</'.$cmd.'>')) $n = $n + 2;
183 }
184 }// else $line = '['.$line.']';
185 //if ($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
186 if ($nn < 0) $nn = 0;
187 if ($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
188 $s = substr($s, $end + 1, strlen($s));
189 $nn = $n;
190 }
191 return $out;
192 }
193}
Note: See TracBrowser for help on using the repository browser.