New function mailto and tel
This commit is contained in:
parent
8fdd7be647
commit
2c300571fa
3 changed files with 51 additions and 0 deletions
|
|
@ -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('<a href="tel:%s">%s</a>',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('<a href="mailto:%s">%s</a>',h($p_email),h($p_email));
|
||||
return $r;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -116,4 +116,5 @@ content[79]="<?php echo htmlspecialchars(_("Les postes comptables sont entre []
|
|||
content[80]="<?php echo htmlspecialchars(_("Oui pour charger les fichiers javascripts et CSS standards"),ENT_QUOTES)?>";
|
||||
content[81]="<?php echo htmlspecialchars(_("Recommendé d'avoir un poste propre"),ENT_QUOTES)?>";
|
||||
content[82]="<?php echo htmlspecialchars(_("valeur en % "),ENT_QUOTES)?>";
|
||||
content[83]="<?php echo htmlspecialchars(_("Données invalides "),ENT_QUOTES)?>";
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -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('<a href="tel:%s">%s</a>',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('<a href="mailto:%s">%s</a>',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");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue