HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: /var/www/html/www.uscornatese.it/json/1
<?php
require_once('../wp-load.php' );
global $wpdb;

function sendMessage($title, $link, $postId){
	$content = array(
		"en" => $title
	);
		
	$fields = array(
		'app_id' => "10b06f3c-021f-446e-9878-7cd2547f4584",
		'included_segments' => array('All'),
		'url' => $link,
      		'headings' => array("en" => "Atalantini.com"),
                'data' => array("postId" => $postId),
		'contents' => $content
	);
		
	$fields = json_encode($fields);
    	print("\nJSON sent:\n");
    	print($fields);
		
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Authorization: Basic ZTUyNDk2ZTAtNGM1OS00MzMzLTllOWUtYjBiYTMxZDJiOTg5'));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	curl_setopt($ch, CURLOPT_HEADER, FALSE);
	curl_setopt($ch, CURLOPT_POST, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

	$response = curl_exec($ch);
	curl_close($ch);
	
	return $response;
}

$sql = "select id, post_title, post_status from wp_posts where post_date >= current_date and post_status = 'publish' and id in (select object_id from wp_term_relationships where term_taxonomy_id <> 16) and id not in (select post_id from notifications where notification_date >= current_date);";
$records = $wpdb->get_results($sql);
foreach ( $records as $record )  {
	echo $record->id . " " . $record->post_title . "\n";
	$url = "https://www.atalantini.online/?p=" . $record->id;
	$title = strip_tags(html_entity_decode($record->post_title));
	$response = sendMessage($title, $url, $record->id);
	$return["allresponses"] = $response;
	$return = json_encode( $return);
	
	print("\n\nJSON received:\n");
	print($return);
	print("\n");
        $wpdb->query( $wpdb->prepare(
               "
                INSERT INTO notifications
                ( post_id )
                VALUES ( %d )
               ",
               $record->id
        ) );

}
?>