forked from thewca/worldcubeassociation.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert legacy changes to PHP results posting code
This partially reverts commit aef4f5c
- Loading branch information
Showing
3 changed files
with
137 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
// data here is loaded into configuration class. Should be accessed by via configuration object (global $config in _framework file). | ||
|
||
$config['database']['host'] = '...'; | ||
$config['database']['user'] = '...'; | ||
$config['database']['pass'] = '...'; | ||
$config['database']['name'] = '...'; | ||
$config['database']['port'] = '...'; | ||
|
||
$config['recaptcha']['publickey'] = '...'; | ||
$config['recaptcha']['privatekey'] = '...'; | ||
|
||
$config['maps']['api_key'] = ''; | ||
|
||
// check for PEAR mail (to send auth email) | ||
if(class_exists('Mail')) { | ||
$config['mail']['pear'] = true; | ||
} else { | ||
$config['mail']['pear'] = false; | ||
} | ||
|
||
if($config['mail']['pear']) { | ||
$config['mail']['from'] = ''; | ||
$config['mail']['host'] = ''; | ||
$config['mail']['port'] = ''; | ||
$config['mail']['user'] = ''; | ||
$config['mail']['pass'] = ''; | ||
} else { | ||
$config['mail']['from'] = '[email protected]'; | ||
} | ||
|
||
|
||
// pathToRoot and filesPath are determined by config class - just a placeholder here. You can enter an explicit value if desired. Include trailing slash. | ||
// pathToRoot is for web urls, etc. May be different than filesystem paths. Eg, "/results/". | ||
$config['pathToRoot'] = ""; | ||
// filesPath is absolute path for system files. May be different than web urls. Eg, "/var/www/results/". | ||
$config['filesPath'] = ""; |
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,31 +1,92 @@ | ||
<?php | ||
|
||
/** | ||
icklerf: | ||
I took liberty to replace each old mysql call with a direct replacement from the dbConn class | ||
This is not the ideal way, but php should be replaced very soon(TM) | ||
PLEASE NOTE: FUNCTIONALITY IN THIS FILE IS SET TO BE DEPRECATED. Eventually PHP will no longer support the MySQL API, so this code | ||
needs to be phased out. Instead, please use or extend the mysqli connection class for any new code needing mysql functionality. | ||
**/ | ||
|
||
establishDatabaseAccess(); | ||
|
||
#---------------------------------------------------------------------- | ||
function establishDatabaseAccess () { | ||
#---------------------------------------------------------------------- | ||
global $config; | ||
$db_config = $config->get('database'); | ||
|
||
#--- Connect to the database server. | ||
# TODO: Upgrade | ||
mysql_connect( $db_config['host'], $db_config['user'], $db_config['pass'] ) | ||
or showDatabaseError( "Unable to connect to the database." ); | ||
|
||
#--- Select the database. | ||
mysql_select_db( $db_config['name'] ) | ||
or showDatabaseError( "Unable to access the database." ); | ||
|
||
dbCommand( "SET NAMES 'utf8'" ); | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
function mysqlEscape ( $string ) { | ||
#---------------------------------------------------------------------- | ||
global $wcadb_conn; | ||
return $wcadb_conn->mysqlEscape($string); | ||
return mysql_real_escape_string( $string ); | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
function dbQuery ( $query ) { | ||
#---------------------------------------------------------------------- | ||
global $wcadb_conn; | ||
return $wcadb_conn->dbQuery($query); | ||
|
||
startTimer(); | ||
|
||
if( wcaDebug() ){ | ||
startTimer(); | ||
global $dbQueryCtr; | ||
$dbQueryCtr++; | ||
echo "\n\n<!-- dbQuery(\n$query\n) -->\n\n"; | ||
echo "<br>"; | ||
stopTimer( 'printing the database query' ); | ||
} | ||
|
||
startTimer(); | ||
$dbResult = mysql_query( $query ) | ||
or showDatabaseError( "Unable to perform database query." ); | ||
stopTimer( "pure database query" ); | ||
|
||
startTimer(); | ||
$rows = array(); | ||
while( $row = mysql_fetch_array( $dbResult )) | ||
$rows[] = $row; | ||
stopTimer( "fetching database query results" ); | ||
|
||
startTimer(); | ||
mysql_free_result( $dbResult ); | ||
stopTimer( "freeing the mysql result" ); | ||
|
||
global $dbQueryTotalTime; | ||
$dbQueryTotalTime += stopTimer( "the whole dbQuery execution" ); | ||
|
||
return $rows; | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
function dbQueryHandle ( $query ) { | ||
#---------------------------------------------------------------------- | ||
global $wcadb_conn; | ||
return $wcadb_conn->dbQuery($query); | ||
|
||
if( wcaDebug() ){ | ||
startTimer(); | ||
global $dbQueryCtr; | ||
$dbQueryCtr++; | ||
echo "\n\n<!-- dbQuery(\n$query\n) -->\n\n"; | ||
echo "<br>"; | ||
stopTimer( 'printing the database query' ); | ||
} | ||
|
||
startTimer(); | ||
$dbResult = mysql_query( $query ) | ||
or showDatabaseError( "Unable to perform database query." ); | ||
global $dbQueryTotalTime; | ||
$dbQueryTotalTime += stopTimer( "pure database query" ); | ||
|
||
return $dbResult; | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
|
@@ -38,8 +99,24 @@ function dbValue ( $query ) { | |
#---------------------------------------------------------------------- | ||
function dbCommand ( $command ) { | ||
#---------------------------------------------------------------------- | ||
global $wcadb_conn; | ||
return $wcadb_conn->dbCommand($command); | ||
|
||
if( wcaDebug() ){ | ||
startTimer(); | ||
global $dbCommandCtr; | ||
$dbCommandCtr++; | ||
$commandForShow = strlen($command) < 1010 | ||
? $command | ||
: substr($command,0,1000) . '[...' . (strlen($command)-1000) . '...]'; | ||
echo "\n\n<!-- dbCommand(\n$commandForShow\n) -->\n\n"; | ||
stopTimer( 'printing the database command' ); | ||
} | ||
|
||
#--- Execute the command. | ||
startTimer(); | ||
$dbResult = mysql_query( $command ) | ||
or showDatabaseError( "Unable to perform database command." ); | ||
global $dbCommandTotalTime; | ||
$dbCommandTotalTime += stopTimer( "executing database command" ); | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
|
@@ -196,6 +273,16 @@ function dbDebug ( $query ) { | |
echo "</table>"; | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
function showDatabaseError ( $message ) { | ||
#---------------------------------------------------------------------- | ||
|
||
#--- Normal users just get a "Sorry", developers/debuggers get more details | ||
die( $_SERVER['SERVER_NAME'] == 'localhost' || wcaDebug() | ||
? "<p>$message<br />\n(" . mysql_error() . ")</p>\n" | ||
: "<p>Problem with the database, sorry. If this persists for several minutes, " . | ||
"please tell us at <a href='mailto:[email protected]'>[email protected]</a></p>" ); | ||
} | ||
|
||
#---------------------------------------------------------------------- | ||
function showDatabaseStatistics () { | ||
|