<?php

	// Loads Modules
	// -----------------------------------------------------	
	$ROOT = Str_Replace('\\', '/', __DIR__);
	Include_Once $ROOT . '/Modules/INI.php';

	
	// Declare URI
	// -----------------------------------------------------	
	$URI 		= "";
	if(isset($_GET['url']))
	{
		$URI = $_GET['url'];
	}
	
	
	// RESTRICT TO HTTPS PROTOCOL
	// -----------------------------------------------------
	PHPRC_APP::REF_CHANGE_PROTOCOL("HTTPS");

	
	// DO NOT USE LOCALHOST
	// -----------------------------------------------------
	PHPRC_APP::REF_BLOCK_LOCALHOST();
	
	
	// Directory Loader [Server]
	// -----------------------------------------------------
	Class PHPDIR
	{   	
	    
	    // [ Server / Directory.php ] 
	    //=========================================================
	    Public Static function LOAD_SERVER($PHPDIR_URI)
	    {
	        // Display home
	        // ............................................
	        if(StrLen($PHPDIR_URI) <= 0)
	        {
	            header("HTTP/1.1 301 Moved Permanently");
	            header("Location: " . PHPSET::$SITE_URL . "/p/index.html");
	            Exit;
	        }
	        
	        // Redirect to proper pages
	        // ............................................
	        else if(PHPRC_FSO_FILE::REF_EXISTS('index.php', PHPSET::$ROOT . '/Server/' . $PHPDIR_URI) === True)
	        {
	            if
	            (
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "/" &&
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "\\"
	            )
	            {
	                $PHPDIR_URI = $PHPDIR_URI . "/";
	            }
	            
	            include PHPSET::$ROOT . '/Server/' . $PHPDIR_URI . 'index.php';
	        }

	        // Redirect to proper pages
	        // ............................................
	        else if(PHPRC_FSO_FILE::REF_EXISTS('index.php', PHPSET::$ROOT . '/Server/' . $PHPDIR_URI) === True)
	        {
	            if
	            (
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "/" &&
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "\\"
	                )
	            {
	                $PHPDIR_URI = $PHPDIR_URI . "/";
	            }
	            
	            include PHPSET::$ROOT . '/Server/' . $PHPDIR_URI . 'index.php';
	        }
	        
	        // Show 404 not dound response
	        // ............................................
	        else
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	        }
	    }
	    
	    
	    // [ Config / index.php ]
	    //=========================================================
	    Public Static function LOAD_CONFIG($PHPDIR_URI)
	    {
	        // Display home
	        // ............................................
	        if(StrLen($PHPDIR_URI) <= 0)
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	            Exit;
	        }
	        
	        // Load as DGV Calculation [Code name(10) + .js(3)]
	        // ............................................
	        else if
	        (
	            StrLen($PHPDIR_URI) >= 10 + 3 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 8) == "dgvcalc/"
	        )
	        {
	            include PHPSET::$ROOT . '/Server/Category/customize/ini_dgvcalc/index.php';
	        }

	        // Load as DGV Column Reorder
	        // ............................................
	        else if
	        (
	            StrLen($PHPDIR_URI) >= 10 + 3 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 11) == "dgvreorder/"
	            )
	        {
	            include PHPSET::$ROOT . '/Server/Category/customize/ini_dgvreorder/index.php';
	        }
	        
	        // Load as ShowHide
	        // ............................................
	        else if
	        (
	            StrLen($PHPDIR_URI) >= 9 + 3 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 9) == "showhide/"
	        )
	        {
	            include PHPSET::$ROOT . '/Server/Category/customize/ini_showhide/index.php';
	        }
	        
	        // Load as ReCaption
	        // ............................................
	        else if
	        (
	            StrLen($PHPDIR_URI) >= 10 + 3 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 10) == "recaption/"
	        )
	        {
	            include PHPSET::$ROOT . '/Server/Category/customize/ini_recaption/index.php';
	        }
	   
	        // Load as Customizer
	        // ............................................
	        else if
	        (
	            StrLen($PHPDIR_URI) >= 11 + 3 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 11) == "customizer/"
	        )
	        {
	            include PHPSET::$ROOT . '/Server/Category/customize/ini_customizer/index.php';
	        }
			
	        // Show 404 not dound response
	        // ............................................
	        else
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	        }
	    }
	    
	    
	    // [ Pages / Directory.php ]
	    //=========================================================
	    Public Static function LOAD_PAGES($PHPDIR_URI)
	    {
	        // Display home
	        // ............................................
	        $FILE_NAME = Basename($PHPDIR_URI);
	        $FILE_PATH = '/Pages/' . PHPVC_STR::VAR_REPLACE($PHPDIR_URI, $FILE_NAME, '');
	        $FILE_EXTENTION = PathInfo($FILE_NAME, PATHINFO_EXTENSION);
	        
	        // Custom: Load from any image extension
	        // ............................................
	        if(StrToUpper($FILE_EXTENTION) == "IMG")
	        {
	            if(PHPVC_STR::VAR_CONTAINS_RIGHT($FILE_PATH , '/'))
	            {
	                PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . $FILE_NAME);
	            }
	            else
	            {
	                PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME);
	            }
	        }
	        
	        // Redirect to proper pages
	        // ............................................
	        if(PHPRC_FSO_FILE::REF_EXISTS($FILE_NAME, PHPSET::$ROOT . $FILE_PATH) === True)
	        {
	            // Do not allow access to Page/import folder
	            if(PHPVC_STR::VAR_CONTAINS_LEFT($FILE_PATH, '/Pages/import'))
	            {
	                PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	                Exit();
	            }
	            
	            // Load Image
	            PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);

	            // Load Font
	            PHPRC_HEADERS::REF_FONT(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);
	            
	            // Load Media
	            PHPRC_HEADERS::REF_MEDIA(PHPSET::$ROOT . $FILE_PATH . $FILE_NAME, $FILE_NAME, true);
	            
	            // Load Document
	            PHPRC_HEADERS::REF_DOCUMENT(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);
	            
	            // Load Scripts
	            $FILE_CONTENTS = PHPRC_FSO_FILE::REF_READALL($FILE_NAME, PHPSET::$ROOT . $FILE_PATH);
	            $FILE_CONTENTS = PHPVC_COMPILER::REF_PROCESS_SCRIPT($FILE_CONTENTS, False);
	            
	            // HTML
	            if
	            (
	                StrToUpper($FILE_EXTENTION) == "HTML" ||
	                StrToUpper($FILE_EXTENTION) == "HTM"
	            )
	            {
	                echo $FILE_CONTENTS;
	                Exit();
	            }
	            
	            // CSS
	            elseif(StrToUpper($FILE_EXTENTION) == "CSS")
	            {
	                Header("Content-type: text/css");
	                echo $FILE_CONTENTS;
	                Exit();
	            }
	            
	            // JS
	            elseif(StrToUpper($FILE_EXTENTION) == "JS")
	            {
	                Header("Content-Type: application/javascript");
	                echo $FILE_CONTENTS;
	                Exit();
	            }      
	        }
	        
	        // Show 404 not dound response
	        // ............................................
	        else
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	        }        
	    }
	    

	    // [ index.php ]
	    //=========================================================
	    Public Static function LOAD_INDEX($PHPDIR_URI)
	    {
	        // Load Pages
	        // ............................................
	        if(StrLen($PHPDIR_URI) >= 2 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 2) == "p/")
	        {
	            if(StrLen($PHPDIR_URI) == 2)
	            {
	                PHPRC_HEADERS::REF_301_MOVED_PERMANENTLY(PHPSET::$SITE_URL . '/p/index.html');
	            }
	            $PHPDIR_URI = PHPVC_STR::VAR_RIGHT($PHPDIR_URI, StrLen($PHPDIR_URI) - 2);
	            self::LOAD_PAGES($PHPDIR_URI);
	        }

	        // Load Configurations
	        // ............................................
	        else if(StrLen($PHPDIR_URI) >= 4 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 4) == "ini/")
	        {
	            self::LOAD_CONFIG(PHPVC_STR::VAR_DLEFT($PHPDIR_URI, 4));
	        }
	        
	        // Load Plesk admin page
	        // ............................................
	        else if
	        (
	            $PHPDIR_URI == "plesk" ||
	            (StrLen($PHPDIR_URI) >= 6 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 6) == "plesk/")
	            )
	        {
	            header("Location: " . PHPSET::$SITE_URL . ":8443");
	        }
	        
	        // Load Server php files
	        // ............................................
	        else
	        {
	            self::LOAD_SERVER($PHPDIR_URI);
	        }
	        
	        // Terminate Request
	        // ............................................
	        exit(); 
	    }
	    
	}
	
	
	// Run directory control
	// -----------------------------------------------------
	PHPDIR::LOAD_INDEX($URI);
	
?>