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