fix: library IDs stay hidden without library access (ruling P13)
Outline, node-get, write outlines, the render summary and replace-text's opaque-node match name no library ID unless the library group is visible and the user has divi_library; read-only still names them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -68,14 +68,20 @@ final class DiviTextSearch
|
||||
}
|
||||
|
||||
/**
|
||||
* Every hit of $page, computed without changing it.
|
||||
* Every hit of $page, computed without changing it. Without $globalIds (ruling P13: no library
|
||||
* access) the library IDs a global instance stores are no text to find: an opaque node is
|
||||
* matched without globalModule/globalParent, as if they were not stored.
|
||||
*
|
||||
* @return array{count: int, samples: list<array<string, string>>,
|
||||
* blocks: list<array{Block, array<string, mixed>}>, skipped_nodes: list<array{id: string, reason: string}>}
|
||||
* @throws InvalidArgumentException When a place would be changed unsafely – the page fails.
|
||||
*/
|
||||
public function replace(DiviPage $page, TextReplacer $replacer, ValueCleaner $cleaner): array
|
||||
{
|
||||
public function replace(
|
||||
DiviPage $page,
|
||||
TextReplacer $replacer,
|
||||
ValueCleaner $cleaner,
|
||||
bool $globalIds = true
|
||||
): array {
|
||||
$count = 0;
|
||||
$samples = [];
|
||||
$blocks = [];
|
||||
@@ -83,7 +89,8 @@ final class DiviTextSearch
|
||||
foreach ($page->index->entries() as $entry) {
|
||||
$block = $entry['block'];
|
||||
if ($block->isDivi() && $block->isOpaque()) {
|
||||
if ($replacer->mentions(Serializer::block($block))) {
|
||||
$markup = $globalIds ? Serializer::block($block) : self::withoutLibraryIds($block);
|
||||
if ($replacer->mentions($markup)) {
|
||||
$skipped[] = ['id' => (string) $entry['id'], 'reason' => self::opaqueReason($block)];
|
||||
}
|
||||
continue;
|
||||
@@ -112,6 +119,22 @@ final class DiviTextSearch
|
||||
return ['count' => $count, 'samples' => $samples, 'blocks' => $blocks, 'skipped_nodes' => $skipped];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruling P13: $block's markup with every globalModule/globalParent left out, at every depth –
|
||||
* only for matching, never saved.
|
||||
*/
|
||||
private static function withoutLibraryIds(Block $block): string
|
||||
{
|
||||
$attrs = $block->attrs();
|
||||
unset($attrs['globalModule'], $attrs['globalParent']);
|
||||
$markup = '<!-- wp:' . $block->name() . ' ' . Serializer::attributes($attrs) . ' -->';
|
||||
foreach ($block->isVoid() ? [] : $block->parts() as $part) {
|
||||
$markup .= $part instanceof Block ? self::withoutLibraryIds($part) : $part;
|
||||
}
|
||||
|
||||
return $markup . '<!-- /wp:' . $block->name() . ' -->';
|
||||
}
|
||||
|
||||
/** Why an opaque node is not changed (global modules are edited in the Divi library, Etappe 3). */
|
||||
private static function opaqueReason(Block $block): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user