File: /var/www/html/corepla/cf.php.ok
<?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 = 896 and post_type in ('articoli','comunicato_stampa','page','pagina_scuola','post');" , ARRAY_A);
$rows = $wpdb->get_results( "select ID, post_type from wp_posts where 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){
//echo $post_id . "<br>";
//echo '<pre>';
// echo '</pre>';
$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'];
echo $key ."<br>" . ord($value). " " . $value . "<br>";
//$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));
echo "DOCUMENTIPAP" . $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;
}
}
}
}
//echo "************<br>";
//echo var_dump($elementi);
//echo "************<br>";
$step = 0;
//PRO
echo $elementi['collection-elementi_editoriali_scuola_8_link_vimeo'];
foreach ($elementi as $elemento) {
foreach ($elemento as $k => $v) {
echo "CHIAVE" . $k . "<br>";
$tipo_campo = "";
if (ord(substr(strip_tags($v),0,1)) == "226") {
echo "CITAAAA";
$tipo_campo = "Citazione";
$row = array(
'citazione' => $v,
'tipologia_contenuto' => $tipo_campo
);
add_row('contenuto', $row, $post_id);
} elseif (strpos($k, "descrizione_occhiello") > -1) {
$tipo_campo = "Occhiello";
$row = array(
'occhiello_testo' => $v,
'tipologia_contenuto' => $tipo_campo
);
add_row('contenuto_flessibile', $row, $post_id);
} elseif (strpos($k, "descrizione") > -1) {
$keyFoto = $k;
$keyFoto = str_replace("_descrizione", "_foto_destra", $keyFoto);
if (isset($foto_destra[$keyFoto])) {
echo "FOTO_DESTRA" . $foto_destra[$keyFoto] . "<br>";
$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 where field_data_field_foto_destra.entity_id = field_data_field_descrizione.entity_id and field_foto_destra_fid in (select field_foto_fid from field_data_field_foto where entity_id = " . $drupal_id . ") and field_descrizione_value like '%" . rtrim(strip_tags($v)) . "%';" , ARRAY_A);
echo "SUUUU" . count($rows1);
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 where field_data_field_foto_destra.entity_id = field_data_field_descrizione.entity_id and field_foto_destra_fid in (select field_foto_fid from field_data_field_foto where entity_id = " . $drupal_id . ") and field_descrizione_value like '%" . 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") {
$tipo_campo = "Testo dx + Foto sx";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'foto_sx_testo_dx' => array(
'immagine' => $foto_destra[$keyFoto],
'testo' => $fielddesc
)
);
add_row('contenuto', $row, $post_id);
}
if ($fieldtype == "testo_sx_foto_dx") {
$tipo_campo = "Testo sx + Foto dx";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'testo_sx_foto_dx' => array(
'immagine' => $foto_destra[$keyFoto],
'testo' => $fielddesc
)
);
add_row('contenuto', $row, $post_id);
}
}
} else {
$tipo_campo = "Testo semplice";
$row = array(
'testo_semplice' => $v,
'tipologia_contenuto' => $tipo_campo
);
add_row('contenuto', $row, $post_id);
}
} elseif (strpos($k, "embed_id") > -1) {
$tipo_campo = "Video";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'video' => array(
'embed-id' => $v
)
);
add_row('contenuto', $row, $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) . "'");
$row = array(
'tipologia_contenuto' => $tipo_campo,
'video_vimeo' => array(
'link_vimeo' => $v,
'titolo' => $titolo
)
);
add_row('contenuto', $row, $post_id);
} elseif (strpos($k, "lista_documenti") > -1) {
echo "<hr><h1>MODULISTICA</h1>";
$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;
echo "ARA" . $arra;
if (is_serialized($arra)) {
$c=unserialize($arra);
$documenti = array();
foreach ($c as $va) {
$documenti[] = array(
'file' => $va,
'descrizione' => $titolo
);
}
} else {
$documenti[] = array(
'file' => $arra,
'descrizione' => $titolo
);
}
$tipo_campo = "Modulistica";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'modulistica' => array(
'titolo_sezione' => $titolo,
'documento' => $documenti
)
);
add_row('contenuto', $row, $post_id);
} elseif (strpos($k, "_fotogallery") > -1) {
echo "<hr><h1>FOTOGALLERY</h1>";
$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;
echo "ARA" . $arra;
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
);
}
$tipo_campo = "Gallery";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'fotogallery' => array(
'titolo_fotogallery' => $titolo,
'immagine' => $documenti
)
);
add_row('contenuto', $row, $post_id);
} elseif (strpos($k, "_lista_video") > -1) {
echo "<hr><h1>VIDEO GALLERY</h1>";
$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;
echo "ARA" . $arra;
if (is_serialized($arra)) {
$c=unserialize($arra);
$documenti = array();
foreach ($c as $va) {
$documenti[] = array(
'embed-id' => $va
);
}
} else {
$documenti[] = array(
'embed-id' => $arra
);
}
$tipo_campo = "Videogallery";
$row = array(
'tipologia_contenuto' => $tipo_campo,
'videogallery' => array(
'titolo_videogallery' => $titolo,
'video' => $documenti
)
);
add_row('contenuto', $row, $post_id);
}
}
$step++;
}
/*
$x = 0;
foreach ($lista_documenti as $val) {
echo "*****" . $x . $titolo[$x] . " " . $val ."<br>";
$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) {
echo "*****" . $val . "<br>";
$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);
}
*/
}
echo "done";
?>