source: trunk/Application/View.php@ 850

Last change on this file since 850 was 796, checked in by chronos, 9 years ago
  • Fixed: Page javascript script was not loaded.
File size: 6.1 KB
Line 
1<?php
2
3define('PAGE_NOT_FOUND', 'Stránka nenalezena');
4
5class BaseView extends View
6{
7 var $TimeStart;
8 var $FormatHTML = false;
9 var $ShowRuntimeInfo = false;
10 var $ClearPage = false;
11 var $BasicHTML = false;
12 var $ParentClass = '';
13 var $ShortTitle;
14 var $FullTitle;
15 var $Encoding;
16 var $Style;
17
18 function __construct($System)
19 {
20 parent::__construct($System);
21
22 $this->FormatHTML = false;
23 $this->ShowRuntimeInfo = false;
24 $this->Encoding = 'utf-8';
25 $this->Style = 'new';
26
27 // TODO: Move to external code
28 if(isset($this->System->Config['Web']['FormatHTML']))
29 $this->FormatHTML = $this->System->Config['Web']['FormatHTML'];
30 if(isset($this->System->Config['Web']['ShowRuntimeInfo']))
31 $this->ShowRuntimeInfo = $this->System->Config['Web']['ShowRuntimeInfo'];
32 if(isset($this->System->Config['Web']['Charset']))
33 $this->Encoding = $this->System->Config['Web']['Charset'];
34 if(isset($this->System->Config['Web']['Style']))
35 $this->Style = $this->System->Config['Web']['Style'];
36 }
37
38 function SystemMessage($Title, $Text)
39 {
40 return('<table align="center"><tr><td><div class="SystemMessage"><h3>'.$Title.'</h3><div>'.$Text.'</div></div></td></tr></table>');
41 //ShowFooter();
42 //die();
43 }
44
45 function ShowNavigation($Page)
46 {
47 if(array_key_exists('REQUEST_URI', $_SERVER))
48 $ScriptName = $_SERVER['REQUEST_URI'];
49 else $ScriptName = '';
50 while(strpos($ScriptName, '//') !== false)
51 $ScriptName = str_replace('//', '/', $ScriptName);
52 if(strpos($ScriptName, '?') !== false)
53 $ScriptName = substr($ScriptName, 0, strrpos($ScriptName, '?'));
54 $ScriptName = substr($ScriptName, strlen($this->System->Link('')));
55 if(substr($ScriptName, -1, 1) == '/') $ScriptName = substr($ScriptName, 0, -1);
56
57 $Output = '';
58 while($Page)
59 {
60 $Output = ' &gt; <a href="'.$this->System->Link($ScriptName).'/">'.$Page->ShortTitle.'</a>'.$Output;
61
62 if(class_exists($Page->ParentClass))
63 {
64 $PageClass = $Page->ParentClass;
65 $Page = new $PageClass($this->System);
66 $ScriptName = substr($ScriptName, 0, strrpos($ScriptName, '/'));
67 } else $Page = null;
68 }
69 $Output = substr($Output, 6);
70 return($Output);
71 }
72
73 function ShowHeader($Page)
74 {
75 $Title = $Page->FullTitle;
76 $Path = $Page->ShortTitle;
77
78 $Navigation = $this->ShowNavigation($Page);
79
80 $BodyParam = '';
81 if(isset($Page->Load)) $BodyParam .= ' onload="'.$Page->Load.'"';
82 if(isset($Page->Unload)) $BodyParam .= ' onunload="'.$Page->Unload.'"';
83 $Output = '<?xml version="1.0" encoding="'.$this->Encoding.'"?>'."\n".
84 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
85 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
86 '<head><link rel="stylesheet" href="'.$this->System->Link('/style/').$this->Style.'/style.css" type="text/css" media="all" />'.
87 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Encoding.'" />'.
88 '<script type="text/javascript" src="'.$this->System->Link('/style/').$this->Style.'/global.js"></script>'.
89 '<title>'.$this->System->Config['Web']['Title'].' - '.$Path.'</title>';
90
91 // Show page headers
92 $Bar = '';
93 foreach($this->System->PageHeaders as $Item)
94 $Output .= call_user_func($Item);
95
96 $Output .= '</head><body'.$BodyParam.'>';
97 if($this->BasicHTML == false)
98 {
99 //$Output .= '<div class="MainTitle">'.$Title.'</div>';
100 $Output .= '<div class="MainTitle"><span class="MenuItem"><strong>Navigace :: </strong> '.$Navigation.'</span><div class="MenuItem2">';
101 $Bar = '';
102 foreach($this->System->Bars['Top'] as $BarItem)
103 $Bar .= call_user_func($BarItem);
104 if(trim($Bar) != '') $Output .= $Bar;
105 else $Output .= '&nbsp;';
106 $Output .= '</div></div>';
107 }
108 return($Output);
109 }
110
111 function ShowFooter()
112 {
113 global $ScriptTimeStart, $Revision, $ReleaseTime;
114
115 $Time = round(GetMicrotime() - $ScriptTimeStart, 2);
116 $Output = '';
117 if($this->BasicHTML == false)
118 {
119 $Output .= '<div id="Footer">'.
120 '<i>| Správa webu: '.$this->System->Config['Web']['Admin'].' | e-mail: '.$this->System->Config['Web']['AdminEmail'].' | '.
121 ' Verze: '.$Revision.' ('.$this->System->HumanDate($ReleaseTime).') |';
122 if($this->ShowRuntimeInfo == true) $Output .= ' Doba generování: '.$Time.' s / '.ini_get('max_execution_time').
123 ' s | Použitá paměť: '.HumanSize(memory_get_peak_usage(FALSE)).' / '.ini_get('memory_limit').'B |';
124 $Output .= '</i></div>';
125 }
126 $Output .= '</body></html>';
127 return($Output);
128 }
129
130 function GetOutput($Page)
131 {
132 $Page->OnSystemMessage = array($this->System->BaseView, 'SystemMessage');
133
134 $Output = $Page->Show();
135 if($Page->ClearPage == false)
136 {
137 $Output = $this->ShowHeader($Page).$Output.$this->ShowFooter();
138 if($this->FormatHTML == true) $Output = $this->FormatOutput($Output);
139 }
140 return($Output);
141 }
142
143 function NewPage($ClassName)
144 {
145 $Page = new $ClassName();
146 $Page->System = $this->System;
147 $Page->Database = $this->Database;
148 $Page->FormatHTML = $this->FormatHTML;
149 return($Page);
150 }
151
152 // XML formating function
153 function FormatOutput($s)
154 {
155 $out = '';
156 $nn = 0;
157 $n = 0;
158 while($s != '')
159 {
160 $start = strpos($s, '<');
161 $end = strpos($s, '>');
162 if($start != 0)
163 {
164 $end = $start - 1;
165 $start = 0;
166 }
167 $line = trim(substr($s, $start, $end + 1));
168 if(strlen($line) > 0)
169 if($line[0] == '<')
170 {
171 if($s[$start + 1] == '/')
172 {
173 $n = $n - 2;
174 $nn = $n;
175 } else
176 {
177 if(strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
178 else $cmd = substr($line, 1, strlen($line) - 2);
179 //echo('['.$cmd.']');
180 if(strpos($s, '</'.$cmd.'>')) $n = $n + 2;
181 }
182 }// else $line = '['.$line.']';
183 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
184 if($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
185 $s = substr($s, $end + 1, strlen($s));
186 $nn = $n;
187 }
188 return($out);
189 }
190}
Note: See TracBrowser for help on using the repository browser.