예제 #1
0
function tryCache ( ) {
#----------------------------------------------------------------------
  global $cacheFile, $config;

  #--- Build whole cacheId
  $cacheIdParts = func_get_args();  # indirect because direct usage results in error before PHP 5.3 (see documentation)
  $cacheId = implode( '_', $cacheIdParts );

  #--- If cacheId is invalid, then don't use the cache
  if ( ! preg_match( '/^\w+$/', $cacheId ) ) {
    cacheLog( "invalid: $cacheId" );
    return;
  }

  #--- If debugging or caching disabled, then don't use the cache
  if ( wcaDebug() || paramExists('nocache') ) {
    cacheLog( "debug/noCache: $cacheId" );
    return;
  }

  #--- If it's in the cache already, then just deliver from cache and exit
  $cacheFile = $config->get('filesPath') . "generated/cache/$cacheId.cache";
  if ( file_exists( $cacheFile ) ) {
    echo "<!-- rfc -->\n";
    echo file_get_contents( $cacheFile );
    cacheLog( "use: $cacheId\t" . filesize($cacheFile) );
    exit;
  }

  #--- Otherwise, start recording for the cache
  ob_start();
}
function checkUpload($maxSize, $allowedExtensions)
{
    # example: list($tempFilename, $errorText) = checkUpload(50000, array('.png', '.gif', '.jpg'))
    # on success returns array(tempFilename, false)
    # on failure returns array(false, errorText)
    #----------------------------------------------------------------------
    #--- Check upload error provided by PHP
    $file = $_FILES["file"];
    if ($file["error"] != UPLOAD_ERR_OK) {
        return array(false, "Upload failed with error code: " . $file["error"]);
    }
    #--- Debug
    if (wcaDebug()) {
        echo "Upload: " . $file["name"] . "<br />";
        echo "Type: " . $file["type"] . "<br />";
        echo "Size: " . $file["size"] / 1000 . " Kb<br />";
        echo "Temp file: " . $file["tmp_name"] . "<br />";
    }
    #--- Check upload size
    if (filesize($_FILES['file']['tmp_name']) > $maxSize) {
        return array(false, 'The file is too big.');
    }
    #--- Check extension
    if (is_string($allowedExtensions)) {
        $allowedExtensions = array($allowedExtensions);
    }
    $extension = strtolower(strrchr($file['name'], '.'));
    if (!in_array($extension, $allowedExtensions)) {
        return array(false, 'Wrong filename extension, allowed are: ' . implode(' ', $allowedExtensions));
    }
    #--- Everything ok, so return filename
    return array($file["tmp_name"], false);
}
예제 #3
0
function stopTimer($message, $forceShow = false)
{
    global $timerStartTimes;
    $elapsed = microtime_float() - array_pop($timerStartTimes);
    if (wcaDebug() || $forceShow) {
        printf("<b>%.4f seconds</b> for '{$message}'<br />", $elapsed);
    }
    return $elapsed;
}
function displayChoicesWithMethod($method, $choices)
{
    #----------------------------------------------------------------------
    if (wcaDebug()) {
        $choices[] = "<input type='hidden' name='debug5926' value='1' />";
    }
    echo "<form method='{$method}' class='form-inline'>\n";
    foreach ($choices as $choice) {
        if (is_array($choice)) {
            $choice = implode("\n", $choice);
        }
        echo "<div class='form-group'>{$choice}</div>\n\n";
    }
    echo "</form>\n\n";
}
function showContent()
{
    #----------------------------------------------------------------------
    #--- In debug mode, just calculate freshly and don't cache
    if (wcaDebug()) {
        showResults();
        return;
    }
    #--- If there's no cache or this is an update request, then freshly build the cache
    if (!file_exists('generated/statistics.cache') || getBooleanParam('update8392')) {
        $startTime = microtime_float();
        ob_start();
        showResults();
        file_put_contents('generated/statistics.cache', ob_get_contents());
        ob_end_clean();
        $logMessage = sprintf("%s: Updating took %.2f seconds.", wcaDate(), microtime_float() - $startTime);
        file_put_contents('generated/statistics.log', "{$logMessage}\n", FILE_APPEND);
        echo "<p>{$logMessage}</p>";
    }
    #--- Show the cache
    echo file_get_contents('generated/statistics.cache');
}
function randomDebug()
{
    return wcaDebug() ? rand(1, 30000) : 1;
}
function showDatabaseStatistics () {
#----------------------------------------------------------------------

  if( wcaDebug() ){
    global $dbQueryCtr, $dbQueryTotalTime, $dbCommandCtr, $dbCommandTotalTime;
    $queryStats = isset($dbQueryCtr) ? sprintf('<br />%d queries in %.4f seconds total', $dbQueryCtr, $dbQueryTotalTime) : '';
    $commandStats = isset($dbCommandCtr) ? sprintf('<br />%d commands in %.4f seconds total', $dbCommandCtr, $dbCommandTotalTime) : '';
    echo "<p style='color:#666'>$queryStats$commandStats</p>";
  }
}
예제 #8
0
<?php
// session information needs to be created before <html> tag is output.  Thus this php code should come at the beginning of the file.
require_once '_parameters.php';
if ( wcaDebug() ) {
  // Show errors in debug mode.
  error_reporting(E_ALL);
  ini_set("display_errors", 1);
} else {
  error_reporting(0);
  ini_set("display_errors", 0);
}
require_once( '_framework.php' );
$standAlone = getBooleanParam( 'standAlone' );

?><!doctype html><html lang="en">
<head>
<title>World Cube Association - Official Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="WCA Website Team" />
<meta name="description" content="Official World Cube Association Competition Results" />
<meta name="keywords" content="rubik's cube,puzzles,competition,official results,statistics,WCA" />
<link rel="shortcut icon" href="<?php print pathToRoot(); ?>images/wca.ico" />

<?php

$jQuery = true; // For bootstrap.

/* Deal with scripts here, for now */
$scripts = new WCAClasses\WCAScripts();
if(isset($jQuery) && $jQuery) {
    $tabLinks .= "<li><a href=\"#container_{$eventId}\">{$eventId}</a></li>\n";
}
echo "\n<div id=\"tabs\" style=\"font-size:1.0em; width:980px; margin:auto; background:white \">\n<ul>\n{$tabLinks}</ul>\n";
#--- Tabbing contents
foreach (array('444bf', '555bf') as $eventId) {
    echo "<div id=\"container_{$eventId}\">";
    showBody($eventId);
    echo "</div>\n";
}
#--- Finish/store/show the page
echo "</div>";
require '../../includes/_footer.php';
$html = ob_get_clean();
#$html = preg_replace( "/'p.php/", "'../p.php", $html );
echo $html;
if (!wcaDebug()) {
    file_put_contents('index.php', $html);
}
#----------------------------------------------------------------------
function showBody($eventId)
{
    #----------------------------------------------------------------------
    #--- Get the data
    $rows = dbQuery("\n    SELECT    personId, personName, min(value1+value2+value3) minSum, count(*) means, 0 minSum2, 0 means2\n    FROM      Results\n    WHERE     eventId = '{$eventId}' and (value1>0)+(value2>0)+(value3>0) = 3\n    GROUP BY  personId\n    ORDER BY  minSum, personName\n  ");
    $also2 = $eventId == '444bf' || $eventId == '555bf';
    if ($also2) {
        $rows = array_merge($rows, dbQuery("\n      SELECT    personId, personName, 0 minSum, 0 means, min(greatest(0,value1)+greatest(0,value2)+greatest(0,value3)) minSum2, count(*) means2\n      FROM      Results\n      WHERE     eventId = '{$eventId}' and (value1>0)+(value2>0)+(value3>0) = 2\n      GROUP BY  personId\n      ORDER BY  minSum2, personName\n    "));
    }
    #--- Output the table header
    TableBegin('results', 7);
    TableHeader(array('Pos', 'Name', 'Best Mean', 'Means', $also2 ? 'Best 2-Mean' : '', $also2 ? '2-Means' : '', ''), array('class="r"', 'class="p"', 'class="r"', 'class="r"', 'class="r"', 'class="r"', 'class="f"'));
function debugParameter($type, $name, $value)
{
    #----------------------------------------------------------------------
    if (wcaDebug()) {
        echo "parameter({$type}) <b>[</b>{$name}<b>]</b> = <b>[</b>{$value}<b>]</b><br />\n";
    }
}