<?php
define(DB_PASSWORD, 'your_base_password');
define(DB_USER, 'your_base_user');
define(DB_HOST, 'localhost(or other host)');
define(DB_BASENAME, 'your_base_name');
function s2one($str) { // replace anymore spaces in string to one
$i=0;
while (substr_count($str, " ") > 0) {
$str = str_replace(" ", " ", $str);
}
return $str;
}
function translitstr($str) {
$tr = array(
"А"=>"a","Б"=>"b","В"=>"v","Г"=>"g","Ґ"=>"g",
"Д"=>"d","Е"=>"e","Є"=>"e","Ж"=>"j","З"=>"z","И"=>"y","І"=>"i","Ї"=>"i",
"Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
"О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
"У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
"Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
"Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
"в"=>"v","г"=>"g","ґ"=>"g","д"=>"d","е"=>"e","є"=>"e","ж"=>"j",
"з"=>"z","и"=>"y","і"=>"i","ї"=>"i","й"=>"y","к"=>"k","л"=>"l",
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
"ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
" "=> "-", "."=> "", ","=> "-","/"=> "-","+"=> "-", "*"=>"x"
);
return strtr($str,$tr);
}
function str2url($urlstr) {
if (preg_match('^A-Za-z0-9_\-', $urlstr) === FALSE) {
echo "Run Translation <br/>";
$urlstr = translitstr($urlstr);
return ucfirst(preg_replace('/[^A-Za-z0-9_\-]/', '', $urlstr));
}
}
function str2keywords($str) {
$tr = array(
" "=> ",", "."=> "", "/"=> ","
);
return strtr($str,$tr);
}
$dbopen = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_BASENAME);
$dbopen->set_charset("utf8");
if ($dbopen->connect_errno) {
echo "Failed to connect to MySQL: (" . $dbopen->connect_errno . ") " . $dbopen->connect_error;
}
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
echo $dbopen->host_info."<br/>";
echo $dbopen->info."<br/>";
echo $dbopen->stat()."<br/>";
echo $dbopen->protocol_version."<hr/>";
$todo = array ('_category','_product');
foreach ($todo as $hose) {
$current_table_name = 'ps'.$hose.'_lang';
$hose = 'id'.$hose;
$dbquery = $dbopen->query("SELECT $hose, link_rewrite, name, meta_keywords FROM $current_table_name ORDER BY $hose");
$i_num_rows = $dbquery->num_rows;
echo $current_table_name.' has rows -> '.$i_num_rows."<br/>";
for ($i = 0; $i < $i_num_rows ; $i++) {
$dbrow = $dbquery->fetch_assoc();
$name = s2one($dbrow['name']);
$translit = str2url(strtolower($name));
$meta_keywords = str2keywords(strtolower($name));
$id_hose = $dbrow[$hose];
print $id_hose.' '.$name."<br/> -> ".$translit.' '.$meta_keywords."<br/><br/>";
if (!$dbopen->query("UPDATE $current_table_name SET link_rewrite = '$translit', meta_keywords = '$meta_keywords',
meta_title = '$name', meta_description = '$name'
WHERE $hose = '$id_hose' LIMIT 1 ")) {
echo 'Can not make update';
}
}
echo "<hr/>";
}
$dbopen->close();