source: trunk/Application/View.php@ 893

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