<?php

/** MEXER NESSE CÓDIGO PODE COMPORMETER COMPLETAMENTE NAS FUNCIONALIDADES DO SEU SITE!!!
 * <b>Core Start.class:</b>
 * Classe de execução inicial!
 * @copyright (c) 2016, Diego Perez Ferreira, Perfect Designer
 */
 
class Core_start extends Core_connect {
	
/** var PDO */
private $Core_connect;	

function __construct() {
// Inicio - Segurança de url, de bloqueio. #########
$bloqued_files_url_injects  = array('.jpg', '.png', '.gif', '.mp3', '.mp4', '.php', '.css', '.js', '.html');
if(strpos(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_DEFAULT), '.jpg')  || strpos(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_DEFAULT), '.png') && !strpos(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_DEFAULT), 'index.php')): 
exit; endif;
// Fim  - Segurança de url, de bloqueio. #########
$pag    = rtrim(filter_input(INPUT_GET, 'url'), "/");
if($pag == ''): $pag = "home"; endif;
define("url", $pag);
if(!file_exists(__DIR__ . DIRECTORY_SEPARATOR  . '../pd-includes/cache-controller/cache/' . md5($pag) . '.txt') || cache_db_optimize == false):
$this->create_define_pag();
else:
echo file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../pd-includes/cache-controller/cache/' . md5($pag) . '.txt');
exit;
endif;
}

public function create_define_pag(){

global $parametros_response;

$pag = rtrim(filter_input(INPUT_GET,'url'), '/');

$readSelection = $parametros_response['select_db'];

if($pag == ''):
$readSelection->ExeRead(" * ", "pd_paginas", "WHERE pag_slug = 'home' ", "pag_slug = {'home'}");
else:
$readSelection->ExeRead(" * ", "pd_paginas", "WHERE pag_slug = '$pag' or pag_slug_complementar = '$pag' or pag_slug_historico LIKE '%$pag%'", "pag_slug = {$pag}, pag_slug_complementar = {$pag}, pag_slug_historico LIKE {$pag}");
endif;

if ($readSelection->getResult()):

define('no_result', true);

foreach ($readSelection->getResult() as $rest):

/* Redirecionamento Permanent urls antigas */
$url_antigas        = explode(",", trim($rest['pag_slug_historico']));
$total_urls_antigas = count($url_antigas);

if($total_urls_antigas > 0): 

/* Redirecionamento Permanent condicoes de sublinks */
if($rest['pag_slug_complementar'] > '' && $pag != $rest['pag_slug_complementar']){ 
$redirect = dominio . $rest['pag_slug_complementar'];
}else{
$redirect = dominio . $rest['pag_slug'];	
}

for($i=0;$i<$total_urls_antigas;$i++){
	
if($url_antigas[$i] == $pag && $pag != ''):
	
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: ' . $redirect );
exit;
	
endif;
	
}

endif;

/* Redirecionamento Permanent condicoes de sublinks */
if($rest['pag_slug_complementar'] > '' && $pag != $rest['pag_slug_complementar']){ 
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: ' . dominio . $rest['pag_slug_complementar'] );
exit;
}

$GLOBALS['parametros_get_page'] = array('custom_header' => $rest['pag_header_habilite'], 'custom_footer' => $rest['pag_footer_habilite'], 'pag_title' => $rest['pag_title'], 'pag_description' => $rest['pag_description'], 'pag_author' => $rest['pag_author'], 'pag_link' => $rest['pag_link'], 'pag_id' => $rest['pag_id'], 'pag_charset' => $rest['pag_charset'], 'pag_name' => $rest['pag_name']);

$link_pag = $rest['pag_link'];

endforeach;

else:

$not = redirect_pag_404;
$pag = rtrim(filter_input(INPUT_GET,'url'), '/');

$readSelection->ExeRead(" * ", "pd_member_roler_values", "WHERE ( val_slug LIKE '%' :ci '%') ", "ci={$pag}");	
	
if ($readSelection->getResult()):

$link_pag = 'paginas/ver_job.php';

$readSelection->ExeRead(" * ", "pd_paginas", " WHERE pag_link = '$link_pag' ", "link={$link_pag}");

define('no_result', true);

foreach ($readSelection->getResult() as $rest):
$GLOBALS['parametros_get_page'] = array('custom_header' => $rest['pag_header_habilite'], 'custom_footer' => $rest['pag_footer_habilite'], 'pag_title' => $rest['pag_title'], 'pag_description' => $rest['pag_description'], 'pag_author' => $rest['pag_author'], 'pag_link' => $rest['pag_link'], 'pag_id' => $rest['pag_id'], 'pag_charset' => $rest['pag_charset'], 'pag_name' => $rest['pag_name']);
endforeach;

else:
	
$readSelection->ExeRead(" * ", "pd_paginas", "WHERE pag_slug = '$pag'", "pag_slug={$not}");	
	
if ($readSelection->getResult()):
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: ' . dominio . redirect_pag_404 );
exit;
else:
Header( 'HTTP/1.1 301 Moved Permanently' );
Header( 'Location: ' . dominio  );
exit;
endif;

endif;

endif;

$linha = '';

$ponteiro = fopen('pd-themes/' . tema . '/' . $link_pag, 'r');
while (!feof ($ponteiro)) {
$linha .= fgets($ponteiro,
4096);	
}

/* Carregar plugins e injetar includes css e js */
$GLOBALS['contents'] =   $linha;

}	

}

?>