chore(php): add temporary debug to content ad injector

This commit is contained in:
FrankZamora
2025-12-10 12:30:27 -06:00
parent 50c411408e
commit 8bbbf484bd

View File

@@ -43,20 +43,24 @@ final class ContentAdInjector
*/ */
public function inject(string $content): string public function inject(string $content): string
{ {
// DEBUG TEMPORAL
$debug = '<!-- ROI_AD_DEBUG: inject() called, content length=' . strlen($content) . ' -->';
// PASO 0: Validar longitud minima (aplica a todos los modos) // PASO 0: Validar longitud minima (aplica a todos los modos)
$minLength = (int)($this->settings['forms']['min_content_length'] ?? 500); $minLength = (int)($this->settings['forms']['min_content_length'] ?? 500);
if (strlen(strip_tags($content)) < $minLength) { if (strlen(strip_tags($content)) < $minLength) {
return $content; return $debug . '<!-- SKIP: too short -->' . $content;
} }
// Determinar modo de operacion // Determinar modo de operacion
$mode = $this->settings['incontent_advanced']['incontent_mode'] ?? 'paragraphs_only'; $mode = $this->settings['incontent_advanced']['incontent_mode'] ?? 'paragraphs_only';
$debug .= '<!-- MODE=' . $mode . ' -->';
if ($mode === 'paragraphs_only') { if ($mode === 'paragraphs_only') {
return $this->injectParagraphsOnly($content); return $debug . $this->injectParagraphsOnly($content);
} }
return $this->injectAdvanced($content); return $debug . $this->injectAdvanced($content);
} }
/** /**
@@ -113,33 +117,38 @@ final class ContentAdInjector
private function injectAdvanced(string $content): string private function injectAdvanced(string $content): string
{ {
$config = $this->settings['incontent_advanced'] ?? []; $config = $this->settings['incontent_advanced'] ?? [];
$debug = '<!-- ADV: config keys=' . implode(',', array_keys($config)) . ' -->';
// Obtener configuracion // Obtener configuracion
$maxAds = (int)($config['incontent_max_total_ads'] ?? 8); $maxAds = (int)($config['incontent_max_total_ads'] ?? 8);
$minSpacing = (int)($config['incontent_min_spacing'] ?? 3); $minSpacing = (int)($config['incontent_min_spacing'] ?? 3);
$priorityMode = $config['incontent_priority_mode'] ?? 'position'; $priorityMode = $config['incontent_priority_mode'] ?? 'position';
$format = $config['incontent_format'] ?? 'in-article'; $format = $config['incontent_format'] ?? 'in-article';
$debug .= '<!-- ADV: maxAds=' . $maxAds . ' minSpacing=' . $minSpacing . ' -->';
// PASO 1: Escanear contenido para encontrar todas las ubicaciones // PASO 1: Escanear contenido para encontrar todas las ubicaciones
$locations = $this->scanContent($content); $locations = $this->scanContent($content);
$debug .= '<!-- ADV: scanContent found ' . count($locations) . ' locations -->';
if (empty($locations)) { if (empty($locations)) {
return $content; return $debug . '<!-- ADV: NO locations found -->' . $content;
} }
// PASO 2: Filtrar por configuracion (enabled) // PASO 2: Filtrar por configuracion (enabled)
$locations = $this->filterByEnabled($locations, $config); $locations = $this->filterByEnabled($locations, $config);
$debug .= '<!-- ADV: filterByEnabled left ' . count($locations) . ' -->';
if (empty($locations)) { if (empty($locations)) {
return $content; return $debug . '<!-- ADV: EMPTY after filterByEnabled -->' . $content;
} }
// PASO 3: Aplicar probabilidad deterministica // PASO 3: Aplicar probabilidad deterministica
$postId = get_the_ID() ?: 0; $postId = get_the_ID() ?: 0;
$locations = $this->applyProbability($locations, $config, $postId); $locations = $this->applyProbability($locations, $config, $postId);
$debug .= '<!-- ADV: applyProbability left ' . count($locations) . ' -->';
if (empty($locations)) { if (empty($locations)) {
return $content; return $debug . '<!-- ADV: EMPTY after applyProbability -->' . $content;
} }
// PASO 4-5: Filtrar por espaciado y limite (segun priority_mode) // PASO 4-5: Filtrar por espaciado y limite (segun priority_mode)
@@ -148,16 +157,19 @@ final class ContentAdInjector
} else { } else {
$locations = $this->filterByPositionFirst($locations, $minSpacing, $maxAds); $locations = $this->filterByPositionFirst($locations, $minSpacing, $maxAds);
} }
$debug .= '<!-- ADV: filterBySpacing left ' . count($locations) . ' -->';
if (empty($locations)) { if (empty($locations)) {
return $content; return $debug . '<!-- ADV: EMPTY after filterBySpacing -->' . $content;
} }
// Ordenar por posicion para insercion correcta // Ordenar por posicion para insercion correcta
usort($locations, fn($a, $b) => $a['position'] <=> $b['position']); usort($locations, fn($a, $b) => $a['position'] <=> $b['position']);
$debug .= '<!-- ADV: INSERTING ' . count($locations) . ' ads -->';
// PASO 6: Insertar anuncios // PASO 6: Insertar anuncios
return $this->insertAds($content, $locations, $format); return $debug . $this->insertAds($content, $locations, $format);
} }
/** /**