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

Last change on this file since 2201 was 2201, checked in by rub, 16 years ago

Replace old use of $lang by l10n function.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: common.inc.php 2201 2008-01-30 22:07:07Z rub $
8// | last update   : $Date: 2008-01-30 22:07:07 +0000 (Wed, 30 Jan 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2201 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
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$header_msgs = array();
114$header_notes = array();
115$filter = array();
116
117@include(PHPWG_ROOT_PATH .'include/mysql.inc.php');
118if (!defined('PHPWG_INSTALLED'))
119{
120  header('Location: install.php');
121  exit;
122}
123
124foreach( array(
125  'array_intersect_key', //PHP 5 >= 5.1.0RC1
126  'hash_hmac', //(hash) - enabled by default as of PHP 5.1.2
127  ) as $func)
128{
129  if (!function_exists($func))
130  {
131    include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php');
132  }
133}
134
135include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
136@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
137include(PHPWG_ROOT_PATH . 'include/constants.php');
138include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
139include(PHPWG_ROOT_PATH . 'include/template.php');
140
141// Database connection
142mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
143or die ( "Could not connect to database server" );
144mysql_select_db( $cfgBase )
145or die ( "Could not connect to database" );
146
147defined('PWG_CHARSET') and defined('DB_CHARSET')
148  or die('PWG_CHARSET and/or DB_CHARSET is not defined');
149if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
150{
151  if (DB_CHARSET!='')
152  {
153    pwg_query('SET NAMES "'.DB_CHARSET.'"');
154  }
155}
156else
157{
158  if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
159  {
160    die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
161  }
162}
163
164//
165// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
166// since basic gallery information is not available
167//
168load_conf_from_db();
169load_plugins();
170
171include(PHPWG_ROOT_PATH.'include/user.inc.php');
172
173
174// language files
175load_language('common.lang');
176if (defined('IN_ADMIN') and IN_ADMIN)
177{
178  load_language('admin.lang');
179}
180trigger_action('loading_lang');
181load_language('local.lang');
182
183// only now we can set the localized username of the guest user (and not in
184// include/user.inc.php)
185if (is_a_guest())
186{
187  $user['username'] = l10n('guest');
188}
189
190// template instance
191if
192  (
193      defined('IN_ADMIN') and IN_ADMIN and
194      isset($user['admin_template']) and
195      isset($user['admin_theme'])
196  )
197{
198  // Admin template
199  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['admin_template'], $user['admin_theme'] );
200}
201else
202{
203  // Classic template
204  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] );
205}
206
207if (isset($user['internal_status']['guest_must_be_guest'])
208    and
209    $user['internal_status']['guest_must_be_guest'] === true)
210{
211  $header_msgs[] = l10n('guest_must_be_guest');
212}
213
214if ($conf['gallery_locked'])
215{
216  $header_msgs[] = l10n('gallery_locked_message');
217
218  if ( script_basename() != 'identification' and !is_admin() )
219  {
220    set_status_header(503, 'Service Unavailable');
221    @header('Retry-After: 900');
222    echo l10n('gallery_locked_message')
223      .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>';
224    exit();
225  }
226}
227
228if ($conf['check_upgrade_feed']
229    and defined('PHPWG_IN_UPGRADE')
230    and PHPWG_IN_UPGRADE)
231{
232
233  // retrieve already applied upgrades
234  $query = '
235SELECT id
236  FROM '.UPGRADE_TABLE.'
237;';
238  $applied = array_from_query($query, 'id');
239
240  // retrieve existing upgrades
241  $existing = get_available_upgrade_ids();
242
243  // which upgrades need to be applied?
244  if (count(array_diff($existing, $applied)) > 0)
245  {
246    $header_msgs[] = 'Some database upgrades are missing, '
247      .'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
248  }
249}
250
251if (is_adviser())
252{
253  $header_msgs[] = l10n('adviser_mode_enabled');
254}
255
256if (count($header_msgs) > 0)
257{
258  $template->assign_block_vars('header_msgs',array());
259  foreach ($header_msgs as $header_msg)
260  {
261    $template->assign_block_vars('header_msgs.header_msg',
262                                 array('HEADER_MSG'=>$header_msg));
263  }
264}
265
266if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
267{
268  include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php');
269  include(PHPWG_ROOT_PATH.'include/filter.inc.php');
270}
271else
272{
273  $filter['enabled'] = false;
274}
275
276if (isset($conf['header_notes']))
277{
278  $header_notes = array_merge($header_notes, $conf['header_notes']);
279}
280
281// default event handlers
282add_event_handler('render_category_literal_description', 'render_category_literal_description');
283add_event_handler('render_category_description', 'render_category_description');
284add_event_handler('render_comment_content', 'htmlspecialchars');
285add_event_handler('render_comment_content', 'parse_comment_content');
286add_event_handler('render_comment_author', 'strip_tags');
287trigger_action('init');
288?>
Note: See TracBrowser for help on using the repository browser.