noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 05/12: New function mailto and tel


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 05/12: New function mailto and tel
Date: Sat, 17 Sep 2022 08:40:57 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 2c300571fa7ba6240497bceecccf4e6f57644b3c
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Sep 14 16:28:28 2022 +0200

    New function mailto and tel
---
 include/lib/ac_common.php               | 25 +++++++++++++++++++++++++
 include/lib/message_javascript.php      |  1 +
 unit-test/include/lib/ac_commonTest.php | 25 +++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

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('<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;
 }
\ 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]="<?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>
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('<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");
+
+    }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]