<?php
if ( get_magic_quotes_gpc() )
{ 
  function stripslashes_deep( $value )
  {
    $value = is_array( $value ) ? array_map( 'stripslashes_deep', $value ) : stripslashes( $value ); 
    return $value; 
  } 
  
  $_POST  = array_map( 'stripslashes_deep', $_POST ); 
  $_GET   = array_map( 'stripslashes_deep', $_GET );
}

function __autoload_my_classes( $classname )
{
  $q = explode( '\\' , $classname );
  $c = array_pop( $q );
  $f = 'autoload/' . implode( '/' , $q ) . '/class.' . $c . '.php';
  
  if ( $c == 'Savant3' )
  {
    require_once 'autoload/Savant3.php';
    return true;
  }
  
  if ( $c == 'PclZip' )
  {
    require_once 'resources/pclzip.lib.php';
    return true;    
  }
  
  if ( $c == 'Securimage' )
  {
    require_once 'resources/securimage/securimage.php';
    return true;
  }
  
  if ( file_exists( $f ) )
    require_once( $f );
}

spl_autoload_register( '__autoload_my_classes' );

define( 'OPD_DIR' , 'autoload/' );
include OPD_DIR . 'opd.class.php';
include 'files/config.php';
include 'resources/securimage/securimage.php';

date_default_timezone_set('Europe/Warsaw');

session_start();

$db = opdClass::create(
                        array(
                            'dsn' => 'mysql:host=' . $database['host'] . ';dbname=' . $database['name'],
                            'user' => $database['user'] ,
                            'password' => $database['password'] ,
                            'cache' => 'Temp/' ,
                            'debugConsole' => false
                            )
                      );
$db -> query('SET NAMES utf8');

$cache      = new \FileCache;
$securimage = new \Securimage;
$securimage -> image_width = 100;
$securimage -> image_height = (int)($securimage -> image_width * 0.35);

if ( file_exists( 'resources/xajax/xajax_core/xajax.inc.php' ) )
  include( 'resources/xajax/xajax_core/xajax.inc.php' );

$lang = \System::getSessionVar( 'lang' );

if ( !\System::getSessionVar( 'token' ) )
  \System::setSessionVar( 'token' , sha1( uniqid( rand() , true ) ) );

if ( !$lang ) 
{
  $lang = \language\FLanguage::loadLang();
  \System::setSessionVar( 'lang' , $lang );
}

\front\controls\Page::checkUrlParams();

$lang   = \System::getSessionVar( 'lang' );
$user   = \System::getSessionVar( 'user' );

if ( !$site = \System::getSessionVar( 'site' ) ) 
{
  $site = new \site\Site;
  \System::setSessionVar( 'site' , $site );
}

include( 'functions/xajax.php' );
if ( file_exists( 'functions/proces.php' ) )
  include 'functions/proces.php';

echo \front\view\Page::show();

if ( !isset( $_COOKIE["cookie_information"] ) )
  echo \site\VSite::drawCookieInformation();
?>