diff --git a/library/Class/Article.php b/library/Class/Article.php index 5755587bee86c0d37655877adbc85cc62a0e517e..9dfc740ab5a33e34ec5d85bd057d48e489165ec3 100644 --- a/library/Class/Article.php +++ b/library/Class/Article.php @@ -690,7 +690,7 @@ class Class_Article extends Storm_Model_Abstract { $this->check($this->getTitre(), "Vous devez compléter le champ 'Titre'"); - $this->check(strlen_utf8($this->getTitre()) <= self::TITLE_MAX_LENGTH, + $this->check(mb_strlen($this->getTitre(),'UTF-8') <= self::TITLE_MAX_LENGTH, sprintf("Le champ 'Titre' doit être inférieur à %d caractères", self::TITLE_MAX_LENGTH)); diff --git a/library/Class/Rss.php b/library/Class/Rss.php index 5841f3f86190f73a9aeeaa8c5c656d5e00a462b2..6607e7a28c84a52fba90aeae22cc9d24d493a0c2 100644 --- a/library/Class/Rss.php +++ b/library/Class/Rss.php @@ -438,7 +438,7 @@ class Class_Rss extends Storm_Model_Abstract { $errorMessage = ''; if ( $data['LIBELLE'] == '' ){ $errorMessage = "Vous devez compléter le champ 'Nom de la catégorie'"; - }elseif ( strlen_utf8($data['libelle']) > 50 ){ + }elseif ( mb_strlen($data['libelle'],'UTF-8') > 50 ){ $errorMessage = "Le champ 'Nom de la catégorie' doit être inférieur à 50 caractères"; } return $errorMessage; @@ -519,7 +519,7 @@ class Class_Rss extends Storm_Model_Abstract { $errorMessage = ''; if ( $data['TITRE'] == '' ){$errorMessage = "Vous devez compléter le champ 'Titre'";} elseif ( $data['URL'] == '' ){$errorMessage = "Vous devez compléter le champ 'Url'";} - elseif ( strlen_utf8($data['URL']) > 250 ){$errorMessage = "Le champ 'Url' doit être inférieur à 250 caractères";} + elseif ( mb_strlen($data['URL'],'UTF-8') > 250 ){$errorMessage = "Le champ 'Url' doit être inférieur à 250 caractères";} else{ // verify that the RSS URL is valid $httpClient = Zend_Registry::get('httpClient'); diff --git a/library/Class/Sitotheque.php b/library/Class/Sitotheque.php index f0485ec604cf2a7b9f6de21dfa283716fcb0934d..7d0d9ff415fc3a180fd0e417a04dfbf8c270046d 100644 --- a/library/Class/Sitotheque.php +++ b/library/Class/Sitotheque.php @@ -221,13 +221,13 @@ class Class_Sitotheque extends Storm_Model_Abstract { public function validate() { $this->check($this->getTitre(), $this->_("Vous devez compléter le champ 'Titre'")); - $this->check(strlen_utf8($this->getTitre()) <= 100, + $this->check(mb_strlen($this->getTitre(),'UTF-8') <= 100, $this->_("Le champ 'Titre' doit être inférieur à 100 caractères")); $this->check($this->getUrl(), $this->_("Vous devez compléter le champ 'Url'")); - $this->check(strlen_utf8($this->getUrl()) <= 250, + $this->check(mb_strlen($this->getUrl(),'UTF-8') <= 250, $this->_("Le champ 'Url' doit être inférieur à 250 caractères")); // $this->check(strlen_utf8($this->getDescription()) <= 250, diff --git a/library/Class/SitothequeCategorie.php b/library/Class/SitothequeCategorie.php index a2ca40432b9d147bae52bedf95d50bc211e58e72..b8700d6000dfe28f8ce2dd427b5d2f6a55fd613b 100644 --- a/library/Class/SitothequeCategorie.php +++ b/library/Class/SitothequeCategorie.php @@ -108,7 +108,7 @@ class Class_SitothequeCategorie extends Storm_Model_Abstract { public function validate() { $this->check($this->getLibelle(), $this->_("Vous devez compléter le champ 'Nom de la catégorie'")); - $this->check(strlen_utf8($this->getLibelle()) <= 50, + $this->check(mb_strlen($this->getLibelle(),'UTF-8') <= 50, $this->_("Le champ 'Nom de la catégorie' doit être inférieur à 50 caractères")); } diff --git a/library/Class/TagNotice.php b/library/Class/TagNotice.php index 0baca3d448ec11b3f3fb7c856d4a1c49fd1c8cba..e5f9883bfc677223e8c3a8f87db3b44a33d5fcca 100644 --- a/library/Class/TagNotice.php +++ b/library/Class/TagNotice.php @@ -49,7 +49,7 @@ class Class_TagNotice { $sql = Zend_Registry::get('sql'); $mot=trim($sql->quote($tag)); - if(strlen_utf8($tag)< 2) return false; + if(mb_strlen($tag,'UTF-8')< 2) return false; // Controle table de codif $id_tag=$this->getIdTag($tag); diff --git a/library/Class/Users.php b/library/Class/Users.php index cea0a486323d3b197b9798a375789682b8a6c51e..94eafb06b386218f95865072cc56e6e1777ef91a 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -641,7 +641,7 @@ class Class_Users extends Storm_Model_Abstract { /* Hook appelé sur save */ public function validate() { $this->check($this->getLogin(), $this->_translate->_("Vous devez compléter le champ 'Identifiant'")); - $this->check(strlen_utf8($this->getLogin()) <= 50, $this->_translate->_("Le champ 'Identifiant' doit être inférieur à 50 caractères")); + $this->check(mb_strlen($this->getLogin(),'UTF-8') <= 50, $this->_translate->_("Le champ 'Identifiant' doit être inférieur à 50 caractères")); if ($this->isNew()) { $this->check($this->ifLoginExist($this->getLogin()) == false, @@ -649,7 +649,7 @@ class Class_Users extends Storm_Model_Abstract { } $this->check($this->getPassword(), $this->_translate->_("Vous devez compléter le champ 'Mot de passe'")); - $this->check(strlen_utf8($this->getPassword()) <= 50, $this->_translate->_("Le champ 'Mot de passe' doit être inférieur à 50 caractères")); + $this->check(mb_strlen($this->getPassword(),'UTF-8') <= 50, $this->_translate->_("Le champ 'Mot de passe' doit être inférieur à 50 caractères")); if ($this->getRoleLevel() > 1 and $this->getRoleLevel() < 5 and $this->getIdSite() == 0) { $cls_role= new ZendAfi_Acl_AdminControllerRoles(); diff --git a/library/fonctions/string.php b/library/fonctions/string.php index 38a1e68b4d777566d800953fb618c0d974804fd2..c03cd7eacf7532767f428dd530d577184595354e 100644 --- a/library/fonctions/string.php +++ b/library/fonctions/string.php @@ -280,42 +280,4 @@ function convertToUtf8($string){ return $string; } -function utf8_substr($str,$from,$len){ - return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. - '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', - '$1',$str); -} - -function strlen_utf8 ($str) -{ - $i = 0; - $count = 0; - $len = strlen ($str); - while ($i < $len) - { - $chr = ord ($str[$i]); - $count++; - $i++; - if ($i >= $len) - break; - - if ($chr & 0x80) - { - $chr <<= 1; - while ($chr & 0x80) - { - $i++; - $chr <<= 1; - } - } - } - return $count; -} -function isPositiveInt($number) { - if(ereg("^[0-9]+$", $number) && (int)$number >= 0){ - return true; - } else { - return false; - } -} diff --git a/tests/library/Class/ArticleTest.php b/tests/library/Class/ArticleTest.php index e8732a1a897b4d5411ad6688c52843484fa8bc4b..8b1ee99ccea88c0030b068105ffe7465fbd472e0 100644 --- a/tests/library/Class/ArticleTest.php +++ b/tests/library/Class/ArticleTest.php @@ -269,6 +269,14 @@ class ArticleWithTraductionsTest extends Storm_Test_ModelTestCase { } + + /** @test */ + function withNullTitreShouldNotBeValid() { + $this->assertContains("Vous devez compléter le champ 'Titre'", + $this->concert->setTitre(null)->validate()->getErrors()); + } + + /** @test */ function withHundredCharactersTitreShouldNotBeValid() { $this->assertContains("Le champ 'Titre' doit être inférieur à 200 caractères",