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