channel->item as $entry ) { $media = $entry->children( 'media', TRUE ); $attributes = $media->content->attributes(); $src = $attributes['url']; $url = trim( $entry->link ); $url = str_replace(strstr( $url, "#"), "", $url ); $url = str_replace(strstr( $url, "?utm"), "", $url ); $url = str_replace(strstr( $url, "?xtor"), "", $url ); $key = md5( $url ); $txt = addslashes( strip_tags( html_entity_decode( $entry->description ) ) ); $title = addslashes( strip_tags( html_entity_decode( $entry->title ) ) ); $nb++; $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `key_media`='$key' OR `url` LIKE '$url%' LIMIT 1" ); if ( trim( $url ) != '' && trim( $title ) != '' && $nb_base == 0 ) { mysqli_query( $mysqli, "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `link`, `step`) VALUES (NULL, '$key', '$id_source', '$url', '0', '0');" ); $id_inserted = $mysqli->insert_id; mysqli_query( $mysqli, "UPDATE `base_news` SET `title`='$title' WHERE `id`='$id_inserted' LIMIT 1" ); mysqli_query( $mysqli, "UPDATE `base_news` SET `txt_clean`='$txt' WHERE `id`='$id_inserted' LIMIT 1" ); } } // Second attempt: If no entries were processed in the first attempt, process the top-level entries if ( !$nb ) { foreach ( $a as $entry ) { $url = $entry->loc; $url = str_replace( strstr( $url, "#" ), "", $url ); $url = str_replace(strstr( $url, "?utm"), "", $url ); $key = md5( $url ); $nb++; $nb_base = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `key_media`='$key' OR `url` LIKE '$url%' LIMIT 1" ); if ( trim( $url ) != '' && $nb_base == 0 ) { mysqli_query( $mysqli, "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `link`, `step`) VALUES (NULL, '$key', '$id_source', '$url', '0', '0');" ); } } } $nb_base_news = mysqli_return_number( $mysqli, "SELECT `id` FROM `base_news` WHERE `media` = '$id_source'" ); mysqli_query( $mysqli, "UPDATE `base_media` SET `nb`='$nb_base_news' WHERE `id`='$id_source' LIMIT 1" ); } // Main script execution $record = fetchLatestURL( $mysqli ); $id_source = $record['id']; $url = trim( $record['url'] ); $last_update = $record['last']; echo "$id_source # $url"; // Exit if the last update is too recent < 1h if ( $last_update + 3600 > $last ) { exit; } updateLastFetched( $mysqli, $id_source, $last ); $data = fetchURLContent( $url ); if( trim( $data )!='' ){ saveToFile( $path . "/sources/rss/" . $id_source . ".txt", $data ); processRSSContent( $mysqli, $data, $id_source ); } echo ""; ?>