forked from galenandrew/php-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* URL Request Utility | ||
* | ||
* @description Functions to help with URL Requests | ||
*/ | ||
|
||
class URLRequest extends Utility { | ||
|
||
//---> Parses Sub Page Requests | ||
public static function get_sub_request_array() | ||
{ | ||
//---> Multi Sub-Page Exists | ||
$sub_reqs_array = explode('/', REQ_PAGE_SUB); | ||
|
||
return $sub_reqs_array; | ||
} | ||
|
||
//---> Parses Sub Page Requests | ||
public static function get_last_sub_request() | ||
{ | ||
//---> Multi Sub-Page Exists | ||
$sub_reqs_array = $this->get_sub_request_array(); | ||
|
||
return array_pop($sub_reqs_array); | ||
} | ||
|
||
//---> Parses Sub Page Requests | ||
public static function get_first_sub_request() | ||
{ | ||
//---> Multi Sub-Page Exists | ||
$sub_reqs_array = $this->get_sub_request_array(); | ||
|
||
return array_shift($sub_reqs_array); | ||
} | ||
|
||
//---> Total # of Sub Page Requests | ||
public static function get_total_sub_request($array = FALSE) | ||
{ | ||
//---> Multi Sub-Page Exists | ||
$sub_reqs_array = !$array ? $this->get_sub_request_array() : $array; | ||
|
||
return count($sub_reqs_array); | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* General Utility | ||
* | ||
* @description General utility functions | ||
*/ | ||
|
||
class Utility { | ||
|
||
//---> Parse URL String to Words | ||
public static function to_words($string, $delimiter = '-') | ||
{ | ||
return ucwords(str_replace($delimiter, ' ', $string)); | ||
} | ||
|
||
//---> Validates form data by data type | ||
public static function validate_data_by_type($data, $data_type='text') | ||
{ | ||
switch(strtolower($data_type)) { | ||
default: | ||
case 'text': | ||
return strlen(stripslashes($data)) <= 2 ? FALSE:TRUE; | ||
break; | ||
case 'name': | ||
return (preg_match('/^[a-zA-Z \.,-]+$/', $data) | ||
&& strlen(stripslashes($data)) >= 2) | ||
? TRUE : FALSE; | ||
break; | ||
case 'email': | ||
$isValid = true; | ||
$atIndex = strrpos($data, "@"); | ||
|
||
if (is_bool($atIndex) && !$atIndex) { | ||
$isValid = false; | ||
} else { | ||
$domain = substr($data, $atIndex+1); | ||
$local = substr($data, 0, $atIndex); | ||
$localLen = strlen($local); | ||
$domainLen = strlen($domain); | ||
|
||
// local part length exceeded | ||
if($localLen < 1 || $localLen > 64) { $isValid = false; } | ||
|
||
// domain part length exceeded | ||
else if($domainLen < 1 || $domainLen > 255) { $isValid = false; } | ||
|
||
// local part starts or ends with '.' | ||
else if($local[0] == '.' || $local[$localLen-1] == '.') { $isValid = false; } | ||
|
||
// local part has two consecutive dots | ||
else if(preg_match('/\\.\\./', $local)) { $isValid = false; } | ||
|
||
// character not valid in domain part | ||
else if(!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { $isValid = false; } | ||
|
||
// domain part has two consecutive dots | ||
else if (preg_match('/\\.\\./', $domain)) { $isValid = false; } | ||
|
||
// character not valid in local part unless local part is quoted | ||
else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { | ||
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } | ||
} | ||
// domain not found in DNS | ||
if($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { $isValid = false; } | ||
} | ||
return $isValid; | ||
break; | ||
case 'url': | ||
return (preg_match('/^(https?:\/\/)?((www\.)|([a-z0-9]+\.))?([a-zA-Z0-9_%\-]*)\b(\.[a-z]{2,4})(\.[a-z]{2})?([\/a-zA-Z0-9_%\?=\.&\-#!]+)?$/', $data)) | ||
? TRUE : FALSE; | ||
break; | ||
case 'phone': | ||
return (strlen(preg_replace("[\D]",'',$data)) == 10) ? TRUE : FALSE; | ||
break; | ||
case 'zip': | ||
return (strlen(preg_replace("[\D]",'',$data)) == 5) || (strlen(preg_replace("[\D]",'',$data)) == 10) ? TRUE : FALSE; | ||
break; | ||
} | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
/** | ||
* ------------------------------------------------------------ * | ||
* PAGE CONTROLLER - Home | ||
* ------------------------------------------------------------ * | ||
*/ | ||
|
||
define('IS_HOME', TRUE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters