diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php index 16ffa8949..5bd7d8f28 100644 --- a/include/lib/ac_common.php +++ b/include/lib/ac_common.php @@ -1621,4 +1621,29 @@ function noalyss_strip_tags($p_string) function noalyss_explode($separator,$string) { if ($string===null) return ''; return explode($separator,$string); +} +/** + * @brief compose a HTML string with phone + * @param string $p_tel + * @return false|string returns false if $p_tel is empty + */ +function phoneTo($p_tel) { + if (!empty($p_tel)) { + $r=sprintf('%s',h($p_tel),h($p_tel)); + return $r; + } + return false; +} + +/** + * @brief compose a HTML string with email + * @param $p_email + * @return false|string returns false if email not valide + */ +function mailTo($p_email) { + if ( filter_var($p_email,FILTER_VALIDATE_EMAIL) ) { + $r=sprintf('%s',h($p_email),h($p_email)); + return $r; + } + return false; } \ No newline at end of file diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php index 5a29c3467..d37b93758 100644 --- a/include/lib/message_javascript.php +++ b/include/lib/message_javascript.php @@ -116,4 +116,5 @@ content[79]=""; content[81]=""; content[82]=""; +content[83]=""; diff --git a/unit-test/include/lib/ac_commonTest.php b/unit-test/include/lib/ac_commonTest.php index 2508a5279..4cbcee8b4 100644 --- a/unit-test/include/lib/ac_commonTest.php +++ b/unit-test/include/lib/ac_commonTest.php @@ -371,4 +371,29 @@ class Ac_CommonTest extends TestCase { $this->assertEquals($expected,noalyss_strip_tags($string)); } + + /** + * @testdox Test the TEL tag + * @return void + */ + function testPhoneTo() + { + $this->assertFalse(phoneTo(""),"Invalide phone"); + $expect=sprintf('%s',h(123),h(123)); + $expect=preg_replace('/\s+/','',$expect); + $this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',phoneTo('123'))),); + } + /** + * @testdox Test the MAILTO tag + * @return void + */ + function testMailTo() + { + $this->assertEmpty(mailTo(""),"Invalide phone"); + $expect=sprintf('%s',h("test@noalyss.be"),h("test@noalyss.be")); + $expect=preg_replace('/\s+/','',$expect); + $this->assertEquals(strtoupper($expect),strtoupper(preg_replace("/\s+/",'',mailTo('test@noalyss.be'))),); + $this->assertFalse(mailTo('test@noalyss.@be'),"Send email to invalidate email"); + + } }