feat: social media aggregator (YouTube, Instagram, TikTok, WordPress)

This commit is contained in:
2026-05-18 17:49:23 +04:00
parent 18cf71a7da
commit 5c3b35cb3c
10 changed files with 1679 additions and 906 deletions
+41 -1
View File
@@ -111,6 +111,46 @@ function isValidWordPressUrl($url) {
return true;
}
/**
* Retourne le nombre total d'articles publiés sur WordPress.
* Lit le header X-WP-Total renvoyé par l'API REST.
*/
function getWordPressPostCount(): ?int {
if (!defined('WORDPRESS_ENABLED') || !WORDPRESS_ENABLED || empty(WORDPRESS_URL)) return null;
if (!isValidWordPressUrl(WORDPRESS_URL)) return null;
$cached = $GLOBALS['simple_api_cache']->get('wp_post_count', []);
if ($cached !== null) return (int) $cached ?: null;
$url = WORDPRESS_URL . '/wp-json/wp/v2/posts?per_page=1&_fields=id';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_USERAGENT => 'KaubuntuRe-WordPress-Integration/1.0',
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
curl_close($ch);
if (!$response || $httpCode < 200 || $httpCode >= 300) return null;
$headers = substr($response, 0, $headerSize);
if (!preg_match('/X-WP-Total:\s*(\d+)/i', $headers, $m)) return null;
$count = (int) $m[1];
$GLOBALS['simple_api_cache']->set('wp_post_count', [], $count, 86400);
return $count;
}
/**
* Récupère les articles WordPress récents
*
@@ -157,7 +197,7 @@ function formatWordPressPosts($posts) {
// Nettoyer l'extrait HTML
$excerpt = '';
if (isset($post['excerpt']['rendered'])) {
$excerpt = wp_strip_all_tags($post['excerpt']['rendered']);
$excerpt = html_entity_decode(wp_strip_all_tags($post['excerpt']['rendered']), ENT_QUOTES | ENT_HTML5, 'UTF-8');
$excerpt = trim($excerpt);
// Limiter à 150 caractères
if (strlen($excerpt) > 150) {