| 1436 | raphael | 1 | <?php
 | 
        
           | 1796 | jpm | 2 | namespace TelaBotanica\Del\Commun;
 | 
        
           | 1436 | raphael | 3 | /**
 | 
        
           |  |  | 4 |  * @author		Raphaël Droz <raphael@tela-botanica.org>
 | 
        
           |  |  | 5 |  * @author		Aurélien PERONNET <aurelien@tela-botanica.org>
 | 
        
           |  |  | 6 |  * @copyright	Copyright (c) 2013, Tela Botanica (accueil@tela-botanica.org)
 | 
        
           |  |  | 7 |  * @license		Licence CECILL http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt
 | 
        
           |  |  | 8 |  * @license		Licence GNU-GPL http://www.gnu.org/licenses/gpl.html
 | 
        
           |  |  | 9 |  * @see http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=ApiIdentiplante01Images
 | 
        
           |  |  | 10 |  */
 | 
        
           | 1796 | jpm | 11 | class MotsClesImage {
 | 
        
           | 1436 | raphael | 12 |   | 
        
           |  |  | 13 | 	// cf: images/VotesImage.php
 | 
        
           |  |  | 14 | 	static function updateStats($db, $id_image) {
 | 
        
           |  |  | 15 | 		$id_image = intval($id_image);
 | 
        
           | 1796 | jpm | 16 | 		if (!$id_image) {
 | 
        
           |  |  | 17 | 			$msg = "Ne peut mettre à jour les statistiques de vote";
 | 
        
           |  |  | 18 | 			throw new Exception($msg, RestServeur::HTTP_CODE_ERREUR);
 | 
        
           |  |  | 19 | 		}
 | 
        
           | 1436 | raphael | 20 |   | 
        
           |  |  | 21 | 		// on utilise toujours cette table de stats (ListeImages) pour les mots-clef "actif".
 | 
        
           | 1796 | jpm | 22 | 		$requete = 'UPDATE del_image_stat '.
 | 
        
           |  |  | 23 | 			"SET nb_tags = (SELECT COUNT(id_tag) FROM del_image_tag WHERE ce_image = $id_image AND actif = 1) ".
 | 
        
           |  |  | 24 | 			"WHERE ce_image = $id_image ".
 | 
        
           |  |  | 25 | 			' -- '.__FILE__.' : '.__LINE__;
 | 
        
           |  |  | 26 | 		$db->requeter($requete);
 | 
        
           | 1436 | raphael | 27 | 	}
 | 
        
           |  |  | 28 |   | 
        
           | 1796 | jpm | 29 | 	//TODO: déplacer les fonctions ci dessus et dessous dans une classe utilitaire
 | 
        
           |  |  | 30 | 	static function normaliserMotCle($motCle, $charset='utf-8') {
 | 
        
           |  |  | 31 | 		$motCle = trim($motCle);
 | 
        
           |  |  | 32 | 		$str = htmlentities($motCle, ENT_NOQUOTES, $charset);
 | 
        
           | 1436 | raphael | 33 | 		$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
 | 
        
           |  |  | 34 | 		$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
 | 
        
           |  |  | 35 | 		$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
 | 
        
           | 1796 | jpm | 36 | 		$str = str_replace(array(' ', '-', "'"), '_', $str);// supprime les espaces, tirets et simple-quotes en underscores
 | 
        
           |  |  | 37 | 		//TODO Voir si on doit mettre en minuscule : $str = mb_strtolower($str);
 | 
        
           |  |  | 38 | 		return $str;
 | 
        
           | 1436 | raphael | 39 | 	}
 | 
        
           | 1796 | jpm | 40 | }
 |