source: trunk/Application/BaseView.php

Last change on this file was 965, checked in by chronos, 3 months ago
  • Added: ZdechovNET favicon.
File size: 5.8 KB
Line 
1<?php
2
3define('PAGE_NOT_FOUND', 'Stránka nenalezena');
4
5class BaseView extends View
6{
7 public bool $FormatHTML = false;
8 public bool $ShowRuntimeInfo = false;
9 public bool $RawPage = false;
10 public bool $BasicHTML = false;
11 public string $ParentClass = '';
12 public string $Title;
13 public string $Description;
14 public string $Encoding;
15 public string $Style;
16
17 function __construct(System $System)
18 {
19 parent::__construct($System);
20
21 $this->FormatHTML = false;
22 $this->ShowRuntimeInfo = false;
23 $this->Encoding = 'utf-8';
24 $this->Style = 'new';
25 }
26
27 function SystemMessage(string $Title, string $Text): string
28 {
29 return '<table align="center"><tr><td><div class="SystemMessage"><h3>'.$Title.'</h3><div>'.$Text.'</div></div></td></tr></table>';
30 //ShowFooter();
31 //die();
32 }
33
34 function ShowNavigation(Page $Page): string
35 {
36 if (array_key_exists('REQUEST_URI', $_SERVER))
37 $ScriptName = $_SERVER['REQUEST_URI'];
38 else $ScriptName = '';
39 while (strpos($ScriptName, '//') !== false)
40 $ScriptName = str_replace('//', '/', $ScriptName);
41 if (strpos($ScriptName, '?') !== false)
42 $ScriptName = substr($ScriptName, 0, strrpos($ScriptName, '?'));
43 $ScriptName = substr($ScriptName, strlen($this->System->Link('')));
44 if (substr($ScriptName, -1, 1) == '/') $ScriptName = substr($ScriptName, 0, -1);
45
46 $Output = '';
47 while ($Page)
48 {
49 $Output = ' &gt; <a href="'.$this->System->Link($ScriptName).'/">'.$Page->Title.'</a>'.$Output;
50
51 if (($Page->ParentClass != null) and class_exists($Page->ParentClass))
52 {
53 $PageClass = $Page->ParentClass;
54 $Page = new $PageClass($this->System);
55 $ScriptName = substr($ScriptName, 0, strrpos($ScriptName, '/'));
56 } else $Page = null;
57 }
58 $Output = substr($Output, 6);
59 return $Output;
60 }
61
62 function ShowHeader(Page $Page): string
63 {
64 $Path = $Page->Title;
65
66 $Navigation = $this->ShowNavigation($Page);
67
68 $BodyParam = '';
69 if (isset($Page->Load)) $BodyParam .= ' onload="'.$Page->Load.'"';
70 if (isset($Page->Unload)) $BodyParam .= ' onunload="'.$Page->Unload.'"';
71 $Output = '<?xml version="1.0" encoding="'.$this->Encoding.'"?>'."\n".
72 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
73 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
74 '<head>'.
75 '<link rel="stylesheet" href="'.$this->System->Link('/style/').$this->Style.'/style.css" type="text/css" media="all" />'.
76 '<link rel="icon" type="image/x-icon" href="/images/favicon.ico">'.
77 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Encoding.'" />'.
78 '<script type="text/javascript" src="'.$this->System->Link('/style/').$this->Style.'/global.js"></script>'.
79 '<title>'.$Path.' - '.Core::Cast($this->System)->Config['Web']['Title'].'</title>';
80
81 // Show page headers
82 $Bar = '';
83 foreach (Core::Cast($this->System)->PageHeaders as $Item)
84 $Output .= call_user_func($Item);
85
86 $Output .= '</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 (Core::Cast($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(): string
102 {
103 global $Revision, $ReleaseTime;
104
105 $Time = round(GetMicrotime() - Core::Cast($this->System)->ScriptTimeStart, 2);
106 $Output = '';
107 if ($this->BasicHTML == false)
108 {
109 $Output .= '<div id="Footer">'.
110 '<i>| Správa webu: '.Core::Cast($this->System)->Config['Web']['Admin'].' | e-mail: '.Core::Cast($this->System)->Config['Web']['AdminEmail'].' | '.
111 ' Verze: '.$Revision.' ('.Core::Cast($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(Page $Page): string
121 {
122 $Page->OnSystemMessage = array(Core::Cast($this->System)->BaseView, 'SystemMessage');
123
124 $Output = $Page->Show();
125 if ($Page->RawPage == false)
126 {
127 $Output = $this->ShowHeader($Page).$Output.$this->ShowFooter();
128 if ($this->FormatHTML == true) $Output = $this->FormatOutput($Output);
129 }
130 return $Output;
131 }
132
133 function NewPage(string $ClassName): Page
134 {
135 $Page = new $ClassName();
136 $Page->System = $this->System;
137 $Page->Database = $this->Database;
138 $Page->FormatHTML = $this->FormatHTML;
139 return $Page;
140 }
141
142 // XML formating function
143 function FormatOutput(string $s): string
144 {
145 $out = '';
146 $nn = 0;
147 $n = 0;
148 while ($s != '')
149 {
150 $start = strpos($s, '<');
151 $end = strpos($s, '>');
152 if ($start != 0)
153 {
154 $end = $start - 1;
155 $start = 0;
156 }
157 $line = trim(substr($s, $start, $end + 1));
158 if (strlen($line) > 0)
159 if ($line[0] == '<')
160 {
161 if ($s[$start + 1] == '/')
162 {
163 $n = $n - 2;
164 $nn = $n;
165 } else
166 {
167 if (strpos($line, ' ')) $cmd = substr($line, 1, strpos($line, ' ') - 1);
168 else $cmd = substr($line, 1, strlen($line) - 2);
169 if (strpos($s, '</'.$cmd.'>')) $n = $n + 2;
170 }
171 }
172 if ($line != '') $out .= (str_repeat(' ', $nn).$line."\n");
173 $s = substr($s, $end + 1, strlen($s));
174 $nn = $n;
175 }
176 return $out;
177 }
178}
Note: See TracBrowser for help on using the repository browser.