From 2bb109b77c69237ff5af71156fed4ae00ba6b054 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 5 Jun 2021 12:56:14 +0200 Subject: [PATCH 1/4] remove wrong file_put_contents --- PgnParser.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/PgnParser.php b/PgnParser.php index 8f5ea93..814b37a 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -104,8 +104,6 @@ private function getPgnGamesAsArray($pgn) $content = "\n\n" . $pgn; $games = preg_split("/\n\n\[/s", $content, -1, PREG_SPLIT_DELIM_CAPTURE); - file_put_contents("parsed.pgn", $content); - for ($i = 1, $count = count($games); $i < $count; $i++) { $gameContent = trim("[" . $games[$i]); if (strlen($gameContent) > 10) { From 0752f04ce44dd9f33e7846982afe81bb58e69ba6 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 5 Jun 2021 13:02:43 +0200 Subject: [PATCH 2/4] Fix bug #11 (lost double quotes in "] pattern --- PgnParser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PgnParser.php b/PgnParser.php index 814b37a..1a2ae77 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -64,8 +64,7 @@ public function setPgnContent($content) private function cleanPgn() { $c = $this->pgnContent; - - $c = preg_replace('/"\]\s{0,10}\[/s', "]\n[", $c); + $c = preg_replace('/"\]\s{0,10}\[/s', "\"]\n[", $c); $c = preg_replace('/"\]\s{0,10}([\.0-9]|{)/s', "\"]\n\n$1", $c); $c = preg_replace("/{\s{0,6}\[%emt[^\}]*?\}/", "", $c); From 6c8c93f4514faee8292bd2ab7047866156b032bd Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 5 Jun 2021 13:12:35 +0200 Subject: [PATCH 3/4] Cancel "$1" style removal in cleanPgn --- PgnParser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/PgnParser.php b/PgnParser.php index 1a2ae77..256224a 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -69,7 +69,6 @@ private function cleanPgn() $c = preg_replace("/{\s{0,6}\[%emt[^\}]*?\}/", "", $c); - $c = preg_replace("/\\$[0-9]+/s", "", $c); $c = str_replace("({", "( {", $c); $c = preg_replace("/{([^\[]*?)\[([^}]?)}/s", '{$1-SB-$2}', $c); $c = preg_replace("/\r/s", "", $c); From 638ad1fd2d2dcd72123def9b9cf57305c26db888 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sat, 5 Jun 2021 20:41:53 +0200 Subject: [PATCH 4/4] keep a string of moves/comments when parsing PGN. --- CHESS_JSON.php | 13 ++++++++----- PgnGameParser.php | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHESS_JSON.php b/CHESS_JSON.php index 57cd594..7f9a77e 100755 --- a/CHESS_JSON.php +++ b/CHESS_JSON.php @@ -11,6 +11,7 @@ class CHESS_JSON { const MOVE_ACTIONS = 'actions'; const MOVE_VARIATIONS = 'variations'; const MOVE_MOVES = 'moves'; + const MOVE_MOVES_STRING = 'movesStr'; const MOVE_CAPTURE = 'capture'; const MOVE_PROMOTE_TO = 'promoteTo'; const MOVE_CASTLE = 'castle'; @@ -29,10 +30,12 @@ class CHESS_JSON { const PGN_KEY_ACTION_CLR_ARROW = "cal"; - protected static $jsKeys = array('MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN','MOVE_COMMENT', - 'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES','MOVE_CAPTURE','MOVE_PROMOTE_TO','MOVE_CASTLE', - 'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE','GAME_BLACK', 'GAME_ECO', - + protected static $jsKeys = array( + 'MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN', + 'MOVE_COMMENT', 'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES', + 'MOVE_MOVES_STRING', 'MOVE_CAPTURE', 'MOVE_PROMOTE_TO', 'MOVE_CASTLE', + 'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE', 'GAME_BLACK', + 'GAME_ECO', ); public static function toJavascript(){ @@ -42,4 +45,4 @@ public static function toJavascript(){ } return 'ludo.CHESS_JSON_KEY = ' . json_encode($ret) .';'; } -} \ No newline at end of file +} diff --git a/PgnGameParser.php b/PgnGameParser.php index 8ef93fc..7cb7ba7 100755 --- a/PgnGameParser.php +++ b/PgnGameParser.php @@ -28,6 +28,7 @@ public function setPgn($pgnGame){ public function getParsedData(){ $this->gameData = $this->getMetadata(); + $this->gameData[CHESS_JSON::MOVE_MOVES_STRING] = $this->getMoveString(); $this->gameData[CHESS_JSON::MOVE_MOVES] = $this->getMoves(); return $this->gameData; } @@ -140,4 +141,4 @@ private function getMoveString() { $gameData = preg_replace("/(\s+)/", " ", $gameData); return trim($gameData); } -} \ No newline at end of file +}