(.*?)<\/blockquote>/us', '𒐫$1𒐫', $text); } function array_map_recursive(callable $callback, $array) { foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = array_map_recursive($callback, $value); } else { $array[$key] = $callback($value); } } return $array; } function convertDataToCompareFormat(array $data): array { return array_map_recursive(function ($v) { return is_string($v) ? convertToUnicodeEnclosure($v) : $v; }, $data); } // ✅ NEW: Strip all non-message keys (keep only 'value') function stripNonMessageKeys($array) { $result = []; foreach ($array as $dateKey => $payload) { if (is_array($payload) && isset($payload['value'])) { $result[$dateKey] = ['value' => $payload['value']]; } } return $result; } function entryExists(array $entry, array $local): bool { $needle = stripNonMessageKeys($entry); $needleJson = json_encode($needle, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); foreach ($local as $item) { $haystack = stripNonMessageKeys($item); $haystackJson = json_encode($haystack, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); if ($needleJson === $haystackJson) return true; } return false; } // Load remote $remoteJson = file_get_contents($remoteUrl); if (!$remoteJson) die(" Failed to load remote JSON."); $remoteRaw = json_decode($remoteJson, true); if (!is_array($remoteRaw)) die(" Failed to decode remote JSON."); // Load local if (!file_exists($localFile)) die(" Local JSON file '$localFile' not found."); $localJson = file_get_contents($localFile); $localRaw = json_decode($localJson, true); if (!is_array($localRaw)) die(" Failed to decode local JSON."); // Normalize local for comparison $localForCompare = array_map('convertDataToCompareFormat', $localRaw); // Find new entries $newRemoteEntries = []; $current_time = date('YmdHis'); // Current timestamp in the format YmdHis foreach ($remoteRaw as $entry) { foreach ($entry as $payload) { if (isset($payload['value']) && strpos($payload['value'], '•acws') !== false) { $original = $entry; $converted = array_map_recursive(function ($v) { return is_string($v) ? convertToBlockquoteTags($v) : $v; }, $entry); if (!entryExists(convertDataToCompareFormat($converted), $localForCompare)) { $newRemoteEntries[] = [ 'original' => $original, 'to_append' => $converted, 'time' => $current_time // Add the 'time' key with the timestamp ]; } break; } } } // Confirm save if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['confirm'])) { if (count($newRemoteEntries) > 0) { $newConverted = array_map(function ($e) { $converted = $e['to_append']; foreach ($converted as $dateKey => &$payload) { if (is_array($payload) && isset($payload['value'])) { $payload['time'] = $e['time']; $hash = substr(md5($payload['value']), 0, 8); $payload['status'] = "{$dateKey}-$hash"; } } return $converted; }, $newRemoteEntries); $newData = array_merge($newConverted, $localRaw); $written = file_put_contents( $localFile, json_encode($newData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ); if ($written === false) { echo "Failed to write to local file.
"; } else { echo "Added " . count($newConverted) . " new entries to
"; $newRemoteEntries = []; } } } ?>$localFile.Review New •acws Entries New
0): ?>•acwsEntriesnew entries found in remote file not present in local.
$entryPair): ?>Original Message #
JSON to be Appended
No new
•acwsentries found.