2004-02-02 00:55:18 +00:00
|
|
|
<?php
|
2004-02-07 19:36:44 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2011-01-18 00:02:52 +00:00
|
|
|
// | Piwigo - a PHP based photo gallery |
|
2008-04-04 22:57:23 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2016-01-14 12:17:58 +01:00
|
|
|
// | Copyright(C) 2008-2016 Piwigo Team http://piwigo.org |
|
2008-04-04 22:57:23 +00:00
|
|
|
// | 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 |
|
2004-02-07 19:36:44 +00:00
|
|
|
// | 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-03-04 23:56:02 +00:00
|
|
|
|
2008-09-05 01:24:01 +00:00
|
|
|
defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
|
|
|
|
|
2004-02-19 00:31:09 +00:00
|
|
|
// determine the initial instant to indicate the generation time of this page
|
2012-01-17 21:58:18 +00:00
|
|
|
$t2 = microtime(true);
|
2004-02-02 00:55:18 +00:00
|
|
|
|
2015-12-10 14:03:54 +01:00
|
|
|
// @set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
|
2004-02-02 00:55:18 +00:00
|
|
|
|
|
|
|
//
|
2004-02-11 22:31:08 +00:00
|
|
|
// 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.
|
2004-02-02 00:55:18 +00:00
|
|
|
//
|
2009-10-09 14:41:30 +00:00
|
|
|
if( !@get_magic_quotes_gpc() )
|
2004-02-02 00:55:18 +00:00
|
|
|
{
|
2008-10-18 00:45:45 +00:00
|
|
|
function sanitize_mysql_kv(&$v, $k)
|
|
|
|
{
|
|
|
|
$v = addslashes($v);
|
|
|
|
}
|
2004-02-11 22:31:08 +00:00
|
|
|
if( is_array( $_GET ) )
|
2004-02-07 11:50:26 +00:00
|
|
|
{
|
2008-10-18 00:45:45 +00:00
|
|
|
array_walk_recursive( $_GET, 'sanitize_mysql_kv' );
|
2004-02-07 11:50:26 +00:00
|
|
|
}
|
2008-10-18 00:45:45 +00:00
|
|
|
if( is_array( $_POST ) )
|
2004-02-07 11:50:26 +00:00
|
|
|
{
|
2008-10-18 00:45:45 +00:00
|
|
|
array_walk_recursive( $_POST, 'sanitize_mysql_kv' );
|
2004-02-07 11:50:26 +00:00
|
|
|
}
|
2008-10-18 00:45:45 +00:00
|
|
|
if( is_array( $_COOKIE ) )
|
2004-02-07 11:50:26 +00:00
|
|
|
{
|
2008-10-18 00:45:45 +00:00
|
|
|
array_walk_recursive( $_COOKIE, 'sanitize_mysql_kv' );
|
2004-02-07 11:50:26 +00:00
|
|
|
}
|
2004-02-02 00:55:18 +00:00
|
|
|
}
|
2008-08-23 01:18:13 +00:00
|
|
|
if ( !empty($_SERVER["PATH_INFO"]) )
|
|
|
|
{
|
|
|
|
$_SERVER["PATH_INFO"] = addslashes($_SERVER["PATH_INFO"]);
|
|
|
|
}
|
2004-02-02 00:55:18 +00:00
|
|
|
|
|
|
|
//
|
2004-02-11 22:31:08 +00:00
|
|
|
// Define some basic configuration arrays this also prevents malicious
|
|
|
|
// rewriting of language and otherarray values via URI params
|
2004-02-02 00:55:18 +00:00
|
|
|
//
|
|
|
|
$conf = array();
|
2011-12-18 21:46:24 +00:00
|
|
|
$page = array(
|
|
|
|
'infos' => array(),
|
|
|
|
'errors' => array(),
|
2012-10-04 16:03:25 +00:00
|
|
|
'warnings' => array(),
|
2011-12-18 21:46:24 +00:00
|
|
|
);
|
2004-02-02 00:55:18 +00:00
|
|
|
$user = array();
|
|
|
|
$lang = array();
|
2006-06-28 22:50:30 +00:00
|
|
|
$header_msgs = array();
|
2006-12-21 21:38:20 +00:00
|
|
|
$header_notes = array();
|
2007-09-29 22:36:00 +00:00
|
|
|
$filter = array();
|
2004-02-19 00:31:09 +00:00
|
|
|
|
2014-10-06 10:45:23 +00:00
|
|
|
foreach(
|
|
|
|
array(
|
|
|
|
'gzopen'
|
|
|
|
) as $func)
|
2007-01-23 01:22:52 +00:00
|
|
|
{
|
|
|
|
if (!function_exists($func))
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-25 22:11:57 +00:00
|
|
|
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
|
2010-03-21 13:31:20 +00:00
|
|
|
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
|
2011-12-29 05:48:16 +00:00
|
|
|
|
2011-12-19 20:25:42 +00:00
|
|
|
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
|
2011-07-01 13:19:35 +00:00
|
|
|
|
2011-12-19 20:25:42 +00:00
|
|
|
@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'config/database.inc.php');
|
|
|
|
if (!defined('PHPWG_INSTALLED'))
|
2011-07-01 13:19:35 +00:00
|
|
|
{
|
2011-12-19 20:25:42 +00:00
|
|
|
header('Location: install.php');
|
|
|
|
exit;
|
2011-07-01 13:19:35 +00:00
|
|
|
}
|
2009-11-29 12:35:19 +00:00
|
|
|
include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');
|
2008-11-10 10:15:04 +00:00
|
|
|
|
|
|
|
if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
|
|
|
|
{
|
2008-12-28 14:23:22 +00:00
|
|
|
@ini_set('error_reporting', $conf['show_php_errors']);
|
|
|
|
@ini_set('display_errors', true);
|
2008-11-10 10:15:04 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 20:52:19 +00:00
|
|
|
include(PHPWG_ROOT_PATH . 'include/constants.php');
|
2004-02-19 00:31:09 +00:00
|
|
|
include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
|
2015-04-24 14:00:50 +00:00
|
|
|
include(PHPWG_ROOT_PATH . 'include/template.class.php');
|
|
|
|
include(PHPWG_ROOT_PATH . 'include/cache.class.php');
|
|
|
|
include(PHPWG_ROOT_PATH . 'include/Logger.class.php');
|
2012-01-17 21:58:18 +00:00
|
|
|
|
2014-05-11 08:26:41 +00:00
|
|
|
$persistent_cache = new PersistentFileCache();
|
2004-02-02 00:55:18 +00:00
|
|
|
|
|
|
|
// Database connection
|
2010-03-21 22:51:36 +00:00
|
|
|
try
|
|
|
|
{
|
2013-02-12 11:06:00 +00:00
|
|
|
pwg_db_connect($conf['db_host'], $conf['db_user'],
|
|
|
|
$conf['db_password'], $conf['db_base']);
|
2010-03-21 22:51:36 +00:00
|
|
|
}
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
2010-06-12 09:55:41 +00:00
|
|
|
my_error(l10n($e->getMessage()), true);
|
2010-03-21 22:51:36 +00:00
|
|
|
}
|
2005-11-24 21:37:29 +00:00
|
|
|
|
2009-11-20 14:17:04 +00:00
|
|
|
pwg_db_check_charset();
|
2007-10-09 01:43:29 +00:00
|
|
|
|
2006-04-27 21:08:50 +00:00
|
|
|
load_conf_from_db();
|
2011-06-25 22:03:12 +00:00
|
|
|
|
2015-04-24 14:00:50 +00:00
|
|
|
$logger = new Logger(array(
|
|
|
|
'directory' => PHPWG_ROOT_PATH . $conf['data_location'] . $conf['log_dir'],
|
|
|
|
'severity' => $conf['log_level'],
|
|
|
|
// we use an hashed filename to prevent direct file access, and we salt with
|
|
|
|
// the db_password instead of secret_key because the log must be usable in i.php
|
|
|
|
// (secret_key is in the database)
|
|
|
|
'filename' => 'log_' . date('Y-m-d') . '_' . sha1(date('Y-m-d') . $conf['db_password']) . '.txt',
|
|
|
|
'globPattern' => 'log_*.txt',
|
|
|
|
'archiveDays' => $conf['log_archive_days'],
|
|
|
|
));
|
|
|
|
|
2011-06-25 22:03:12 +00:00
|
|
|
if (!$conf['check_upgrade_feed'])
|
|
|
|
{
|
|
|
|
if (!isset($conf['piwigo_db_version']) or $conf['piwigo_db_version'] != get_branch_from_version(PHPWG_VERSION))
|
|
|
|
{
|
|
|
|
redirect(get_root_url().'upgrade.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-27 05:26:44 +00:00
|
|
|
ImageStdParams::load_from_db();
|
|
|
|
|
2013-02-07 05:43:44 +00:00
|
|
|
session_start();
|
2006-12-14 00:58:57 +00:00
|
|
|
load_plugins();
|
2004-02-02 00:55:18 +00:00
|
|
|
|
2011-07-01 13:19:35 +00:00
|
|
|
// users can have defined a custom order pattern, incompatible with GUI form
|
|
|
|
if (isset($conf['order_by_custom']))
|
|
|
|
{
|
|
|
|
$conf['order_by'] = $conf['order_by_custom'];
|
|
|
|
}
|
|
|
|
if (isset($conf['order_by_inside_category_custom']))
|
|
|
|
{
|
|
|
|
$conf['order_by_inside_category'] = $conf['order_by_inside_category_custom'];
|
|
|
|
}
|
|
|
|
|
2004-12-20 19:26:43 +00:00
|
|
|
include(PHPWG_ROOT_PATH.'include/user.inc.php');
|
2005-08-08 20:52:19 +00:00
|
|
|
|
2013-03-03 22:24:15 +00:00
|
|
|
if (in_array( substr($user['language'],0,2), array('fr','it','de','es','pl','hu','ru','nl','tr','da') ) )
|
2010-03-18 14:30:04 +00:00
|
|
|
{
|
|
|
|
define('PHPWG_DOMAIN', substr($user['language'],0,2).'.piwigo.org');
|
2010-02-01 18:53:59 +00:00
|
|
|
}
|
2010-03-18 14:30:04 +00:00
|
|
|
elseif ('zh_CN' == $user['language']) {
|
2010-02-01 18:53:59 +00:00
|
|
|
define('PHPWG_DOMAIN', 'cn.piwigo.org');
|
|
|
|
}
|
2013-05-09 12:24:30 +00:00
|
|
|
elseif ('pt_BR' == $user['language']) {
|
|
|
|
define('PHPWG_DOMAIN', 'br.piwigo.org');
|
|
|
|
}
|
2009-03-13 23:43:50 +00:00
|
|
|
else {
|
|
|
|
define('PHPWG_DOMAIN', 'piwigo.org');
|
|
|
|
}
|
|
|
|
define('PHPWG_URL', 'http://'.PHPWG_DOMAIN);
|
2010-10-30 15:07:18 +00:00
|
|
|
|
|
|
|
if(isset($conf['alternative_pem_url']) and $conf['alternative_pem_url']!='')
|
|
|
|
{
|
|
|
|
define('PEM_URL', $conf['alternative_pem_url']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
define('PEM_URL', 'http://'.PHPWG_DOMAIN.'/ext');
|
|
|
|
}
|
2006-10-20 02:17:53 +00:00
|
|
|
|
2005-08-08 20:52:19 +00:00
|
|
|
// language files
|
2007-10-08 23:46:09 +00:00
|
|
|
load_language('common.lang');
|
2008-07-02 01:11:26 +00:00
|
|
|
if ( is_admin() || (defined('IN_ADMIN') and IN_ADMIN) )
|
2005-08-08 20:52:19 +00:00
|
|
|
{
|
2007-10-08 23:46:09 +00:00
|
|
|
load_language('admin.lang');
|
2005-08-08 20:52:19 +00:00
|
|
|
}
|
2014-06-02 07:55:46 +00:00
|
|
|
trigger_notify('loading_lang');
|
2011-01-17 18:48:13 +00:00
|
|
|
load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
|
2005-08-08 20:52:19 +00:00
|
|
|
|
2006-10-20 02:17:53 +00:00
|
|
|
// only now we can set the localized username of the guest user (and not in
|
|
|
|
// include/user.inc.php)
|
2007-06-05 22:01:15 +00:00
|
|
|
if (is_a_guest())
|
2006-10-20 02:17:53 +00:00
|
|
|
{
|
2008-01-30 22:07:07 +00:00
|
|
|
$user['username'] = l10n('guest');
|
2006-10-20 02:17:53 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 12:44:38 +01:00
|
|
|
// in case an auth key was provided and is no longer valid, we must wait to
|
|
|
|
// be here, with language loaded, to prepare the message
|
|
|
|
if (isset($page['auth_key_invalid']) and $page['auth_key_invalid'])
|
|
|
|
{
|
|
|
|
$page['errors'][] =
|
|
|
|
l10n('Your authentication key is no longer valid.')
|
|
|
|
.sprintf(' <a href="%s">%s</a>', get_root_url().'identification.php', l10n('Login'))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2006-10-20 02:17:53 +00:00
|
|
|
// template instance
|
2010-04-18 18:59:37 +00:00
|
|
|
if (defined('IN_ADMIN') and IN_ADMIN )
|
2008-11-04 01:47:48 +00:00
|
|
|
{// Admin template
|
2010-03-13 00:00:52 +00:00
|
|
|
$template = new Template(PHPWG_ROOT_PATH.'admin/themes', $conf['admin_theme']);
|
2007-06-21 20:49:45 +00:00
|
|
|
}
|
|
|
|
else
|
2008-11-04 01:47:48 +00:00
|
|
|
{ // Classic template
|
2012-06-07 21:33:30 +00:00
|
|
|
$theme = $user['theme'];
|
|
|
|
if (script_basename() != 'ws' and mobile_theme())
|
|
|
|
{
|
|
|
|
$theme = $conf['mobile_theme'];
|
|
|
|
}
|
2012-02-15 16:52:24 +00:00
|
|
|
$template = new Template(PHPWG_ROOT_PATH.'themes', $theme );
|
2007-06-21 20:49:45 +00:00
|
|
|
}
|
2006-10-20 02:17:53 +00:00
|
|
|
|
2010-03-31 20:36:32 +00:00
|
|
|
if ( !isset($conf['no_photo_yet']) )
|
2010-03-14 23:56:21 +00:00
|
|
|
{
|
2010-03-31 20:36:32 +00:00
|
|
|
include(PHPWG_ROOT_PATH.'include/no_photo_yet.inc.php');
|
2010-03-14 23:56:21 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 09:23:04 +00:00
|
|
|
if (isset($user['internal_status']['guest_must_be_guest'])
|
|
|
|
and
|
|
|
|
$user['internal_status']['guest_must_be_guest'] === true)
|
|
|
|
{
|
2010-03-02 14:54:22 +00:00
|
|
|
$header_msgs[] = l10n('Bad status for user "guest", using default status. Please notify the webmaster.');
|
2007-07-07 09:23:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-12 21:52:16 +00:00
|
|
|
if ($conf['gallery_locked'])
|
|
|
|
{
|
2010-03-02 14:54:22 +00:00
|
|
|
$header_msgs[] = l10n('The gallery is locked for maintenance. Please, come back later.');
|
2006-02-12 21:52:16 +00:00
|
|
|
|
2007-01-02 22:57:33 +00:00
|
|
|
if ( script_basename() != 'identification' and !is_admin() )
|
2006-02-12 21:52:16 +00:00
|
|
|
{
|
2007-06-27 22:50:36 +00:00
|
|
|
set_status_header(503, 'Service Unavailable');
|
|
|
|
@header('Retry-After: 900');
|
2009-05-06 21:09:06 +00:00
|
|
|
header('Content-Type: text/html; charset='.get_pwg_charset());
|
2010-03-02 14:54:22 +00:00
|
|
|
echo '<a href="'.get_absolute_root_url(false).'identification.php">'.l10n('The gallery is locked for maintenance. Please, come back later.').'</a>';
|
2008-09-17 01:48:31 +00:00
|
|
|
echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size
|
2006-02-12 21:52:16 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 20:51:51 +00:00
|
|
|
if ($conf['check_upgrade_feed'])
|
2006-06-22 19:21:56 +00:00
|
|
|
{
|
2009-02-13 13:01:03 +00:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
|
|
|
|
if (check_upgrade_feed())
|
2006-10-20 02:17:53 +00:00
|
|
|
{
|
|
|
|
$header_msgs[] = 'Some database upgrades are missing, '
|
2007-01-24 05:07:08 +00:00
|
|
|
.'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
|
2006-10-20 02:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
2005-12-03 17:33:38 +00:00
|
|
|
|
2006-06-28 22:50:30 +00:00
|
|
|
if (count($header_msgs) > 0)
|
2006-06-22 21:28:54 +00:00
|
|
|
{
|
2008-03-02 00:29:27 +00:00
|
|
|
$template->assign('header_msgs', $header_msgs);
|
|
|
|
$header_msgs=array();
|
2006-06-22 21:28:54 +00:00
|
|
|
}
|
2006-11-08 04:28:30 +00:00
|
|
|
|
2007-01-15 00:09:14 +00:00
|
|
|
if (!empty($conf['filter_pages']) and get_filter_page_value('used'))
|
2006-12-21 21:38:20 +00:00
|
|
|
{
|
|
|
|
include(PHPWG_ROOT_PATH.'include/filter.inc.php');
|
|
|
|
}
|
2007-01-15 00:09:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$filter['enabled'] = false;
|
|
|
|
}
|
2006-12-21 21:38:20 +00:00
|
|
|
|
|
|
|
if (isset($conf['header_notes']))
|
|
|
|
{
|
|
|
|
$header_notes = array_merge($header_notes, $conf['header_notes']);
|
|
|
|
}
|
|
|
|
|
2006-11-08 04:28:30 +00:00
|
|
|
// default event handlers
|
2007-10-02 05:38:54 +00:00
|
|
|
add_event_handler('render_category_literal_description', 'render_category_literal_description');
|
2009-02-05 03:03:30 +00:00
|
|
|
if ( !$conf['allow_html_descriptions'] )
|
|
|
|
{
|
|
|
|
add_event_handler('render_category_description', 'nl2br');
|
|
|
|
}
|
2010-12-23 05:22:19 +00:00
|
|
|
add_event_handler('render_comment_content', 'render_comment_content');
|
2007-06-07 18:50:25 +00:00
|
|
|
add_event_handler('render_comment_author', 'strip_tags');
|
2011-11-05 16:15:58 +00:00
|
|
|
add_event_handler('render_tag_url', 'str2url');
|
2008-08-28 00:32:39 +00:00
|
|
|
add_event_handler('blockmanager_register_blocks', 'register_default_menubar_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL-1);
|
2013-02-02 07:09:52 +00:00
|
|
|
if ( !empty($conf['original_url_protection']) )
|
|
|
|
{
|
2014-06-18 19:51:42 +00:00
|
|
|
add_event_handler('get_element_url', 'get_element_url_protection_handler');
|
|
|
|
add_event_handler('get_src_image_url', 'get_src_image_url_protection_handler');
|
2013-02-02 07:09:52 +00:00
|
|
|
}
|
2014-06-02 07:55:46 +00:00
|
|
|
trigger_notify('init');
|
2010-10-30 15:07:18 +00:00
|
|
|
?>
|