chore(php): add temporary debug to content ad injector
This commit is contained in:
@@ -43,20 +43,24 @@ final class ContentAdInjector
|
||||
*/
|
||||
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)
|
||||
$minLength = (int)($this->settings['forms']['min_content_length'] ?? 500);
|
||||
if (strlen(strip_tags($content)) < $minLength) {
|
||||
return $content;
|
||||
return $debug . '<!-- SKIP: too short -->' . $content;
|
||||
}
|
||||
|
||||
// Determinar modo de operacion
|
||||
$mode = $this->settings['incontent_advanced']['incontent_mode'] ?? 'paragraphs_only';
|
||||
$debug .= '<!-- MODE=' . $mode . ' -->';
|
||||
|
||||
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
|
||||
{
|
||||
$config = $this->settings['incontent_advanced'] ?? [];
|
||||
$debug = '<!-- ADV: config keys=' . implode(',', array_keys($config)) . ' -->';
|
||||
|
||||
// Obtener configuracion
|
||||
$maxAds = (int)($config['incontent_max_total_ads'] ?? 8);
|
||||
$minSpacing = (int)($config['incontent_min_spacing'] ?? 3);
|
||||
$priorityMode = $config['incontent_priority_mode'] ?? 'position';
|
||||
$format = $config['incontent_format'] ?? 'in-article';
|
||||
$debug .= '<!-- ADV: maxAds=' . $maxAds . ' minSpacing=' . $minSpacing . ' -->';
|
||||
|
||||
// PASO 1: Escanear contenido para encontrar todas las ubicaciones
|
||||
$locations = $this->scanContent($content);
|
||||
$debug .= '<!-- ADV: scanContent found ' . count($locations) . ' locations -->';
|
||||
|
||||
if (empty($locations)) {
|
||||
return $content;
|
||||
return $debug . '<!-- ADV: NO locations found -->' . $content;
|
||||
}
|
||||
|
||||
// PASO 2: Filtrar por configuracion (enabled)
|
||||
$locations = $this->filterByEnabled($locations, $config);
|
||||
$debug .= '<!-- ADV: filterByEnabled left ' . count($locations) . ' -->';
|
||||
|
||||
if (empty($locations)) {
|
||||
return $content;
|
||||
return $debug . '<!-- ADV: EMPTY after filterByEnabled -->' . $content;
|
||||
}
|
||||
|
||||
// PASO 3: Aplicar probabilidad deterministica
|
||||
$postId = get_the_ID() ?: 0;
|
||||
$locations = $this->applyProbability($locations, $config, $postId);
|
||||
$debug .= '<!-- ADV: applyProbability left ' . count($locations) . ' -->';
|
||||
|
||||
if (empty($locations)) {
|
||||
return $content;
|
||||
return $debug . '<!-- ADV: EMPTY after applyProbability -->' . $content;
|
||||
}
|
||||
|
||||
// PASO 4-5: Filtrar por espaciado y limite (segun priority_mode)
|
||||
@@ -148,16 +157,19 @@ final class ContentAdInjector
|
||||
} else {
|
||||
$locations = $this->filterByPositionFirst($locations, $minSpacing, $maxAds);
|
||||
}
|
||||
$debug .= '<!-- ADV: filterBySpacing left ' . count($locations) . ' -->';
|
||||
|
||||
if (empty($locations)) {
|
||||
return $content;
|
||||
return $debug . '<!-- ADV: EMPTY after filterBySpacing -->' . $content;
|
||||
}
|
||||
|
||||
// Ordenar por posicion para insercion correcta
|
||||
usort($locations, fn($a, $b) => $a['position'] <=> $b['position']);
|
||||
|
||||
$debug .= '<!-- ADV: INSERTING ' . count($locations) . ' ads -->';
|
||||
|
||||
// PASO 6: Insertar anuncios
|
||||
return $this->insertAds($content, $locations, $format);
|
||||
return $debug . $this->insertAds($content, $locations, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user