HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/ilya/data/www/povoleni.ru/modules/services/get_news.php
<?

function getElementsByClass(&$parentNode, $tagName, $className) {
    $nodes=array();

    $childNodeList = $parentNode->getElementsByTagName($tagName);
    for ($i = 0; $i < $childNodeList->length; $i++) {
        $temp = $childNodeList->item($i);
        if (stripos($temp->getAttribute('class'), $className) !== false) {
            $nodes[]=$temp;
        }
    }

    return $nodes;
}
/////////////////

$result = query("SELECT * FROM `news_sources` ORDER BY `id`;");

//$result = query("SELECT * FROM `news_sources` WHERE `id`=5 ORDER BY `id`;");

if(mysqli_num_rows($result)>0)
	while($data = mysqli_fetch_array($result)) {

		$page = DOMDocument::loadHTMLFile($data['url']);

		$elements = getElementsByClass($page,"h2","article_title");

		foreach($elements as $article) {

			$title = $article->firstChild->nodeValue;
			$url = "https://www.mzv.cz".$article->firstChild->getAttribute('href');
			$added = preg_replace('/\s+/S', " ", $article->nextSibling->nextSibling->nextSibling->nextSibling->nodeValue);

			if(strpos($added," | ")) {
				list($added,$updated) = explode(" | Aktualizováno: ",str_replace(" / "," ",$added));

				$added = date("Y-m-d H:i:s",strtotime($added));
				$updated = date("Y-m-d H:i:s",strtotime($updated));
			}
			else {
				$added = str_replace(" / "," ",$added);

				$added = date("Y-m-d H:i:s",strtotime($added));		
				$updated = "00-00-0000 00:00:00";
			}

			$result2 = query("SELECT * FROM `news` WHERE `source_id`=".$data['id']." AND `added`='".$added."' AND `updated`='".$updated."' AND `url`='".$url."';");

			if(mysqli_num_rows($result2)==0) {
				$result3 = query("SELECT * FROM `news` WHERE `source_id`=".$data['id']." AND `added`='".$added."' AND `url`='".$url."';");

				if(mysqli_num_rows($result3)==0) {
					query("INSERT INTO `news` (`source_id`, `title`, `added`, `updated`, `updated_local`, `url`) VALUES (".$data['id'].", '".mysqli_real_escape_string($global_vars['db_connection'],$title)."','".$added."', '".$updated."', NOW(), '".$url."');");

					query("INSERT INTO `news_rss` (`source_id`, `datetime`, `title`, `text`, `url`) VALUES ('".$data['id']."',NOW(),'Поволени.ру - ".$data['name']." // Опубликована новость','На сайте ".$data['name_where']." произошло обновление новости «".$title."»','".$url."');");

					$message = "На сайте ".$data['name_where']." опубликована новость «".$title."» - ".$url;
					$message_heading = "МИД ЧР - ".$data['name']." // Опубликована новость";	
				}
				elseif(mysqli_num_rows($result3)==1) {
					$data3 = mysqli_fetch_array($result3);

					query("UPDATE `news` SET `updated`='".$updated."', `title`='".mysqli_real_escape_string($global_vars['db_connection'],$title)."', `updated_local`=NOW() WHERE `url`='".$url."';");

					query("INSERT INTO `news_rss` (`source_id`, `datetime`, `title`, `text`, `url`) VALUES ('".$data['id']."',NOW(),'Поволени.ру - ".$data['name']." // Обновление новости','На сайте ".$data['name_where']." произошло обновление новости «".$title."»','".$url."');");

					$message = "На сайте ".$data['name_where']." произошло обновление новости «".$title."» - ".$url;
					$message_heading = "МИД ЧР - ".$data['name']." // Обновление новости";
				}

				//mail("mailbox@rudomilov.com,info@podebrady.ru",$message_heading,$message);

				query("UPDATE `news_subscriptions` SET `is_sent`=0 WHERE `news_source_id`='".$data['id']."';");

				$result3 = query("SELECT * FROM `news_subscriptions` WHERE `news_source_id`='".$data['id']."';");
				if(mysqli_num_rows($result3)>0) {
					while($data3=mysqli_fetch_array($result3)) {
						send_telegram($data3['telegram_id'],$message);
						print "Send message to telegram ID ".$data3['telegram_id']."<br />";
						query("UPDATE `news_subscriptions` SET `is_sent`=1 WHERE `news_source_id`='".$data['id']."' AND `telegram_id`='".$data3['telegram_id']."';");
					}
				}

			}

		}


	}

?>