Advertisement
ShadyPL

plik index silnika shadyego

May 4th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package: Brutal Hero RPG
  4.  * @version: 0.0.1.0 <beta>
  5.  */
  6.  
  7. require_once './libs/Config.php';
  8.  
  9. class Router
  10. {
  11.     public static function getTrace( )
  12.     {
  13.         $trace = array_filter( explode( '/', str_replace( VAR_ROOT, '', $_SERVER['REQUEST_URI'] ) ) );
  14.  
  15.         foreach ( $trace as $track )
  16.         {
  17.             $track = explode( '=', $track );
  18.  
  19.             if ( empty( $track[1] ) )
  20.             {
  21.                 $_GET[$track[0]] = '';
  22.             }
  23.             else
  24.             {
  25.                 $_GET[$track[0]] = $track[1];
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static function setTrace( $action )
  31.     {
  32.         header( 'Location: ' . VAR_ROOT . $action );
  33.         exit;
  34.     }
  35. }
  36.  
  37. class Buffer
  38. {
  39.     public static function start( )
  40.     {
  41.         ob_start( );
  42.     }
  43.  
  44.     public static function get( )
  45.     {
  46.         return ob_get_contents( );
  47.     }
  48.  
  49.     public static function get_clean( )
  50.     {
  51.         return ob_get_clean( );
  52.     }
  53.  
  54.     public static function clean( )
  55.     {
  56.         ob_end_clean( );
  57.     }
  58.  
  59.     public static function end( )
  60.     {
  61.         ob_end_flush( );
  62.     }
  63. }
  64.  
  65. class Filter
  66. {
  67.     public static function string( $data )
  68.     {
  69.         return filter_var( trim( $data ), FILTER_SANITIZE_STRING );
  70.     }
  71.  
  72.     public static function int( $data )
  73.     {
  74.         return filter_var( $data, FILTER_SANITIZE_NUMBER_INT );
  75.     }
  76.  
  77.     public static function float( $data )
  78.     {
  79.         return filter_var( $data, FILTER_SANITIZE_NUMBER_FLOAT );
  80.     }
  81.  
  82.     public static function txt( $data )
  83.     {
  84.         return nl2br( addslashes( strip_tags( trim( $data ) ) ) );
  85.     }
  86.  
  87.     public static function email_check( $email )
  88.     {
  89.         return !filter_var( $email, FILTER_VALIDATE_EMAIL );
  90.     }
  91. }
  92.  
  93. class Init
  94. {
  95.     protected $controller;
  96.  
  97.     public function __construct( )
  98.     {
  99.         Buffer::start( );
  100.  
  101.         Router::getTrace( );
  102.  
  103.         if ( empty( $_GET['action'] ) )
  104.         {
  105.             $this->defaultController( );
  106.         }
  107.         else
  108.         {
  109.             $this->loadController( );
  110.         }
  111.     }
  112.  
  113.     public function defaultController( )
  114.     {
  115.         $_GET['action'] = 'start';
  116.         $_GET['task']   = 'index';
  117.  
  118.         require './mvc/controllers/start.php';
  119.  
  120.         $this->controller = new StartController( );
  121.         $this->controller->index( );
  122.     }
  123.  
  124.     public function loadController( )
  125.     {
  126.         $_GET['action'] = Filter::string( $_GET['action'] );
  127.  
  128.         $path = './mvc/controllers/' . $_GET['action'] . '.php';
  129.  
  130.         $_GET['action'] .= 'Controller';
  131.  
  132.         if ( is_file( $path ) )
  133.         {
  134.             require $path;
  135.  
  136.             $this->controller = new $_GET['action']( );
  137.  
  138.             $this->loadTask( );
  139.         }
  140.         else
  141.         {
  142.             Router::setTrace( 'action=error/task=notfound' );
  143.         }
  144.     }
  145.  
  146.     public function loadTask( )
  147.     {
  148.         if ( empty( $_GET['task'] ) )
  149.         {
  150.             Router::setTrace( 'action=error/task=notfound' );
  151.         }
  152.  
  153.         $_GET['task'] = Filter::string( $_GET['task'] );
  154.  
  155.         if ( method_exists( $this->controller, $_GET['task'] ) )
  156.         {
  157.             $this->controller->$_GET['task']( );
  158.         }
  159.         else
  160.         {
  161.             Router::setTrace( 'action=error/task=notfound' );
  162.         }
  163.     }
  164.  
  165.     public function __destruct( )
  166.     {
  167.         Buffer::end( );
  168.     }
  169. }
  170.  
  171. new Init( );
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement