<?php
Class URL_Parser {
/*
- @ Jon Holderman - Version 1.3 - 01/08/06
- @ Project Name: URL Parser
- @ hide@address.com
-
- There are two URL template types that can be used, one is used for non-subfolders
- the other is for subfolders when neecded. They both can be used together in one site
- as long as the format stays the same throughout.
-
- Type 1 (No Sublinks): dir/DIRECTORY_FOLDER/PAGE.EXT
- Type 2 (With Sublinks): dir/DIRECTORY_FOLDER/CHILD_FOLDER/PAGE.EXT
-
- The extension type is for easy integration for any site, or use of different file types
-
- || Main Argument Variables ||
-
- DIRECTORY_FOLDER = $dir
- CHILD_FOLDER = $child
- PAGE = $page
- EXT = $ext
-
- || Default Variables ||
-
- When a user first comes to the site he/she will have no URL variables set, so we need to make some for them
- so they have a page to look at
-
- DEFAULT_DIRECTORY = $dft_dir
- DEFAULT_PAGE = $dft_page
- DEFAULT_EXT = $dft_ext
-
- || Error Variables ||
-
- If the file that is checked does not exist and ERROR_CHECK is turned on it will send
- the user to a pre-selected error page. This is also a security setting to avoid URL Varaible injection
-
- ERROR_CHECK = $error_chk
- ERROR_DIR = $error_dir
- ERROR_PAGE = $error_page
- ERROR_EXT = $error_ext
-
- || Usage ||
<?php
// Be sure to add this to the very top of your pages, best before <html>
include_once('source/classes.php');
$url = new URL_Parser($dir = $_GET['dir'], $child = $_GET['child'], $page = $_GET['page'], $ext = "php");
// Where ever this line appears is where the contact will be placed.
include_once($url->URL_Construction());
?>
*/
var $dir; // Diretory of the Links
var $child; // The Child Folder [ If Applicable ]
var $page; // The Page to be called
var $ext; // Extension of the file type to be used
var $dft_dir; // Default directory to use
var $dft_page; // Default page to use
var $dft_ext; // Default extension to use
var $error_chk; // Error checking On or Off, 1 = On, 2 = Off
var $error_dir; // Error directory to be used
var $error_page; // Error Page to be shown
var $error_ext; // The file extension of the page to be shown
var $url; // URL Path
function URL_Parser($dir, $child, $page, $ext) {
$this->dir = $dir;
$this->child = $child;
$this->page = $page;
$this->ext = $ext;
$this->dft_dir = "community";
$this->dft_page = "home";
$this->dft_ext = "php";
$this->error_chk = 1;
$this->error_dir = "error";
$this->error_page = "index";
$this->error_ext = "php";
$this->url = $url;
}
function URL_Construction() {
# -- > CHECK DIR
if($this->dir == TRUE) {
// Do Nothing
} else {
// No dir variable set
$this->dir = $this->dft_dir;
}
# -- > CHECK PAGE
if($this->page == TRUE) {
// Do Nothing
} else {
// No page variable set
$this->page = $this->dft_page;
}
# -- > CHECK EXT
if($this->ext == TRUE) {
// Do Nothing
} else {
// No page variable set
$this->ext = $this->dft_ext;
}
# -- > CHECK CHILD
if($this->child == TRUE) {
// Use Child Template
$this->url = "dir/" . $this->dir . "/" . $this->child . "/" . $this->page . "." . $this->ext;
} else {
// Dont Use Child Template
$this->url = "dir/" . $this->dir . "/" . $this->page . "." . $this->ext;
}
# -- > CHECK FILE EXISTS
if(@file_exists($this->url)) {
// File Exists
return $this->url;
} else {
// File Doesnt Exist
if($this->error_chk == 1) {
$this->url = "dir/" . $this->error_dir . "/" . $this->error_page . "." . $this->error_ext;
return $this->url;
} else {
return $this->url;
}
}
}
}
?>