init
This commit is contained in:
64
functions/redirect.php
Normal file
64
functions/redirect.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* functions/redirect.php
|
||||
*
|
||||
* This class is used for header modification and page redirection.
|
||||
*
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com/Core
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Hermes\Functions;
|
||||
|
||||
class Redirect {
|
||||
/**
|
||||
* The main redirect function. This will automatically call the
|
||||
* error controller if the value passed to it is numerical. It will
|
||||
* automatically populate the url based on the config and add the
|
||||
* $data string at the end
|
||||
*
|
||||
* @param string|int $data - The desired redirect location (string for location and integer for error page).
|
||||
*/
|
||||
public static function to( $data ) {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
if ( is_numeric( $data ) ) {
|
||||
header( 'Location: ' . Route::getAddress() . 'Errors/' . $data );
|
||||
}
|
||||
$url = Route::getAddress() . $data;
|
||||
if ( filter_var( $url, FILTER_VALIDATE_URL ) != false ) {
|
||||
header( 'Location: ' . $url );
|
||||
}
|
||||
}
|
||||
|
||||
public static function home() {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
header( 'Location: ' . Route::getAddress() );
|
||||
}
|
||||
|
||||
public static function external( $data ) {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
return;
|
||||
}
|
||||
$url = filter_var( $data, FILTER_SANITIZE_URL );
|
||||
if ( filter_var( $url, FILTER_VALIDATE_URL ) != false ) {
|
||||
header( 'Location: ' . $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the current page.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function reload() {
|
||||
if ( ! HERMES_REDIRECTS_ENABLED ) {
|
||||
exit();
|
||||
}
|
||||
header( 'Refresh:0' );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user