Хранилища Subversion ant

Редакция

Редакция 375 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 375 Редакция 388
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
/**
-
 
15
 * Description of Template
-
 
16
 *
14
17
 * @author alexw
-
 
18
 */
-
 
19
 //TODO Вместо Smarty лучше написать свой очень простой шаблонизатор - монстра использовать не целесообразно
-
 
20
class Template {
15
class Template {
21
    private     $path   = NULL;
16
    private     $path   = NULL;
22
    protected   $self   = array();
17
    protected   $self   = array();
23
18
24
    public function __construct($folder) {
19
    public function __construct($folder) {
25
        $this->path = $folder;
20
        $this->path = $folder;
26
    }
21
    }
27
   
22
   
28
    public function display($name) {
23
    public function display($name) {
29
        $fh = fopen($this->path.$name, "r");
24
        $fh = fopen($this->path.$name, "r");
30
        $content = fread($fh, filesize($this->path.$name));
25
        $content = fread($fh, filesize($this->path.$name));
31
        fclose($fh);
26
        fclose($fh);
32
        preg_match_all("/{([\d\w]+)}/", $content, $matches);
27
        preg_match_all("/{([\d\w]+)}/", $content, $matches);
33
        $tmpl = $matches[1];
28
        $tmpl = $matches[1];
34
        for($i=0;$i<=count($tmpl);$i++) {      
29
        for($i=0;$i<=count($tmpl);$i++) {      
35
            $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content);
30
            $content = str_replace("{".$tmpl[$i]."}", $this->__get($tmpl[$i]), $content);
36
        }
31
        }
37
32
38
        echo $content;
33
        echo $content;
39
    }
34
    }
40
35
41
    public function assign($attr, $value) {
36
    public function assign($attr, $value) {
42
        return $this->self[$attr] = $value;
37
        return $this->self[$attr] = $value;
43
    }    
38
    }    
44
39
45
    public function __get($attr = null) {
40
    public function __get($attr = null) {
46
        return $this->self[$attr];
41
        return $this->self[$attr];
47
    }
42
    }
48
}
43
}
49
?>
44
?>
50
 
45