function fetch_feed_content($url) { $response = wp_remote_get($url); if (is_wp_error($response)) { return false; } return wp_remote_retrieve_body($response); } function ae_update_news_ajax() { check_ajax_referer('ae_nonce', 'security'); if (!current_user_can('manage_options')) { wp_die('Unauthorized user'); } $selected_feed = sanitize_text_field($_POST['feeds']); if ($selected_feed == 'all') { $feeds = get_option('ae_feeds', array()); $feed_urls = array_values(array_column($feeds, 'url')); } else { $feed_urls = array($selected_feed); } if (empty($feed_urls)) { $response = array('error' => 'Nenhum feed selecionado.'); echo json_encode($response); wp_die(); } $feed_data = array(); $now = new DateTime(); foreach ($feed_urls as $feed_url) { $feed_content = fetch_feed_content($feed_url); if ($feed_content === false) { $response = array('error' => 'Não foi possível acessar o feed: ' . esc_url($feed_url)); echo json_encode($response); wp_die(); } $feed_xml = simplexml_load_string($feed_content); if ($feed_xml === false) { $response = array('error' => 'Erro ao processar o XML do feed: ' . esc_url($feed_url)); echo json_encode($response); wp_die(); } foreach ($feed_xml->channel->item as $item) { $pubDate = new DateTime((string) $item->pubDate); $interval = $now->diff($pubDate); if ($interval->days >= 1) { continue; } $title = sanitize_text_field((string) $item->title); $description = wp_kses_post((string) $item->description); $source = sanitize_text_field((string) $feed_xml->channel->title); $date = $pubDate->format('Y-m-d H:i:s'); $feed_data[] = array( 'title' => $title, 'description' => $description, 'source' => $source, 'date' => $date ); } } $collected_posts = get_option('ae_collected_posts', array()); $titles = array_column($collected_posts, 'title'); foreach ($feed_data as $data) { if (!in_array($data['title'], $titles)) { $collected_posts[] = $data; } } usort($collected_posts, function($a, $b) { return strtotime($b['date']) - strtotime($a['date']); }); update_option('ae_collected_posts', $collected_posts); if (empty($feed_data)) { $response = array( 'progress' => 100, 'message' => 'Nenhuma nova notícia encontrada.', 'new_results' => $collected_posts, 'finished' => true ); } else { $response = array( 'progress' => 100, 'message' => 'Atualização concluída!', 'new_results' => $collected_posts, 'finished' => true ); } echo json_encode($response); wp_die(); } add_action('wp_ajax_ae_update_news_ajax', 'ae_update_news_ajax'); function fetch_and_save_news_ajax() { check_ajax_referer('ae_nonce', 'security'); if (!current_user_can('manage_options')) { wp_send_json_error('Você não tem permissão para realizar esta ação.'); } $feed_name = sanitize_text_field($_POST['feed_name']); $feed_url = esc_url_raw($_POST['feed_url']); $use_news_api = sanitize_text_field($_POST['use_news_api']); if (empty($feed_name) || empty($feed_url)) { wp_send_json_error('Nome do feed e URL são obrigatórios.'); } $collected_posts = fetch_and_save_news($feed_name, $feed_url, $use_news_api); if ($collected_posts) { wp_send_json_success($collected_posts); } else { wp_send_json_error('Erro ao coletar notícias. Verifique a URL do feed ou a chave API.'); } } add_action('wp_ajax_fetch_and_save_news_ajax', 'fetch_and_save_news_ajax'); function fetch_and_save_news($feed_name, $feed_url, $use_news_api) { $articles = array(); if ($use_news_api) { $articles = fetch_news_from_api($feed_name); } else { $feed_content = fetch_feed_content($feed_url); if ($feed_content) { $feed_xml = simplexml_load_string($feed_content); foreach ($feed_xml->channel->item as $item) { $articles[] = array( 'title' => sanitize_text_field($item->title), 'description' => wp_kses_post($item->description), 'url' => esc_url($item->link), 'date' => date('Y-m-d H:i:s', strtotime($item->pubDate)) ); } } else { return false; } } $collected_posts = get_option('ae_collected_posts', array()); $titles = array_column($collected_posts, 'title'); foreach ($articles as $article) { if (!in_array($article['title'], $titles)) { $collected_posts[] = $article; } } usort($collected_posts, function($a, $b) { return strtotime($b['date']) - strtotime($a['date']); }); update_option('ae_collected_posts', $collected_posts); return $collected_posts; } function fetch_news_from_api($feed_name) { $api_key = get_option('news_api_key', ''); if (empty($api_key)) { return false; } $url = 'https://newsapi.org/v2/everything?' . http_build_query(array( 'q' => $feed_name, 'apiKey' => $api_key )); $response = wp_remote_get($url); if (is_wp_error($response)) { return false; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (empty($data['articles'])) { return array(); } $articles = array(); foreach ($data['articles'] as $article) { $articles[] = array( 'title' => sanitize_text_field($article['title']), 'description' => wp_kses_post($article['description']), 'url' => esc_url($article['url']), 'date' => date('Y-m-d H:i:s', strtotime($article['publishedAt'])) ); } return $articles; } 1.0PIRANOThttps://piranot.com.brJúnior Cardosohttps://piranot.com.br/author/admin/Lingerie de Luxo no Vestuário!rich600338<blockquote class="wp-embedded-content" data-secret="IE61uK7gmv"><a href="https://piranot.com.br/2013/11/22/noticias/lingerie-de-luxo-vestuario/">Lingerie de Luxo no Vestuário!</a></blockquote><iframe sandbox="allow-scripts" security="restricted" src="https://piranot.com.br/2013/11/22/noticias/lingerie-de-luxo-vestuario/embed/#?secret=IE61uK7gmv" width="600" height="338" title="“Lingerie de Luxo no Vestuário!” — PIRANOT" data-secret="IE61uK7gmv" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe><script type="text/javascript"> /* <![CDATA[ */ /*! This file is auto-generated */ !function(d,l){"use strict";l.querySelector&&d.addEventListener&&"undefined"!=typeof URL&&(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&&!/[^a-zA-Z0-9]/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),o=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),c=new RegExp("^https?:$","i"),i=0;i<o.length;i++)o[i].style.display="none";for(i=0;i<a.length;i++)s=a[i],e.source===s.contentWindow&&(s.removeAttribute("style"),"height"===t.message?(1e3<(r=parseInt(t.value,10))?r=1e3:~~r<200&&(r=200),s.height=r):"link"===t.message&&(r=new URL(s.getAttribute("src")),n=new URL(t.value),c.test(n.protocol))&&n.host===r.host&&l.activeElement===s&&(d.top.location.href=t.value))}},d.addEventListener("message",d.wp.receiveEmbedMessage,!1),l.addEventListener("DOMContentLoaded",function(){for(var e,t,s=l.querySelectorAll("iframe.wp-embedded-content"),r=0;r<s.length;r++)(t=(e=s[r]).getAttribute("data-secret"))||(t=Math.random().toString(36).substring(2,12),e.src+="#?secret="+t,e.setAttribute("data-secret",t)),e.contentWindow.postMessage({message:"ready",secret:t},"*")},!1)))}(window,document); /* ]]> */ </script> https://piranot.com.br/wp-content/uploads/nicole-scherzinger-photoshoot-014.jpg600796