diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 9c182350d2..847d82d318 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -57,23 +57,14 @@ function create_course($wanted_code, $title, $tutor_name, $category_code, $cours return false; } - -function generate_course_code($course_title) +// TODO: Such a function might be useful in other places too. It might be moved in the CourseManager class. +// Also, the function might be upgraded for avoiding code duplications. +function generate_course_code($course_title, $encoding = null) { - global $charset; - - //$wantedCode = strtr($course_title, "�����������������������������������������������������������", "AAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy"); - //$wantedCode = substr(str_replace( - // array('Á','À','Â','Ä','Ã','Å','Æ' ,'Ç','É','È','Ê','Ë','Í','Ì','Î','Ï','Ĩ','Ó','Ò','Ô','Ö','Õ','Ø' ,'Œ' ,'Ú','Ù','Û','Ü','Ũ','Ÿ','Ý','Ð','Ñ','ß' ,'à','á','â','ä','ã','å','æ' ,'ç','Š','é','è','ê','ë','ì','í','î','ï','ĩ','ò','ó','ô','ö','õ','ø' ,'œ' ,'ú','ù','û','ü','ũ','ÿ','ý','ñ','š','€'), - // array('A','A','A','A','A','A','Ae','C','E','E','E','E','I','I','I','I','I','O','O','O','O','O','Oe','Oe','U','U','U','U','U','Y','Y','D','N','SS','a','a','a','a','a','a','ae','c','S','e','e','e','e','i','i','i','i','i','o','o','o','o','o','oe','oe','u','u','u','u','u','y','y','n','š','Euro'), - // $course_title) - // ,0,20); - - $string = api_htmlentities(api_strtolower(str_replace('"','',$course_title), $charset), ENT_QUOTES, $charset); - $string = strtoupper(preg_replace("/&(.)(acute|grave|cedil|circ|ring|tilde|uml|slash|elig|Elig|mp);/", "$1", $string)); - $string = preg_replace(api_add_pcre_unicode_modifier("/[^A-Z0-9]/", $charset), "", api_html_entity_decode($string, ENT_QUOTES, $charset)); - - return $string; + if (empty($encoding)) { + $encoding = api_get_system_encoding(); + } + return substr(preg_replace('/[^A-Z0-9]/', '', strtoupper(api_transliterate($course_title, $encoding))), 0, 20); } diff --git a/main/inc/lib/multibyte_string_functions.lib.php b/main/inc/lib/multibyte_string_functions.lib.php index 58ce665a91..eaae8fb76b 100644 --- a/main/inc/lib/multibyte_string_functions.lib.php +++ b/main/inc/lib/multibyte_string_functions.lib.php @@ -349,7 +349,7 @@ function api_str_ireplace($search, $replace, $subject, & $count = null, $encodin $subject_lower = api_strtolower($subject, $encoding); $total_matched_strlen = 0; $i = 0; - while (preg_match(api_add_pcre_unicode_modifier('/(.*?)'.preg_quote($search, '/').'/s', $encoding), $subject_lower, $matches)) { + while (api_preg_match('/(.*?)'.preg_quote($search, '/').'/s', $subject_lower, $matches, 0, 0, $encoding)) { $matched_strlen = api_strlen($matches[0], $encoding); $subject_lower = api_substr($subject_lower, $matched_strlen, api_strlen($subject_lower, $encoding), $encoding); $offset = $total_matched_strlen + api_strlen($matches[1], $encoding) + ($i * (api_strlen($replace, $encoding) - 1)); diff --git a/main/inc/lib/pear/HTML/QuickForm/Renderer/ArraySmarty.php b/main/inc/lib/pear/HTML/QuickForm/Renderer/ArraySmarty.php index ec55e91953..fd06bb8c6a 100644 --- a/main/inc/lib/pear/HTML/QuickForm/Renderer/ArraySmarty.php +++ b/main/inc/lib/pear/HTML/QuickForm/Renderer/ArraySmarty.php @@ -185,7 +185,7 @@ class HTML_QuickForm_Renderer_ArraySmarty extends HTML_QuickForm_Renderer_Array // name has unbalanced square brackets. Dunno whether we really // need this after the fix for #8123, but I'm wary of making big // changes to this code. - preg_match(api_add_pcre_unicode_modifier('/([^]]*)\\[([^]]*)\\]/'), $ret['name'], $matches); + api_preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches); if (isset($matches[1])) { $sKeysSub = api_substr_replace($ret['name'], '', 0, api_strlen($matches[1])); $sKeysSub = str_replace(