|
<?php |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require 'vendor/autoload.php'; |
|
|
|
|
|
include("functions_mysqli.php"); |
|
|
|
$path = $_SERVER ['DOCUMENT_ROOT']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDomPath( $url ) { |
|
$parsedUrl = parse_url( $url ); |
|
if ( !$parsedUrl || !isset( $parsedUrl['scheme'] ) || !isset( $parsedUrl['host'] ) ) { |
|
return false; |
|
} |
|
return "{$parsedUrl['scheme']}://{$parsedUrl['host']}"; |
|
} |
|
|
|
|
|
$result = mysqli_query( $mysqli, "SELECT `id`, `url`, `media` FROM `base_news` WHERE `link`='0' AND `step` > 0 ORDER BY Rand() LIMIT 1" ); |
|
$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 "<span style='font-family: verdana;font-size: .9em;'>$id_source) $url_source => $dom <br /><br />"; |
|
|
|
|
|
mysqli_query($mysqli, "UPDATE `base_news` SET `link`='1' WHERE `id`='$id_source' LIMIT 1"); |
|
|
|
|
|
$htmlContent = ''; |
|
$file_path = "$path/sources/html_news/$id_source.txt"; |
|
if ( file_exists( $file_path ) ){ |
|
$htmlContent = implode( '', file( $file_path ) ); |
|
} else { |
|
echo "<script type=\"text/javascript\">location.href='" . $_SERVER['REQUEST_URI'] . "';</script>"; |
|
} |
|
|
|
$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) { |
|
|
|
|
|
} elseif ($nb_base_news) { |
|
|
|
|
|
} elseif (substr_count($url, "-") > 6 && substr_count($url, $dom) && !substr_count( $url, '.jpg' ) && !substr_count( $url, '.png' ) && !substr_count( $url, 'mailto' ) ) { |
|
|
|
echo "<span style='color:#008000;'># $url </span><br />"; |
|
$insertQuery = "INSERT INTO `base_news` (`id`, `key_media`, `media`, `url`, `step`) VALUES (NULL, '$key', '$id_media', '$url', '0');"; |
|
mysqli_query($mysqli, $insertQuery); |
|
} |
|
} |
|
|
|
|
|
echo "<script type=\"text/javascript\">location.href='" . $_SERVER['REQUEST_URI'] . "';</script>"; |
|
|
|
?> |
|
|
|
|