Ignore:
Timestamp:
Dec 22, 2010, 1:01:25 PM (13 years ago)
Author:
mistic100
Message:
  • Corrections de bugs
  • Améliorations mineures
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PHP_Optimisateur/files/functions.php

    r8195 r8226  
    55\***************************************/
    66
    7 // Affiche les textes
     7// Affiche les textes localisés
    88function l10n($code){
    99        global $Lang;
     
    2121}
    2222
    23 // Trouve la langue
     23// Trouve la langue, retourne la langue de l'utilisateur et les langues installées
    2424function GetLanguage(){
    2525        // tableau avec les langues installées
     
    6464        } else {
    6565                return true;
    66                
    6766        }
    6867}
     
    7069// Supprime un repertoire non-vide
    7170function rrmdir($dir) {
     71        $dir = rtrim($dir, '/');
    7272        if (is_dir($dir)) {
    7373                $objects = scandir($dir);
     
    159159                        } else if (preg_match('#^([0-9]*)$#', $value)) {
    160160                                settype($array[$key], 'int');           
    161                         } else if (preg_match('#^([0-9]*)(.|,)([0-9]*)$#', $value)) {
     161                        } else if (preg_match('#^([0-9]*)(\.|,)([0-9]*)$#', $value)) {
    162162                                settype($array[$key], 'float');         
    163163                        }
     
    171171function bool_to_string($bool, $just_echo=0) {
    172172        global $Lang;
    173         # $just_echo pour pouvoir afficher un booléen tel quel
     173        # $just_echo pour pouvoir afficher un booléen tel quel (echo true; n'affiche rien)
    174174        if (is_bool($bool)) {
    175175                if ($bool) {
     
    184184        }
    185185}
     186
     187// Converti une chaine de config et tableau associatif
     188function ExplodeString($string, $sep1=';', $sep2=':') {
     189        $result = array();
     190        $a = explode($sep1, $string);
     191        foreach ($a as $s) {
     192           $v = explode($sep2, $s);
     193           $result[$v[0]] = $v[1];
     194        }
     195        return $result;
     196}
     197
     198// Converti une couleur HEX et RGB
     199function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') {
     200        $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
     201        $rgbArray = array();
     202       
     203        if (strlen($hexStr) == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster
     204                $colorVal = hexdec($hexStr);
     205                $rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
     206                $rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
     207                $rgbArray['b'] = 0xFF & $colorVal;
     208        } elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations
     209                $rgbArray['r'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
     210                $rgbArray['g'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
     211                $rgbArray['b'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
     212        } else {
     213                return false; //Invalid hex color code
     214        }
     215       
     216        return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; // returns the rgb string or the associative array
     217}
    186218?>
Note: See TracChangeset for help on using the changeset viewer.