source: trunk/include/common.inc.php @ 364

Last change on this file since 364 was 364, checked in by gweltas, 20 years ago

Split of langage files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                            common.inc.php                             |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-02-19 00:31:09 +0000 (Thu, 19 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 364 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27if( !defined("PHPWG_ROOT_PATH") )
28{
29        die ("Hacking attempt!");
30}
31// determine the initial instant to indicate the generation time of this page
32$t1 = explode( ' ', microtime() );
33$t2 = explode( '.', $t1[0] );
34$t2 = $t1[1].'.'.$t2[1];
35
36set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
37
38//
39// addslashes to vars if magic_quotes_gpc is off this is a security
40// precaution to prevent someone trying to break out of a SQL statement.
41//
42if( !get_magic_quotes_gpc() )
43{
44  if( is_array( $_GET ) )
45  {
46    while( list($k, $v) = each($_GET) )
47    {
48      if( is_array($_GET[$k]) )
49      {
50        while( list($k2, $v2) = each($_GET[$k]) )
51        {
52          $_GET[$k][$k2] = addslashes($v2);
53        }
54        @reset($_GET[$k]);
55      }
56      else
57      {
58        $_GET[$k] = addslashes($v);
59      }
60    }
61    @reset($_GET);
62  }
63 
64  if( is_array($_POST) )
65  {
66    while( list($k, $v) = each($_POST) )
67    {
68      if( is_array($_POST[$k]) )
69      {
70        while( list($k2, $v2) = each($_POST[$k]) )
71        {
72          $_POST[$k][$k2] = addslashes($v2);
73        }
74        @reset($_POST[$k]);
75      }
76      else
77      {
78        $_POST[$k] = addslashes($v);
79      }
80    }
81    @reset($_POST);
82  }
83
84  if( is_array($_COOKIE) )
85  {
86    while( list($k, $v) = each($_COOKIE) )
87    {
88      if( is_array($_COOKIE[$k]) )
89      {
90        while( list($k2, $v2) = each($_COOKIE[$k]) )
91        {
92          $_COOKIE[$k][$k2] = addslashes($v2);
93        }
94        @reset($_COOKIE[$k]);
95      }
96      else
97      {
98        $_COOKIE[$k] = addslashes($v);
99      }
100    }
101    @reset($_COOKIE);
102  }
103}
104
105//
106// Define some basic configuration arrays this also prevents malicious
107// rewriting of language and otherarray values via URI params
108//
109$conf = array();
110$page = array();
111$user = array();
112$lang = array();
113
114
115include(PHPWG_ROOT_PATH .'config.php');
116if( !defined("PHPWG_INSTALLED") )
117{
118  header( 'Location: install.php' );
119  exit;
120}
121
122
123include(PHPWG_ROOT_PATH . 'include/constants.php');
124include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
125include(PHPWG_ROOT_PATH . 'include/template.php');
126include(PHPWG_ROOT_PATH . 'include/vtemplate.class.php');
127include(PHPWG_ROOT_PATH . 'include/config.inc.php');
128
129//
130// Database connection
131//
132
133mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
134or die ( "Could not connect to server" );
135mysql_select_db( $cfgBase )
136or die ( "Could not connect to database" );
137       
138//
139// Obtain and encode users IP
140//
141if ( getenv( 'HTTP_X_FORWARDED_FOR' ) != '' )
142{
143  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
144
145  if ( preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",
146                  getenv('HTTP_X_FORWARDED_FOR'), $ip_list) )
147  {
148    $private_ip = array( '/^0\./'
149                         ,'/^127\.0\.0\.1/'
150                         ,'/^192\.168\..*/'
151                         ,'/^172\.16\..*/'
152                         ,'/^10.\.*/'
153                         ,'/^224.\.*/'
154                         ,'/^240.\.*/'
155      );
156    $client_ip = preg_replace($private_ip, $client_ip, $ip_list[1]);
157  }
158}
159else
160{
161  $client_ip = ( !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : ( ( !empty($_ENV['REMOTE_ADDR']) ) ? $_ENV['REMOTE_ADDR'] : $REMOTE_ADDR );
162}
163$user_ip = encode_ip($client_ip);
164
165//
166// Setup forum wide options, if this fails then we output a CRITICAL_ERROR
167// since basic forum information is not available
168//
169$sql = 'SELECT * FROM '.CONFIG_TABLE;
170if( !($result = mysql_query($sql)) )
171{
172  die("Could not query config information");
173}
174
175$row =mysql_fetch_array($result);
176// rertieving the configuration informations for site
177// $infos array is used to know the fields to retrieve in the table "config"
178// Each field becomes an information of the array $conf.
179// Example :
180//            prefix_thumbnail --> $conf['prefix_thumbnail']
181$infos = array( 'prefix_thumbnail', 'webmaster', 'mail_webmaster', 'access',
182                'session_id_size', 'session_keyword', 'session_time',
183                'max_user_listbox', 'show_comments', 'nb_comment_page',
184                'upload_available', 'upload_maxfilesize', 'upload_maxwidth',
185                'upload_maxheight', 'upload_maxwidth_thumbnail',
186                'upload_maxheight_thumbnail','log','comments_validation',
187                'comments_forall','authorize_cookies','mail_notification' );
188// affectation of each field of the table "config" to an information of the
189// array $conf.
190foreach ( $infos as $info ) {
191  if ( isset( $row[$info] ) ) $conf[$info] = $row[$info];
192  else                        $conf[$info] = '';
193  // If the field is true or false, the variable is transformed into a boolean
194  // value.
195  if ( $conf[$info] == 'true' or $conf[$info] == 'false' )
196  {
197    $conf[$info] = get_boolean( $conf[$info] );
198  }
199}
200
201//---------------
202// A partir d'ici il faudra dispatcher le code dans d'autres fichiers
203//---------------
204
205include(PHPWG_ROOT_PATH . 'include/user.inc.php');
206
207// displaying the username in the language of the connected user, instead of
208// "guest" as you can find in the database
209if ( $user['is_the_guest'] ) $user['username'] = $lang['guest'];
210include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' );
211define('PREFIX_TABLE', $table_prefix);
212?>
Note: See TracBrowser for help on using the repository browser.