2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
26 /** The x.org version */
27 public $version = '@VERSION@';
29 public $mode = 'rw'; // 'rw' => read/write,
34 public $dbdb = 'x4dat';
35 public $dbhost = 'localhost';
36 public $dbuser = 'x4dat';
37 public $dbpwd = 'x4dat';
38 public $dbcharset = 'utf8';
42 public $register_skin;
52 public function __construct($sess)
54 $this->session
= $sess;
55 $this->spoolroot
= dirname(dirname(__FILE__
));
58 if (isset($_SERVER) && isset($_SERVER['SERVER_NAME'])) {
59 $base = empty($_SERVER['HTTPS']) ?
'http://' : 'https://';
60 $this->baseurl
= @trim
($base .$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
61 $this->baseurl_http
= @trim
('http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']), '/');
67 private function read_ini_file($filename)
69 $array = parse_ini_file($filename, true
);
70 if (!is_array($array)) {
73 foreach ($array as $cat => $conf) {
74 $c = strtolower($cat);
75 foreach ($conf as $k => $v) {
76 if ($c == 'core' && property_exists($this, $k)) {
79 if (!isset($this->$c)) {
80 $this->$c = new stdClass
;
88 private function read_config()
90 $this->read_ini_file($this->spoolroot
.'/configs/platal.ini');
91 $this->read_ini_file($this->spoolroot
.'/configs/platal.conf');
92 if (file_exists($this->spoolroot
.'/spool/conf/platal.dynamic.conf')) {
93 $this->read_ini_file($this->spoolroot
.'/spool/conf/platal.dynamic.conf');
97 /** Writes an ini file separated in categories
98 * @param filename the name of the file to write (overwrite existing)
99 * @param categories an array of categories (array of keys and values)
101 private static function write_ini_file($filename, &$categories)
105 $f = fopen($filename, 'w');
106 foreach ($categories as $cat => $conf) {
107 fwrite($f, '; {{{ '.$cat."\n\n");
108 fwrite($f, '['.$cat.']'."\n\n");
109 foreach ($conf as $k => $v) {
110 fwrite($f, $k.' = "'.str_replace('"','\\"',$v).'"'."\n");
112 fwrite($f, "\n".'; }}}'."\n");
114 fwrite($f, '; vim:set syntax=dosini foldmethod=marker:'."\n");
118 /** Change dynamic config file
119 * @param conf array of keys and values to add or replace
120 * @param category name of category to change
122 * Opens the dynamic conf file and set values from conf in specified
123 * category. Updates config vars too.
125 public function change_dynamic_config($conf, $category = 'Core')
127 $dynamicfile = $this->spoolroot
.'/spool/conf/platal.dynamic.conf';
128 if (file_exists($dynamicfile)) {
129 $array = parse_ini_file($dynamicfile, true
);
133 if (!is_array($array)) {
134 // dynamic conf is empty
135 $array = array($category => $conf);
137 // looks for a category that looks the same (case insensitive)
139 foreach ($array as $m => &$c) {
140 if (strtolower($m) == strtolower($category)) {
146 // this category doesn't exist yet
147 $array[$category] = $conf;
149 // this category already exists
150 $conflower = array();
151 foreach ($conf as $k => $v) {
152 $conflower[strtolower($k)] = $v;
154 // $conflower is now same as $conf but with lower case keys
155 // replaces values of keys that already exists
156 foreach ($array[$same] as $k => $v) {
157 if (isset($conflower[strtolower($k)])) {
158 $array[$same][$k] = $conflower[strtolower($k)];
159 unset($conflower[strtolower($k)]);
163 foreach ($conf as $k => $v) {
164 if (isset($conflower[strtolower($k)])) {
165 $array[$same][$k] = $v;
170 // writes the file over
171 PlatalGlobals
::write_ini_file($dynamicfile, $array);
172 // rereads the new config to correctly set vars
173 $this->read_ini_file($dynamicfile);
176 public function bootstrap($conf, $callback, $category = 'Core')
179 $category = strtolower($category);
180 foreach ($conf as $key) {
181 if (!isset($this->$category->$key)) {
187 call_user_func($callback);
191 private function setlocale()
193 setlocale(LC_MESSAGES
, $this->locale
);
194 setlocale(LC_TIME
, $this->locale
);
195 setlocale(LC_CTYPE
, $this->locale
);
196 date_default_timezone_set($this->timezone
);
197 mb_internal_encoding("UTF-8");
200 public function asso($key=null
)
206 if ($p = strpos($gp, '/')) {
207 $gp = substr($gp, 0, $p);
211 $res = XDB
::query('SELECT a.*, d.nom AS domnom,
212 FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc,
213 FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub
214 FROM groupex.asso AS a
215 LEFT JOIN groupex.dom AS d ON d.id = a.dom
216 WHERE diminutif = {?}', $gp);
217 if (!($aid = $res->fetchOneAssoc())) {
226 } elseif ( isset($aid[$key]) ) {
234 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: