# Set template of block
if (!function_exists('setTemplateBlock')) {
function setTemplateBlock($tpl, $val = '') {
global $theme, $conf, $pos, $blockfile, $b_id, $home;
if ($pos == 's' || $pos == 'o') {
$bname = empty($blockfile) ? 'fly-block-'.$b_id : 'fly-'.str_replace('.php', '', $blockfile);
} else {
$bname = empty($blockfile) ? 'block-'.$b_id : str_replace('.php', '', $blockfile);
}
$file = 'templates/'.$theme.'/'.$bname.'.html';
$file = file_exists($file) ? $file : false;
if ($file) {
static $argc, $cach;
if ($argc != $file || !isset($cach)) {
$argc = $file;
$cach = file_get_contents($argc);
}
} else {
switch($pos) {
case 'l':
$bname ='block-left';
break;
case 'r':
$bname ='block-right';
break;
case 'c':
$bname ='block-center';
break;
case 'd':
$bname ='block-down';
break;
case 's':
$bname ='block-fly';
break;
case 'o':
$bname ='block-fly';
break;
default:
$bname ='block-all';
break;
}
$file = getThemeFile($bname);
if ($file) {
static $argc, $cach;
if ($argc != $file || !isset($cach)) {
$argc = $file;
$cach = file_get_contents($argc);
}
} else {
$file = getThemeFile('block-all');
if ($file) {
static $argc, $cach;
if ($argc != $file || !isset($cach)) {
$argc = $file;
$cach = file_get_contents($argc);
}
} else {
$cach = '<fieldset><legend>{%title%}</legend>{%content%}</fieldset>';
}
}
}
# Associative array of values passed to the template
$value = array('{%theme%}' => $theme);
$value = is_array($val) ? array_merge($value, $val) : $value;
return str_replace(array_keys($value), array_values($value), $cach);
}
}