0 ORDER BY Rand() LIMIT 1" ); // AND `media` > 214 $row = mysqli_fetch_assoc( $result ); if (!$row) { exit('No unprocessed news source found.'); } $id_source = $row["id"]; $url_source = trim( $row["url"] ); $id_media = $row["media"]; $last = date( "U" ); $dom = getDomPath( $url_source ); echo "$id_source) $url_source => $dom

"; // Mark the source as processed mysqli_query($mysqli, "UPDATE `base_news` SET `link`='1' WHERE `id`='$id_source' LIMIT 1"); // Load the source content $htmlContent = ''; $file_path = "$path/sources/html_news/$id_source.txt"; if ( file_exists( $file_path ) ){ $htmlContent = implode( '', file( $file_path ) ); } else { echo ""; } $doc = \phpQuery::newDocument($htmlContent); foreach ( $doc['a'] as $link ) { $url = trim( pq( $link )->attr( 'href' ) ); $url = str_replace( strstr( $url, "#" ), "", $url ); $url = str_replace( strstr( $url, "?utm"), "", $url ); $url = str_replace(strstr( $url, "?xtor"), "", $url ); if ( !substr_count( $url, "//" ) ) { $url = ( substr( $url, 0, 1 ) != '/' ) ? $dom . '/' . $url : $dom . $url; } elseif( !substr_count( $url, "http" ) ){ $url = 'https:' . $url; } $key = md5( $url ); $nb_base_news = mysqli_return_number($mysqli, "SELECT `id` FROM `base_news` WHERE `url` LIKE '$url%' OR `key_media`='$key' LIMIT 1"); if (substr($url, 0, strlen($dom)) != $dom) { // Not the source domain // echo "# $url
"; } elseif ($nb_base_news) { // Already in the database // echo "# $url
"; } elseif (substr_count($url, "-") > 6 && substr_count($url, $dom) && !substr_count( $url, '.jpg' ) && !substr_count( $url, '.png' ) && !substr_count( $url, 'mailto' ) ) { // Add the link to the database echo "# $url
"; $insertQuery = "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `step`) VALUES (NULL, '$key', '$id_media', '$url', '0');"; mysqli_query($mysqli, $insertQuery); } } // Refresh the page echo ""; ?>