2009-06-30 08:07:14 +00:00
< ? php
2009-06-30 09:40:37 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/lib/common.php,v 1.68.2.6 2005/10/22 04:42:40 wurley Exp $
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:07:14 +00:00
* Contains code to be executed at the top of each phpLDAPadmin page .
* include this file at the top of every PHP file .
2009-06-30 09:29:51 +00:00
*
* This file will " pre-initialise " a PLA environment so that any PHP file will have a consistent
* environment with other PLA PHP files .
*
* This code WILL NOT check that all required functions are usable / readable , etc . This process has
* been moved to index . php ( which really is only called once when a browser hits PLA for the first time ) .
*
* The list of ADDITIONAL function files is now defined in functions . php .
*
* @ package phpLDAPadmin
2009-06-30 08:07:14 +00:00
*/
2009-06-30 09:40:37 +00:00
@ define ( 'LIBDIR' , '../lib/' );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
# For PHP5 backward/forward compatibility
if ( ! defined ( 'E_STRICT' ))
define ( 'E_STRICT' , 2048 );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
# General functions needed to proceed (pla_ldap_search(), pla_error(), get_object_attrs(), etc.)
2009-06-30 08:10:17 +00:00
ob_start ();
2009-06-30 09:29:51 +00:00
require_once realpath ( LIBDIR . 'functions.php' );
2009-06-30 08:10:17 +00:00
ob_end_clean ();
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
/* Our custom error handler receives all error notices that pass the error_reporting ()
level set above . */
set_error_handler ( 'pla_error_handler' );
2009-06-30 09:40:37 +00:00
# Disable error reporting until all our required functions are loaded.
error_reporting ( 0 );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
/* Creates the language array which will be populated with localized strings
based on the user - configured language . */
2009-06-30 08:09:20 +00:00
$lang = array ();
2009-06-30 09:29:51 +00:00
/*
* functions . php should have defined our pla_function_files array , listing all our
* required functions ( order IS important ) .
* index . php should have checked they exist and are usable - we ' ll assume that the user
* has been via index . php , and fixed any problems already .
*/
ob_start ();
foreach ( $pla_function_files as $file_name ) {
require_once realpath ( $file_name );
2009-06-30 09:22:30 +00:00
}
2009-06-30 09:29:51 +00:00
# Now read in config_default.php, which also reads in config.php
require_once realpath ( LIBDIR . 'config_default.php' );
ob_end_clean ();
2009-06-30 08:09:20 +00:00
2009-06-30 09:40:37 +00:00
# We are now ready for error reporting.
# Turn on all notices and warnings. This helps us write cleaner code (we hope at least)
if ( phpversion () >= " 5 " ) {
# Work-around to get PLA to work in PHP5
ini_set ( " zend.ze1_compatibility_mode " , 1 );
# E_DEBUG is PHP5 specific and prevents warnings about using 'var' to declare class members
error_reporting ( E_DEBUG );
} else
# For PHP4
error_reporting ( E_ALL );
2009-06-30 09:29:51 +00:00
/**
* At this point we have read all our additional function PHP files and our configuration .
*/
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
# Check our custom variables.
$config -> CheckCustom ();
2009-06-30 08:10:17 +00:00
2009-06-30 09:29:51 +00:00
if ( pla_session_start ())
run_hook ( 'post_session_init' , array ());
2009-06-30 08:10:17 +00:00
2009-06-30 09:29:51 +00:00
/*
* Language configuration . Auto or specified ?
* Shall we attempt to auto - determine the language ?
*/
2009-06-30 09:40:37 +00:00
2009-06-30 09:29:51 +00:00
$language = $config -> GetValue ( 'appearance' , 'language' );
2009-06-30 09:40:37 +00:00
# Get english by default, in case there are tags that are missing.
ob_start ();
include LANGDIR . " recoded/en.php " ;
ob_end_clean ();
2009-06-30 09:29:51 +00:00
if ( $language == " auto " ) {
# Make sure their browser correctly reports language. If not, skip this.
if ( isset ( $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) {
# get the languages which are spetcified in the HTTP header
$HTTP_LANGS1 = preg_split ( " /[;,]+/ " , $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] );
$HTTP_LANGS2 = preg_split ( " /[;,]+/ " , $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] );
foreach ( $HTTP_LANGS2 as $key => $value ) {
$value = preg_split ( " /[-]+/ " , $value );
$HTTP_LANGS2 [ $key ] = $value [ 0 ];
2009-06-30 08:09:20 +00:00
}
2009-06-30 09:29:51 +00:00
$HTTP_LANGS = array_merge ( $HTTP_LANGS1 , $HTTP_LANGS2 );
foreach ( $HTTP_LANGS as $HTTP_LANG ) {
# try to grab one after the other the language file
2009-06-30 09:40:37 +00:00
$language_file = LANGDIR . " recoded/ $HTTP_LANG .php " ;
if ( file_exists ( $language_file ) &&
is_readable ( $language_file )) {
2009-06-30 09:22:30 +00:00
ob_start ();
2009-06-30 09:40:37 +00:00
include $language_file ;
2009-06-30 09:22:30 +00:00
ob_end_clean ();
2009-06-30 09:29:51 +00:00
break ;
2009-06-30 08:09:20 +00:00
}
}
}
2009-06-30 09:29:51 +00:00
} else {
# grab the language file configured in config.php
if ( $language != null ) {
if ( 0 == strcmp ( $language , 'english' ) )
$language = 'en' ;
2009-06-30 09:40:37 +00:00
$language_file = LANGDIR . " recoded/ $language .php " ;
if ( file_exists ( $language_file ) &&
is_readable ( $language_file )) {
2009-06-30 09:29:51 +00:00
ob_start ();
2009-06-30 09:40:37 +00:00
include $language_file ;
2009-06-30 09:29:51 +00:00
ob_end_clean ();
} else {
2009-06-30 09:40:37 +00:00
pla_error ( sprintf ( 'Could not read language file "%s". Either the file does not exist, or its permissions do not allow phpLDAPadmin to read it.' , $language_file ));
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 08:09:20 +00:00
}
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
# If config.php doesn't create the templates array, create it here.
if ( ! isset ( $templates ) || ! is_array ( $templates ))
2009-06-30 08:09:20 +00:00
$templates = array ();
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
# Always including the 'custom' template (the most generic and flexible)
$templates [ 'custom' ] =
array ( 'desc' => 'Custom' ,
'icon' => 'images/object.png' ,
'handler' => 'custom.php' );
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
/*
* Strip slashes from GET , POST , and COOKIE variables if this
* PHP install is configured to automatically addslashes ()
*/
if ( get_magic_quotes_gpc () && ( ! isset ( $slashes_stripped ) || ! $slashes_stripped )) {
array_stripslashes ( $_REQUEST );
2009-06-30 08:07:14 +00:00
array_stripslashes ( $_GET );
2009-06-30 08:09:20 +00:00
array_stripslashes ( $_POST );
array_stripslashes ( $_COOKIE );
2009-06-30 09:22:30 +00:00
array_stripslashes ( $_FILES );
2009-06-30 08:07:14 +00:00
$slashes_stripped = true ;
}
2009-06-30 09:29:51 +00:00
/*
* Update $_SESSION [ 'activity' ]
* for timeout and automatic logout feature
*/
if ( isset ( $_REQUEST [ 'server_id' ])) {
$ldapserver = $ldapservers -> Instance ( $_REQUEST [ 'server_id' ]);
if ( $ldapserver -> haveAuthInfo ())
set_lastactivity ( $ldapserver );
}
2009-06-30 08:07:14 +00:00
?>