Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей.
Здесь обсуждаются безопасность, программирование, технологии и многое другое.
Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
 |
|

10.03.2010, 10:53
|
|
Members of Antichat - Level 5
Регистрация: 01.04.2007
Сообщений: 1,268
Провел на форуме: 10046345
Репутация:
4589
|
|
PHP код:
<?php
class Template {
/**
* Переменные шаблона
*
* @var array
*/
protected $vars;
/**
* Файл шаблона
*
* @var string
*/
private $template;
public $tblocks;
public function __construct() {
$this->vars = array();
$this->template = '';
$this->tblocks = array();
}
/**
* Объявить переменную шаблона
*
* @param string $var
* @param string $value
*/
public function set($var, $value = '') {
$this->vars[$var] = $value;
}
/**
* Установить файл шаблона
*
* @param string $tpl
*/
public function assign($tpl) {
$this->template = PATH. 'templates/'. $tpl. '.tpl';
if (file_exists($this->template)) {
$this->template = file_get_contents($this->template);
$matches = array();
$count = preg_match_all('/{row::([A-Za-z0-9]+)}(.*){\/row::/', $this->template, $matches);
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
$this->tblocks[$matches[1][$i]] = $matches[2][$i];
}
$this->template = preg_replace('/{row::([A-Za-z0-9]+)}(.+){\/row::([A-Za-z0-9]+)}\\n/i', '', $this->template);
}
} else {
echo '<small><b>Error.</b> Template <u>'.basename($this->template). '</u> is not exists!</small><br />';
$this->template = '';
}
}
/**
* Пропарсить шаблон
*
*/
public function display($eval = False) {
if ($this->template) {
foreach ($this->vars AS $var => $value) {
$this->template = str_replace('{'. $var. '}', $value, $this->template);
if (empty($value)) {
$this->template = preg_replace('/{block::'. $var. '}(.+){\/block::'. $var. '}\\n/i', '', $this->template);
} else {
$this->template = str_replace(array('{block::'. $var. '}', '{/block::'. $var. '}'), '', $this->template);
}
}
if ($eval) {
eval('?>'. $this->template);
} else {
echo $this->template;
}
}
unset($this->vars);
unset($this->tblocks);
unset($this->template);
}
}
?>
|
|
|

10.03.2010, 16:14
|
|
Познающий
Регистрация: 26.10.2007
Сообщений: 83
Провел на форуме: 394231
Репутация:
50
|
|
я как раз почти закончил свой шаблонизатор, магу дать исходник... или даже переделать для работы с твоим двиглом но есть кое какие условия ($$ мя не интересуют)
PS: если ТС интересно то пиши в личку
|
|
|

10.03.2010, 16:26
|
|
Познающий
Регистрация: 17.02.2010
Сообщений: 64
Провел на форуме: 132243
Репутация:
1
|
|
они может и от туда. по крайней мере мне это рано делать (по знаниям).
но это нужно - люди просят.
|
|
|

19.03.2010, 10:36
|
|
Познающий
Регистрация: 17.02.2010
Сообщений: 64
Провел на форуме: 132243
Репутация:
1
|
|
Бьюсь с дминкой - нифига не получается(
хочет кто помочь? ссылка на архив в начале страницы..
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|