Skip to content

Commit

Permalink
Remove global php path variables in favor of constants for path confi…
Browse files Browse the repository at this point in the history
…guration.

These may be configured through the webserver. The 'core' and 'classes' paths are
now hardcoded under the directory specified by APPLICATION_PATH.  These directories
are deprecated and will be removed once the entire application has been refactored.

Configuration files have been moved out of webroot. Use the correct path.

Update autoload to load from the legacy core directory first, then the application directory.
Account for namespacing in the application directory.
  • Loading branch information
Daryn Warriner authored and davidhicks committed Aug 20, 2011
1 parent 78d6bcc commit 3b26bff
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 105 deletions.
27 changes: 1 addition & 26 deletions application/configs/config_defaults_inc.php
Expand Up @@ -163,32 +163,7 @@
* absolute path to your installation. Requires trailing / or \
* @global string $g_absolute_path
*/
$g_absolute_path = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;

/**
* absolute patch to your core files. The default is usually OK,
* unless you moved the 'core' directory out of your webroot (recommended).
* @global string $g_core_path
*/
$g_core_path = $g_absolute_path . 'core' . DIRECTORY_SEPARATOR;

/**
* absolute path to class files. Requires trailing / or \
* @global string $g_class_path
*/
$g_class_path = $g_core_path . 'classes' . DIRECTORY_SEPARATOR;

/**
* absolute path to library files. Requires trailing / or \
* @global string $g_library_path
*/
$g_library_path = $g_absolute_path . 'library' . DIRECTORY_SEPARATOR;

/**
* absolute path to language files. Requires trailing / or \
* @global string $g_language_path
*/
$g_language_path = $g_absolute_path . 'lang' . DIRECTORY_SEPARATOR;
$g_absolute_path = realpath( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' ) . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR;

/**
* absolute path to custom strings file.
Expand Down
4 changes: 0 additions & 4 deletions application/core/config_api.php
Expand Up @@ -597,10 +597,6 @@ function config_is_private( $p_config_var ) {
case 'smtp_port':
case 'email_send_using_cronjob':
case 'absolute_path':
case 'core_path':
case 'class_path':
case 'library_path':
case 'language_path':
case 'session_save_path':
case 'session_handler':
case 'session_validation':
Expand Down
2 changes: 1 addition & 1 deletion application/core/custom_field_api.php
Expand Up @@ -73,7 +73,7 @@
$g_custom_field_types[CUSTOM_FIELD_TYPE_DATE] = 'standard';

foreach( $g_custom_field_types as $type ) {
require_once( config_get_global( 'core_path' ) . 'cfdefs' . DIRECTORY_SEPARATOR . 'cfdef_' . $type . '.php' );
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'cfdefs' . DIRECTORY_SEPARATOR . 'cfdef_' . $type . '.php' );
}

function custom_field_allow_manage_display( $p_type, $p_display ) {
Expand Down
2 changes: 1 addition & 1 deletion application/core/database_api.php
Expand Up @@ -37,7 +37,7 @@
require_api( 'logging_api.php' );
require_api( 'utility_api.php' );

define( 'ADODB_DIR', config_get( 'library_path' ) . 'adodb' );
define( 'ADODB_DIR', 'adodb' );
require_lib( 'adodb' . DIRECTORY_SEPARATOR . 'adodb.inc.php' );

/**
Expand Down
2 changes: 1 addition & 1 deletion application/core/lang_api.php
Expand Up @@ -69,7 +69,7 @@ function lang_load( $p_lang, $p_dir = null ) {
// Step 1 - Load Requested Language file
// @@ and if file doesn't exist???
if( $p_dir === null ) {
include_once( config_get( 'language_path' ) . 'strings_' . $p_lang . '.txt' );
include_once( LANGUAGES_PATH . DIRECTORY_SEPARATOR . 'strings_' . $p_lang . '.txt' );
} else {
if( is_file( $p_dir . 'strings_' . $p_lang . '.txt' ) ) {
include_once( $p_dir . 'strings_' . $p_lang . '.txt' );
Expand Down
2 changes: 1 addition & 1 deletion application/core/logging_api.php
Expand Up @@ -114,7 +114,7 @@ function log_event( $p_level, $p_msg, $p_backtrace = null ) {
break;
case 'firebug':
if( !class_exists( 'FirePHP' ) ) {
if( file_exists( config_get_global( 'library_path' ) . 'FirePHPCore' . DIRECTORY_SEPARATOR . 'FirePHP.class.php' ) ) {
if( file_exists( LIBRARY_PATH . DIRECTORY_SEPARATOR . 'FirePHPCore' . DIRECTORY_SEPARATOR . 'FirePHP.class.php' ) ) {
require_lib( 'FirePHPCore' . DIRECTORY_SEPARATOR . 'FirePHP.class.php' );
}
}
Expand Down
4 changes: 4 additions & 0 deletions application/core/obsolete.php
Expand Up @@ -158,3 +158,7 @@
config_obsolete( 'session_key' );
config_obsolete( 'dhtml_filters', 'use_dynamic_filters' );
config_obsolete( 'use_iis' );
config_obsolete( 'core_path' );
config_obsolete( 'class_path' );
config_obsolete( 'library_path' );
config_obsolete( 'language_path' );
2 changes: 1 addition & 1 deletion application/core/wiki_api.php
Expand Up @@ -52,7 +52,7 @@ function wiki_init() {
if( wiki_enabled() ) {

# handle legacy style wiki integration
require_once( config_get_global( 'class_path' ) . 'MantisCoreWikiPlugin.class.php' );
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'MantisCoreWikiPlugin.class.php' );
switch( config_get_global( 'wiki_engine' ) ) {
case 'dokuwiki':
plugin_child( 'MantisCoreDokuwiki' );
Expand Down
39 changes: 0 additions & 39 deletions docbook/Admin_Guide/en-US/Configuration.xml
Expand Up @@ -110,45 +110,6 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_core_path</term>
<listitem>
<para>This is the path to the core directory of your installation.
The default value is usually OK but it is recommended
that you move the 'core' directory out of your webroot.
Requires trailing DIRECTORY_SEPARATOR character.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_class_path</term>
<listitem>
<para>This is the path to the classes directory which is a sub-directory of core by default.
The default value is typically OK. Requires trailing DIRECTORY_SEPARATOR.
character.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_library_path</term>
<listitem>
<para>This is the path to the library directory of your installation.
The default value is usually OK but it is recommended
that you move the 'library' directory out of your webroot.
Requires trailing DIRECTORY_SEPARATOR character.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_language_path</term>
<listitem>
<para>This is the path to the language directory of your installation.
The default value is usually OK but it is recommended
that you move the 'language' directory out of your webroot.
Requires trailing DIRECTORY_SEPARATOR character.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_manual_url</term>
<listitem>
Expand Down
11 changes: 6 additions & 5 deletions public/admin/check/check_integrity_inc.php
Expand Up @@ -157,24 +157,25 @@ function check_file_integrity_recursive( $p_directory, $p_base_directory, $p_rel
);
check_file_integrity_recursive( $t_absolute_base_dir, $t_absolute_base_dir, '', $t_ignore_files );

$t_base_dir = realpath( config_get_global( 'core_path' ) ) . DIRECTORY_SEPARATOR;
$t_base_dir = APPLICATION_PATH . DIRECTORY_SEPARATOR;
$t_ignore_files = array(
'core/classes/'
);
check_file_integrity_recursive( $t_base_dir, $t_base_dir, 'core/', $t_ignore_files );

$t_base_dir = realpath( config_get_global( 'class_path' ) ) . DIRECTORY_SEPARATOR;
# this check is for the legacy classes
$t_base_dir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR;
check_file_integrity_recursive( $t_base_dir, $t_base_dir, 'core/classes/' );

$t_base_dir = realpath( config_get_global( 'library_path' ) ) . DIRECTORY_SEPARATOR;
$t_base_dir = LIBRARY_PATH . DIRECTORY_SEPARATOR;
$t_ignore_files = array(
'library/jpgraph/',
'library/FirePHPCore/'
);
check_file_integrity_recursive( $t_base_dir, $t_base_dir, 'library/', $t_ignore_files );

$t_base_dir = realpath( config_get_global( 'language_path' ) ) . DIRECTORY_SEPARATOR;
check_file_integrity_recursive( $t_base_dir, $t_base_dir, 'lang/' );
$t_base_dir = realpath( LANGUAGE_PATH . DIRECTORY_SEPARATOR );
check_file_integrity_recursive( $t_base_dir, $t_base_dir, 'languages/' );

$t_builtin_plugins = array(
'MantisCoreFormatting',
Expand Down
10 changes: 2 additions & 8 deletions public/admin/check/check_paths_inc.php
Expand Up @@ -38,10 +38,6 @@

$t_path_config_names = array(
'absolute_path',
'core_path',
'class_path',
'library_path',
'language_path'
);

# Handle file upload default path only if attachments stored on disk
Expand All @@ -50,6 +46,7 @@
}

$t_paths = array();

foreach( $t_path_config_names as $t_path_config_name ) {
$t_new_path = array();
$t_new_path['config_value'] = config_get_global( $t_path_config_name );
Expand Down Expand Up @@ -88,11 +85,8 @@
return;
}

# The entire app has been removed from the web tree. Moveable paths are now only configurable via webserver conf
$t_moveable_paths = array(
'core_path',
'class_path',
'library_path',
'language_path'
);

if( $t_paths['absolute_path']['real_path'] !== false ) {
Expand Down
2 changes: 1 addition & 1 deletion public/admin/index.php
Expand Up @@ -72,7 +72,7 @@ function print_info_row( $p_description, $p_value ) {
</tr>
<?php
print_info_row( lang_get( 'site_path' ), config_get( 'absolute_path' ) );
print_info_row( lang_get( 'core_path' ), config_get( 'core_path' ) );
print_info_row( lang_get( 'core_path' ), APPLICATION_PATH );
print_info_row( lang_get( 'plugin_path' ), config_get( 'plugin_path' ) );
?>
</table>
Expand Down
63 changes: 47 additions & 16 deletions public/core.php
Expand Up @@ -49,6 +49,30 @@
* @uses utf8/str_pad.php
*/

// Set the initial include_path. for performance
// reasons, it's best to move this to your web server configuration or php.ini
// for production.
set_include_path(implode(PATH_SEPARATOR, array(
realpath(dirname(__FILE__) . '/../library'),
get_include_path(),
)));

// Define path to application directory
defined('LIBRARY_PATH')
|| define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library') );

// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application') );

// Define path to languages directory
defined('LANGUAGES_PATH')
|| define('LANGUAGES_PATH', realpath(dirname(__FILE__) . '/../languages') );

// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

/**
* Before doing anything... check if MantisBT is down for maintenance
*
Expand All @@ -68,7 +92,7 @@
ob_start();

# Load supplied constants
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'constant_inc.php' );
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'constant_inc.php' );

# Load user-defined constants (if required)
if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'custom_constants_inc.php' ) ) {
Expand All @@ -78,11 +102,11 @@
$t_config_inc_found = false;

# Include default configuration settings
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_defaults_inc.php' );
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'config_defaults_inc.php' );

# config_inc may not be present if this is a new install
if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_inc.php' ) ) {
require_once( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config_inc.php' );
if ( file_exists( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'config_inc.php' ) ) {
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'config_inc.php' );
$t_config_inc_found = true;
}

Expand All @@ -100,10 +124,10 @@
# Define an API inclusion function to replace require_once
function require_api( $p_api_name ) {
global $g_api_included;
global $g_core_path;

if ( !isset( $g_api_included[$p_api_name] ) ) {
$t_existing_globals = get_defined_vars();
require_once( $g_core_path . $p_api_name );
require_once( APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . $p_api_name );
$t_new_globals = array_diff_key( get_defined_vars(), $GLOBALS, array( 't_existing_globals' => 0, 't_new_globals' => 0 ) );
foreach ( $t_new_globals as $t_global_name => $t_global_value ) {
global $$t_global_name;
Expand All @@ -119,10 +143,10 @@ function require_api( $p_api_name ) {
# Define an API inclusion function to replace require_once
function require_lib( $p_library_name ) {
global $g_libraries_included;
global $g_library_path;

if ( !isset( $g_libraries_included[$p_library_name] ) ) {
$t_existing_globals = get_defined_vars();
require_once( $g_library_path . $p_library_name );
require_once( $p_library_name );
$t_new_globals = array_diff_key( get_defined_vars(), $GLOBALS, array( 't_existing_globals' => 0, 't_new_globals' => 0 ) );
foreach ( $t_new_globals as $t_global_name => $t_global_value ) {
global $$t_global_name;
Expand All @@ -133,21 +157,29 @@ function require_lib( $p_library_name ) {
}

# Define an autoload function to automatically load classes when referenced
function __autoload( $className ) {
global $g_class_path;
global $g_library_path;
function __autoload( $p_class_name ) {

# check the old classes directory @todo this should be removed once pages are migrated to the new application structure
$t_require_path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $p_class_name . '.class.php';
if ( file_exists( $t_require_path ) ) {
require( $t_require_path );
return;
}

# handle any namespaces
$t_class_name = str_replace( '\\', '/', $p_class_name );

$t_require_path = $g_class_path . $className . '.class.php';
$t_require_path = APPLICATION_PATH . DIRECTORY_SEPARATOR . $t_class_name . '.class.php';

if ( file_exists( $t_require_path ) ) {
require_once( $t_require_path );
require( $t_require_path );
return;
}

$t_require_path = $g_library_path . 'rssbuilder' . DIRECTORY_SEPARATOR . 'class.' . $className . '.inc.php';
$t_require_path = 'rssbuilder' . DIRECTORY_SEPARATOR . 'class.' . $t_class_name . '.inc.php';

if ( file_exists( $t_require_path ) ) {
require_once( $t_require_path );
include( $t_require_path );
return;
}
}
Expand All @@ -156,7 +188,6 @@ function __autoload( $className ) {
spl_autoload_register( '__autoload' );

# Load UTF8-capable string functions
define( 'UTF8', $g_library_path . 'utf8' );
require_lib( 'utf8/utf8.php' );
require_lib( 'utf8/str_pad.php' );

Expand Down
2 changes: 1 addition & 1 deletion public/manage_overview_page.php
Expand Up @@ -78,7 +78,7 @@
</tr>
<tr <?php echo helper_alternate_class() ?>>
<th class="category"><?php echo lang_get( 'core_path' ) ?></th>
<td><?php echo config_get( 'core_path' ) ?></td>
<td><?php echo APPLICATION_PATH . DIRECTORY_SEPARATOR ; ?></td>
</tr>
<tr <?php echo helper_alternate_class() ?>>
<th class="category"><?php echo lang_get( 'plugin_path' ) ?></th>
Expand Down

0 comments on commit 3b26bff

Please sign in to comment.