/**
* The required files
*/
if (defined('HTML_BASE_PAGE_PATH')) {
require_once(HTML_BASE_PAGE_PATH.'/Meta.php');
require_once(HTML_BASE_UTIL_PATH.'/Htmlspecialchars.php');
}
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
if (defined('HTML_BASE_UTIL_PATH')) {
require_once(HTML_BASE_UTIL_PATH.'/Link.php');
}
/**
* Redirect to the specified url.
* If the headers are already sent,
* try to use the html meta HttpEquip refresh tag
* Note: It is your responsibility to get the html, print it and then exit
* <code>
* Usage:
* $redirect = new Redirect();
* $html = $redirect->go($url,$params,$time);
* print $html; // Print the Redirect message text
* exit; // Skip further data processing
* Or
* $html = Redirect::go($url,$params,$time);
* print $html; // Print the Redirect message text
* exit; // Skip further data processing
* </code>
* @package basic
*/
class Redirect {
/**
* Constructor
*/
function Redirect() {
}
/**
* Go to the specified url.
* The url and the params are checked for any '?' characters
* @param String $url The url to redirect to
* @param String $params The params to append, no leading '?' or '&'
* @param String $time The time to redirect in seconds
* @return String the html
*/
function go($url='',$params='',$time='') {
$html = '';
$theTime = $time!=''?$time:REDIRECT_TIME;
$theUrl = $url!=''?$url:$_SERVER['PHP_SELF'];
if ($params!='') {
// Does the url already contain a '?'
if (strpos( $theUrl,'?')!==false) {
$theUrl .= '&'.$params;
} else {
// Does the params already contain a '?'
if (strpos( $params,'?')!==false) {
$theUrl .= $params; // already a '?'
} else {
$theUrl .= '?'.$params;
}
}
}
$filename = '';
$lineno = '';
$html .= "<html><head>\r\n";//die($html);
if (headers_sent($filename, $lineno)) {
/**
* If the url does not coantain 'http: //'
* Then assume that the $url is a relative path then set $url = httphost + $url
*/
if (strpos( $theUrl,'http:/'.'/')===false) {
// Does the url already contain a '/'
if (strpos( $theUrl,'/')!==false) {
// Ignore
} else {
$theUrl = '/'.$theUrl;
}
$theUrl = 'http:/'.'/'.$_SERVER['HTTP_HOST'].$theUrl;
}
$msg = TEXT_REDIRECT_HEADERS_ARE_SENT." see $filename, $lineno";
if (defined('HTML_LOG_UTIL_PATH')) {
Log::info(__FILE__,__LINE__,$msg);
}
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$html .= "<!-- Redirect::go($url,$params) $msg -->\r\n";
}
if (defined('HTML_BASE_PAGE_PATH')) {
$link = new Link(LINK_TEXT_CLICK_HERE,$theUrl,'',LINK_TITLE_CLICK_HERE);
$meta = new Meta();
$meta->setHttpEquiv(META_HTTP_EQUIV_REFRESH, "$theTime;URL=$theUrl", META_SHOW_HTTP_EQUIV_EXPIRES);
$refresh = $meta->getHttpEquiv(META_HTTP_EQUIV_REFRESH, META_SHOW_HTTP_EQUIV_EXPIRES);
/**
* Work-around for the headers_sent()
* <meta HttpEquiv="refresh" content="$time;URL=$url" />
*/
$html .= "$refresh\r\n";
$html .= $link->getHtml()."<br />\r\n";
} else {
$html .= "<!-- No Base package -->\r\n";
$html .= '<meta http-equiv="refresh" content="'.$theTime.';URL='.$theUrl.'" ></meta>'."\r\n";
$html .= '<a class="" href="'.$theUrl.'" title="'.LINK_TITLE_CLICK_HERE.'">'.LINK_TEXT_CLICK_HERE."</a><br />\r\n";
}
$html .= "<!-- $msg -->\r\n";
} else {
// 2008-03-23 CMS
header("Location: $theUrl");
//header("Refresh: $theTime;url=$theUrl");
$html .= TEXT_REDIRECT_UPDATING_PLEASE_WAIT;
$msg = "Redirect.go() Time: $theTime Url: $theUrl";
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$html .= "header(Refresh: $theTime;url=$theUrl)<br />\r\n";
$html .= "$url<br />\r\n";
foreach ($_POST as $key=>$value) {
if ($key=='password' || (defined('SELECT_LOGIN_PASSWORD') && $key==SELECT_LOGIN_PASSWORD) || (defined('REQUEST_CMS_PASSWORD') && $key==REQUEST_CMS_PASSWORD)) {
$html .= "$key=********<br />\r\n";
} else {
$html .= "$key=".Htmlspecialchars::encode(stripslashes($value))."<br />\r\n";
}
}
$html .= "<br />$msg\r\n";
} else {
$html .= "<br /><!-- $msg -->\r\n";
}
}
$html .= "</head></html>\r\n";
return $html;
}
/**
* Get the html code
* @return String The html code
*/
function getHtml() {
return "No html code";
}
}
?>