/** * Render paywall */ public function renderPaywall($content) { // Skip if in Elementor editor if ($this->isElementorEditor()) { return $content; } // Check if we should show full paywall or teaser+paywall $showFullPaywall = apply_filters('en_paywall_show_full', false); if ($showFullPaywall) { // Show only the paywall CTA, no content at all return $this->getCTA(); } // Configuration - Montrer les 2 premières LIGNES $teaserLines = apply_filters('en_paywall_teaser_lines', 2); // Split content into lines while preserving HTML $teaser = ''; $remaining = $content; // Method 1: Try to split by sentences first $sentences = preg_split('/(?<=[.!?])\s+/', strip_tags($content), -1, PREG_SPLIT_NO_EMPTY); if (count($sentences) >= $teaserLines) { // Take first X sentences as "lines" $teaserText = implode(' ', array_slice($sentences, 0, $teaserLines)); // Find where this text ends in the original HTML content $plainContent = strip_tags($content); $cutPosition = strpos($plainContent, substr($teaserText, -20)); // Find last 20 chars if ($cutPosition !== false) { // Try to find the corresponding position in HTML $tempContent = $content; $htmlPosition = 0; $textPosition = 0; while ($textPosition < $cutPosition && $htmlPosition < strlen($content)) { if ($content[$htmlPosition] === '<') { // Skip HTML tag $closeTag = strpos($content, '>', $htmlPosition); $htmlPosition = $closeTag + 1; } else { $textPosition++; $htmlPosition++; } } // Cut at paragraph boundary if possible $nextP = strpos($content, '
', $htmlPosition); if ($nextP !== false && $nextP - $htmlPosition < 200) { $teaser = substr($content, 0, $nextP + 4); $remaining = substr($content, $nextP + 4); } else { // Fallback: just add the text in a paragraph $teaser = '' . $teaserText . '...
'; } }