[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");
+
+ }
}
- [Noalyss-commit] [noalyss] branch master updated (da636cf6e -> f1d3862e1), Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 07/12: Improve test, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 04/12: Task #0002125: Contact , devrait être refait sur le modèle de Fiche->résumé, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 08/12: Task #0002125: type , missed phoneTo for mobile , phone and faxTo, several emails separated by a comma, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 01/12: Fix Bug : accounting history was not shown when dble clicked, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 06/12: SQL If nothing is loaded return false, otherwise true, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 02/12: New #0002193: Possibilité d'ajouter directement une note aux opérations Cosmetic : change icon for enlarging operation label, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 09/12: Improve PHPUNIT, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 11/12: New #2195 0002195: Création catégorie : ordre des attributs, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 03/12: Improve autoloader, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 05/12: New function mailto and tel,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 12/12: Improve #0002196: Comptes Alphanumériques calculés trop longs, Dany De Bontridder, 2022/09/17
- [Noalyss-commit] [noalyss] 10/12: Add function linkTo for URL, Dany De Bontridder, 2022/09/17