2011-03-28 14:21:28 +00:00
|
|
|
<?
|
|
|
|
// Example :
|
|
|
|
// $TPL = new TEMPLATE;
|
|
|
|
// $TPL->open('inv.tpl');
|
2013-06-18 08:00:48 +00:00
|
|
|
// $TPL->set('ADDRESS1', $TPL->str_align(57, $UADDRESS1, 'l', ' '));
|
2011-03-28 14:21:28 +00:00
|
|
|
// $TPL->get();
|
|
|
|
|
|
|
|
class TEMPLATE {
|
2013-04-30 18:18:07 +00:00
|
|
|
var $file = '';
|
|
|
|
var $vars = array();
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
function open($file) {
|
2013-04-30 18:18:07 +00:00
|
|
|
$this->file = file($file);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 08:01:02 +00:00
|
|
|
function set($name, $var, $ifnone = '<span style="font-style: italic;">-None-</span>') {
|
2013-04-30 18:18:07 +00:00
|
|
|
if ($name != '') {
|
2013-05-28 08:01:02 +00:00
|
|
|
$this->vars[$name][0] = $var;
|
|
|
|
$this->vars[$name][1] = $ifnone;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show() {
|
2013-05-28 08:01:02 +00:00
|
|
|
$TMPVAR = '';
|
|
|
|
for ($i = 0; $i < sizeof($this->file); $i++) {
|
|
|
|
$TMPVAR = $this->file[$i];
|
2013-04-30 18:18:07 +00:00
|
|
|
foreach ($this->vars as $k=>$v) {
|
|
|
|
if ($v[1] != '' && $v[0] == '') {
|
|
|
|
$v[0] = $v[1];
|
|
|
|
}
|
2013-05-28 08:01:02 +00:00
|
|
|
$TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
print $TMPVAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get() {
|
2013-06-13 08:01:05 +00:00
|
|
|
$RESULT = '';
|
|
|
|
$TMPVAR = '';
|
|
|
|
for ($i = 0; $i < sizeof($this->file); $i++) {
|
2013-05-28 08:01:02 +00:00
|
|
|
$TMPVAR = $this->file[$i];
|
2013-04-30 18:18:07 +00:00
|
|
|
foreach ($this->vars as $k=>$v) {
|
|
|
|
if ($v[1] != '' && $v[0] == '') {
|
|
|
|
$v[0] = $v[1];
|
|
|
|
}
|
2013-05-28 08:01:02 +00:00
|
|
|
$TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-05-28 08:01:02 +00:00
|
|
|
$RESULT.= $TMPVAR;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
return $RESULT;
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:01:02 +00:00
|
|
|
function str_align($len, $str, $align, $fill) {
|
2013-04-30 18:18:07 +00:00
|
|
|
$strlen = strlen($str);
|
|
|
|
if ($strlen > $len) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return substr($str, 0, $len);
|
|
|
|
|
2013-04-30 18:18:07 +00:00
|
|
|
} elseif (($strlen == 0) || ($len == 0)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return '';
|
|
|
|
|
|
|
|
} else {
|
2013-04-30 18:18:07 +00:00
|
|
|
if (($align == 'l') || ($align == 'left')) {
|
2013-05-28 08:01:02 +00:00
|
|
|
$result = $str.str_repeat($fill, ($len - $strlen));
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-04-30 18:18:07 +00:00
|
|
|
} elseif (($align == 'r') || ($align == 'right')) {
|
2013-05-28 08:01:02 +00:00
|
|
|
$result = str_repeat($fill, ($len - $strlen)).$str;
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2013-04-30 18:18:07 +00:00
|
|
|
} elseif (($align == 'c') || ($align == 'center')) {
|
|
|
|
$snm = intval(($len - $strlen) / 2);
|
|
|
|
if (($strlen + ($snm * 2)) == $len) {
|
2013-05-28 08:01:02 +00:00
|
|
|
$result = str_repeat($fill, $snm).$str;
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
} else {
|
2013-05-28 08:01:02 +00:00
|
|
|
$result = str_repeat($fill, $snm + 1).$str;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-05-28 08:01:02 +00:00
|
|
|
$result.= str_repeat($fill, $snm);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|