searchValue = preg_quote($searchValue, '/'); $this->regexFlags = 'ims'; if ($isRegex) { $this->searchValue = str_replace('/', '\/', $searchValue); } if ($isCaseSensitive) { $this->regexFlags = 'ms'; } $this->replaceValue = $replaceValue; } /** * Replace matches with a given string in a given list of files. * * @param array $fileFieldsArray * @return bool true on success */ public function replaceInFiles(array $fileFieldsArray): bool { if (!$this->replaceValue || empty($fileFieldsArray)) { Debug::log('No files or replacement string'); return false; } foreach ($fileFieldsArray as $FileFields) { $data = DataFile::read($FileFields->path) ?? array(); $data = $this->replaceInData($data, $FileFields->fields); DataFile::write($data, $FileFields->path); } Cache::clear(); return true; } /** * Replace matches in block data recursively. * * @param array $blocks * @return array the processed blocks */ private function replaceInBlocksRecursively(array $blocks): array { foreach ($blocks as $index => $block) { if ($block->type == 'section') { $block->data->content->blocks = $this->replaceInBlocksRecursively($block->data->content->blocks); } else { foreach ($block->data as $key => $value) { if (Search::isValidBlockProperty($key)) { $block->data->{$key} = $this->replaceInValueRecursively($value); } } } $blocks[$index] = $block; } return $blocks; } /** * Replace matches in data for a given list of keys. * * @param array $data * @param array $fields * @return array the processed data array */ private function replaceInData(array $data, array $fields): array { foreach ($fields as $field) { if (str_starts_with($field, '+') && is_object($data[$field])) { $data[$field]->blocks = $this->replaceInBlocksRecursively($data[$field]->blocks); Debug::log($data[$field]->blocks, 'Blocks'); } else { $data[$field] = $this->replaceString($data[$field]); } } return $data; } /** * Replace searched string in a value that is either a string or an multidimensional array of strings. * * @param mixed $value * @return mixed $value */ private function replaceInValueRecursively(mixed $value): mixed { if (is_array($value) || is_object($value)) { $array = array(); foreach ($value as $key => $item) { $array[$key] = $this->replaceInValueRecursively($item); } return is_object($value) ? (object) $array : $array; } return $this->replaceString($value); } /** * Check whether a value is a string and then perfom a replace. * * @param mixed $value * @return mixed * @psalm-return ($value is string ? string : mixed) */ private function replaceString(mixed $value): mixed { if (is_string($value)) { return preg_replace( '/' . $this->searchValue . '/' . $this->regexFlags, $this->replaceValue, $value ); } return $value; } } __halt_compiler();----SIGNATURE:----atC/eBrIQ+p/EuoDFJXqX+tdfYJLquRS7F3TY+qwrheVyOCKPaJRac6w1hmX9B4MYIdEA0qJOazJtnjgEyT6O4j8QaR6gzxV9L/d+HE3cM/fQz99kGpOxzXxrcWhdN/rWGl6n+G+m4pMGx+1RzIvL1KJqCsVTHublp3oYtUz5MCEoldwGI1nEuVTGs11DBfT0ao3UEXybQ/nN2T9Ju+WyvTUrQxkWweprhJDgbPYNYSpdIizKlTn2vKlCoLarRp8ib9nt3EHVUP4YUz9/IjVmCO6pRzLDxBghUcTiDqHEzTdLR+FIKvd86dgCmTZSdX4b5hdEfQW+h9GGG3m9ArYLnpqkymzbMN6zAxsiDcl8VOi1tTW1yKmTcRxdr4SKbeS3Zt7HEN20Ba3ugeGMoPuDlKfK7Lnr+kwNuFZxX8E35sw9yuRF/26FISXaQ6IT5yCuTsLnz+2d/A7XfBy2ToEzz+T4Z3Y2/Kubu79bFygIRgfuQ0CHwfG+Nvss9uiL9m9pwE8wJN/ag0qf47BrFZwkm0DvESCMd5yW8X/CF6h081PsA9vKui2jw19YQHSgKuiwtBfRVw0wZDtLQCsa+mZylQr/03o95TYNbjcptoXbVbbjney1Sx7AwpCSl8MDJipmkdW1OmpXSRtr5zPcufutrAzJTHI5+rRbBi20+MxKGI=----ATTACHMENT:----NjQ5Mzg3MTE4OTE2OTI1MiAxNTMzMTM1NDg0MDIyNjA2IDMzMjA4MDM5NzM0MDY2NA==