source: trunk/View.php@ 39

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