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

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

Resolved issue 0000712: PWG-ERROR-VERSION on remote synchronization

Merge branch-1_7 2211:2212 into BSF

  • 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: common.inc.php 2213 2008-02-16 13:27:50Z rub $
8// | last update   : $Date: 2008-02-16 13:27:50 +0000 (Sat, 16 Feb 2008) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2213 $
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  'preg_last_error', // PHP 5 >= 5.2.0
128  ) as $func)
129{
130  if (!function_exists($func))
131  {
132    include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php');
133  }
134}
135
136include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
137@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
138include(PHPWG_ROOT_PATH . 'include/constants.php');
139include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
140include(PHPWG_ROOT_PATH . 'include/template.php');
141
142// Database connection
143mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
144or die ( "Could not connect to database server" );
145mysql_select_db( $cfgBase )
146or die ( "Could not connect to database" );
147
148defined('PWG_CHARSET') and defined('DB_CHARSET')
149  or die('PWG_CHARSET and/or DB_CHARSET is not defined');
150if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
151{
152  if (DB_CHARSET!='')
153  {
154    pwg_query('SET NAMES "'.DB_CHARSET.'"');
155  }
156}
157else
158{
159  if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
160  {
161    die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
162  }
163}
164
165//
166// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
167// since basic gallery information is not available
168//
169load_conf_from_db();
170load_plugins();
171
172include(PHPWG_ROOT_PATH.'include/user.inc.php');
173
174
175// language files
176load_language('common.lang');
177if (defined('IN_ADMIN') and IN_ADMIN)
178{
179  load_language('admin.lang');
180}
181trigger_action('loading_lang');
182load_language('local.lang');
183
184// only now we can set the localized username of the guest user (and not in
185// include/user.inc.php)
186if (is_a_guest())
187{
188  $user['username'] = l10n('guest');
189}
190
191// template instance
192if
193  (
194      defined('IN_ADMIN') and IN_ADMIN and
195      isset($user['admin_template']) and
196      isset($user['admin_theme'])
197  )
198{
199  // Admin template
200  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['admin_template'], $user['admin_theme'] );
201}
202else
203{
204  // Classic template
205  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] );
206}
207
208if (isset($user['internal_status']['guest_must_be_guest'])
209    and
210    $user['internal_status']['guest_must_be_guest'] === true)
211{
212  $header_msgs[] = l10n('guest_must_be_guest');
213}
214
215if ($conf['gallery_locked'])
216{
217  $header_msgs[] = l10n('gallery_locked_message');
218
219  if ( script_basename() != 'identification' and !is_admin() )
220  {
221    set_status_header(503, 'Service Unavailable');
222    @header('Retry-After: 900');
223    echo l10n('gallery_locked_message')
224      .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>';
225    exit();
226  }
227}
228
229if ($conf['check_upgrade_feed']
230    and defined('PHPWG_IN_UPGRADE')
231    and PHPWG_IN_UPGRADE)
232{
233
234  // retrieve already applied upgrades
235  $query = '
236SELECT id
237  FROM '.UPGRADE_TABLE.'
238;';
239  $applied = array_from_query($query, 'id');
240
241  // retrieve existing upgrades
242  $existing = get_available_upgrade_ids();
243
244  // which upgrades need to be applied?
245  if (count(array_diff($existing, $applied)) > 0)
246  {
247    $header_msgs[] = 'Some database upgrades are missing, '
248      .'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
249  }
250}
251
252if (is_adviser())
253{
254  $header_msgs[] = l10n('adviser_mode_enabled');
255}
256
257if (count($header_msgs) > 0)
258{
259  $template->assign_block_vars('header_msgs',array());
260  foreach ($header_msgs as $header_msg)
261  {
262    $template->assign_block_vars('header_msgs.header_msg',
263                                 array('HEADER_MSG'=>$header_msg));
264  }
265}
266
267if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
268{
269  include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php');
270  include(PHPWG_ROOT_PATH.'include/filter.inc.php');
271}
272else
273{
274  $filter['enabled'] = false;
275}
276
277if (isset($conf['header_notes']))
278{
279  $header_notes = array_merge($header_notes, $conf['header_notes']);
280}
281
282// default event handlers
283add_event_handler('render_category_literal_description', 'render_category_literal_description');
284add_event_handler('render_category_description', 'render_category_description');
285add_event_handler('render_comment_content', 'htmlspecialchars');
286add_event_handler('render_comment_content', 'parse_comment_content');
287add_event_handler('render_comment_author', 'strip_tags');
288trigger_action('init');
289?>
Note: See TracBrowser for help on using the repository browser.