source: branches/branch-1_7/include/common.inc.php @ 2177

Last change on this file since 2177 was 2118, checked in by rvelices, 17 years ago
  • merge r 2117 from trunk (render_category_description and render_category_literal_description events refactoring)
  • fix admin multiview plugin
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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// | branch        : BSF (Best So Far)
8// | file          : $Id: common.inc.php 2118 2007-10-02 05:42:22Z rvelices $
9// | last update   : $Date: 2007-10-02 05:42:22 +0000 (Tue, 02 Oct 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 2118 $
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// +-----------------------------------------------------------------------+
27
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die('Hacking attempt!');
31}
32// determine the initial instant to indicate the generation time of this page
33$t1 = explode( ' ', microtime() );
34$t2 = explode( '.', $t1[0] );
35$t2 = $t1[1].'.'.$t2[1];
36
37set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
38
39//
40// addslashes to vars if magic_quotes_gpc is off this is a security
41// precaution to prevent someone trying to break out of a SQL statement.
42//
43if( !get_magic_quotes_gpc() )
44{
45  if( is_array( $_GET ) )
46  {
47    while( list($k, $v) = each($_GET) )
48    {
49      if( is_array($_GET[$k]) )
50      {
51        while( list($k2, $v2) = each($_GET[$k]) )
52        {
53          $_GET[$k][$k2] = addslashes($v2);
54        }
55        @reset($_GET[$k]);
56      }
57      else
58      {
59        $_GET[$k] = addslashes($v);
60      }
61    }
62    @reset($_GET);
63  }
64
65  if( is_array($_POST) )
66  {
67    while( list($k, $v) = each($_POST) )
68    {
69      if( is_array($_POST[$k]) )
70      {
71        while( list($k2, $v2) = each($_POST[$k]) )
72        {
73          $_POST[$k][$k2] = addslashes($v2);
74        }
75        @reset($_POST[$k]);
76      }
77      else
78      {
79        $_POST[$k] = addslashes($v);
80      }
81    }
82    @reset($_POST);
83  }
84
85  if( is_array($_COOKIE) )
86  {
87    while( list($k, $v) = each($_COOKIE) )
88    {
89      if( is_array($_COOKIE[$k]) )
90      {
91        while( list($k2, $v2) = each($_COOKIE[$k]) )
92        {
93          $_COOKIE[$k][$k2] = addslashes($v2);
94        }
95        @reset($_COOKIE[$k]);
96      }
97      else
98      {
99        $_COOKIE[$k] = addslashes($v);
100      }
101    }
102    @reset($_COOKIE);
103  }
104}
105
106//
107// Define some basic configuration arrays this also prevents malicious
108// rewriting of language and otherarray values via URI params
109//
110$conf = array();
111$page = array();
112$user = array();
113$lang = array();
114$header_msgs = array();
115$header_notes = array();
116$filter = array();
117
118@include(PHPWG_ROOT_PATH .'include/mysql.inc.php');
119if (!defined('PHPWG_INSTALLED'))
120{
121  header('Location: install.php');
122  exit;
123}
124
125foreach( array(
126  'array_intersect_key', //PHP 5 >= 5.1.0RC1
127  'hash_hmac', //(hash) - enabled by default as of PHP 5.1.2
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
148//
149// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
150// since basic gallery information is not available
151//
152load_conf_from_db();
153load_plugins();
154
155include(PHPWG_ROOT_PATH.'include/user.inc.php');
156
157
158// language files
159include_once(get_language_filepath('common.lang.php'));
160if (defined('IN_ADMIN') and IN_ADMIN)
161{
162  include_once(get_language_filepath('admin.lang.php'));
163}
164trigger_action('loading_lang');
165@include_once(get_language_filepath('local.lang.php'));
166
167// only now we can set the localized username of the guest user (and not in
168// include/user.inc.php)
169if ($user['is_the_guest'])
170{
171  $user['username'] = $lang['guest'];
172}
173
174// template instance
175if
176  (
177      defined('IN_ADMIN') and IN_ADMIN and
178      isset($user['admin_template']) and
179      isset($user['admin_theme'])
180  )
181{
182  // Admin template
183  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['admin_template'], $user['admin_theme'] );
184}
185else
186{
187  // Classic template
188  $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] );
189}
190
191if (isset($user['internal_status']['guest_must_be_guest'])
192    and
193    $user['internal_status']['guest_must_be_guest'] === true)
194{
195  $header_msgs[] = l10n('guest_must_be_guest');
196}
197
198if ($conf['gallery_locked'])
199{
200  $header_msgs[] = $lang['gallery_locked_message'];
201
202  if ( script_basename() != 'identification' and !is_admin() )
203  {
204    echo $lang['gallery_locked_message']
205      .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>';
206    exit();
207  }
208}
209
210if ($conf['check_upgrade_feed']
211    and defined('PHPWG_IN_UPGRADE')
212    and PHPWG_IN_UPGRADE)
213{
214
215  // retrieve already applied upgrades
216  $query = '
217SELECT id
218  FROM '.UPGRADE_TABLE.'
219;';
220  $applied = array_from_query($query, 'id');
221
222  // retrieve existing upgrades
223  $existing = get_available_upgrade_ids();
224
225  // which upgrades need to be applied?
226  if (count(array_diff($existing, $applied)) > 0)
227  {
228    $header_msgs[] = 'Some database upgrades are missing, '
229      .'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
230  }
231}
232
233if (is_adviser())
234{
235  $header_msgs[] = $lang['adviser_mode_enabled'];
236}
237
238if (count($header_msgs) > 0)
239{
240  $template->assign_block_vars('header_msgs',array());
241  foreach ($header_msgs as $header_msg)
242  {
243    $template->assign_block_vars('header_msgs.header_msg',
244                                 array('HEADER_MSG'=>$header_msg));
245  }
246}
247
248if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
249{
250  include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php');
251  include(PHPWG_ROOT_PATH.'include/filter.inc.php');
252}
253else
254{
255  $filter['enabled'] = false;
256}
257
258if (isset($conf['header_notes']))
259{
260  $header_notes = array_merge($header_notes, $conf['header_notes']);
261}
262
263// default event handlers
264add_event_handler('render_category_literal_description', 'render_category_literal_description');
265add_event_handler('render_category_description', 'render_category_description');
266add_event_handler('render_comment_content', 'htmlspecialchars');
267add_event_handler('render_comment_content', 'parse_comment_content');
268add_event_handler('render_comment_author', 'strip_tags');
269trigger_action('init');
270?>
Note: See TracBrowser for help on using the repository browser.