Hi !
I made I light modification of the file /manager/processors/save_content.processor.php in order to replace accents in case of automatic creation of aliases.
The issue cames when a French user didn’t mention the alias while creating a page. For exemple if I choose a title like "Bonjour à la communauté ModX !" for a page, the alias would be "bonjour-la-communautmodx", which is not optimal for SEO. This modification provides the following alias "bonjour-a-la-communaute-modx".
It could be improved for others special chars and be included directly in the following line
$alias = strtr($alias, array(chr(196) => 'Ae', chr(214) => 'Oe', chr(220) => 'Ue', chr(228) => 'ae', chr(246) => 'oe', chr(252) => 'ue', chr(223) => 'ss'));
... but I don’t know every special chars...
Here is the modification :
- Open the following file : /manager/processors/save_content.processor.php
- Find the stripAlias function (around line 561)
- Replace this function with the following new one :
function stripAlias($alias) {
global $modx;
if(strtoupper($modx->config['modx_charset'])=='UTF-8') $alias = utf8_decode($alias);
$alias = strtr($alias, array(chr(196) => 'Ae', chr(214) => 'Oe', chr(220) => 'Ue', chr(228) => 'ae', chr(246) => 'oe', chr(252) => 'ue', chr(223) => 'ss'));
/*Modification By Olivier for aliases internationalization */
$pattern = Array("/é/", "/è/", "/ê/", "/ç/", "/à/", "/â/", "/î/", "/ï/", "/ù/", "/ô/", "/ñ/");
$rep_pat = Array("e", "e", "e", "c", "a", "a", "i", "i", "u", "o", "n");
$alias = preg_replace($pattern, $rep_pat, $alias);
/* ------------ END OF MODIFICATION ----------------- */
$alias = strip_tags($alias);
//$alias = strtolower($alias);
$alias = preg_replace('/&.+?;/', '', $alias); // kill entities
$alias = preg_replace('/[^\.%A-Za-z0-9 _-]/', '', $alias);
$alias = preg_replace('/\s+/', '-', $alias);
$alias = preg_replace('|-+|', '-', $alias);
$alias = preg_replace('|-+|', '-', $alias);
$alias = trim($alias, '-');
return $alias;
}
++
Olivier