source: branches/rsr.v5.1/web/app/env.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 5.2 KB
RevLine 
[1]1<?php
2
3  class env
4  {
5    public $config_file;
6    public $PATHES;
7    public $PARAMS;
8    public $CONFIG;
9    public $prefix;
10    public $additional_get_params;
11    public $bdd;
12    public $acces;
13    public $mod_path;
14
15    function __construct($config_file, $path_prefix = "")
16    { $this->mod_path = "";
17      $this->config_file = $config_file;
18      if(file_exists($config_file))
19      { $this->PATHES = array();
20        $this->bdd = array();
21        $this->CONFIG = array();
22        require $config_file;
23        if(file_exists($this->path("app")."config.xml"))
24        { $app_config = simplexml_load_file($this->path("app")."config.xml");
25          foreach($app_config->pathes[0] as $path_name => $path_value)
26          { $this->PATHES[$path_name] = $this->path("app").utf8_decode($path_value);
27          }
28          $this->PATHES["punbb"] = str_replace("app/../", "", $this->PATHES["punbb"]);
29          $this->PARAMS = array();
30          foreach($app_config->params[0] as $code_param => $get_param)
31          { $this->PARAMS[$code_param] = utf8_decode($get_param);
32          }
33          $this->init_additional_get_params();
34          $this->prefix = utf8_decode($app_config->prefix);
35          $this->bdd["prefix_code"] = utf8_decode($app_config->sql_prefix);
36        }
37        else
38        { echo "[erreur] config : impossible de trouver le fichier de configuration pour l'application";
39          exit();
40        }
41      }
42      else
43      { echo "[erreur] config : impossible de trouver le fichier de configuration pour l'installation";
44        exit();
45      }
46    }
47
48    function set_config($config)
49    { if(is_array($config))
50      { foreach($config as $key => $value) $this->CONFIG[$key] = $value;
51        return true;
52      }
53      return false;
54    }
55
56    function init_additional_get_params()
57    { $this->additional_get_params = array();
58      $_params = $_SERVER["QUERY_STRING"];
59      $v_params = explode("&", $_params);
60      foreach($v_params as $param)
61      { if($param)
62        { $key = strpos($param, "=") === false ? $param : substr($param, 0, strpos($param, "="));
63          $value = strpos($param, "=") === false ? "" : substr($param, strpos($param, "=") + 1);
64          if(!$this->is_a_param($key)) $this->additional_get_params[$key] = $value;
65        }
66      }
67    }
68
69    function is_a_param($key)
70    { foreach($this->PARAMS as $_key => $_value) if(strcmp($key, $_value) == 0) return true;
71      return false;
72    }
73
74    function path($name) { return $this->PATHES[$name]; }
75    function param($name) { return $this->PARAMS[$name]; }
76    function config($name) { return $this->CONFIG[$name]; }
77
78    function url($_params, $script_name = "index.php", $_url = "")
79    { if($_url)
80      { if
81        ( strpos($_url, "http://") === 0  ||
82          strpos($_url, "https://") === 0 ||
83          strpos($_url, "ftp://") === 0
84        ) $url = $_url;
85        else $url = $this->path("web").$_url;
86      }
87      elseif($_params)
88      { $get_params = "";
89        foreach($this->additional_get_params as $key => $value) $get_params .= ($get_params ? "&amp;" : "?").$key."=".$value;
90        foreach($_params as $key => $value) $get_params .= ($get_params ? "&amp;" : "?").$this->param($key)."=".$value;
91        $url = $this->path("web").$script_name.$get_params;
92      }
93      return $url;
94    }
95
96    function out_file_exists($file)
97    { return
98      ( $this->config("out") ?
99          file_exists($this->config("out").$file) ||
100          file_exists($this->path("out").$file) ||
101          file_exists($this->path("dist_out").$file)
102        : file_exists($this->path("out").$file) ||
103          file_exists($this->path("dist_out").$file)
104      );
105    }
106
107    function out_file($file)
108    { return
109      ( $this->config("out") ?
110          ( file_exists($this->config("out").$file) ?
111              $this->config("out").$file
112            : ( file_exists($this->path("out").$file) ?
113                  $this->path("out").$file
114                : (file_exists($this->path("dist_out").$file) ? $this->path("dist_out").$file : $file)
115              )
116          )
117        : ( file_exists($this->path("out").$file) ?
118              $this->path("out").$file
119            : (file_exists($this->path("dist_out").$file) ? $this->path("dist_out").$file : $file)
120          )
121      );
122    }
123
124    function aff_content()
125    { $env = $this;
126      if($env->message) require $env->out_file("views/message.php");
127      if($env->out_file_exists("content/".$env->prefix.$env->e.".php"))
128      { require $env->out_file("content/".$env->prefix.$env->e.".php");
129      }
130    }
131
132    function aff_emplacement($emplacement)
133    { $env = $this;
134      if($env->out["blocs"]["list"]) foreach($env->out["blocs"]["list"] as $id_bloc => $bloc)
135      { if($bloc["emplacement"] == $emplacement)
136        { $env->out["bloc"] = $bloc;
137          $env->_aff_bloc();
138        }
139      }
140    }
141
142    function aff_bloc($bloc)
143    { $env = $this;
144      if($env->out["blocs"]["list"]) foreach($env->out["blocs"]["list"] as $id_bloc => $_bloc)
145      { if(is_int($bloc) ? $id_bloc == $bloc : $_bloc["nom"] == $bloc)
146        { $env->out["bloc"] = $env->out["blocs"]["list"][$id_bloc];
147          $env->_aff_bloc();
148        }
149      }
150    }
151
152    function _aff_bloc()
153    { $env = $this;
154      require $env->out_file("views/bloc.php");
155    }
156
157  }
158
159?>
Note: See TracBrowser for help on using the repository browser.