Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package: Brutal Hero RPG
- * @version: 0.0.1.0 <beta>
- */
- require_once './libs/Config.php';
- class Router
- {
- public static function getTrace( )
- {
- $trace = array_filter( explode( '/', str_replace( VAR_ROOT, '', $_SERVER['REQUEST_URI'] ) ) );
- foreach ( $trace as $track )
- {
- $track = explode( '=', $track );
- if ( empty( $track[1] ) )
- {
- $_GET[$track[0]] = '';
- }
- else
- {
- $_GET[$track[0]] = $track[1];
- }
- }
- }
- public static function setTrace( $action )
- {
- header( 'Location: ' . VAR_ROOT . $action );
- exit;
- }
- }
- class Buffer
- {
- public static function start( )
- {
- ob_start( );
- }
- public static function get( )
- {
- return ob_get_contents( );
- }
- public static function get_clean( )
- {
- return ob_get_clean( );
- }
- public static function clean( )
- {
- ob_end_clean( );
- }
- public static function end( )
- {
- ob_end_flush( );
- }
- }
- class Filter
- {
- public static function string( $data )
- {
- return filter_var( trim( $data ), FILTER_SANITIZE_STRING );
- }
- public static function int( $data )
- {
- return filter_var( $data, FILTER_SANITIZE_NUMBER_INT );
- }
- public static function float( $data )
- {
- return filter_var( $data, FILTER_SANITIZE_NUMBER_FLOAT );
- }
- public static function txt( $data )
- {
- return nl2br( addslashes( strip_tags( trim( $data ) ) ) );
- }
- public static function email_check( $email )
- {
- return !filter_var( $email, FILTER_VALIDATE_EMAIL );
- }
- }
- class Init
- {
- protected $controller;
- public function __construct( )
- {
- Buffer::start( );
- Router::getTrace( );
- if ( empty( $_GET['action'] ) )
- {
- $this->defaultController( );
- }
- else
- {
- $this->loadController( );
- }
- }
- public function defaultController( )
- {
- $_GET['action'] = 'start';
- $_GET['task'] = 'index';
- require './mvc/controllers/start.php';
- $this->controller = new StartController( );
- $this->controller->index( );
- }
- public function loadController( )
- {
- $_GET['action'] = Filter::string( $_GET['action'] );
- $path = './mvc/controllers/' . $_GET['action'] . '.php';
- $_GET['action'] .= 'Controller';
- if ( is_file( $path ) )
- {
- require $path;
- $this->controller = new $_GET['action']( );
- $this->loadTask( );
- }
- else
- {
- Router::setTrace( 'action=error/task=notfound' );
- }
- }
- public function loadTask( )
- {
- if ( empty( $_GET['task'] ) )
- {
- Router::setTrace( 'action=error/task=notfound' );
- }
- $_GET['task'] = Filter::string( $_GET['task'] );
- if ( method_exists( $this->controller, $_GET['task'] ) )
- {
- $this->controller->$_GET['task']( );
- }
- else
- {
- Router::setTrace( 'action=error/task=notfound' );
- }
- }
- public function __destruct( )
- {
- Buffer::end( );
- }
- }
- new Init( );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement