Location: PHPKode > projects > Write2Left > index.php
<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: index.php
| Description:
|   Wrapper script through which all of W2L is loaded
| Created Jun-28-2003
+------------------------------------------------------
*/

// Lets get a timer started first thing. 
list( $msec, $sec ) = explode( ' ', microtime() );
$start_time = $sec + $msec;

// I ain't wussing out here.. :P
error_reporting  ( E_ALL );
set_magic_quotes_runtime( 0 );

// Seeds all random numbers. stolen graciously from the PHP manual. :)
function make_seed() 
{
	list( $usec, $sec ) = explode( ' ', microtime() );
	return ( float ) $sec + ( ( float ) $usec * 100000 );
}
srand( make_seed() );

// Better have our config, or we're in trouble :S
require( './config.php' );

// Lets load up the default scripts 
require( './general.php' );

$func = new functions();

/* Class: W2L
 * Description:
 *   Info class to hold info about the current iteration of the script
 */
class W2L
{
	var $version	= "Public Preview 1";
	var $time_now	= 0;
	var $settings	= array();
    var $input  	= array();
    var $errors		= "";

	function W2L()
	{
		global $CONFIG, $func;

		$this->time_now = time();
		$this->settings = $CONFIG;
		$this->input	= $func->safe_input();
		set_error_handler( array( 'W2L', 'error_handler' ) );
	}
	
	function error_handler( $errno, $errmsg, $filename, $linenum, $vars )
	{
		global $W2L;
		
		if( substr( $errmsg, 0, 6 ) == 'mail()' )
			return;
		
	    $errortype = array (
            1   =>  "Error",
            2   =>  "Warning",
            4   =>  "Parsing Error",
            8   =>  "Notice",
            16  =>  "Core Error",
            32  =>  "Core Warning",
            64  =>  "Compile Error",
            128 =>  "Compile Warning",
            256 =>  "User Error",
            512 =>  "User Warning",
            1024=>  "User Notice"
            );
		
		$W2L->errors .= <<<EOF
Type: $errortype[$errno]
Message: $errmsg
Filename: $filename
Line: $linenum
EOF;

		$W2L->errors .= "\n\n";
	}	
}

// And then we create our main object
$W2L = new W2L();


// Load up our database module
require( "./Database/".$W2L->settings['db_driver'].".php" );

$db = new database(	$W2L->settings['db_server'], 
					$W2L->settings['db_user'], 
					$W2L->settings['db_pass'],
					$W2L->settings['db_name'],
					$W2L->settings['db_prefix'] );

// Clear out old sessions
$db->query( "DELETE FROM w2l_sessions WHERE last_time < " . ( time() - $CONFIG['session_timeout'] ) );

// Create some user info/validate our current info
$userinfo = new userinfo();

$base_actions = array ( 'Login' => '',
						'Main' => 'can_login',
						'Users' => 'can_users',
						'Weblogs' => 'can_logs',
						'Options' => 'can_options',
						'Installer' => 'can_install',
						'Import' => 'can_import',
						'Logout' => '',
						'Log' => 'can_access',
						'NewPost' => 'can_post',
						'EditPosts' => 'can_edit',
						'FindPosts' => 'can_post',
						'Upload' => 'can_upload',
						'Rebuild' => 'can_template',
						'Templates' => 'can_template',
						'Blocks' => 'can_template',
						'Cats' => 'can_config',
						'Config' => 'can_config',
						'Plugins' => 'can_config',
						'Subs' => 'can_notify',
						'View' => '',
						'Export' => 'can_edit' );

// Define our default Action if one doesn't exist
if ( !array_key_exists( 'Action', $W2L->input ) )
{
	$W2L->input['Action'] = "Main";
}

if ( $userinfo->id == 0 )
{
	$W2L->input['Action'] = "Login";
}

// Update our user's session, now that some work is done...	
$userinfo->update_session( $userinfo->session_id );

// Ready our output
$output = new display();

//Load the driver for our action
if( array_key_exists( $W2L->input['Action'], $base_actions ) )
{
	$perms = array_merge( $userinfo->perms, $userinfo->log_perms );
	
	if( !array_key_exists( $base_actions[$W2L->input['Action']], $perms ) )
	{
		require( "./Base/".$W2L->input['Action'].".php" );
	}
	else if( $perms[$base_actions[$W2L->input['Action']]] == 1 )
	{
		require( "./Base/".$W2L->input['Action'].".php" );
	}
	else
	{
		if ( $userinfo->id == 0 )
		{
			require( "./Base/Login.php" );
		}
		else
		{
			require( "./Base/Main.php" );
		}
	}

}
else
{
	if ( $userinfo->id == 0 )
	{
		require( "./Base/Login.php" );
	}
	else
	{
		require( "./Base/Main.php" );
	}
}

// Run the loaded driver
$driver->run();

// Do our output. Yippee!
$output->do_output();

// Lets get the end time now that were all done..
list( $msec, $sec ) = explode( ' ', microtime() );
$end_time = $sec + $msec;

// We should only see this if we're in some form of debug mode...
print "<div align=\"center\">Page generated in " . round( $end_time - $start_time, 3 ) . " seconds. " . $db->querycount . " queries made.</div><br />";

print "<div style='background-color:#EEF2F7;padding:5px;border:dashed 1px #778899; width: 800px; overflow:hidden; font-weight: normal;'>$query<br />";
foreach( $W2L->input as $key => $value )
{
	print "<b>$key</b> - $value<br />";
}
print "</div><br />";

$i = 0;
foreach( $db->querylist as $query )
{
	print "<div style='background-color:#EEF2F7;padding:5px;border:dashed 1px #778899; width: 800px; overflow:hidden'>$query<br />Time: {$db->querytimes[$i]}</div><br />";
	$i++;
}
?>
Return current item: Write2Left