/**
* re-implemented from Redaxo core with added EP
*
* replaces special chars in article name
* @param $name       (string) article name
* @param $article_id (string) article id
* @param $clang      (string) clang
*/
function seo42_parse_article_name($name, $article_id, $clang)
{
    global $REX, $I18N;
    static $firstCall = true;
    static $translation = array();
    if ($firstCall) {
        $globalSpecialChars = explode('|', $REX['ADDON']['seo42']['settings']['global_special_chars']);
        $globalSpecialCharsRewrite = explode('|', $REX['ADDON']['seo42']['settings']['global_special_chars_rewrite']);
        foreach ($REX['CLANG'] as $clangId => $clangName) {
            $inheritedClangId = seo42_utils::getInheritedClang($clangId);
            if (isset($REX['ADDON']['seo42']['settings']['lang'][$inheritedClangId]['special_chars']) && isset($REX['ADDON']['seo42']['settings']['lang'][$inheritedClangId]['special_chars_rewrite'])) {
                $specialChars = explode('|', $REX['ADDON']['seo42']['settings']['lang'][$inheritedClangId]['special_chars']);
                $specialCharsRewrite = explode('|', $REX['ADDON']['seo42']['settings']['lang'][$inheritedClangId]['special_chars_rewrite']);
            } else {
                $specialChars = array();
                $specialCharsRewrite = array();
            }
            $translation[$clangId] = array('search' => array_merge($specialChars, $globalSpecialChars), 'replace' => array_merge($specialCharsRewrite, $globalSpecialCharsRewrite));
        }
        $firstCall = false;
    }
    // SANITIZE STUFF
    $name = trim($name, " \t\r\n-.");
    $name = str_replace('/', '-', $name);
    $name = str_replace('.', '-', $name);
    $parsedName = str_replace('+', '-', urlencode(preg_replace('/ {2,}/', ' ', preg_replace('/[^a-zA-Z_\\-0-9 ]/', '', str_replace($translation[$clang]['search'], $translation[$clang]['replace'], $name)))));
    $parsedName = trim($parsedName, "-");
    // "• articlename" was "-articlename"
    // SANITIZE MULTIPLE "-" IN PATHNAME
    $parsedName = preg_replace('/[-]{1,}/', $REX['ADDON']['seo42']['settings']['url_whitespace_replace'], $parsedName);
    return $parsedName;
}