| 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 load_template($templ) {
$st = getmicrotime();
$tpl = new show_template;
$tpl->template = $templ;
$tpl->print_out();
$GLOBALS['measure']['tpl_exec'] += getmicrotime() - $st;
// $fin = getmicrotime() - $st;
// echo "<!-- $templ || $fin -->";
}
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
var $cancel_loop = false; //cancel loop
# Has the template already been analyzed?
function start() {
$cache = true;
if (isset($GLOBALS['tplcache'][$this->template])) {
//have it compiled before
$this->act = $GLOBALS['tplcache'][$this->template]->act;
$this->loop = $GLOBALS['tplcache'][$this->template]->loop;
$this->ifs = $GLOBALS['tplcache'][$this->template]->ifs;
$this->templ = $GLOBALS['tplcache'][$this->template]->templ;
}
elseif(@filemtime(dirname(dirname(__file__)).'/templates/compiled/'.md5($this->template)) == @filemtime($this->template) && $cache) {
$f = fopen(dirname(dirname(__file__)).'/templates/compiled/'.md5($this->template),'r');
$s = fread($f,filesize(dirname(dirname(__file__)).'/templates/compiled/'.md5($this->template)));
fclose($f);
$this = unserialize($s);
}
else {
//analyze
$this->get();
//save in cache
if ($cache) {
$time = time();
$fname = dirname(dirname(__file__)).'/templates/compiled/'.md5($this->template);
$f = fopen($fname,'w');
fwrite($f,serialize($this));
fclose($f);
touch($fname,filemtime($this->template));
}
}
}
function make_php() {
//get template content
$f = fopen($this->template,'r');
if (!$f) return false;
$s = fread($f,filesize($this->template));
fclose($f);
//if structures
$s = str_replace('<!--[If End]-->','<? } ?>',$s);
//loop structures
$s = str_replace('<!--[Loop End]-->','<? } ?>',$s);
//includes
$s = preg_replace('\<\!\-\-\[Include File (.*)\]\-\-\>',"<? include '\\1'; ?>",$s);
//template includes
}
# Get template content and analyze
function get() {
$startp = getmicrotime();
//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) == '<!--[') {
if ($nx != '') $this->templ[] = $nx;
$this->templ[] = $s;
$nx = '';
}
elseif (substr($s,0,2) == '<?') {
if ($nx != '') $this->templ[] = $nx;
$nx = $s;
}
else
$nx .= ($nx != '' ? "\n" : '').$s;
if (substr($nx,-2) == '?>') {
$this->templ[] = $nx;
$nx = '';
}
}
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->ifs[$key]['start'] = $key;
$startedif[] = $key;
$this->act[$key] = 'if_start';
}
if (substr($value,0,11) == '<!--[If End') {
$last = $startedif[count($startedif)-1];
$this->ifs[$last]['end'] = $key;
array_pop($startedif);
}
if (substr($value,0,12) == '<!--[If Else') {
$last = $startedif[count($startedif)-1];
$this->ifs[$last]['else'] = $key;
}
}
//loops
elseif (substr($value,0,9) == '<!--[Loop') {
if (substr($value,0,15) == '<!--[Loop Start') {
$this->loop[$key]['start'] = $key;
$startedloop[] = $key;
$this->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,21) == '<!--[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';
}
$GLOBALS['tplcache'][$this->template] = $this;
$GLOBALS['measure']['compile'] += getmicrotime() - $startp;
}
# The main function
function print_out() {
//get template
$this->start();
//output content
$this->exec_block(0, count($this->templ)-1, 0);
}
# Read next line
function templ_read() {
$this->tpi++;
return $this->templ[$this->tpi];
}
# Replace variables
function template_replace_vars($s) {
return preg_replace('/<%(.*)%>/sUe', '$this->do_format("\\1",$s)', $s);
}
# Format replaced vars
function do_format($value,$s) {
global $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;
}
# Execute template block
function exec_block($start, $end, $jump = -2) {
$this->tpi = $start - 1;
while ($this->tpi < $end) {
$s = $this->templ_read();
$this->s = $this->template_replace_vars($s);
if ($this->act[$this->tpi] == 'continue_loop') return false;
if ($this->act[$this->tpi] == 'break_loop') {
$this->cancel_loop = true;
return false;
}
eval('$this->'.$this->act[$this->tpi].'();');
}
if ($jump != -2)
$this->tpi = $jump;
}
# Echo a line
function do_print() {
echo $this->s;
}
# If structure
function if_start() {
global $names, $en;
extract($names);
$cond = substr($this->s,14);
$cond = substr($cond,0,strpos($cond,']-->'));
$evstr = '$out = ('.$cond.');';
@eval($evstr);
if ($out) {
//returns true, let's do something
$end = isset($this->ifs[$this->tpi]['else']) ? $this->ifs[$this->tpi]['else'] : $this->ifs[$this->tpi]['end'];
$this->exec_block($this->tpi+1, $end-1, $this->ifs[$this->tpi]['end']);
}
else {
//returns false, go to else or end
if (isset($this->ifs[$this->tpi]['else'])) {
//else block present
$this->exec_block($this->ifs[$this->tpi]['else']+1, $this->ifs[$this->tpi]['end']-1, $this->ifs[$this->tpi]['end']);
}
else {
//go to end of if structure
$this->tpi = $this->ifs[$this->tpi]['end'];
}
}
}
# Loops
function loop_start() {
global $names, $en;
extract($names);
$cond = substr($this->s,16);
$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);
$from = (int)$from;
if ($to == '') $to = 'max';
}
//mysql query as array?
if (substr($cond,0,6) == 'QUERY:') {
//process query
$cond = substr($cond,6);
eval('$query = "'.$cond.'";');
$result = sql_query($query);
//create loop array
$looparray = array();
while ($line = sql_fetch_assoc($result))
$looparray[] = $line;
$en['lastq'] = $result;
}
//PHP array as loop array?
elseif (substr($cond,0,1) == '$') {
$glob = strpos($cond,'[') ? substr($cond,0,strpos($cond,'[')) : $cond;
eval('global '.$glob.';');
eval('$looparray = '.$cond.';');
}
//For loop
elseif ($type == 'for') {
$looparray = array();
for ($k = $from; $k <= $to; $k++)
$looparray[]['index'] = $k;
}
//check bounds
if ($to == 'max') $to = count($looparray);
if (!$from) {
$from = 1;
$to = count($looparray);
}
if ($from == 0) $from = 1;
//slice offsets off the array
$en['total_count'] = count($looparray);
for ($k = count($looparray); $k > $to; $k--) array_pop($looparray);
for ($k = 2; $k <= $from; $k++) array_shift($looparray);
//and now just do the stuff...
$st = $this->tpi;
$end = $this->loop[$this->tpi]['end'];
$en['loops_count'] = count($looparray);
while (count($looparray) > 0) {
$this->cancel_loop = false;
$en['loop_key'] = key($looparray);
$loopentry = array_shift($looparray);
$en['loops_index'] = $from++;
$en['loops_left'] = count($looparray);
$en = array_merge($en, $loopentry);
$this->exec_block($this->loop[$st]['start']+1,$this->loop[$st]['end']-1,$this->loop[$st]['end']);
if ($this->cancel_loop == true) {echo 'break'; break; }
}
$this->tpi = $end;
}
# Eval
function do_eval() {
global $names, $en;
extract($names);
$ev = substr($this->s,2,-2);
eval($ev);
}
# Array
function do_array() {
global $names, $en;
extract($names);
$incl = substr($this->s,11);
$arr = substr($incl,0,strpos($incl,' '));
$incl = substr($incl,strlen($arr)+1);
$incl = substr($incl,0,strpos($incl,']-->'));
eval('$query = "'.$incl.'";');
$line = sql_fetch_assoc(sql_query($query));
eval($arr.' = array_merge('.$arr.',$line);');
}
# Include file
function include_file() {
global $names, $en;
extract($names);
$incl = substr($this->s,18);
$incl = substr($incl,0,strpos($incl,']'));
include $incl;
}
# Include template
function include_template() {
global $names, $en;
$incl = substr($this->s,22);
$incl = substr($incl,0,strpos($incl,']'));
load_template($incl);
}
}
//parses email templates
function emailtemplatetxt($subj,$text) {
global $en;
$cns = get_defined_constants();
$out[body] = preg_replace('/%%(.*)%%/sUe', "\$en['\\1']", $text);
$out[body] = preg_replace('/##(.*)##/sUe', "\$cns['\\1']", $out[body]);
$out[subj] = preg_replace('/%%(.*)%%/sUe', "\$en['\\1']", $subj);
$out[subj] = preg_replace('/##(.*)##/sUe', "\$cns['\\1']", $out[subj]);
return $out;
}
//parses email templates
function emailtemplate($template_file) {
global $en;
$f = fopen($template_file,'r');
if (!$f) die('Couldn`t open '.$template_file.'!');
$lines = 0;
while (!feof($f)) {
$lines++;
$s = chop(fgets($f,4096));
if ($lines == 1){ $out[subj] = $s;} else
{$out[body] .= $s."\n";}
}
fclose($f);
return emailtemplatetxt($out['subj'],$out['body']);
}
?>