-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathview.php
More file actions
260 lines (245 loc) · 5.67 KB
/
view.php
File metadata and controls
260 lines (245 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
namespace GenH
{
class View
{
private $level;
private $html_start = 0;
private $head_start = 0;
private $body_start = 0;
private $debug = 0;
public function debug($var, $line)
{
echo 'ligne '.$line.' : debug N°'.$this->debug.' : ';
$this->debug++;
var_dump($var);
echo '<br><br>';
}
public function start()
{
if (!$this->html_start) {
$code = '<!DOCTYPE html>'."\n".'<html>';
$this->html_start = 1;
$this->levelUp();
return $code;
}
return '';
}
public function end()
{
$code = $this->bodyEnd();
if ($this->html_start) {
$this->html_start = 0;
$this->levelDown();
$code .= "\n".$this->level.'</html>';
}
return $code;
}
public function bodyStart()
{
if (!$this->body_start) {
$code = '';
$code .= "\n".$this->level().'<body>';
$this->body_start = 1;
return $code;
}
return '';
}
public function bodyEnd()
{
if ($this->body_start) {
$code = '';
$code .= "\n".$this->level().'</body>';
$this->body_start = 0;
return $code;
}
return '';
}
public function view($array)
{
$code = '';
if (gettype($array) == 'array') {
$i = 0;
$c = count($array);
$this->levelUp();
while ($i < $c) {
if (gettype($array[$i]) == 'object') {
$add = $array[$i]->getCode($this);
if(!empty($add))
$code .= "\n".$this->level.$add;
}else if (gettype($array[$i]) == 'string') {
$add = $array[$i];
if(!empty($add))
$code .= "\n".$this->level.$add;
}
$i++;
}
$this->levelDown();
}else if (!empty($array) && gettype($array) == 'string'){
$code .= htmlspecialchars($array);
}else if (!empty($array) && gettype($array) == 'object'){
if (gettype($array) == 'object') {
$add = $array->getCode($this);
if(!empty($add))
$code .= "\n".$this->level.$add;
}else if (gettype($array) == 'string') {
$add = $array;
if(!empty($add))
$code .= "\n".$this->level.$add;
}
}
//$this->debug($array, __LINE__);//l'entrée
//$this->debug($code, __LINE__);//la sortie
return $code;
}
public function error($texte)
{
return $this->view(array(0 =>
New Div(array(
new P($texte),
new Img(array('src' => '/images/warning.png', 'alt' => 'erreur'))
), array('class' => 'erreur'))
));
}
private function levelUp()
{
$this->level .= "\t";
}
private function levelDown()
{
$this->level = substr($this->level, 0, -1);
}
public function level()
{
return $this->level;
}
}
//__construct($array)
class Element
{
public $array;
public $attribut;
public function __construct($array = NULL)
{
if (!empty($array))
$this->array = $array;
return 1;
}
public function getAttribut()
{
if(!empty($this->attribut))
{
return $this->attribut;
}else{
$class = get_class($this);
$this->attribut = explode('\\' , strtolower($class))[1];
return $this->attribut;
}
}
public function getCode($view)
{
$code = '<'.$this->getAttribut();
if (!empty($this->array)) {
if (gettype($this->array) == 'array'){
foreach ($this->array as $cle => $element) {
$code .= ' '.$cle.'="'.$element.'"';
}
}else{
$code .= htmlspecialchars($this->array);
}
}
$code .= '>';
return $code;
}
}
//__construct($content, $array)
class Container
{
public $array;
private $attribut;
public $content;
public function __construct($content = '', $array = NULL)
{
if (!empty($array))
$this->array = $array;
if (!empty($content))
$this->content = $content;
return 1;
}
public function getAttribut()
{
if(!empty($this->attribut))
{
return $this->attribut;
}else{
$class = get_class($this);
$this->attribut = explode('\\' , strtolower($class))[1];
return $this->attribut;
}
}
public function getCode($view)
{
$code = '';
if(!empty($this->array) || !empty($this->content)){
$code = '<'.$this->getAttribut();
if (!empty($this->array)) {
foreach ($this->array as $cle => $element) {
if (!empty($element) && !empty($cle))
$code .= ' '.$cle.'="'.$element.'"';
}
}
$code .= '>';
if(gettype($this->content) == 'string'){
$code .= "\n".$view->level()."\t".htmlspecialchars($this->content)."\n".$view->level();
}else{
$add = $view->view($this->content);
$code .= $add."\n".$view->level();
}
$code .= '</'.$this->getAttribut().'>';
}
if($code == '<'.$this->getAttribut().'></'.$this->getAttribut().'>')
$code = '';
return $code;
}
}
class Input extends Element{}
class Link extends Element{}
class Meta extends Element{}
class Img extends Element{}
class Script extends Container{}
class Style extends Container{}
class Div extends Container{}
class Pre extends Container{}
class Ul extends Container{}
class Li extends Container{}
class Header extends Container{}
class Title extends Container{}
class Head extends Container{}
class Form extends Container{}
class Button extends Container{}
class A extends Container{}
class P extends Container{}
class I extends Container{}
class Span extends Container{}
class Strong extends Container{}
class Em extends Container{}
class Code extends Container{}
class H1 extends Container{}
class H2 extends Container{}
class H3 extends Container{}
class H4 extends Container{}
class H5 extends Container{}
class H6 extends Container{}
class TextArea extends Container{}
class Canvas extends Container{}
class Label extends Container{}
class Select extends Container{}
class Option extends Container{}
class Line
{
public function getCode($view)
{
return '<br>';
}
}
}