Поделюсь)
<?php
define('DS', DIRECTORY_SEPARATOR);
define('APP_PATH', realpath(dirname(__FILE__)).DS);
require_once APP_PATH.'config.php';
try {
$db = new PDO("mysql:host=".DB_HOSTNAME.";dbname=".DB_DATABASE, DB_USERNAME, DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
catch (Exception $e) {
echo $e->getMessage();
}
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$exceptions = array();
foreach ($db->query('SELECT query from url_alias') as $row) {
$path = $row['query'];
preg_match("/^(.*)_id=(\d+$)/iU",$path,$matches);
if ($matches[1] == 'category')
$exceptions['category'][] = $matches[2];
elseif($matches[1] == 'vendor') $exceptions['vendor'][] = $matches[2];
else $exceptions[$matches[1]][] = $matches[2];
}
//Результаты
$insert = array();
//Обход производителей
foreach ($db->query('SELECT manufacturer_id as id,name from manufacturer') as $row) {
if (!in_array($row['id'],$exceptions['vendor']))
$insert[] = array(
'query'=>'manufacturer_id='.$row['id'],
'keyword'=>slug($row['name'])
);
}
//Обход категорий
foreach ($db->query('SELECT category_id as id,name from category_description') as $row) {
if (!in_array($row['id'],$exceptions['category']))
$insert[] = array(
'query'=>'category_id='.$row['id'],
'keyword'=>$row['id'].'-'.slug($row['name'])
);
}
//Обход продуктов
foreach ($db->query('SELECT product_id as id,model from product') as $row) {
$insert[] = array(
'query'=>'product_id='.$row['id'],
'keyword'=>(strlen($row['model'])>0)?$row['id'].'-'.slug($row['model']):$row['id']
);
}
//Обход новостей
foreach ($db->query('SELECT news_id as id,title from news_description') as $row) {
if (!in_array($row['id'],$exceptions['news']))
$insert[] = array(
'query'=>'news_id='.$row['id'],
'keyword'=>$row['id'].'-'.slug($row['title'])
);
}
//Обход инфо-страниц
foreach ($db->query('SELECT information_id as id,title from information_description') as $row) {
if (!in_array($row['id'],$exceptions['information']))
$insert[] = array(
'query'=>'info_id='.$row['id'],
'keyword'=>$row['id'].'-'.slug($row['title'])
);
}
$fields = array('query'=>PDO::PARAM_STR, 'keyword'=>PDO::PARAM_STR);
foreach ($insert as $r) {
echo "INSERT INTO `url_alias` (`query`,`keyword`) VALUES('{$r['query']}','{$r['keyword']}');<br />";
}
//Slugify
function slug($title) {
$gost = array(
"Є"=>"EH","І"=>"I","і"=>"i","№"=>"#","є"=>"eh",
"А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D",
"Е"=>"E","Ё"=>"JO","Ж"=>"ZH",
"З"=>"Z","И"=>"I","Й"=>"JJ","К"=>"K","Л"=>"L",
"М"=>"M","Н"=>"N","О"=>"O","П"=>"P","Р"=>"R",
"С"=>"S","Т"=>"T","У"=>"U","Ф"=>"F","Х"=>"KH",
"Ц"=>"C","Ч"=>"CH","Ш"=>"SH","Щ"=>"SHH","Ъ"=>"'",
"Ы"=>"Y","Ь"=>"","Э"=>"EH","Ю"=>"YU","Я"=>"YA",
"а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d",
"е"=>"e","ё"=>"jo","ж"=>"zh",
"з"=>"z","и"=>"i","й"=>"jj","к"=>"k","л"=>"l",
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"kh",
"ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"shh","ъ"=>"",
"ы"=>"y","ь"=>"","э"=>"eh","ю"=>"yu","я"=>"ya","«"=>"","»"=>"","—"=>"-"," "=>"-",
")"=>"-","("=>"-","*"=>"-","&"=>"-","/"=>"-"
);
$return = trim(strtr($title, $gost), '-');
$return = strtolower($return);
$return = str_replace("--","-",$return);
$return = preg_replace("![^\w\d\s-]*!iU","",$return);
return $return;
}