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/images.php
<?php
require_once('../wp-load.php' );
global $wpdb;

function getImageFromText($html) {
        preg_match_all('/<img[^>]+>/i',$html, $result);

        //print_r($result);
        $img = array();
        foreach( $result as $img_tag) {
                preg_match_all('/(src)=("[^"]*")/i',$img_tag[0], $im);
        }
        return $im[2][0];
}


$sql = "(select * from wp_posts where post_status = 'publish');";
$records = $wpdb->get_results($sql);

$values = array();
foreach ( $records as $record )  {
	$id = $record->ID;
	$date = $record->post_date;
	$pdate = explode("-", substr($date, 0, 10));
	$post_date = $pdate[2] . "-" . $pdate[1] . "-" . $pdate[0]; 
        $record->post_title = strip_tags(strtolower($record->post_title));
	$record->post_date = $post_date . " " . substr($date, 11, 8);
	$value = get_field( "immagine_gallery", $id );
	$image = $value['url'];
        if ($image == "") {
           $checkContent = strtolower($record->post_content);
           if (strpos($checkContent, "<img ") > -1) {
              $image = getImageFromText(strtolower($record->post_content));
              $image = str_replace("\"", "", $image);
           }
        }
        $wpdb->query( $wpdb->prepare(
               "
                INSERT INTO post_images
                ( post_id, image )
                VALUES ( %d, %s )
               ",
               $record->id,
		$image
        ) );

}
?>