function insert_key_into_db($file, $key, $path, $line) { global $insert_list, $insert_sql, $dbx; if (sizeof($insert_list) > 600) { $sql = $insert_sql . implode(',', $insert_list); // echo $sql.'<br>';exit; mysqli_query($dbx, $sql) or die($sql . '<br>' . mysqli_error($dbx)); $insert_list = array(); } // echo " ('$file','$key') <br>"; if (is_array($key)) { echo $line . ' ' . $path . ' ' . $file . '<br>'; print_r($key); exit; } if (hasUpperCaseLetter($key)) { $keywords = explode(",", substr(preg_replace("/([A-Z])/", ',\\1', $key), 1)); //preg_match_all('/[A-Z][^A-Z]*/',$str,$results); $keywords = strtolower(implode('_', $keywords)); } else { $keywords = $key; } if (in_array($keywords, array('variation_theme', 'variation_data', 'nit_of_measure', 'parent', 'child', 'clothing_type'))) { return; } $insert_list[] = " ('{$file}','{$key}','{$keywords}','{$path}','{$line}','" . md5($path) . "') "; }
function put_line($file_key, $path, $key, $lang, $data, $line, $at_line, $universe) { global $dbx, $error_file, $insert_list, $lang_list, $alt_list, $alt_list_all, $def_text, $replace_text; if (sizeof($data) == 0 && empty($data) || empty($data)) { return; } if ($key == 'av_output' && $file_key == 'digitalcamera') { return; } if (sizeof($data) == 5) { array_splice($data, 1, 0, ''); } // if($file_key=='autopart'&&$lang=='es'){ // print_r($data); // // } $alt_key = ''; // if(isset($alt_list[strtolower($universe)][$file_key][$key])){ // $alt_key = $alt_list[$universe][$file_key][$key]; // } if ($alt_key == '' && isset($alt_list[$key])) { $alt_key = $alt_list[$key]; } if ($alt_key == '' && isset($alt_list_all[$key])) { $alt_key = $alt_list_all[$key]; } $jdata = json_encode($data); $md = md5($jdata); $fmd = md5($path); if (isset($lang_list[$path][$key][$lang]) && $lang_list[$path][$key][$lang] == $md) { return; } $lang_list[$path][$key][$lang] = $md; if (sizeof($data) == 1) { if (strpos($data[0], '":"')) { $data = explode(':', $data[0]); $key = $data[0]; } elseif (strpos($data[0], '";"')) { $data = explode(';', $data[0]); $key = $data[0]; } elseif (strpos($data[0], ';')) { $data = explode(';', $data[0]); $key = $data[0]; } else { echo '^^^' . $path . ''; echo ' #line#' . $at_line . '#' . '<br>'; echo 'data is wrong<pre>' . print_r($data, true) . '</pre><br>'; exit; } foreach ($data as $k => $v) { $data[$k] = str_replace(array("\\'", "'"), "\\'", $v); $data[$k] = str_replace(array("\\'"), "\\'", $data[$k]); $data[$k] = str_replace(array('"'), "", $data[$k]); } } if (sizeof($data) > 20) { $error_file[$path] = $path; return; } else { if (sizeof($data) > 6) { // $error_file[$path]= $path; echo '^^^' . $path . ''; echo ' #line#' . $at_line . '#' . '<br>'; echo 'data is wrong<pre>' . print_r($data, true) . '</pre><br>'; return; } elseif (sizeof($data[1]) < 30 && empty($data[1]) && empty($data[2]) && empty($data[3]) && empty($data[4]) && empty($data[5])) { return; } elseif (empty($data[3]) && empty($data[5])) { // echo '^^^'.$path.''; // echo ' #line#'.$at_line.'#'.'<br>'; // echo 'data is wrong<pre>'.print_r($data,true).'</pre><br>'; // return; if (!isset($data[4])) { print_r($data); } $data[5] = $data[4]; $data[4] = ''; } } if ($data[5] == '' && $data[4] == '' && $data[3] == '' && $data[2] == '') { echo 'skip empty info line<br>'; return; } // if (hasUpperCaseLetter($key)) { $keywords = explode(",", substr(preg_replace("/([A-Z])/", ',\\1', $key), 1)); //preg_match_all('/[A-Z][^A-Z]*/',$str,$results); $keywords = str_replace(' ', '', $keywords); $key = strtolower(implode('_', $keywords)); } $t = htmlentities($data[5], ENT_COMPAT, 'UTF-8'); if (isset($replace_text[$t])) { $data[5] = $replace_text[$t]; } if (strpos($data[5], 'Souhait') !== false) { $data[5] = 'Souhaité'; } if (!in_array($lang, array('us', 'uk')) && isset($def_text['def'][strtolower($data[5])])) { if (isset($def_text[$lang]) && isset($def_text[$lang][$def_text['def'][strtolower($data[5])]])) { $data[5] = $def_text[$lang][$def_text['def'][strtolower($data[5])]]; } } if (trim($data[5]) == '') { $data[5] = $def_text[$lang][0]; } foreach ($data as $k => $v) { $data[$k] = str_replace(array('‘', '’', "‘", "’", chr(145), chr(146)), "\\'", $data[$k]); if (in_array($lang, array('us', 'uk'))) { $data[$k] = mb_convert_encoding($data[$k], 'UTF-8', 'ISO-8859-1'); } } $pos = strpos($key, '1 - '); if ($pos !== false) { $key = substr($key, 0, $pos); } $pos = strpos($data[1], '1 - '); if ($pos !== false) { $data[1] = substr($data[1], 0, $pos); } if ($key == 'is_adult_product') { $data[5] = $def_text[$lang][$def_text['def']['preferred']]; } $insert_list[] = " ('{$key}','{$lang}','{$file_key}','{$path}','{$fmd}','{$data[0]}','{$data[1]}','{$data[2]}','{$data[3]}','{$data[4]}','{$data[5]}','{$alt_key}') "; // if($md=='14a6ed8a4ccab9023a0255a234ac19ca'){ // echo 'data is wrong<pre>'.print_r($insert_list,true).'</pre><br>'; // $sql = "replace into dict (tkey,lang,filename,filepath,col_1,col_2,col_3,col_4,col_5,col_6) values ".implode(',',$insert_list); // mysqli_query($dbx,$sql) or die($sql.'<br>'.mysqli_error($dbx)); // echo $sql; // $insert_list = array(); // exit; // } if (sizeof($insert_list) > 100) { $sql = "replace into dict (tkey,lang,filename,filepath,filemd,col_1,col_2,col_3,col_4,col_5,col_6,alt_tkey) values " . implode(',', $insert_list); mysqli_query($dbx, $sql) or die($sql . '<br>' . mysqli_error($dbx)); $insert_list = array(); } // echo $sql.'<br>'; }