Редакция 475 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 475 | Редакция 554 | ||
---|---|---|---|
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 apt-distributives
|
5 | * distributives, based on Debian
|
- | |
6 | * http://alex-w.org.ru/p/antng/
|
5 | * http://alex-w.org.ru/p/antng/
|
7 | *
|
6 | *
|
8 | * Copyright (c) 2009 Alexander Wolf
|
7 | * Copyright (c) 2009 Alexander Wolf
|
9 | * Dual licensed under the MIT and GNU LGPL licenses.
|
8 | * Dual licensed under the MIT and GNU LGPL licenses.
|
10 | * http://alex-w.org.ru/p/antng/license
|
9 | * http://alex-w.org.ru/p/antng/license
|
11 | *
|
10 | *
|
12 | */
|
11 | */
|
13 | 12 | ||
14 | class Template { |
13 | class Template { |
15 | private $path = NULL; |
14 | private $path = NULL; |
16 | protected $self = array(); |
15 | protected $self = array(); |
17 | 16 | ||
18 | /**
|
17 | /**
|
19 | * Конструктора класса Template - работа с шаблонами
|
18 | * Конструктора класса Template - работа с шаблонами
|
20 | *
|
19 | *
|
21 | * @author Alexander Wolf
|
20 | * @author Alexander Wolf
|
22 | * @category Template
|
21 | * @category Template
|
23 | *
|
22 | *
|
24 | * @param string $folder
|
23 | * @param string $folder
|
25 | */
|
24 | */
|
26 | public function __construct($folder) { |
25 | public function __construct($folder) { |
27 | $this->path = $folder; |
26 | $this->path = $folder; |
28 | }
|
27 | }
|
29 | 28 | ||
30 | /**
|
29 | /**
|
31 | * Отображение шаблона
|
30 | * Отображение шаблона
|
32 | *
|
31 | *
|
33 | * @author Alexander Wolf
|
32 | * @author Alexander Wolf
|
34 | * @category Template
|
33 | * @category Template
|
35 | *
|
34 | *
|
36 | * @param string $name
|
35 | * @param string $name
|
37 | */
|
36 | */
|
38 | public function display($name) { |
37 | public function display($name) { |
39 | $fh = fopen($this->path.$name, "r"); |
38 | $fh = fopen($this->path.$name, "r"); |
40 | $content = fread($fh, filesize($this->path.$name)); |
39 | $content = fread($fh, filesize($this->path.$name)); |
41 | fclose($fh); |
40 | fclose($fh); |
42 | preg_match_all("/{([\d\w]+)}/", $content, $matches); |
41 | preg_match_all("/{([\d\w]+)}/", $content, $matches); |
43 | $tmpl = $matches[1]; |
42 | $tmpl = $matches[1]; |
44 | for($i=0;$i<=count($tmpl);$i++) { |
43 | for($i=0;$i<=count($tmpl);$i++) { |
45 | $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content); |
44 | $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content); |
46 | }
|
45 | }
|
47 | 46 | ||
48 | echo $content; |
47 | echo $content; |
49 | }
|
48 | }
|
50 | 49 | ||
51 | /**
|
50 | /**
|
52 | * Связывание блока с визуальным отображением оного (назначение значения переменной)
|
51 | * Связывание блока с визуальным отображением оного (назначение значения переменной)
|
53 | *
|
52 | *
|
54 | * @author Alexander Wolf
|
53 | * @author Alexander Wolf
|
55 | * @category Template
|
54 | * @category Template
|
56 | *
|
55 | *
|
57 | * @param string $attr
|
56 | * @param string $attr
|
58 | * @param string $value
|
57 | * @param string $value
|
59 | * @return string
|
58 | * @return string
|
60 | */
|
59 | */
|
61 | public function assign($attr, $value) { |
60 | public function assign($attr, $value) { |
62 | return $this->self[$attr] = $value; |
61 | return $this->self[$attr] = $value; |
63 | }
|
62 | }
|
64 | 63 | ||
65 | /**
|
64 | /**
|
66 | * Извлечение визуального вида блока по его имени (возвращение значения переменной)
|
65 | * Извлечение визуального вида блока по его имени (возвращение значения переменной)
|
67 | *
|
66 | *
|
68 | * @author Alexander Wolf
|
67 | * @author Alexander Wolf
|
69 | * @category Template
|
68 | * @category Template
|
70 | *
|
69 | *
|
71 | * @param string $attr
|
70 | * @param string $attr
|
72 | * @return string
|
71 | * @return string
|
73 | */
|
72 | */
|
74 | public function __get($attr = null) { |
73 | public function __get($attr = null) { |
75 | return $this->self[$attr]; |
74 | return $this->self[$attr]; |
76 | }
|
75 | }
|
77 | }
|
76 | }
|
78 | ?>
|
77 | ?>
|
79 | 78 |