0f745a708b2794024eaa1b9538eb47885d5b7622
[mtweb] / mw / env / modules / mw_env_urls.php
1 <?php
2
3   class mw_env_urls extends mw_env{
4
5     var $additional_get_params;
6
7     function init_additional_get_params(){
8       $this->additional_get_params = array();
9       $_params = $_SERVER["QUERY_STRING"];
10       $v_params = explode("&", $_params);
11       foreach($v_params as $param){
12         if($param){
13           $key = strpos($param, "=") === false ? $param : substr($param, 0, strpos($param, "="));
14           $value = strpos($param, "=") === false ? "" : substr($param, strpos($param, "=") + 1);
15           if(!$this->is_a_param($key)) $this->additional_get_params[$key] = $value;
16         }
17       }
18     }
19
20     function is_a_param($key){
21       foreach($this->get_PARAMS() as $_key => $_value) if(strcmp($key, $_value) == 0) return true;
22       return false;
23     }
24
25     function url($action = "", $_params = array(), $script_name = null){
26       $script_name = isset($script_name) ? $script_name : ($this->config("script_name") ? $this->config("script_name") : "index.php");
27       if($action) $_params["e"] = $action;
28       $get_params = "";
29       if(isset($this->additional_get_params)) foreach($this->additional_get_params as $key => $value) $get_params .= ($get_params ? "&amp;" : "?").$key."=".$value;
30       foreach($_params as $key => $value) $get_params .= ($get_params ? "&amp;" : "?").$this->param($key)."=".$value;
31       return $this->path("web").$script_name.$get_params;
32     }
33
34     function redirect($url, $message, $wait = 1){
35       $this->set_etat("reponses/html/redirect_javascript", false);
36       $this->set_out(
37         "redirect",
38         array(
39           "url" => str_replace("&amp;", "&", $url),
40           "message" => $message,
41           "wait" => $wait
42         )
43       );
44       if(!headers_sent()){
45         if($wait) header_remove("Location");
46         else header("Location: ".str_replace("&amp;", "&", $url));
47       }
48     }
49
50   }
51
52 ?>