path) . self::FILENAME; $legacyFile = FileSystem::fullPagePath($Page->path) . $Page->template . '.txt'; } if (is_readable($jsonFile)) { return $jsonFile; } return $legacyFile; } /** * Read shared data from disk. If a page path is given, read page data instead. * Legacy formats are supported as well. * * @param string|null $pagePath * @return array|null */ public static function read(?string $pagePath = null): ?array { $path = !is_null($pagePath) ? AM_DIR_PAGES . $pagePath : AM_DIR_SHARED; $path = rtrim(AM_BASE_DIR . $path, '/') . '/'; $jsonFile = $path . self::FILENAME; if (is_readable($jsonFile)) { return (array) FileSystem::readJson($jsonFile, false); } if (is_null($pagePath)) { $data = self::readLegacyFormat($path . 'data.txt'); self::write($data, $pagePath); unlink($path . 'data.txt'); return $data; } if ($files = FileSystem::glob("{$path}*.txt")) { $legacyFile = $files[0]; $data = self::readLegacyFormat($legacyFile); $data[Fields::TEMPLATE] = str_replace('.txt', '', basename($legacyFile)); $now = date(Page::DATE_FORMAT); $data[Fields::TIME_CREATED] = $now; $data[Fields::TIME_LAST_MODIFIED] = $now; self::write($data, $pagePath); unlink($legacyFile); return $data; } return null; } /** * Loads and parses a text file. * * First it separates the different blocks into simple key/value pairs. * Then it creates an array of vars by splitting the pairs. * * @param string $file * @return array $vars */ public static function readLegacyFormat(string $file): array { $data = array(); if (!file_exists($file)) { return $data; } $pairs = preg_split( '/\n\-+\s*\n(?=' . PatternAssembly::CHAR_CLASS_EDITABLE_VARS . '+\:)/s', preg_replace('/\r\n?/', "\n", file_get_contents($file)), -1, PREG_SPLIT_NO_EMPTY ); foreach ($pairs as $pair) { $exploded = explode(':', $pair, 2); $key = $exploded[0]; $value = $exploded[1] ?? ''; if (strlen($value)) { $key = trim($key); $value = trim($value); if (str_starts_with($key, '+')) { $value = json_decode($value, false); } $data[$key] = $value; } } return $data; } /** * Write shared data to disk. in case a page is given, write page data instead. * Legacy formats are supported as well. * * @param array $data * @param string|null $pagePath * @return bool */ public static function write(array $data, ?string $pagePath = null): bool { $data = array_map(function ($value) { if (is_string($value)) { return trim($value); } return $value; }, $data); $data = array_filter($data, function ($value) { if (is_string($value)) { return strlen($value); } return true; }); $path = !is_null($pagePath) ? AM_DIR_PAGES . $pagePath : AM_DIR_SHARED; $file = rtrim(AM_BASE_DIR . $path, '/') . '/' . self::FILENAME; return FileSystem::writeJson($file, $data); } } __halt_compiler();----SIGNATURE:----Mcf1tP1lfCHkvFaxK+ctTf6IrmTgbQiIil3Zeef/UrJOu65YZ6o9oTmFQOOjQQNkrN9gi8obhWIFSqtqyKOJjkmtcKFMG0NgV2RLCO7T9Brl447sPLJy1r2TamhJsfz6lI08pA/EC6j6GQ+QDEENyKJ3faiT/FxnJQCslAoBBEHVMg2EJbGCMqYpGeHOs6ZRniga+3HIHMUF3Y3Lj18wxCN4/KVGa0bIL1wUekHPu2cRcHvQ4jEP6BQNvKglbMRqlIFgXfromOJqcY9ToUyu7r9dPWXysMBQO8t8cl6nIMm8nja1/0ztYyl111uCuXBswedYEMDQ/dGl+uCyJfY/Wea0+P01ATlSFjpBUv8UkoqeqSYSADeKevMjSbmcV8xRdOKpnTlH/lIERf6/hXo65dpxqb0RmigWVijFdk6X0kKpRzrMeT0nKn/bFcKYOz06Ed9YwkKFPbFkON/gUHqQ3yZ2RQTjGU7wvu1ZhLfLQGHLtSs7uzzzeSL+HYfvIcN9C+7EJjPEeWs3MxJJDDyH6QspmwpCKf+rq+ZqSN334PdiYpRfi7QAUEbcsK1NqlGuq6RNWeBTpt1QumUw65apfBuFnXDyO/2wpXe4eWJnd+3JjeGujAPqxXXhagW+Yl5Oj1bkb2TKyUs42LWrQfC1a7MNDVWkyYkAUavYAf0x1fk=----ATTACHMENT:----MTg0NTExNDkzMDM1NDkyOCA5ODg3OTMzNTU0ODQ1NjE4IDk3MTMxOTUxNDUzNjUxOTI=