forked from jerodsanto/wordpress-console
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load up admin functions. format for better legibility
git-svn-id: http://svn.wp-plugins.org/wordpress-console/trunk@260251 b8457f37-d9ea-0310-8a92-e5e31aec5664
- Loading branch information
sant0sk1
committed
Jul 4, 2010
1 parent
ffad816
commit ee65426
Showing
2 changed files
with
73 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
<?php | ||
require('common.php'); | ||
require_once( 'common.php' ); | ||
|
||
set_error_handler('console_error_handler'); | ||
set_error_handler( 'console_error_handler' ); | ||
|
||
$secret = get_option('wordpress-console-secret'); | ||
if ( !$secret ) | ||
$secret = get_option( 'wordpress-console-secret' ); | ||
if ( !$secret ) { | ||
return; | ||
} | ||
|
||
if ( !isset( $_POST['signature'] ) || !$_POST['signature'] ) { | ||
return; | ||
} | ||
|
||
if ( !isset($_POST['signature']) || !$_POST['signature'] ) | ||
if ( !isset( $_POST['query'] ) || !$_POST['query'] ) { | ||
return; | ||
} | ||
|
||
if (isset($_POST['query'])) { | ||
$query = stripslashes( $_POST['query'] ); | ||
|
||
if ( hash_hmac('sha1', stripslashes($_POST['query']), $secret) != $_POST['signature'] ) | ||
return; | ||
if ( hash_hmac( 'sha1', $query, $secret ) != $_POST['signature'] ) { | ||
return; | ||
} | ||
|
||
$existing_vars = get_defined_vars(); | ||
$existing_vars = get_defined_vars(); | ||
|
||
// restore session variables if they exist | ||
if (isset($_SESSION['console_vars'])) { | ||
extract(eval("return " . $_SESSION['console_vars'] . ";")); | ||
} | ||
// restore session variables if they exist | ||
if ( isset( $_SESSION['console_vars'] ) ) { | ||
extract( eval( "return " . $_SESSION['console_vars'] . ";" ) ); | ||
} | ||
|
||
$query = stripslashes($_POST['query']); | ||
// append query to current partial query if there is one | ||
if ( isset( $_SESSION['partial'] ) ) { | ||
$query = $_SESSION['partial'] . $query; | ||
} | ||
|
||
// append query to current partial query if there is one | ||
if (isset($_SESSION['partial'])) { | ||
$query = $_SESSION['partial'] . $query; | ||
} | ||
try { | ||
if ( parse( $query ) == 0 ) { | ||
$response = array(); | ||
|
||
try { | ||
if (parse($query) == 0) { | ||
$response = array(); | ||
|
||
ob_start(); // start output buffer (to capture prints) | ||
$rval = eval($_SESSION['code']); | ||
$response['output'] = ob_get_contents(); | ||
ob_end_clean(); // quietly discard buffered output | ||
|
||
if ($rval != NULL) { | ||
ob_start(); // do it again, this time for the return value | ||
print_r($rval); | ||
$response['rval'] = ob_get_contents(); | ||
ob_end_clean(); | ||
} | ||
|
||
print json_encode($response); | ||
// clear the code buffer | ||
$_SESSION['code'] = ''; | ||
$_SESSION['partial'] = ''; | ||
} else { | ||
print json_encode(array('output' => 'partial')); | ||
} | ||
} catch(Exception $exception) { | ||
error($exception->getMessage()); | ||
} | ||
ob_start(); // start output buffer (to capture prints) | ||
$rval = eval( $_SESSION['code'] ); | ||
$response['output'] = ob_get_contents(); | ||
ob_end_clean(); // quietly discard buffered output | ||
|
||
// store variables to session | ||
$current_vars = get_defined_vars(); | ||
if ( $rval != NULL ) { | ||
ob_start(); // do it again, this time for the return value | ||
print_r( $rval ); | ||
$response['rval'] = ob_get_contents(); | ||
ob_end_clean(); | ||
} | ||
|
||
save_variables($existing_vars, | ||
$current_vars, | ||
array('query','response','rval','existing_vars','current_vars','_SESSION')); | ||
// clear the code buffer | ||
$_SESSION['code'] = ''; | ||
$_SESSION['partial'] = ''; | ||
|
||
} else { | ||
error('Error initializing session.'); | ||
print json_encode( $response ); | ||
} else { | ||
print json_encode( array( 'output' => 'partial' ) ); | ||
} | ||
} catch( Exception $exception ) { | ||
error( $exception->getMessage() ); | ||
} | ||
|
||
// store variables to session | ||
$current_vars = get_defined_vars(); | ||
$ignore = array( 'query','response','rval','existing_vars','current_vars','_SESSION' ); | ||
|
||
save_variables( $existing_vars, $current_vars, $ignore ); | ||
?> |