source: trunk/Common/Page.php@ 771

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