Редакция 373 | Редакция 375 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 373 | Редакция 374 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | *
|
3 | *
|
4 | * Codename: ant-ng - generator of sources.list for Debian and
|
4 | * Codename: ant-ng - generator of sources.list for Debian and
|
5 | * distributives, based on Debian
|
5 | * distributives, based on Debian
|
6 | * http://alex-w.org.ru/p/antng/
|
6 | * http://alex-w.org.ru/p/antng/
|
7 | *
|
7 | *
|
8 | * Copyright (c) 2009 Alexander Wolf
|
8 | * Copyright (c) 2009 Alexander Wolf
|
9 | * Dual licensed under the MIT and GNU LGPL licenses.
|
9 | * Dual licensed under the MIT and GNU LGPL licenses.
|
10 | * http://alex-w.org.ru/p/antng/license
|
10 | * http://alex-w.org.ru/p/antng/license
|
11 | *
|
11 | *
|
12 | */
|
12 | */
|
13 | 13 | ||
14 | /**
|
14 | /**
|
15 | * Description of Template
|
15 | * Description of Template
|
16 | *
|
16 | *
|
17 | * @author alexw
|
17 | * @author alexw
|
18 | */
|
18 | */
|
19 | //TODO Вместо Smarty лучше написать свой очень простой шаблонизатор - монстра использовать не целесообразно
|
19 | //TODO Вместо Smarty лучше написать свой очень простой шаблонизатор - монстра использовать не целесообразно
|
20 | class Template { |
20 | class Template { |
21 | private $path = NULL; |
21 | private $path = NULL; |
- | 22 | protected $self = array(); |
|
22 | 23 | ||
23 | public function __construct($folder) { |
24 | public function __construct($folder) { |
24 | $this->path = $folder; |
25 | $this->path = $folder; |
25 | }
|
26 | }
|
26 | 27 | ||
27 | public function display($name) { |
28 | public function display($name) { |
28 | $fh = fopen($this->path.$name, "r"); |
29 | $fh = fopen($this->path.$name, "r"); |
29 | $content = fread($fh, filesize($this->path.$name)); |
30 | $content = fread($fh, filesize($this->path.$name)); |
30 | fclose($fh); |
31 | fclose($fh); |
31 | preg_match_all("/({[\d\w]+})/", $content, $matches); |
32 | preg_match_all("/({[\d\w]+})/", $content, $matches); |
32 | $tmpl = $matches[0]; |
33 | $tmpl = $matches[0]; |
33 | for($i=0;$i<=count($tmpl);$i++) { |
34 | for($i=0;$i<=count($tmpl);$i++) { |
34 | $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content); |
35 | $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content); |
35 | }
|
36 | }
|
36 | 37 | ||
37 | echo $content; |
38 | echo $content; |
38 | }
|
39 | }
|
39 | 40 | ||
40 | public function assign($attr, $value) { |
41 | public function assign($attr, $value) { |
41 | return $this->self[$attr] = $value; |
42 | return $this->self[$attr] = $value; |
42 | }
|
43 | }
|
43 | 44 | ||
44 | public function __get($attr = null) { |
45 | public function __get($attr = null) { |
45 | return $this->self[$attr]; |
46 | return $this->self[$attr]; |
46 | }
|
47 | }
|
47 | }
|
48 | }
|
48 | ?>
|
49 | ?>
|
49 | 50 |