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