diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2012-03-13 17:57:07 -0400 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2012-03-13 17:57:07 -0400 |
commit | fe5d18095e298f4323571f10c8c8e2c18b8dcf33 (patch) | |
tree | 89806b5f4160eee5898e0c2408ef9159782c1ec7 | |
parent | b58a5c84293e9a74ab401094f8fff16fdb9cce5f (diff) | |
download | ampache-fe5d18095e298f4323571f10c8c8e2c18b8dcf33.tar.gz ampache-fe5d18095e298f4323571f10c8c8e2c18b8dcf33.tar.bz2 ampache-fe5d18095e298f4323571f10c8c8e2c18b8dcf33.zip |
Refactor similar init code into new init-tiny.php
Several places were doing operations that were practically the same
(loading core libraries and setting some variables), with varying
levels of success in remembering to do the right things in the right
order. Making a separate minimal init.php that doesn't worry about
some of the sanity checks and session bumpf makes this cleaner and
easier to maintain.
-rw-r--r-- | admin/system.php | 4 | ||||
-rw-r--r-- | bin/install/install_db.inc | 19 | ||||
-rw-r--r-- | install.php | 35 | ||||
-rw-r--r-- | lib/init-tiny.php | 84 | ||||
-rw-r--r-- | lib/init.php | 52 | ||||
-rw-r--r-- | play/index.php | 1 | ||||
-rw-r--r-- | test.php | 23 |
7 files changed, 94 insertions, 124 deletions
diff --git a/admin/system.php b/admin/system.php index e2fc0faa..eefc1d7f 100644 --- a/admin/system.php +++ b/admin/system.php @@ -26,9 +26,7 @@ * @link http://www.ampache.org/ */ -require '../lib/init.php'; -require_once Config::get('prefix') . '/lib/debug.lib.php'; -require_once Config::get('prefix') . '/modules/horde/Browser.php'; +require_once '../lib/init.php'; if (!Access::check('interface',100) OR Config::get('demo_mode')) { access_denied(); diff --git a/bin/install/install_db.inc b/bin/install/install_db.inc index 73d9c474..b09e1eb7 100644 --- a/bin/install/install_db.inc +++ b/bin/install/install_db.inc @@ -29,29 +29,12 @@ if(php_sapi_name() != 'cli') { exit(1); } -error_reporting(E_ERROR); - define('NO_SESSION', 1); define('CLI', 1); -define('INIT_LOADED', 1); $path = dirname(__FILE__); $prefix = realpath($path . '/../../'); -require_once $prefix . '/lib/install.php'; -require_once $prefix . '/lib/debug.lib.php'; -require_once $prefix . '/lib/general.lib.php'; -require_once $prefix . '/lib/class/config.class.php'; -require_once $prefix . '/lib/class/error.class.php'; -require_once $prefix . '/lib/class/vauth.class.php'; -require_once $prefix . '/lib/class/database_object.abstract.php'; -require_once $prefix . '/lib/class/preference.class.php'; -require_once $prefix . '/lib/class/access.class.php'; -require_once $prefix . '/lib/ui.lib.php'; -require_once $prefix . '/lib/log.lib.php'; -require_once $prefix . '/lib/gettext.php'; - -Config::set('prefix', $prefix, true); -$configfile = $prefix . '/config/ampache.cfg.php'; +require_once $prefix . '/lib/init-tiny.php'; $options = getopt( 'h:d:f:p:P:u:U:w:', diff --git a/install.php b/install.php index b1316cff..57687251 100644 --- a/install.php +++ b/install.php @@ -5,7 +5,7 @@ * * * LICENSE: GNU General Public License, version 2 (GPLv2) - * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved + * Copyright (c) 2001 - 2012 Ampache.org All Rights Reserved * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License v2 @@ -21,34 +21,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * @package Ampache - * @copyright 2001 - 2011 Ampache.org + * @copyright 2001 - 2012 Ampache.org * @license http://opensource.org/licenses/gpl-2.0 GPLv2 * @link http://www.ampache.org/ */ -// Set the Error level manualy... I'm to lazy to fix notices -error_reporting(E_ALL ^ E_NOTICE); - -require_once 'lib/general.lib.php'; -require_once 'lib/class/config.class.php'; -require_once 'lib/class/error.class.php'; -require_once 'lib/class/vauth.class.php'; -require_once 'lib/class/database_object.abstract.php'; -require_once 'lib/class/preference.class.php'; -require_once 'lib/class/access.class.php'; -require_once 'lib/ui.lib.php'; -require_once 'lib/log.lib.php'; -require_once 'modules/horde/Browser.php'; -require_once 'lib/install.php'; -require_once 'lib/debug.lib.php'; -require_once 'lib/gettext.php'; - -if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; } -else { $http_type = "http://"; } - $prefix = dirname(__FILE__); -Config::set('prefix', $prefix, true); -$configfile = "$prefix/config/ampache.cfg.php"; +require_once $prefix . '/lib/init-tiny.php'; set_error_handler('ampache_error_handler'); @@ -62,19 +41,13 @@ if (!install_check_status($configfile)) { } define('INSTALL','1'); -/** - * @ignore - */ -define('INIT_LOADED','1'); -/* Clean up incomming variables */ +/* Clean up incoming variables */ $web_path = scrub_in($_REQUEST['web_path']); $username = scrub_in($_REQUEST['local_username']); $password = $_REQUEST['local_pass']; $hostname = scrub_in($_REQUEST['local_host']); $database = scrub_in($_REQUEST['local_db']); -if ($_SERVER['HTTPS'] == 'on') { $http_type = "https://"; } -else { $http_type = "http://"; } // Correct potential \ or / in the dirname $safe_dirname = rtrim(dirname($_SERVER['PHP_SELF']),"/\\"); diff --git a/lib/init-tiny.php b/lib/init-tiny.php new file mode 100644 index 00000000..101662ef --- /dev/null +++ b/lib/init-tiny.php @@ -0,0 +1,84 @@ +<?php +/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */ +/** + * Minimal init for use in install + * + * LICENSE: GNU General Public License, version 2 (GPLv2) + * Copyright (c) 2001 - 2012 Ampache.org All Rights Reserved + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License v2 + * 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. + * + * @package Ampache + * @copyright 2001 - 2012 Ampache.org + * @license http://opensource.org/licenses/gpl-2.0 GPLv2 + * @link http://www.ampache.org/ + */ + +// Do a check for PHP5 because nothing will work without it +if (floatval(phpversion()) < 5) { + echo "ERROR: Ampache requires PHP5"; + exit; +} + +error_reporting(E_ERROR); // Only show fatal errors in production + +$ampache_path = dirname(__FILE__); +$prefix = realpath($ampache_path . "/../"); +$configfile = $prefix . '/config/ampache.cfg.php'; +require_once $prefix . '/lib/general.lib.php'; +require_once $prefix . '/lib/class/config.class.php'; + +if (!function_exists('gettext')) { + require_once $prefix . '/modules/emulator/gettext.php'; +} + +// Define some base level config options +Config::set('prefix', $prefix); + +/* + Check to see if this is http or https +*/ +if ((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) + || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') + || Config::get('force_ssl')) { + $http_type = "https://"; +} +else { + $http_type = "http://"; +} + +// Define that we've loaded the INIT file +define('INIT_LOADED', 1); + +// Core includes we can't do with the autoloader +require_once $prefix . '/lib/preferences.php'; +require_once $prefix . '/lib/debug.lib.php'; +require_once $prefix . '/lib/log.lib.php'; +require_once $prefix . '/lib/ui.lib.php'; +require_once $prefix . '/lib/gettext.php'; +require_once $prefix . '/lib/batch.lib.php'; +require_once $prefix . '/lib/themes.php'; +require_once $prefix . '/lib/class/localplay.abstract.php'; +require_once $prefix . '/lib/class/database_object.abstract.php'; +require_once $prefix . '/lib/class/playlist_object.abstract.php'; +require_once $prefix . '/lib/class/media.interface.php'; +require_once $prefix . '/modules/horde/Browser.php'; + +/* Set up the flip class */ +flip_class(array('odd','even')); + +// Merge GET then POST into REQUEST effectively stripping COOKIE without +// depending on a PHP setting change for the effect +$_REQUEST = array_merge($_GET, $_POST); +?> diff --git a/lib/init.php b/lib/init.php index 955a065b..1c87be25 100644 --- a/lib/init.php +++ b/lib/init.php @@ -30,44 +30,15 @@ // fixes some CSS issues ob_start(); -// Do a check for PHP5 because nothing will work without it -if (floatval(phpversion()) < 5) { - echo "ERROR: Ampache requires PHP5"; - exit; -} - -error_reporting(E_ERROR); // Only show fatal errors in production - $ampache_path = dirname(__FILE__); $prefix = realpath($ampache_path . "/../"); -$configfile = "$prefix/config/ampache.cfg.php"; -require_once $prefix . '/lib/general.lib.php'; -require_once $prefix . '/lib/class/config.class.php'; +require_once $prefix . '/lib/init-tiny.php'; // Explicitly load vauth and enable the custom session handler. // Relying on autoload may not always load it before sessiony things are done. require_once $prefix . '/lib/class/vauth.class.php'; vauth::_auto_init(); -if (!function_exists('gettext')) { - require_once $prefix . '/modules/emulator/gettext.php'; -} - -// Define some base level config options -Config::set('prefix', $prefix); - -/* - Check to see if this is http or https -*/ -if ((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) - || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') - || Config::get('force_ssl') == true) { - $http_type = "https://"; -} -else { - $http_type = "http://"; -} - // Set up for redirection on important error cases $path = preg_replace('#(.*)/(\w+\.php)$#', '$1', $_SERVER['PHP_SELF']); $path = $http_type . $_SERVER['HTTP_HOST'] . $path; @@ -135,20 +106,7 @@ $results['mysql_username'] = $results['database_username']; $results['mysql_hostname'] = $results['database_hostname']; $results['mysql_db'] = $results['database_name']; -// Define that we've loaded the INIT file -define('INIT_LOADED','1'); - // Library and module includes we can't do with the autoloader -require_once $prefix . '/lib/preferences.php'; -require_once $prefix . '/lib/log.lib.php'; -require_once $prefix . '/lib/ui.lib.php'; -require_once $prefix . '/lib/gettext.php'; -require_once $prefix . '/lib/batch.lib.php'; -require_once $prefix . '/lib/themes.php'; -require_once $prefix . '/lib/class/localplay.abstract.php'; -require_once $prefix . '/lib/class/database_object.abstract.php'; -require_once $prefix . '/lib/class/playlist_object.abstract.php'; -require_once $prefix . '/lib/class/media.interface.php'; require_once $prefix . '/modules/getid3/getid3.php'; require_once $prefix . '/modules/nusoap/nusoap.php'; require_once $prefix . '/modules/phpmailer/class.phpmailer.php'; @@ -156,7 +114,6 @@ require_once $prefix . '/modules/phpmailer/class.smtp.php'; require_once $prefix . '/modules/infotools/Snoopy.class.php'; require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php'; require_once $prefix . '/modules/infotools/lastfm.class.php'; -//require_once $prefix . '/modules/infotools/jamendoSearch.class.php'; require_once $prefix . '/modules/php_musicbrainz/mbQuery.php'; require_once $prefix . '/modules/ampacheapi/AmpacheApi.lib.php'; @@ -276,9 +233,6 @@ header ("Content-Type: text/html; charset=" . Config::get('site_charset')); unset($array); unset($results); -/* Set up the flip class */ -flip_class(array('odd','even')); - /* Check to see if we need to perform an update */ if (!defined('OUTDATED_DATABASE_OK')) { if (Update::need_update()) { @@ -293,8 +247,4 @@ $GLOBALS['xmlrpc_internalencoding'] = Config::get('site_charset'); if (Config::get('debug')) { error_reporting(E_ALL); } - -// Merge GET then POST into REQUEST effectively stripping COOKIE without -// depending on a PHP setting change for the effect -$_REQUEST = array_merge($_GET,$_POST); ?> diff --git a/play/index.php b/play/index.php index a2c10aaa..20d73913 100644 --- a/play/index.php +++ b/play/index.php @@ -35,7 +35,6 @@ */ define('NO_SESSION','1'); require_once '../lib/init.php'; -require_once Config::get('prefix') . '/modules/horde/Browser.php'; ob_end_clean(); /* These parameters had better come in on the url. */ @@ -5,7 +5,7 @@ * * * LICENSE: GNU General Public License, version 2 (GPLv2) - * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved + * Copyright (c) 2001 - 2012 Ampache.org All Rights Reserved * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License v2 @@ -21,30 +21,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * @package Ampache - * @copyright 2001 - 2011 Ampache.org + * @copyright 2001 - 2012 Ampache.org * @license http://opensource.org/licenses/gpl-2.0 GPLv2 * @link http://www.ampache.org/ */ -// Set the Error level manualy... I'm to lazy to fix notices -error_reporting(0); - $prefix = dirname(__FILE__); -$configfile = "$prefix/config/ampache.cfg.php"; -$row_classes = array('even','odd'); - -define('INIT_LOADED','1'); - -require_once $prefix . '/lib/general.lib.php'; -require_once $prefix . '/lib/log.lib.php'; -require_once $prefix . '/lib/class/config.class.php'; -require_once $prefix . '/lib/class/dba.class.php'; -require_once $prefix . '/lib/ui.lib.php'; -require_once $prefix . '/lib/class/error.class.php'; -require_once $prefix . '/lib/class/config.class.php'; -require_once $prefix . '/lib/debug.lib.php'; - -Dba::_auto_init(); +require_once $prefix . '/lib/init-tiny.php'; switch ($_REQUEST['action']) { case 'config': |