<?php
require 'system/core.php';
// файл
$page_file = $config['default']['page'];
// версия
$page_version = $config['default']['version'];
// заголовок
$page_title = $config['default']['title'];
// заголовки
$page_headers = array();
// переменные доступные в файлах
$page_vars = array('ua' => $http['ua'],
'ip' => $http['ip'],
'uri' => $http['uri'],
'host' => $http['host'],
'unix_time' => $sys['t'],
'is_web' => $http['web']);
if(substr_count($http['ae'],'deflate'))
{
function output_compress($output)
{
return gzdeflate($output, 9);
}
header('Content-Encoding: deflate');
ob_start('output_compress');
ob_implicit_flush(0);
}
elseif(substr_count($http['ae'],'gzip'))
{
function output_compress($output,$mark = true)
{
return gzencode($output, 9);
}
header('Content-Encoding: gzip');
ob_start('output_compress');
ob_implicit_flush(0);
}
elseif(substr_count($http['ae'],'x-gzip'))
{
function output_compress($output)
{
$size = strlen($output);
$crc = crc32($output);
$output = gzcompress($output, 9);
$output = substr($output, 0, strlen($output) - 4);
return "\x1f\x8b\x08\x00\x00\x00\x00\x00".$output.pack('V',$crc).pack('V',$size);
}
header('Content-Encoding: x-gzip');
ob_start('output_compress');
ob_implicit_flush(0);
}
else
{
function output_compress($output)
{
return $output;
}
ob_start();
}
if(isset($_GET['f']))$page_file = preg_replace('#[^a-zA-Z-0-9_/]#i','null',$_GET['f']);
if(!file_exists('pages/'.$page_file.'.slsp'))
{
error('Запрошенный файл не найден');
}
$content = trim(file_get_contents('pages/'.$page_file.'.slsp'));
############# Обрабатываем заэкранированные команды
function process_commands($cnt){ return htmlspecialchars(substr($cnt[0],1)); }
$content = preg_replace_callback('#[\\\\]{1}<!--([[:space:]])?SLS\|([^>]*)([[:space:]])?-->#ui','process_commands',$content);
############# Проверка
if(stripos($content,'<!-- SLS|PageNotDirectCall -->') !== false)error('Файл не для прямого вызова');
############# Подключаем файлы вверха и низа
$content = trim(file_get_contents('system/allup.slss')).$content.trim(file_get_contents('system/alldown.slss'));
################################################################ Основные команды
if(preg_match('#<!-- SLS\|Include:([^>]*) -->#ui',$content,$result))
{
$content = preg_replace('#<!-- SLS\|Include:([^>]*) -->(\r\n)?#ui',(file_exists('pages/'.$result[1].'.slsp') ? trim(file_get_contents('pages/'.$result[2].'.slsp')) : '<b>Файл '.$result[2].'.slsp не найден!</b>'),$content);
}
if(preg_match('#<!-- SLS\|PageVersion:(wml|html) -->#ui',$content,$result))
{
$content = preg_replace('#<!-- SLS\|PageVersion:(wml|html) -->(\r\n)?#ui',null,$content);
$page_version = trim($result[1]);
}
if(preg_match('#<!-- SLS\|PageTitle:([^>]*) -->#ui',$content,$result))
{
$content = preg_replace('#<!-- SLS\|PageTitle:([^>]*) -->(\r\n)?#ui',null,$content);
$page_title = trim($result[1]);
}
if(preg_match('#<!-- SLS\|PageAutoBr -->#iu',$content))
{
$content = nl2br(preg_replace('#<!-- SLS\|PageAutoBr -->(\r\n)?#iu',null,$content));
}
################################################################ Функции
if(preg_match_all('#<!-- SLS\|Date(\:([^>]*))? -->#ui',$content,$result))
{
foreach($result[2] as $key => $format)
{
$content = preg_replace('#<!-- SLS\|Date(\:([^>]*))? -->(\r\n)?#ui',date((!empty($format) ? $format : 'G:i d.m.Y')),$content,1);
}
}
if(preg_match_all('#<!-- SLS\|Header:([^>]*) -->#ui',$content,$results))
{
for($count = count($results[0]), $i = 0;$i < $count;$i ++)
{
preg_match_all('#"([^"]*)"(?:;)?#ui',$results[1][$i],$results2);
for($c = count($results2[1]),$j = 0;$j < $c;$j ++)
{
$page_headers[] = $results2[1][$j];
}
$content = preg_replace('#<!-- SLS\|Header:([^>]*) -->(\r\n)?#ui',null,$content,1);
}
}
################################################################ Переменные
if(preg_match_all('#<!-- SLS\|Var:([^[:space:]>=]*)(=([^[:space:]>]*))? -->#ui',$content,$results))
{
for($count = count($results[0]), $i = 0;$i < $count;$i ++)
{
$return = null;
$var = trim($results[1][$i]);
if(empty($results[2][$i]))
{
if(isset($page_vars[$var]))
{
$return = $page_vars[$var];
}
}
else
{
# dump($results[3]);
$page_vars[$var] = $results[3][$i];
}
$content = preg_replace('#<!-- SLS\|Var:([^>]*)(?:=([>]*))? -->(\r\n)?#ui',$return,$content,1);
}
}
################################################################ PHP
if($config['admin']['exec_php'] == 1 && preg_match_all('#<!-- SLS\|phpOn -->(.*)<!-- SLS\|phpOff -->#uUsi',$content,$results))
{
for($count = count($results[0]), $i = 0;$i < $count;$i ++)
{
$code = trim($results[1][$i]);
if(substr($code,0,5) == '<?php')$code = substr($code,5);
elseif(substr($code,0,2) == '<?')$code = substr($code,2);
if(substr($code,-2,2) == '?>')$code = substr($code,0,-2);
ob_start();
eval(trim($code));
$result = ob_get_contents();
ob_end_clean();
$content = preg_replace('#<!-- SLS\|phpOn -->(.*)<!-- SLS\|phpOff -->(\r\n)?#uUsi',$result,$content,1);
}
}
if(preg_match_all('#<!-- SLS\|phpColorOn -->(.*)<!-- SLS\|phpColorOff -->#uUsi',$content,$results))
{
for($count = count($results[0]), $i = 0;$i < $count;$i ++)
{
$code = trim($results[1][$i]);
if(substr($code,0,5) != '<?php')
{
$open_tag = true;
$code = '<?php '.$code;
}
#
if(substr($code,-2,2) != '?>')
{
$close_tag = true;
$code .= ' ?>';
}
$result = highlight_string($code,true);
if(isset($open_tag))
{
$result = preg_replace('~<span style="color: '.ini_get('highlight.default').'"><\?php([^<>]*)<\/span>~isuU','',$result,1);
}
if(isset($close_tag))
{
$result = preg_replace('~<span style="color: '.ini_get('highlight.default').'">\?><\/span>~isuU','',$result,1);
}
$content = preg_replace('#<!-- SLS\|phpColorOn -->(.*)<!-- SLS\|phpColorOff -->(\r\n)?#uUsi',trim($result),$content,1);
}
}
################################################################ Заголовки & Шапки/Ноги
if($page_version == 'html')
{
$page_headers[] = 'Content-type: text/html; charset=UTF-8';
if(file_exists('system/fulluphtml.slss'))
{
$header = str_replace(array('{$page_title}','{$path}'),array($page_title,$config['other']['path']),trim(file_get_contents('system/fulluphtml.slss')));
}
else
{
$header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">';
$header .= '<html>';
$header .= '<head>';
$header .= '<title>'.$page_title.'</title>';
$header .= '</head><body>';
}
if(file_exists('system/fulldownhtml.slss'))
{
$footer = trim(file_get_contents('system/fulldownhtml.slss'));
}
else
{
$footer = '</body></html>';
}
}
else
{
$page_headers[] = 'Content-Type: text/vnd.wap.wml; charset=utf-8';
if(file_exists('system/fullupwml.slss'))
{
$header = str_replace(array('{$page_title}','{$path}'),array($page_title,$config['other']['path']),trim(file_get_contents('system/fullupwml.slss')));
}
else
{
$header = '<?xml version="1.0" encoding="utf-8"?>';
$header .= '<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml_1.3.xml">';
$header .= '<wml>';
$header .= '<card id="card1" title="'.$page_title.'">';
$header .= '<p>';
}
if(file_exists('system/fulldownwml.slss'))
{
$footer = trim(file_get_contents('system/fulldownwml.slss'));
}
else
{
$footer = '</p>';
$footer .= '</card></wml>';
}
}
$page_headers[] = 'X-Work-On: SLSCMSv'.SLSVER;
for($count = count($page_headers),$i = 0;$i < $count;$i ++)
{
header($page_headers[$i]);
}
################################################################ Сопственно вывод
echo trim(str_replace('<!-- SLS|MicroTime -->',round(microtime(true) - $sys['mt'],3),($header.$content.$footer)));
ob_end_flush();
exit;
?>