| Server IP : 208.122.213.31 / Your IP : 216.73.216.45 Web Server : Apache System : Linux msd6191.mjhst.com 4.18.0-553.137.1.el8_10.x86_64 #1 SMP Wed Jun 24 11:40:24 UTC 2026 x86_64 User : WHMCS_MIA_382 ( 1001) PHP Version : 7.4.33 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/httpd/html/baberankings.com.bak/members/kernel/ |
Upload File : |
<?
/* K-Rate
(C) Rinalds Uzkalns, 2003-2004. All Rights Reserved
http://turn-k.net
Version: 1.00 (22.09.04)
*/
?>
<?
//class_template('templates/aim/header.tpl');
function class_template($templ) {
$tpl = new show_template;
$tpl->$template = $templ;
$tpl->print_out();
}
class show_template {
var $templ = array(); //template data
var $tpi = 0; //template current line index
var $template = ''; //template path
var $s = ''; //current line
var $loop = array(); //loop structures
var $if = array(); //if structures
var $act = array(); //actions for each line
# Constructor function
function show_template() {
global $names, $en;
extract ($names);
}
function print_out() {
//get template content
$f = fopen($this->template,'r');
if (!$f) return false;
while (!feof($f)) {
$s = chop(fgets($f,4096));
if ($s == '') continue;
if (substr($s,0,5) == '<!--[' || substr($s,0,2) == '<?') {
if ($nx != '') $this->templ[] = $nx;
$this->templ[] = $s;
$nx = '';
} else
$nx .= "\n".$s;
}
if ($nx != '') $this->templ[] = $nx;
fclose($f);
//analyze content
foreach ($this->templ as $key => $value) {
//ordinary output
if (substr($value,0,5) != '<!--[' && substr($value,0,2) != '<?') {
$this->act[$key] = 'do_print';
}
//if conditions
elseif (substr($value,0,7) == '<!--[If') {
if (substr($value,0,13) == '<!--[If Start') {
$this->if[$key]['start'] = $key;
$startedif[] = $key;
$this->act[$key] = 'if_start';
}
if (substr($value,0,11) == '<!--[If End') {
$last = $startedif[count($startedif)-1];
$this->if[$last]['end'] = $key;
array_pop($startedif);
}
if (substr($value,0,12) == '<!--[If Else') {
$last = $startedif[count($startedif)-1];
$this->if[$last]['else'] = $key;
}
}
//loops
elseif (substr($value,0,9) == '<!--[Loop') {
if (substr($value,0,15) == '<!--[Loop Start') {
$this->loop[$key]['start'] = $key;
$startedloop[] = count($this->loop)-1;
$act[$key] = 'loop_start';
}
if (substr($value,0,13) == '<!--[Loop End') {
$last = $startedloop[count($startedloop)-1];
$this->loop[$last]['end'] = $key;
array_pop($startedloop);
}
}
//eval
elseif (substr($value,0,2) == '<?') {
$this->act[$key] = 'do_eval';
}
//array
elseif (substr($value,0,10) == '<!--[Array') {
$this->act[$key] = 'do_array';
}
//include file
elseif (substr($value,0,17) == '<!--[Include File') {
$this->act[$key] = 'include_file';
}
//include template
elseif (substr($value,0,17) == '<!--[Include Template') {
$this->act[$key] = 'include_template';
}
//loop - continue
elseif ($value == '<!--[Continue]-->') {
$this->act[$key] = 'continue_loop';
}
//loop - break
elseif ($value == '<!--[Break]-->') {
$this->act[$key] = 'break_loop';
}
//error or html comment apparently - just print it out
else
$this->act[$key] = 'do_print';
}
//output content
while ($this->tpi != count($templ)) {
$this->s = $this->template_replace_vars($this->templ_read());
eval('$this->'.$act[$this->tpi].'();');
}
}
# Read next line
function templ_read() {
$tpi++;
return $templ[$tpi];
}
# Replace variables
function template_replace_vars($s) {
$s = preg_replace('/<%(.*)%>/sUe', "$this->do_format('\\1',$s)", $s);
}
# Format replaced vars
function do_format($value,$s) {
$value = (isset($en[$value]) ? $en[$value] : @constant($value));
$i = strtolower($s);
if (strpos($i,'echo') || strpos($i,'define')) {
$value = str_replace('"','`',$value);
$value = str_replace(chr(39),'`',$value);
}
return $value;
}
# Execute template block
function exec_block($start, $end, $jump = 0) {
$this->tpi = $start;
while ($this->tpi != $end) {
$this->s = $this->template_replace_vars($this->templ_read());
eval('$this->'.$act[$this->tpi].'();');
}
}
# Echo a line
function do_print() {
echo $this->s;
}
# If structure
function if_start() {
$cond = substr($this->s,strlen('<!--[If Start '));
$cond = substr($cond,0,strpos($cond,']-->'));
$evstr = '$out = ('.$cond.');';
@eval($evstr);
if ($out) {
//returns true, let's do something
$end = isset($this->if[$this->tpi]['else']) ? $this->if[$this->tpi]['else'] : $this->if[$this->tpi]['end'];
exec_block($this->tpi+1, $end, $this->if[$this->tpi]['end']+1);
}
else {
//returns false, go to else or end
if (isset($this->if[$this->tpi]['else'])) {
//else block present
$this->exec_block($this->if[$this->tpi]['else']+1, $this->if[$this->tpi]['end'], $this->if[$this->tpi]['end']+1);
}
else {
//go to end of if structure
$this->tpi = $this->if[$this->tpi]['end']+1;
}
}
}
}
function template_if($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi;
extract($names);
//If Start?
if (substr($s,0,strlen('<!--[If Start')) == '<!--[If Start') {
$cond = substr($s,strlen('<!--[If Start '));
$cond = substr($cond,0,strpos($cond,']-->'));
$evstr = '$out = ('.$cond.');';
@eval($evstr);
$ifcn[$curr_tpl] = $ifcn[$curr_tpl] + 1;
$if[$curr_tpl][$ifcn[$curr_tpl]] = $out;
$elsif[$curr_tpl][$ifcn[$curr_tpl]] = $out;
$s = '';
if (!$if[$curr_tpl][$ifcn[$curr_tpl]] && isset($if[$curr_tpl][$ifcn[$curr_tpl]])) { //false > skip until the end of condition
$canstop = false;
$iflev[$curr_tpl] = $ifcn[$curr_tpl];
while (!$canstop) {
$s = templ_read($curr_tpl);
if ($s == '<!--[If End]-->') {
if ($iflev[$curr_tpl] == $ifcn[$curr_tpl]) $canstop = true;
if ($iflev[$curr_tpl] != $ifcn[$curr_tpl]) $ifcn[$curr_tpl]--;
} elseif
($s == '<!--[If Else]-->') {
if ($iflev[$curr_tpl] == $ifcn[$curr_tpl]) $canstop = true;
} elseif
(substr($s,0,strlen('<!--[If Elsif ')) == '<!--[If Elsif ') {
if ($iflev[$curr_tpl] == $ifcn[$curr_tpl]) $canstop = true;
} elseif
(substr($s,0,strlen('<!--[If Start')) == '<!--[If Start') {
$ifcn[$curr_tpl]++;
}
}
} else {
}
}
//If Else?
if ($s == '<!--[If Else]-->') {
$if[$curr_tpl][$ifcn[$curr_tpl]] = !$if[$curr_tpl][$ifcn[$curr_tpl]];
if ($beenelsif[$curr_tpl][$ifcn[$curr_tpl]]) $if[$curr_tpl][$ifcn[$curr_tpl]] = false;
$s = '';
}
//If Elsif?
if (substr($s,0,strlen('<!--[If Elsif ')) == '<!--[If Elsif ') {
$cond = substr($s,strlen('<!--[If Elsif '));
$cond = substr($cond,0,strpos($cond,']'));
$out = false;
$evstr = 'if ('.$cond.') $out = TRUE;';
@eval($evstr);
$if[$curr_tpl][$ifcn[$curr_tpl]] = $out;
$s = '';
if ($elsif[$curr_tpl][$ifcn[$curr_tpl]]) $if[$curr_tpl][$ifcn[$curr_tpl]] = false;
if ($elsif[$curr_tpl][$ifcn[$curr_tpl]]) $beenelsif[$curr_tpl][$ifcn[$curr_tpl]] = true;
if ($out) $elsif[$curr_tpl][$ifcn[$curr_tpl]] = true;
}
//If End?
if ($s == '<!--[If End]-->') {
$ifcn[$curr_tpl]--;
$s = '';
}
return $s;
}
function template_array($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi;
extract($names);
$incl = substr($s,strlen('<!--[Array '));
$arr = substr($incl,0,strpos($incl,' '));
$incl = substr($incl,strlen($arr)+1);
$incl = substr($incl,0,strpos($incl,']-->'));
eval('$query = "'.$incl.'";');
$result = sql_query($query);
$temparray = array(); $npk = 0;
while ($line = sql_fetch_assoc($result))
$temparray[++$npk] = $line;
if (substr($arr,0,1) == '>') $arr = substr($arr,1);
$arr = str_replace(chr(92),'',$arr);
if (!$temparray[1]) $temparray[1] = array();
eval($arr.' = array_merge('.$arr.',$temparray[1]);');
return '';
}
function do_format($value) {
global $s, $en;
$value = (isset($en[$value]) ? $en[$value] : @constant($value));
$i = strtolower($s);
if (strpos($i,'echo') || strpos($i,'define')) {
$value = str_replace('"','`',$value);
$value = str_replace(chr(39),'`',$value);
}
return $value;
}
function template_replace_vars($s) {
global $replacer, $s;
// $s = preg_replace('/##(.*)##/sUe', "do_format('\\1')", $s);
$s = preg_replace('/<%(.*)%>/sUe', "do_format('\\1')", $s);
return $s;
}
function template_loop_start($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi, $loopdata;
extract($names);
$loops[$curr_tpl]++;
$en['loops_index'] = 0;
$loopstart[$curr_tpl][$loops[$curr_tpl]] = $tpi[$curr_tpl];
$cond = substr($s,strlen('<!--[Loop Start '));
$cond = substr($cond,0,strpos($cond,']-->'));
//from-to?
if (substr($cond,0,1) == '[') {
$bounds = substr($cond,1,strpos($cond,'] ')-1);
if (strpos($bounds,':'))
list($type,$bounds) = explode(':',$bounds);
$cond = substr($cond,strpos($cond,'] ')+2);
list($from,$to) = explode(',',$bounds);
$loopdata[$curr_tpl][$loops[$curr_tpl]]['from'] = $from;
$loopdata[$curr_tpl][$loops[$curr_tpl]]['to'] = $to;
if ($loopdata[$curr_tpl][$loops[$curr_tpl]]['from'] == '') $loopdata[$curr_tpl][$loops[$curr_tpl]]['from'] = 0;
if ($loopdata[$curr_tpl][$loops[$curr_tpl]]['to'] == '') $loopdata[$curr_tpl][$loops[$curr_tpl]]['from'] = 1000000;
}
//mysql query as array?
if (substr($cond,0,6) == 'QUERY:') {
$cond = substr($cond,6);
eval('$query = "'.$cond.'";');
$npk = 0; $looparray[$curr_tpl][$loops[$curr_tpl]] = array();
$result = sql_query($query);
while ($line = sql_fetch_assoc($result))
$looparray[$curr_tpl][$loops[$curr_tpl]][++$npk] = $line;
$en['lastq'] = $result;
}
//PHP array as loop array?
elseif (substr($cond,0,1) == '$') {
eval('global '.$cond.';');
eval('$looparray[$curr_tpl][$loops[$curr_tpl]] = '.$cond.';');
}
elseif ($type == 'for') {
$looparray[$curr_tpl][$loops[$curr_tpl]] = array();
for ($k = $loopdata[$curr_tpl][$loops[$curr_tpl]]['from']; $k <= $loopdata[$curr_tpl][$loops[$curr_tpl]]['to']; $k++)
$looparray[$curr_tpl][$loops[$curr_tpl]][]['index'] = $k;
}
//find the end of the loop
$loopneedend = 1;
while ($loopneedend != 0) {
$s = templ_read($curr_tpl);
if (substr($s,0,strlen('<!--[Loop Start ')) == '<!--[Loop Start ') $loopneedend++;
if ($s == '<!--[Loop End]-->') {$loopneedend--;}
if ($loopneedend == 0) $loopends[$curr_tpl][$loops[$curr_tpl]] = $tpi[$curr_tpl];
}
return $s;
}
function template_loop_end($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi, $loopdata;
if ($loopends[$curr_tpl][$loops[$curr_tpl]] == $tpi[$curr_tpl]) {
if (count($looparray[$curr_tpl][$loops[$curr_tpl]]) == 0) { //loop ends
$loops[$curr_tpl]--;
} else {
//if loop range
if (isset($loopdata[$curr_tpl][$loops[$curr_tpl]]['from']))
while (($en['loops_index']+1 < $loopdata[$curr_tpl][$loops[$curr_tpl]]['from'] || $en['loops_index']+1 > $loopdata[$curr_tpl][$loops[$curr_tpl]]['to']) && count($looparray[$curr_tpl][$loops[$curr_tpl]])>0) {
$loopentry = array_shift($looparray[$curr_tpl][$loops[$curr_tpl]]);
$en['loops_left'] = count($looparray[$curr_tpl][$loops[$curr_tpl]]);
$en['loops_index']++;
if ($en['loops_index'] > $loopdata[$curr_tpl][$loops[$curr_tpl]]['to']) {
$en['loops_index'] += count($looparray[$curr_tpl][$loops[$curr_tpl]]);
$looparray[$curr_tpl][$loops[$curr_tpl]] = array();
}
}
if (count($looparray[$curr_tpl][$loops[$curr_tpl]]) == 0) return false;
$en['loop_key'] = key($looparray[$curr_tpl][$loops[$curr_tpl]]);
$loopentry = array_shift($looparray[$curr_tpl][$loops[$curr_tpl]]);
if (!is_array($loopentry)) $en['loop_value'] = $loopentry;
$en = array_merge($en,$loopentry);
$tpi[$curr_tpl] = $loopstart[$curr_tpl][$loops[$curr_tpl]]; //go back to loop beginning
$en['loops_left'] = count($looparray[$curr_tpl][$loops[$curr_tpl]]);
if (isset($loopdata[$curr_tpl][$loops[$curr_tpl]]['from'])) {
$en['loops_left'] = $loopdata[$curr_tpl][$loops[$curr_tpl]]['to']-$en['loops_index']-1;//,$en['loops_left']);
}
$en['loops_index']++;
}
$s = '';
return $s;
}
}
function template_load_template($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi;
extract($names);
$incl = substr($s,strlen('<!--[Include Template '));
$incl = substr($incl,0,strpos($incl,']'));
load_template($incl);
$s = '';
return $s;
}
function template_include($s) {
global $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi;
extract($names);
$incl = substr($s,strlen('<!--[Include File '));
$incl = substr($incl,0,strpos($incl,']'));
include $incl;
$s = '';
return $s;
}
$t_id = 0; $curr_tpl = 0; $templ = array(); $tpi = array(); $looparray = $loops = $loopends = $loops = array();
function templ_read($template) {
global $templ, $tpi;
$tpi[$template]++;
return $templ[$template][$tpi[$template]];
}
function _getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function load_template($template) {
global $template_cache, $names, $profs, $ifcn, $if, $iflev, $en, $s, $elsif, $beenelsif, $loops, $loopstart, $loopentry, $loopends, $looparray, $t_id, $curr_tpl, $templ, $tpi;
extract($names);
$time_start = getmicrotime();
//allocate template ID
$t_id++;
$tid = $t_id;
$ifcn[$tid] = 0;
$if[$tid][0] = TRUE;
//get template content
$f = fopen($template,'r');
if (!$f) return false;
while (!feof($f)) {
$s = chop(fgets($f,4096));
if ($s == '') continue;
if (substr($s,0,5) == '<!--[' || substr($s,0,2) == '<?') {
if ($nx != '') $templ[$tid][++$tplzz] = $nx;
$templ[$tid][++$tplzz] = $s;
$nx = '';
} else
$nx .= "\n".$s;
}
if ($nx != '') $templ[$tid][++$tplzz] = $nx;
fclose($f);
// $templ[$tid] = @file($template); if (!$templ[$tid]) return false;
// $tplzz = count($templ[$tid]);
//if (strpos($template,'box_foot.tpl'))
// print_r($templ[$tid]);
// exit;
while ($tpi[$tid] != count($templ[$tid])) {
$s = templ_read($tid);
$curr_tpl = $tid;
//if (strpos($s,'#') !== false)
$s = template_replace_vars($s);
//if operators
if (substr($s,0,7) == '<!--[If') $s = template_if($s);
//last if was false?
if (!$if[$tid][$ifcn[$tid]]) continue;
//no more statements, print output?
if (substr($s,0,5) != '<!--[' && substr($s,0,2) != '<?') {
if ($if[$tid][$ifcn[$tid]] && $s != '' && !$codestart) echo $s."\n";
if ($codestart) $code .= $s."\n";
continue;
}
//get array?
if (substr($s,0,strlen('<!--[Array ')) == '<!--[Array ') $s = template_array($s);
//PHP code?
if ($s == '<?') {
$code = '';
while ($s != '?>' && $s !== false) {
$s = templ_read($tid);
if ($s != '?>') $code .= "\n".$s;
}
// $code = template_replace_vars($code);
// echo strlen($code);
// echo $code;
eval($code);
$s = '';
}
//one line PHP code?
if (substr($s,0,2)=='<?' && substr($s,strlen($s)-2,2)=='?>') {$s = substr($s,2,strlen($s)-4); eval($s);$s = '';}
//include file?
if (substr($s,0,17) == '<!--[Include File') $s = template_include($s);
//include template?
if (substr($s,0,21) == '<!--[Include Template') $s = template_load_template($s);
//go to next loop iteration
if ($s == '<!--[Continue]-->')
while ($s != '<!--[Loop End]-->') $s = templ_read($tid);
//stop loop
if ($s == '<!--[Break]-->') {
while ($s != '<!--[Loop End]-->') $s = templ_read($tid);
$looparray[$curr_tpl][$loops] = array(); //clear loop data array
}
//Loop Start?
if (substr($s,0,strlen('<!--[Loop Start ')) == '<!--[Loop Start ') $s = template_loop_start($s);
//Loop End?
if ($s == '<!--[Loop End]-->') $s = template_loop_end($s);
if ($if[$tid][$ifcn[$tid]] && $s != '' && !$codestart) echo $s."\n";
if ($codestart) $code .= $s."\n";
}
$timespent = _getmicrotime()-$time_start;
$en['temptot'] += $timespent;
echo "<!-- $template ".($timespent)." (all - $en[temptot]) -->";
// sofar($template);
}
//parses email templates
function emailtemplate($template_file) {
global $en;
$f = fopen($template_file,'r');
$lines = 0;
while (!feof($f)) {
$lines++;
$s = chop(fgets($f,4096));
if ($lines == 1){ $out[subj] = $s;} else
{$out[body] .= $s."\n";}
}
$cns = get_defined_constants();
$out[body] = preg_replace('/%%(.*)%%/sUe', "\$en['\\1']", $out[body]);
$out[body] = preg_replace('/##(.*)##/sUe', "\$cns['\\1']", $out[body]);
$out[subj] = preg_replace('/%%(.*)%%/sUe', "\$en['\\1']", $out[subj]);
$out[subj] = preg_replace('/##(.*)##/sUe', "\$cns['\\1']", $out[subj]);
fclose($f);
return $out;
}
?>