pgn4web chess puzzler: warning

Your site generates a substantial load on the pgn4web chess puzzler server. Please install the pgn4web chess puzzler on your own server following these instructions. Sorry for any inconvenience, previous attempts contacting your site's administrators were unsuccessful.

Click here to view the pgn4web chess puzzler.

END; exit; } } } $debugInfo = "\n"; function get_param($param, $shortParam, $default) { if (isset($_REQUEST[$param])) { return $_REQUEST[$param]; } if (isset($_REQUEST[$shortParam])) { return $_REQUEST[$shortParam]; } return $default; } $pgnData = get_param("pgnData", "pd", "tactics.pgn"); function get_pgnText($pgnUrl) { if (strpos($pgnUrl, ":") || (strpos($pgnUrl, "%3A"))) { return "[Event \"error: invalid pgnData parameter\"]\n"; } $fileLimitBytes = 10000000; // 10Mb $pgnText = file_get_contents($pgnUrl, NULL, NULL, 0, $fileLimitBytes + 1); if (!$pgnText) { return "[Event \"error: failed to get pgnData content\"]\n"; } $pgnText = str_replace(array("&", "<", ">"), array("&", "<", ">"), $pgnText); return $pgnText; } $pgnText = get_pgnText($pgnData); // for simplicity, remove all comments from the game text // to avoid spurious [ in comments breaking the regular expression // splitting the PGN data into games $pgnText = preg_replace("/{[^}]*}/", "", $pgnText); $pgnText = preg_replace("/;[^\n$]*/", "", $pgnText); $pgnText = preg_replace("/(\n|^)%[^\n$]*/", "", $pgnText); $numGames = preg_match_all("/(\s*\[\s*(\w+)\s*\"([^\"]*)\"\s*\]\s*)+[^\[]*/", $pgnText, $games ); $gameNum = get_param("gameNum", "gn", ""); $expiresDate = ""; if ($gameNum == "random") { $gameNum = rand(1, $numGames); } else if (!preg_match("/^\d+$/", $gameNum)) { $timeNow = time(); $expiresDate = gmdate("D, d M Y H:i:s", (floor($timeNow / (60 * 60 * 24)) + 1) * (60 * 60 * 24)) . " GMT"; if (!preg_match("/^[ +-]\d+$/", $gameNum)) { $gameNum = 0; } // space is needed since + is urldecoded as space $gameNum = floor(($gameNum + ($timeNow / (60 * 60 * 24))) % $numGames) + 1; } else if ($gameNum < 1) { $gameNum = 1; } else if ($gameNum > $numGames) { $gameNum = $numGames; } $debugInfo .= "#" . ($gameNum ^ $numGames) . "." . $numGames . "\n"; $gameNum -= 1; $pgnGame = $games[0][$gameNum]; $lightColorHex = get_param("lightColorHex", "lch", "EFF4EC"); // FFCC99 $lightColorHexCss = "#" . $lightColorHex; $darkColorHex = get_param("darkColorHex", "dch", "C6CEC3"); // CC9966 $darkColorHexCss = "#" . $darkColorHex; $controlBackgroundColorHex = get_param("controlBackgroundColorHex", "cbch", "EFF4EC"); // FFCC99 $controlBackgroundColorHexCss = "#" . $controlBackgroundColorHex; $controlTextColorHex = get_param("controlTextColorHex", "ctch", "888888"); // 663300 $controlTextColorHexCss = "#" . $controlTextColorHex; $squareSize = get_param("squareSize", "ss", "30"); $squareSizeCss = $squareSize . "px"; if ($squareSize < 20) { $squareSize = 20; } if ($squareSize < 30) { $borderStyleCss = "none"; $highlightBorderStyleCss = "none"; $borderSize = 0; $borderSizeCss = $borderSize; } else { $borderStyleCss = "solid"; $highlightBorderStyleCss = "inset"; $borderSize = ceil($squareSize / 50); $borderSizeCss = $borderSize . "px"; } $bareSquareSize = $squareSize - 2 * $borderSize; $bareSquareSizeCss = $bareSquareSize . "px"; function defaultPieceSize($ss) { $pieceSizeOptions = array(20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 52, 56, 60, 64, 72, 80, 88, 96, 112, 128, 144, 300); $targetPieceSize = floor(0.8 * $ss); for ($ii=count($pieceSizeOptions)-1; $ii>=0; $ii--) { if ($pieceSizeOptions[$ii] <= $targetPieceSize) { return $pieceSizeOptions[$ii]; } } return $pieceSizeOptions[0]; } $pieceSize = defaultPieceSize($squareSize - 2 * $borderSize); $pieceSizeCss = $pieceSize . "px"; $pieceFont = get_param("pieceFont", "pf", "default"); if ($pieceFont == "a") { $pieceFont = "alpha"; } if ($pieceFont == "m") { $pieceFont = "merida"; } if ($pieceFont == "u") { $pieceFont = "uscf"; } if (($pieceFont == "random") || ($pieceFont == "r")) { $randomPiece = rand(0, 2); switch ($randomPiece) { case 1: $pieceFont = "alpha"; break; case 2: $pieceFont = "merida"; break; default: $pieceFont = "uscf"; break; } } if (($pieceFont == "hash") || ($pieceFont == "h")) { // $hashPiece = strlen($pgnGame) % 3; $hashPiece = $gameNum % 3; switch ($hashPiece) { case 1: $pieceFont = "alpha"; break; case 2: $pieceFont = "merida"; break; default: $pieceFont = "uscf"; break; } } if (($pieceFont == "default") || ($pieceFont == "d")) { if ($pieceSize < 28) { $pieceFont = "uscf"; } else { if ($pieceSize > 39) { $pieceFont = "merida"; } else { $pieceFont = "alpha"; } } } $boardSize = $squareSize * 8; $boardSizeCss = $boardSize . "px"; $buttonHeight = $squareSize; $buttonHeightCss = $buttonHeight . "px"; $buttonWidth = $squareSize * 4; $buttonWidthCss = $buttonWidth . "px"; $buttonFontSize = floor($squareSize / 2.5); if ($buttonFontSize < 10) { $buttonFontSize = 10; } $buttonFontSizeCss = $buttonFontSize . "px"; $buttonPadding = floor($squareSize / 10); $sidetomoveBorder = floor($buttonFontSize / 18) + 1; $sidetomoveBorderCss = $sidetomoveBorder . "px"; $sidetomoveHeight = floor(0.8 * $buttonFontSize - 2 * $sidetomoveBorder); $sidetomoveHeightCss = $sidetomoveHeight . "px"; $sidetomoveWidth = $sidetomoveHeight; $sidetomoveWidthCss = $sidetomoveWidth . "px"; $frameBorderColorHex = get_param("frameBorderColorHex", "fbch", "C6CEC3"); if ($frameBorderColorHex == "none") { $frameBorderStyleCss = "none"; $frameBorderWidth = 0; $frameBorderWidthCss = "0"; $frameBorderColorHex = "000000"; } else { $frameBorderStyleCss = "outset"; $frameBorderWidth = ceil($squareSize / 50); $frameBorderWidthCss = $frameBorderWidth . "px"; } $frameBorderColorHexCss = "#" . $frameBorderColorHex; $frameWidth = $boardSize; $frameWidthCss = $frameWidth . "px"; $frameHeight = $boardSize + $buttonHeight; $frameHeightCss = $frameHeight . "px"; // undocumented features $backgroundColorHex = get_param("backgroundColorHex", "bch", "transparent"); if (preg_match("/^[0123456789ABCDEF]{6}$/i", $backgroundColorHex)) { $backgroundColorHexCss = "#" . $backgroundColorHex; } else { $backgroundColorHexCss = $backgroundColorHex; } $framePadding = get_param("framePadding", "fp", 0); if ($framePadding != 0) { $framePaddingCss = $framePadding . "px"; } else { $framePaddingCss = $framePadding; } $rawGame = ""; $fenString = get_param("fenString", "fs", ""); if (($fenString == "true") || ($fenString == "t")) { if (preg_match('/\[\s*FEN\s*"([^"]*)"\s*\]/', $pgnGame, $matches)) { $rawGame = $matches[1]; } } $pgnOnly = get_param("pgnOnly", "po", ""); if (($pgnOnly == "true") || ($pgnOnly == "t")) { $rawGame = $pgnGame; } $pgnOnlyMini = get_param("pgnOnlyMini", "pom", ""); if (($pgnOnlyMini == "true") || ($pgnOnlyMini == "t")) { if (preg_match('/\[\s*FEN\s*"[^"]*"\s*\]/', $pgnGame, $matches)) { $rawGame = "[SetUp \"1\"]\n" . $matches[0] . "\n\n"; } $rawGame = $rawGame . preg_replace('/\[\s*\w+\s*"[^"]*"\s*\]\s*/', "", $pgnGame); } // end of undocumented features $outerFrameWidth = $frameWidth + 2 * $frameBorderWidth + 2 * $framePadding; $outerFrameHeight = $frameHeight + 2 * $frameBorderWidth + 2 * $framePadding; function curPageURL() { if ((isset($_SERVER["SERVER_NAME"])) && (isset($_SERVER["REQUEST_URI"]))) { $pageURL = 'http'; if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on")) { $pageURL .= "s"; } $pageURL .= "://"; if ((isset($_SERVER["SERVER_PORT"])) && ($_SERVER["SERVER_PORT"] != "80")) { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } } else { $pageURL = ""; } return $pageURL; } $thisPage = curPageURL(); $expiresMeta = ""; if ($expiresDate) { header("expires: " . $expiresDate); $expiresMeta = ""; } if ($rawGame) { header("content-type: application/x-chess-pgn; charset=utf-8"); header("content-disposition: inline; filename=puzzler.pgn"); print $rawGame; exit; } header("content-type: text/html; charset=utf-8"); print << $expiresMeta chess puzzler
END; ?>