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/corepla/cf.php
<?php 
require_once( '/var/www/html/corepla/wp-load.php' ); 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$posts_id = array();
$rows =  $wpdb->get_results( "select ID, post_type from wp_posts where  ID = 901 and post_type in ('articoli','comunicato_stampa','page','pagina_scuola','post');" , ARRAY_A);


foreach($rows as $row){
	$posts_id[] = $row['ID'];
}
//$post_id = 719;
foreach($posts_id as $post_id){
$c = 0;
$descrizione = array();
$titolo = array();
$lista_documenti = array();
$link_vimeo = array();
$embed_id = array();
$elementi = array();
$foto_sinistra = array();
$foto_destra = array();

$rows =  $wpdb->get_results( "select meta_key, meta_value from wp_postmeta where post_id = " . $post_id , ARRAY_A);
foreach($rows as $row){
        $key = $row['meta_key'];
        $val = $row['meta_value'];
        $value = $row['meta_value'];
	//$val = str_replace(" ","",implode(" ",$value));
	$print = 1;
        if (str_replace(" ","",$value) == "") {
			$print = 0;
        }
        if (strpos($val, "field_") > -1) {
			$print = 0;
        }
	if ($print == 1) {
          if ($value != "") {
		//add_row('drupal_text_repeater_' . $c . '_drupal_text_descrizione', $val, $post_id);
		if (strpos($key, "lista_documenti") > -1) {
			$lista_documenti[] = $value;
                        $elementi[] = array($key => ($value));
		}
                if (strpos($key, "descrizione") > -1) {
                        $descrizione[] = $value;
                        $elementi[] = array($key => ($value));
                }
                if (strpos($key, "titolo") > -1) {
                        $titolo[] = $value;
                }
                if (strpos($key, "link_vimeo") > -1) {
                        $link_vimeo[] = $value;
                        $elementi[] = array($key => ($value));
                }
                if (strpos($key, "embed_id") > -1) {
                        $embed_id[] = $value;
	                $elementi[] = array($key => ($value));
                }
                if (strpos($key, "foto_sinistra") > -1) {
                        $foto_sinistra[] = $value;
                }
                if (strpos($key, "foto_destra") > -1) {
                        $foto_destra[$key] =  $value;
                }
            }
	}
}
$step = 0;
//PRO
foreach ($elementi as $elemento) {
	foreach ($elemento as $k => $v) {
		$tipo_campo = "";
                if (ord(substr(strip_tags($v),0,1)) == "226") {
                        add_row(
                            'contenuto_flessibile', [
                            'acf_fc_layout'       => 'citazione',
                            'citazione_testo' => $v,
                        ], $post_id);
                } elseif (strpos($k, "descrizione_occhiello") > -1) {
			add_row(
			    'contenuto_flessibile', [
			    'acf_fc_layout'       => 'occhiello',
			    'occhiello_testo' => $v,
			], $post_id);
               } elseif (strpos($k, "descrizione") > -1) {
			$keyFoto = $k;
			$keyFoto = str_replace("_descrizione", "_foto_destra", $keyFoto);
			if (isset($foto_destra[$keyFoto])) {
				echo "KEYFOTO presente" .$keyFoto  . "\n";
	                        $drupal_id = $wpdb->get_var("select meta_value from wp_postmeta where post_id = " . $post_id . " and meta_key = '_fgd2wp_old_node_id'"); 
                                $rows1 =  $wpdb->get_results( "select field_data_field_foto_destra.entity_id, field_data_field_foto_destra.bundle, field_foto_destra_title,field_descrizione_value from field_data_field_foto_destra, field_data_field_descrizione, field_data_field_elementi_editoriali_scuola  where field_elementi_editoriali_scuola_value = field_data_field_foto_destra.entity_id and field_data_field_foto_destra.entity_id = field_data_field_descrizione.entity_id and field_data_field_elementi_editoriali_scuola.entity_id = " . $drupal_id . " and field_descrizione_value like '%" . rtrim(strip_tags($v)) . "%';" , ARRAY_A);
echo "select field_data_field_foto_destra.entity_id, field_data_field_foto_destra.bundle, field_foto_destra_title,field_descrizione_value from field_data_field_foto_destra, field_data_field_descrizione, field_data_field_elementi_editoriali_scuola  where field_elementi_editoriali_scuola_value = field_data_field_foto_destra.entity_id and field_data_field_foto_destra.entity_id = field_data_field_descrizione.entity_id and field_data_field_elementi_editoriali_scuola.entity_id = " . $drupal_id . " and field_descrizione_value like '%" . rtrim(strip_tags($v)) . "%';" ;
				foreach($rows1 as $row1){
				        $fieldtype  = $row1['bundle'];
                                        $fieldtitle = $row1['field_foto_destra_title'];
                                        $fielddesc  = $row1['field_descrizione_value'];
					if ($fieldtype == "testo_dx_foto_sx") {
                                                add_row(
                                                    'contenuto_flessibile', [
                                                    'acf_fc_layout'       => 'foto_sx_testo_dx',
                                                    'foto_sx_testo_dx_testo' => $fielddesc,
                                                    'foto_sx_testo_dx_immagine' => $foto_destra[$keyFoto],
                                                ], $post_id);
						echo "ADD> foto_sx_testo_dx\n";
					}
                                        if ($fieldtype == "testo_sx_foto_dx") {
		                                add_row(
		                                    'contenuto_flessibile', [
		                                    'acf_fc_layout'       => 'testo_sx_foto_dx',
		                                    'testo_sx_foto_dx_testo' => $fielddesc,
		                                    'testo_sx_+_foto_dx_immagine' => $foto_destra[$keyFoto],
		                                ], $post_id);
                                                echo "ADD> testo_sx_foto_dx\n";
                                        }
				}
			} else {
                        	add_row(
                        	    'contenuto_flessibile', [
                        	    'acf_fc_layout'       => 'testo_semplice',
                        	    'testo_semplice_testo' => $v,
                        	], $post_id);
			}
		} elseif (strpos($k, "embed_id") > -1) {
                                add_row(
                                    'contenuto_flessibile', [
                                    'acf_fc_layout'       => 'video',
                                    'video_embed_id' => $v,
                                    'video_titolo' => '',
                                ], $post_id);
                } elseif (strpos($k, "vimeo") > -1) {
                        $tipo_campo = "Vimeo";
			$titolo = $wpdb->get_var( "SELECT meta_value FROM wp_postmeta where meta_key = '" . str_replace("_link_vimeo","_titolo",$k) . "'"); 
                                add_row(
                                    'contenuto_flessibile', [
                                    'acf_fc_layout'       => 'video_vimeo',
                                    'video_vimeo_link' => $v,
                                    'video_vimeo_titolo' => $titolo,
                                ], $post_id);
                } elseif (strpos($k, "lista_documenti") > -1) {
			$file_titolo = str_replace("_lista_documenti", "_titolo", $k);
                        $titolo = $wpdb->get_var( "SELECT meta_value FROM wp_postmeta where meta_key = '" . $file_titolo . "' and post_ID = " . $post_id); 
			$arra = $v;
			if (is_serialized($arra)) {
		        $c=unserialize($arra);
			$documenti = array();
		        foreach ($c as $va) {
				$documenti[] =   array(
						    'modulistica_file_-_url' => $va,
						    'modulistica_file_-_titolo' => $titolo
				);
		        }
			} else {
                               $documenti[] =   array(
                                                    'modulistica_file_-_url' => $arra,
                                                    'modulistica_file_-_titolo' => $titolo
                                );      
			}
                                add_row(
                                    'contenuto_flessibile', [
                                    'acf_fc_layout'       => 'modulistica',
                                    'modulistica_file' => $documenti,
                                    'modulistica_titolo' => $titolo,
                                ], $post_id);
                } elseif (strpos($k, "_fotogallery") > -1) {
                        $file_titolo = str_replace("_fotogallery", "_titolo", $k);
                        $titolo = $wpdb->get_var( "SELECT meta_value FROM wp_postmeta where meta_key = '" . $file_titolo . "' and post_ID = " . $post_id); 
                        $arra = $v;
                        if (is_serialized($arra)) {
                        $c=unserialize($arra);
                        $documenti = array();
                        foreach ($c as $va) {
                                $documenti[] =   array(
                                                    'foto' => $va,
                                                    'titolo_foto' => $titolo
                                );
                        }
                        } else {
                               $documenti[] =   array(
                                                    'foto' => $arra,
                                                    'titolo_foto' => $titolo
                                );
                        }
                                add_row(
                                    'contenuto_flessibile', [
                                    'acf_fc_layout'       => 'fotogallery',
                                    'fotogallery_immagini' => $documenti,
                                    'titolo_fotogallery' => $titolo,
                                ], $post_id);
                } elseif (strpos($k, "_lista_video") > -1) {
                        $file_titolo = str_replace("_lista_video", "_titolo", $k);
                        $titolo = $wpdb->get_var( "SELECT meta_value FROM wp_postmeta where meta_key = '" . $file_titolo . "' and post_ID = " . $post_id); 
                        $arra = $v;
                        if (is_serialized($arra)) {
                        $c=unserialize($arra);
                        $documenti = array();
                        foreach ($c as $va) {
                                $documenti[] =   array(
                                                    'videogallery_video_embed_id' => $va
                                );
                        }
                        } else {
                               $documenti[] =   array(
                                                    'videogallery_video_embed_id' => $arra
                                );
                        }
                                add_row(
                                    'contenuto_flessibile', [
                                    'acf_fc_layout'       => 'videogallery',
                                    'videogallery_video' => $documenti,
                                    'titolo_videogallery' => $titolo,
                                ], $post_id);

                }

	}
	$step++;
}
/*
$x = 0;
foreach ($lista_documenti as $val) {
        $row = array(
	    'titolo'	       => $titolo[$x],
            'listadocumenti'   => $val
        );
        add_row('drupal_listadocumenti_group', $row, $post_id);
	$x++;
}

foreach ($descrizione as $val) {
	$row = array(
	    'descrizione'   => $val
	);
	add_row('drupal_descrizione_group', $row, $post_id);
}
foreach ($titolo as $val) {
        $row = array(
            'titolo'   => $val
        );
        add_row('drupal_titolo_group', $row, $post_id);
}
foreach ($lista_documenti as $val) {
        $row = array(
            'listadocumenti'   => $val
        );
        add_row('drupal_listadocumenti_group', $row, $post_id);
}
foreach ($link_vimeo as $val) {
        $row = array(
            'linkvimeo'   => $val
        );
        add_row('drupal_linkvimeo_group', $row, $post_id);
}
foreach ($embed_id as $val) {
        $row = array(
            'embedid'   => $val
        );
        add_row('drupal_embedid_group', $row, $post_id);
}
*/
}
?>