1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based picture gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
// determine the initial instant to indicate the generation time of this page
$t1 = explode( ' ', microtime() );
$t2 = explode( '.', $t1[0] );
$t2 = $t1[1].'.'.$t2[1];
@set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
//
// addslashes to vars if magic_quotes_gpc is off this is a security
// precaution to prevent someone trying to break out of a SQL statement.
//
if( !@get_magic_quotes_gpc() )
{
function sanitize_mysql_kv(&$v, $k)
{
$v = addslashes($v);
}
if( is_array( $_GET ) )
{
array_walk_recursive( $_GET, 'sanitize_mysql_kv' );
}
if( is_array( $_POST ) )
{
array_walk_recursive( $_POST, 'sanitize_mysql_kv' );
}
if( is_array( $_COOKIE ) )
{
array_walk_recursive( $_COOKIE, 'sanitize_mysql_kv' );
}
}
if ( !empty($_SERVER["PATH_INFO"]) )
{
$_SERVER["PATH_INFO"] = addslashes($_SERVER["PATH_INFO"]);
}
//
// Define some basic configuration arrays this also prevents malicious
// rewriting of language and otherarray values via URI params
//
$conf = array();
$page = array();
$user = array();
$lang = array();
$header_msgs = array();
$header_notes = array();
$filter = array();
@include(PHPWG_ROOT_PATH .'local/config/database.inc.php');
if (!defined('PHPWG_INSTALLED'))
{
header('Location: install.php');
exit;
}
foreach( array(
'array_intersect_key', //PHP 5 >= 5.1.0RC1
'hash_hmac', //(hash) - enabled by default as of PHP 5.1.2
'preg_last_error', // PHP 5 >= 5.2.0
) as $func)
{
if (!function_exists($func))
{
include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php');
}
}
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');
if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
{
@ini_set('error_reporting', $conf['show_php_errors']);
@ini_set('display_errors', true);
}
include(PHPWG_ROOT_PATH . 'include/constants.php');
include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
include( PHPWG_ROOT_PATH .'include/template.class.php');
// Database connection
try
{
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
$conf['db_password'], $conf['db_base']);
}
catch (Exception $e)
{
my_error(l10n($e->getMessage(), true));
}
pwg_db_check_charset();
load_conf_from_db();
load_plugins();
include(PHPWG_ROOT_PATH.'include/user.inc.php');
if (in_array( substr($user['language'],0,2), array('fr','it','de','es','pl','hu','ru') ) )
{
define('PHPWG_DOMAIN', substr($user['language'],0,2).'.piwigo.org');
}
elseif ('zh_CN' == $user['language']) {
define('PHPWG_DOMAIN', 'cn.piwigo.org');
}
else {
define('PHPWG_DOMAIN', 'piwigo.org');
}
define('PHPWG_URL', 'http://'.PHPWG_DOMAIN);
define('PEM_URL', 'http://'.PHPWG_DOMAIN.'/ext');
// language files
load_language('common.lang');
if ( is_admin() || (defined('IN_ADMIN') and IN_ADMIN) )
{
load_language('admin.lang');
}
trigger_action('loading_lang');
load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
// only now we can set the localized username of the guest user (and not in
// include/user.inc.php)
if (is_a_guest())
{
$user['username'] = l10n('guest');
}
// template instance
if (( defined('IN_ADMIN') and IN_ADMIN )
or (defined('PWG_HELP') and PWG_HELP))
{// Admin template
$template = new Template(PHPWG_ROOT_PATH.'admin/themes', $conf['admin_theme']);
}
else
{ // Classic template
$template = new Template(PHPWG_ROOT_PATH.'themes', $user['theme'] );
}
// The "No Photo Yet" feature: if you have no photo yet in your gallery, the
// gallery displays only a big box to show you the way for adding your first
// photos
if (
!isset($conf['no_photo_yet']) // the message disappears at first photo
and !(defined('IN_ADMIN') and IN_ADMIN) // no message inside administration
and script_basename() != 'identification' // keep the ability to login
)
{
$query = '
SELECT
COUNT(*)
FROM '.IMAGES_TABLE.'
;';
list($nb_photos) = pwg_db_fetch_row(pwg_query($query));
if (0 == $nb_photos)
{
$template->set_filenames(array('no_photo_yet'=>'no_photo_yet.tpl'));
$url = $conf['no_photo_yet_url'];
if (substr($url, 0, 4) != 'http')
{
$url = get_root_url().$url;
}
$template->assign(array('next_step_url' => $url));
$template->pparse('no_photo_yet');
exit();
}
else
{
conf_update_param('no_photo_yet', 'false');
}
}
if (isset($user['internal_status']['guest_must_be_guest'])
and
$user['internal_status']['guest_must_be_guest'] === true)
{
$header_msgs[] = l10n('Bad status for user "guest", using default status. Please notify the webmaster.');
}
if ($conf['gallery_locked'])
{
$header_msgs[] = l10n('The gallery is locked for maintenance. Please, come back later.');
if ( script_basename() != 'identification' and !is_admin() )
{
set_status_header(503, 'Service Unavailable');
@header('Retry-After: 900');
header('Content-Type: text/html; charset='.get_pwg_charset());
echo '<a href="'.get_absolute_root_url(false).'identification.php">'.l10n('The gallery is locked for maintenance. Please, come back later.').'</a>';
echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size
exit();
}
}
if ($conf['check_upgrade_feed'])
{
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
if (check_upgrade_feed())
{
$header_msgs[] = 'Some database upgrades are missing, '
.'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
}
}
if (is_adviser())
{
$header_msgs[] = l10n('Adviser mode enabled');
}
if (count($header_msgs) > 0)
{
$template->assign('header_msgs', $header_msgs);
$header_msgs=array();
}
if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
{
include(PHPWG_ROOT_PATH.'include/filter.inc.php');
}
else
{
$filter['enabled'] = false;
}
if (isset($conf['header_notes']))
{
$header_notes = array_merge($header_notes, $conf['header_notes']);
}
// default event handlers
add_event_handler('render_category_literal_description', 'render_category_literal_description');
if ( !$conf['allow_html_descriptions'] )
{
add_event_handler('render_category_description', 'nl2br');
}
add_event_handler('render_comment_content', 'htmlspecialchars');
add_event_handler('render_comment_content', 'parse_comment_content');
add_event_handler('render_comment_author', 'strip_tags');
add_event_handler('blockmanager_register_blocks', 'register_default_menubar_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL-1);
trigger_action('init');
?>
|