|
Тема |
Re: Как правите дизайна ? [re: voyager] |
|
Автор |
edembg (Ученик) |
|
Публикувано | 12.01.05 09:30 |
|
|
Ми аз ползвам това:
<?php
class tpl_gen
{
var $indent = 0, $indent_str = "", $keys = array(), $vars = array(), $property = array();
var $template = "";
function tpl_gen($template)
{
$this->template = $template;
}
function set_indent($indent)
{
$this->indent = $indent;
$this->indent_str = "";
for ($i = 0; $i < $indent; $i++)
{
$this->indent_str .= "\t";
}
}
function inc_indent()
{
$this->indent_str .= "\t";
}
function dec_indent()
{
$this->indent_str = substr($this->indent_str, 1);
}
function var_set($name, $value)
{
$this->vars[$name] = $value;
}
function key_set($name, $value)
{
$this->keys[$name] = $value;
}
function property_set($value)
{
$this->property = $value;
}
function tbl_row_beg()
{
$code = $this->indent_str."<tr>\n";
return ($code);
}
function tbl_row_end()
{
$code = $this->indent_str."</tr>\n";
return ($code);
}
function table($values)
{
$code = "";
foreach ($values as $bval)
{
$this->dec_indent();
$code .= $this->tbl_row_beg();
$this->inc_indent();
$i = 0;
foreach ($bval as $sval)
{
$code .= $this->indent_str.'<td';
if ($this->property[$i] != '') $code .= ' '.$this->property[$i];
$code .= '>'.$sval."</td>\n";
$i++;
}
$this->dec_indent();
$code .= $this->tbl_row_end();
$this->inc_indent();
}
return ($code);
}
function option($content, $selected)
{
$out = "";
foreach ($content as $key => $val)
{
$out .= $this->indent_str.'<option value="'.$key.'"';
if (in_array($key, $selected)) $out .= ' selected="true"';
$out .= '>'.$val.'</option>'."\n";
}
return ($out);
}
function image($path, $alt,$height, $width, $border = 0, $end = "")
{
return ($this->indent_str.'<img src="'.$path.'" alt="'.$alt.'" height="'.$height.'" width="'.$width.'" border="'.$border.'">'.$end);
}
function link($URL, $label, $class = "", $title = "", $target = "", $end = "")
{
$res = $this->indent_str.'<a href="'.$URL.'"';
if ($title != "") $res .= ' title="'.$title.'"';
if ($target != "") $res .= ' target="'.$target.'"';
if ($class != "") $res .= ' class="'.$class.'"';
$res .= '>'.$label.'</a>'.$end;
return ($res);
}
function gen()
{
extract($this->keys);
extract($this->vars);
$fp = fopen($this->template, 'r');
if (!fp) return("Error opening template");
$var = fgets($fp, 1024);
$var = trim($var);
$$var = "";
while(!FEOF($fp))
{
$content .= fread($fp, 4096);
}
fclose($fp);
eval($content);
return ($$var);
}
}
?>
А шаблона е нещо такова:
page
$page .= ' <table width="100%" border="1" cellspacing="0" cellpadding="10">
<tr>
<td valign="top" width="120">
Name: '.$poster_name.'
<p>Date: '.$post_date.'</p>
</td>
<td valign="top">
'.$post.'
<div align="right"><a href="#top" class="link">Top</a></div>
</td>
</tr>
</table>
';
Всичко става лесно и бързо. Няма шаблонен език и други зврънгулки.
И най-ярките личности си плащат тока.
|
| |
|
|
|