65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* functions/redirect.php
|
|
*
|
|
* This class is used for header modification and page redirection.
|
|
*
|
|
* @version 1.0.5
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com/libraries/Hermes
|
|
* @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' );
|
|
}
|
|
}
|