/** * https://github.com/elgg/elgg/issues/3210 - Don't remove -s in friendly titles * https://github.com/elgg/elgg/issues/2276 - improve char encoding */ public function test_friendly_title() { $cases = array("B&N > Amazon, OK? <bold> 'hey!' \$34" => "bn-amazon-ok-bold-hey-34", "a-a_a a\na\ra\ta\va!a\"a#a\$a%aa'a(a)a*a+a,a.a/a:a;a=a?a@a[a\\a]a^a`a{a|a}a~a" => "a-a-a-a-a-a-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "-_ hello _-" => "hello", "Iñtërnâtiônàlizætiøn, AND 日本語" => 'internationalizaetion-and-%E6%97%A5%E6%9C%AC%E8%AA%9E'); // where available, string is converted to NFC before transliteration if (\Elgg\Translit::hasNormalizerSupport()) { $form_d = "Å"; // A followed by 'COMBINING RING ABOVE' (U+030A) $cases[$form_d] = "a"; } foreach ($cases as $case => $expected) { $friendly_title = elgg_get_friendly_title($case); $this->assertIdentical($expected, $friendly_title); } }
/** * When given a title, returns a version suitable for inclusion in a URL * * @param string $title The title * * @return string The optimized title * @since 1.7.2 */ function elgg_get_friendly_title($title) { // return a URL friendly title to short circuit normal title formatting $params = array('title' => $title); $result = elgg_trigger_plugin_hook('format', 'friendly:title', $params, null); if ($result) { return $result; } // titles are often stored HTML encoded $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8'); $title = \Elgg\Translit::urlize($title); return $title; }