<?php if(!defined("security")): exit; endif; // SEGURANÇA CONTRA ACESSO DIRETO VIA URL!!! ######



define('base', dominio . '/pd-themes/'. tema .'/');

if(connect_type == 'PDO'):

$protocolo    = (strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https') === false) ? 'http' : 'https';
$host  = $_SERVER['HTTP_HOST'];$UrlAtual  = $protocolo . '://' . $host;
$script   = $_SERVER['SCRIPT_NAME'];$UrlAtual     = $protocolo . '://' . $host . $script;
$parametros   = $_SERVER['QUERY_STRING'];
$UrlAtual     = @$protocolo . '://' . @$host . @$script . '?' . @$parametros;

$GLOBALS['get']  =  filter_input_array(INPUT_GET, FILTER_DEFAULT);
$GLOBALS['post'] =  filter_input_array(INPUT_POST, FILTER_DEFAULT);
 
$GLOBALS['js']  = '';
$GLOBALS['css']  = '';
 
include(__DIR__ . DIRECTORY_SEPARATOR . 'PDO/autoload.php');

$select         = new Core_select;
$shortcode      = new Shortcode;
$register_files = new Register_files;
$updateSiteViews = new Core_update;

/* VARIAVEIS GLOBAIS */
$GLOBALS['parametros_response'] = array('select_db' => $select,  'update_db' => $updateSiteViews, 'shortcode' => $shortcode, 'register_file' => $register_files );
global $parametros_response;

$a = array('{base}', '{dominio}', '{host}');	
$b = array(base, dominio, $UrlAtual);		

if(!isset($_GET['create_cache'])):
$_GET['create_cache'] = false;
endif;

new Core_start;
global $parametros_get_page;

$a = array('{base}', '{dominio}', '{tema}', '{host}');	
$b = array(base, dominio, tema, $UrlAtual);	

include(__DIR__ . DIRECTORY_SEPARATOR  . '../pd-themes/' . tema . '/functions.php');
include(__DIR__ . DIRECTORY_SEPARATOR  . '../pd-plugins/autoload.php');

function pd_footer(){
global $js;		
echo $js;		
}

function pd_header(){
global $css;		
echo $css;	
}

// Modo Cache Aplication active #######################################################################
if(cache_db_optimize == true && filter_input(INPUT_GET, 'create_cache') == false  && no_result == true  && cache_db_optimize == true){
include(__DIR__ . DIRECTORY_SEPARATOR  . 'cache-controller/index.php');
}

function header_page($header){
if($header == 0):		   
return include(__DIR__ . DIRECTORY_SEPARATOR . '../pd-themes' . DIRECTORY_SEPARATOR . tema . DIRECTORY_SEPARATOR . 'header.php');
endif;	
}

function footer_page($footer, $a, $b){
if($footer == 0):	 
echo    str_replace($a, $b, utf8_encode( file_get_contents( __DIR__ . DIRECTORY_SEPARATOR . '../pd-themes' . DIRECTORY_SEPARATOR . tema . DIRECTORY_SEPARATOR . 'footer.php') ) );
echo pd_footer();
endif;
}

$teste  = 0;

if($teste != 1){	

if(!empty($get['create_cache']) && no_result == true && cache_db_optimize == true){
	
header_page($parametros_get_page['custom_header']);	
	
echo utf8_encode( str_replace($a, $b, $contents) );

footer_page($parametros_get_page['custom_footer'], $a, $b);

}elseif(no_result == true && cache_db_optimize == false){

$teste = 0;
	
header_page($parametros_get_page['custom_header']);	

if($parametros_get_page['custom_header'] == 0){	

 if($parametros_get_page['pag_charset'] == 0){
	 
   echo  utf8_encode( str_replace($a, $b, $contents) ) ;

 }else{
	 
   echo  str_replace($a, $b, $contents)  ;	 

 }

}else{
	
echo str_replace($a, $b, $contents);
}

footer_page($parametros_get_page['custom_footer'], $a, $b);

}

}

endif;
		
?>