%s\n", $group['name']); printf("\n"); } } function displayGamesList($pgnfile) { static $num=1; if (!file_exists($pgnfile)) { printf("

%s: not such file or directory.

", $pgnfile); } $parser = new PgnParser($pgnfile, false); $gameListUnparsed = $parser->getUnparsedGames(); // array $gameList=$parser->getGames(); printf("
\n"); printf("

Download PGN

", $pgnfile); printf("\n", $num); $num++; printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); $i=1; foreach ($gameList as $game) { printf(" \n"); printf(" \n", $i); printf(" \n", htmlspecialchars($pgnfile)); printf(" \n", htmlspecialchars($game['date'])); printf(" \n", htmlspecialchars($game['white'])); if (isset($game['metadata']['whiteelo'])) { printf(" \n", htmlspecialchars($game['metadata']['whiteelo'])); } else { printf(" \n"); } printf(" \n", htmlspecialchars($game['black'])); if (isset($game['metadata']['blackelo'])) { printf(" \n", htmlspecialchars($game['metadata']['blackelo'])); } else { printf(" \n"); } printf(" \n", htmlspecialchars($game['result'])); printf(" \n", ($game['plycount'] + 1) / 2); //echo "
";
    //print_r($game);
    //echo "
"; printf(" \n", isset($game['metadata']['ecot']) ? $game['metadata']['ecot'] : (isset($game['eco']) ? $game['eco'] : "?")); printf(" \n"); /* printf(" \n", "showgame.phtml", htmlspecialchars($pgnfile), $i); */ printf(" \n", htmlspecialchars($game['event'])); printf(" \n", isset($game['round']) && ctype_digit($game['round']) ? $game['round']: "-"); if (isset($game['site'])) { printf(" \n", htmlspecialchars($game['site'])); } else { printf(" \n"); } printf(" \n"); $i++; } printf("\n"); printf("
#urlDateWhiteEloBlackEloResultMovesECOOpeningEventRoundPlace
%d%s%s%s%s?%s%s?%s%d%s"); if (isset($game['metadata']['openingt'])) { printf("%s", $game['metadata']['openingt']); if (isset($game['metadata']['variationt'])) printf(", %s", $game['metadata']['variationt']); } else if (isset($game['metadata']['opening'])) { printf("%s", $game['metadata']['opening']); if (isset($game['metadata']['variation'])) printf(", %s", $game['metadata']['variation']); } else { printf("?"); } printf("%s?file=%s&game=%d%s%s%s?
\n"); printf("
\n"); printf("
\n"); } function getGameJson($pgnfile, $game="1") { // check arguments //printf("
");
  if (! (preg_match("/^[0-9]+$/", $game))) {
    printf("Game number: [%s] is not an integer\n", htmlspecialchars($game));
    return "";
  }
  //printf("game=%d\n\n", $game);
  if (! (preg_match("/^[-\/a-zA-Z0-9]+\.pgn$/", $pgnfile))) {
    printf("Wrong filename\n");
    return "";
  }
  //printf("file=%s\n", $pgnfile);

  //$parser = new PgnParser( 'annotated.pgn', false );
  //$gamelist_unparsed = $parser->getUnparsedGames(); // array
  //var_dump( $gamelist_unparsed );
  //return;

  $parser = new PgnParser($pgnfile, false);
  //$gameListUnparsed = $parser->getUnparsedGames(); // array
  $gameList=$parser->getGames();
  $game--;
  //printf("game=%d size=%d\n", $game, sizeof($gameListUnparsed));
  if ($game < 0 || $game >= sizeof($gameList)) {
    printf("Wrong game number\n");
    return "";
  }
  $theGame=$gameList[$game];

  //print_r($parser);
  //print_r($gameListUnparsed);
  //printf("STR=+%s+\n", $thegamestring);
  //printf("JSONSTR=+%s+\n", json_encode($thegamestring));
  //printf("\n
"); return $theGame; } function getGameString($pgnfile, $game="1") { // check arguments //printf("
");
  if (! (preg_match("/^[0-9]+$/", $game))) {
    printf("Game number: not an integer\n");
    return "";
  }
  //printf("game=%d\n\n", $game);
  if (! (preg_match("/^[-\/a-zA-Z0-9]+\.pgn$/", $pgnfile))) {
    printf("Wrong filename\n");
    return "";
  }
  //printf("file=%s\n", $pgnfile);

  //$parser = new PgnParser( 'annotated.pgn', false );
  //$gamelist_unparsed = $parser->getUnparsedGames(); // array
  //var_dump( $gamelist_unparsed );
  //return;

  $parser = new PgnParser($pgnfile, false);
  // $gameListUnparsed = $parser->getUnparsedGames(); // array
  $gameList=$parser->getGames();
  $game--;
  //printf("game=%d size=%d\n", $game, sizeof($gameListUnparsed));
  if ($game < 0 || $game >= sizeof($gameList)) {
    printf("Wrong game number\n");
    return "";
  }
  //printf("
");
  //print_r($gameList);
  $thegamestring=$gameList[$game]['movesStr'];
  //printf("
"); //print_r($parser); //print_r($gameListUnparsed); //printf("STR=+%s+\n", $thegamestring); //printf("JSONSTR=+%s+\n", json_encode($thegamestring)); //printf("\n
"); return addslashes(json_encode($thegamestring)); } ?>