/////////////////////////////////
/// CLASES CARGADAS ///
///////////////////////////////
/*
· $GLOBALS['Metas']
· $GLOBALS['Util']
· Idioma
· $GLOBALS['Con']
· $GLOBALS['Config']
/////////////////////////////////
/// METODOS ///
///////////////////////////////
· incluye('archivo.ext'); // 26/06/2013 - Carga js y css || Heredado de MEtas.
· extrae_cadena($limitador_i,$limitador_f,$cadena) // 26/06/2013 - Extrae un trozo de cadena delimitada
· inyecta_cadena($limitador_i,$limitador_f,$cadena,$sustituto)
*/
/////////////////////////////////
/// ERROR REPORTING ///
///////////////////////////////
/*
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('log_errors', 'On');
*/
/*
echo "
";
var_dump(debug_backtrace());
echo "
";
print_r(debug_backtrace(), true);
*/
class CEngine{
public $EN_DESAROLLO;
public $ATRAS = 'javascript:history.go(-1);';
public $tiempoInicial;
function __construct(){
/////////////////////////////////
/// INICIO SESSIION ///
///////////////////////////////
header('Content-Type: text/html; charset=UTF-8');
ini_set('session.cache_expire',1260); # duran 20 minutos las variables de sesion
session_start();
if (version_compare(phpversion(), '5.2.0', '<')) { // 5.3.3
die('La versión de php que usa tu Servidor es demasiado antigüa, necesitas como mínimo la 5.3.3');
}
//// *CS : Por si viene de otra web, solo funcionará una vez publicada en internet
/*if(md5(__FILE__) != $_SESSION['pw_unica']){
session_unset();
session_destroy();
session_start();
$_SESSION['pw_unica'] = md5(__FILE__);
}*/
$this->tiempoInicial = microtime(true);
/////////////////////////////////
/// CARGAMOS CLASES ///
///////////////////////////////
//// CONECTAMOS A LA SQL ////
include_once(dirname(dirname(dirname(__FILE__))).'/config/bbdd.php'); # datos de conexion a la BDD
include_once(dirname(dirname(dirname(__FILE__))).'/class/conexion.php');
$GLOBALS['Con'] = new CConexion;
$GLOBALS['Con']->conectar();
//// CARGAMOS EL CONFIG DE LA WEB ////
include_once(dirname(dirname(dirname(__FILE__))).'/class/config.php');
$Config = new CSuperConfig($GLOBALS['Con']);
$GLOBALS['Config'] = $Config->obtener_uno();
unset($Config);
if($GLOBALS['Config']->WEB_CERRADA == '1'){
header("Location: ".$GLOBALS['Config']->URL."503.php");
die();
}
//// LOS MODULOS ACTIVOS ///
include_once($GLOBALS['Config']->DIRBASE.'/class/niveles_admin.php');
$niveles_admin = new CNiveles_admin($GLOBALS['Con']);
$this->PERMISOS = $niveles_admin->obtener_key(1);
unset($niveles_admin);
//// CARGAMOS LAS UTILIDADES ////
include_once($GLOBALS['Config']->DIRBASE.'/class/util.php');
$GLOBALS['Util'] = new CUtil();
//// ESTADISTICAS DE VISITA ///
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaVisitas/megaVisitas.php');
$visitas = new CmegaVisitas();
}
public function inicia(){
include_once('class/metatags.php');
//// CARGAMOS LOS IDIOMAS ////
include_once($GLOBALS['Config']->DIRBASE.'/class/idiomas.php');
$idioma = new CSuperIdiomas($GLOBALS['Con']);
$GLOBALS['Idiomas'] = $idioma->obtener(null,1); // solo los activos
if(isset($_POST['id_idioma'])){
$_SESSION['id_idioma'] = $_POST['id_idioma'];
} else if(isset($_GET['id_idioma'])){
$_SESSION['id_idioma'] = $_GET['id_idioma'];
} else if(!isset($_SESSION['id_idioma']) || !$_SESSION['id_idioma'] > 0){
// La primera vez que entra en el index . Idioma aun sin seleccionar.
$_SESSION['id_idioma'] = 1; // idioma por defecto
$idioma_navegador = strtoupper(substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2));
for($i=0;$iISO) $_SESSION['id_idioma'] = $GLOBALS['Idiomas'][$i]->ID_IDIOMA;
}
}
$GLOBALS['Isos'] = array();
if(isset($GLOBALS['Idiomas'])) {
for ($i = 0; $i < count($GLOBALS['Idiomas']); $i++) {
$GLOBALS['Idiomas'][$i]->ISO = strtolower($GLOBALS['Idiomas'][$i]->ISO);
if (!is_object($GLOBALS['Isos'][$GLOBALS['Idiomas'][$i]->ID_IDIOMA])) {
$GLOBALS['Isos'][$GLOBALS['Idiomas'][$i]->ID_IDIOMA] = new stdClass;
}
$GLOBALS['Isos'][$GLOBALS['Idiomas'][$i]->ID_IDIOMA]->ISO = $GLOBALS['Idiomas'][$i]->ISO;
if ($GLOBALS['Idiomas'][$i]->ID_IDIOMA == $_SESSION['id_idioma']) $GLOBALS['Idioma'] = $GLOBALS['Idiomas'][$i];
}
}
if(!isset($GLOBALS['Idioma'])){
// Está intentando cargar un idioma no activo
$_SESSION['id_idioma'] = 1; // idioma por defecto
$GLOBALS['Idioma'] = $GLOBALS['Idiomas'][1];
}
unset($idioma);
// para evitar contenido duplicado se envia directamente al idioma por defecto o seleccionado al entrar al dominio
$path = explode('/', $_SERVER['SCRIPT_NAME']);
if(!isset($_GET['id_idioma']) && end($path) === 'index.php'){
/*
$metas = new CSuperMetatags($GLOBALS['Con']);
echo $metas->crearHtaccess();
*/
@header('Location: '.$GLOBALS['Config']->URL.$GLOBALS['Idioma']->ISO.'/');
}
//// CARGAMOS LAS METAS ////
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaMetatags/megaMetatags.php');
//// CARGAMOS LA TRADUCCION ////
include_once($GLOBALS['Config']->DIRBASE.'/modulos/traduccion_web/traduccion_web.php');
///// CLIENTES //////
if($this->PERMISOS[132]){
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaClientes/megaClientes.php');
$GLOBALS['Clientes'] = new CMegaClientes($GLOBALS['Con']);
}
///// CESTA //////
if($this->PERMISOS[164]){ // el id de los pedidos
// carga las divisas si hay tienda
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaDivisas/megaDivisas.php');
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaCesta/megaCesta.php');
}
//$this->carga_clases_extra($clases_extra); // clases particulares de este proyecto que se cargarán siempre.
/////////////////////////////////
/// VARIOS ///
///////////////////////////////
//// ELIMINAMOS VARIABLES PELIGROSAS ////
foreach($_GET as $clave => $valor){
$_GET[$clave] = $GLOBALS['Con']->filtro($valor);
}
foreach($_POST as $clave => $valor){
$_POST[$clave] = $GLOBALS['Con']->filtro($valor);
}
$dominio = $_SERVER['SERVER_NAME'];
if($dominio == 'www.cerotec.es'){
// EN DESARROLLO
$this->EN_DESAROLLO = 1;
}else{
// EN INTERNET
$this->EN_DESAROLLO = 0;
ini_set('display_errors',0);
error_reporting(false);
}
unset($dominio);
///// BOLETIN //////
if(isset($_POST['newsletter'])){
include_once($GLOBALS['Config']->DIRBASE.'/modulos/megaBoletin/megaBoletin.php');
}
//////////////////////////////////////////
/// PARTICULARIDADES DE ESTE PROYECTO ///
////////////////////////////////////////
function bonito($numero, $txt = null){
if($numero > 0){
$numero = round($numero,2);
$numero = $numero == 0 ? '0' : number_format($numero,2,',','.');
$numero = explode(',',$numero);
//if($numero[1] == '00'){
// $numero = $numero[0];
//}else{
$numero = $numero[0].','.$numero[1].'';
//}
}else{
if(is_null($txt))
$numero ='00,00';
else
$numero = $txt;
}
return $numero;
}
}
function __destruct(){
// se auto-ejecuto al morir la instancia, es decir, cuando la web se carga al 100%.
$GLOBALS['Con']->desconectar();
}
public function cerrar(){
if($this->EN_DESAROLLO){
echo $this->memoria_consumida();
}
/*
PARA DEPURAR LA MEMORIA
echo '';
print_r($GLOBALS);
echo '
';*/
// en algunos servidores el _destruct no funciona y se usa esto.
$GLOBALS['Con']->desconectar(1);
}
private function memoria_consumida(){
$memoria_usada = round(memory_get_peak_usage() / 1024,1) ;
$diferencia = round($memoria_usada-$_SESSION['ultima_memoria_usada'],1);
$tiempo = microtime(true)-$this->tiempoInicial;
$_SESSION['ultima_memoria_usada'] = $memoria_usada;
return "Memoria usada: ".number_format($memoria_usada,1)." KB (".$diferencia.") KB
Tiempo de carga: ".round($tiempo,3)." segundos
";
}
private function carga_clases_extra($clases_extra_){
global $Con;
for($x=0;$xmemoria_actual;
if(!isset($this->tiempo_actual)) $this->tiempo_actual = $this->tiempoInicial;
$diferencia = (microtime(true)-$this->tiempo_actual)*100;
echo "".$n.": ".round($diferencia_t,4)." | ".number_format($diferencia_m,3)."
";
$this->tiempo_actual = microtime(true);
$this->memoria_actual = $memoria_usada;
}
}
// Lo inicio.
$GLOBALS['Engine'] = new CEngine();
$GLOBALS['Engine']->inicia();
?>
///////////////////////////////////
// CLASE //
/////////////////////////////////
include_once($GLOBALS['Config']->DIRBASE.'/class/categorias.php');
class CMegaCategorias extends CSuperCategorias{
public $CONFIG;
public $CATEGORIA_ACTUAL;
function __construct(){
$this->name = 'Categorías Web';
$this->version = 1.0;
$this->author = 'Sergio Romero';
$this->description = 'Gestiona todo lo referente a categorías en la web';
$this->CONEXION = new CConexion($GLOBALS['Con']->MYSQLi);
}
public function setea_metas($obj){
$GLOBALS['Metas']->TITLE = $obj->TITLE != '' ? $obj->TITLE : $obj->NOMBRE;
$GLOBALS['Metas']->DESCRIPTION = $obj->DESCRIPTION != '' ? $obj->DESCRIPTION : $GLOBALS['Util']->nletras_enteras($obj->DESCRIPCION,160);
if($_GET['pagina'] > 0) $pagina = '?&pagina='.$_GET['pagina'];
for($i=0;$iRUTA_IDIOMAS[$GLOBALS['Idiomas'][$i]->ID_IDIOMA] = $obj->enlace_amigable(null,$GLOBALS['Idiomas'][$i]->ID_IDIOMA).$pagina;
}
}
// Crea el camino de hormigas hasta la categoria raiz
public function setea_hormiga($id_categoria){
$lista = $this->dame_padres($id_categoria);
if(isset($lista)){
for($n=0;$nsetea($lista[$n]);
hormiga(''.$yo->NOMBRE.'
',$yo->URL);
}
}
}
public function setea($obj){
if($obj->IMAGEN == '') $obj->IMAGEN = 'sin_foto.jpg'; // por si no tiene foto subida.
$obj->URL = $this->mi_url($obj);
return $obj;
}
public function dame_padres($id_categoria){
$quedan_hijos = 1;
$hijos = array();
while($quedan_hijos){
$yo = $this->obtener_uno($id_categoria, $GLOBALS['Idioma']->ID_IDIOMA);
if(is_object($yo)){ // por si no tiene permisos.
$hijos[] = $yo;
if($yo->ID_CATEGORIA_PADRE != 0)
$id_categoria = $yo->ID_CATEGORIA_PADRE;
else
$quedan_hijos = 0;
}else{
$quedan_hijos = 0;
}
}
$hijos = array_reverse($hijos);
return $hijos;
}
public function dame_nivel($id_categoria, $dame_n_productos = null, $orden = null){
$arbol = array();
if(is_null($orden))
$this->CONEXION->ORDEN = 'p.orden';
else
$this->CONEXION->ORDEN = $orden;
$this->CATEGORIAS = $this->obtener(null, $GLOBALS['Idioma']->ID_IDIOMA, $id_categoria,1);
if(!is_null($dame_n_productos))
$nproductos = $this->cuantos_productos();
if(isset($this->CATEGORIAS)){
for($c=0;$cCATEGORIAS);$c++){
$yo = $this->CATEGORIAS[$c];
$yo = $this->setea($yo);
$yo->PRODUCTOS = $nproductos[$yo->ID_CATEGORIA];
$arbol[] = $yo;
}
}
return $arbol;
}
public function dame_arbol($id_categoria_padre = 0){
$arbol = array();
$this->CONEXION->ORDEN = 'orden';
$categorias = $this->obtener(null, $GLOBALS['Idioma']->ID_IDIOMA, $id_categoria_padre,1);
if(isset($categorias)){
for($c=0;$csetea($yo);
$yo->HIJOS = $this->dame_arbol($yo->ID_CATEGORIA);
$arbol[] = $yo;
}
}
return $arbol;
}
public function monta_menu($arbol, $nivel = 0, $abre_todas = null){
if($GLOBALS['Categoria']->ID_CATEGORIA > 0) // hay categoria pulsada
$arbol_abiertas = $this->dame_padres($GLOBALS['Categoria']->ID_CATEGORIA);
return $this->monta_menu_desplegado($arbol, $nivel, $arbol_abiertas, $abre_todas);
}
public function monta_menu_desplegado($arbol, $nivel = 0, $arbol_abiertas = null, $abre_todas = null){
$tmp = '';
// if($nivel == 0) $ini = 1; else $ini = 0;
$ini = 0;
if(isset($arbol)){
for($c=$ini;$cHIJOS)){ // tiene hijos
$abierta = 0;
if(!is_null($abre_todas)){
$abierta = 1;
}else{
if(isset($arbol_abiertas)){
for($a=0;$a< count($arbol_abiertas);$a++){
if($arbol_abiertas[$a]->ID_CATEGORIA == $yo->ID_CATEGORIA){
$abierta = 1;
break;
}
}
}
}
}
if($yo->ID_CATEGORIA != 1){ // Evito la portada
if($abierta){
if($GLOBALS['Categoria']->ID_CATEGORIA == $yo->ID_CATEGORIA) // y seleccionada
$tmp.= '- '.$yo->NOMBRE.'
';
else
$tmp.= '- '.$yo->NOMBRE.'
';
$tmp.= $this->monta_menu($yo->HIJOS,$nivel+1);
}else{
if($GLOBALS['Categoria']->ID_CATEGORIA == $yo->ID_CATEGORIA){
$tmp.= '- '.$yo->NOMBRE.'
';
}else{
$tmp.= '- '.$yo->NOMBRE.'
';
}
}
}
unset($yo);
}
}
$tmp.= '
';
return $tmp;
}
public function dame_destacadas($cantidad){
$this->CONEXION->ORDEN = 'orden';
$this->CONEXION->MOSTRAR = $cantidad;
$tmp = array();
$categorias = $this->obtener(null, $GLOBALS['Idioma']->ID_IDIOMA, $id_categoria_padre,1, null, 1);
if(isset($categorias) && $cantidad > count($categorias)){
// Por si no hay suficientes
$diferencia = $cantidad-count($categorias);
$this->CONEXION->MOSTRAR = $diferencia;
$categorias2 = $this->obtener(null, $GLOBALS['Idioma']->ID_IDIOMA, $id_categoria_padre,1);
}
if(isset($categorias)){
for($c=0;$csetea($categorias[$c]);
}
}
if(isset($categorias2)){
for($c=0;$csetea($categorias2[$c]);
}
}
return $tmp;
}
/* public function obtener_uno_inteligente($par = null){
$par['ID_CATEGORIA'] = $par['ID_CATEGORIA'] ? $par['ID_CATEGORIA'] : 'automatico'; // por si lo borran del config publico, que por defecto siempre sea automático.
$par['IDIOMA'] = $par['IDIOMA'] ? $par['IDIOMA'] : 'automatico';
switch ($par['ID_CATEGORIA']){
case 'automatico':
if(isset($_GET['id_categoria']) && $_GET['id_categoria'] > 0) $id_categoria = $_GET['id_categoria']; else $id_categoria = null;
break;
case '0':
$id_producto = null;
break;
default:
if($par['ID_CATEGORIA'] > 0) $id_categoria = $par['ID_CATEGORIA']; else $id_categoria = null;
}
switch ($par['IDIOMA']){
case 'automatico':
$id_idioma = $_SESSION['id_idioma'] > 0 ? $_SESSION['id_idioma'] : 1;
break;
default:
if($par['IDIOMA'] > 0) $id_idioma = $par['IDIOMA']; else $id_idioma = 1;
}
return $GLOBALS['Categorias']->obtener_uno($id_categoria,$id_idioma);
}*/
//function dame_url($obj){
//return $GLOBALS['Iso'].'/'.$obj->NOMBRE_ACTUAL.'/familia/'.$obj->ID_CATEGORIA_ACTUAL;
//}
}
$GLOBALS['Categorias'] = new CMegaCategorias();
?>