Differences From Artifact [da8a9f5dd6]:

To Artifact [bcd9673938]:


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    {
        $ts = self::get_datetime($ts);

        if (null === $ts) {
            return $ts;
        }

        $date = strftime($format, $ts->getTimestamp());

        $date = strtr($date, self::FRENCH_DATE_NAMES);
        return $date;
    }

    static public function date_fr($ts, $format = null)
    {
        $ts = self::get_datetime($ts);








|
<
<







89
90
91
92
93
94
95
96


97
98
99
100
101
102
103
    {
        $ts = self::get_datetime($ts);

        if (null === $ts) {
            return $ts;
        }

        $date = Translate::strftime($format, $ts, 'fr_FR');


        return $date;
    }

    static public function date_fr($ts, $format = null)
    {
        $ts = self::get_datetime($ts);

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
            return 0;
        }

        if (!preg_match('/^-?(\d+)(?:[,.](\d{1,2}))?$/', $value, $match)) {
            throw new UserException(sprintf('Le montant est invalide : %s. Exemple de format accepté : 142,02', $value));
        }

        $value = $match[1] . str_pad(@$match[2], 2, '0', STR_PAD_RIGHT);
        $value = (int) $value;
        return $value;
    }

    static public function money_format($number, string $dec_point = ',', string $thousands_sep = ' ', $zero_if_empty = true): string {
        if ($number == 0) {
            return $zero_if_empty ? '0' : '0,00';







|







159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
            return 0;
        }

        if (!preg_match('/^-?(\d+)(?:[,.](\d{1,2}))?$/', $value, $match)) {
            throw new UserException(sprintf('Le montant est invalide : %s. Exemple de format accepté : 142,02', $value));
        }

        $value = $match[1] . str_pad($match[2] ?? '', 2, '0', STR_PAD_RIGHT);
        $value = (int) $value;
        return $value;
    }

    static public function money_format($number, string $dec_point = ',', string $thousands_sep = ' ', $zero_if_empty = true): string {
        if ($number == 0) {
            return $zero_if_empty ? '0' : '0,00';
337
338
339
340
341
342
343


344
345
346
347
348
349
350
    static public function getCountryList()
    {
        return Translate::getCountriesList('fr');
    }

    static public function getCountryName($code)
    {


        $list = self::getCountryList();

        if (!isset($list[$code]))
            return false;

        return $list[$code];
    }







>
>







335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
    static public function getCountryList()
    {
        return Translate::getCountriesList('fr');
    }

    static public function getCountryName($code)
    {
        $code = strtoupper($code);

        $list = self::getCountryList();

        if (!isset($list[$code]))
            return false;

        return $list[$code];
    }
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879


880

881
882

883
884
885
886
887



888

889
890
891
892
893
894
895
            }
            $h /= 6;
        }

        return array($h * 360, $s, $l);
    }

    static public function HTTPCache(?string $hash, int $last_change): bool
    {
        $etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : null;
        $last_modified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;

        if ($etag === $hash && $last_modified >= $last_change) {
            header('HTTP/1.1 304 Not Modified', true, 304);
            exit;
        }




        header(sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $last_change)));


        if ($etag) {
            header(sprintf('Etag: %s', $hash));
        }

        header('Cache-Control: private');





        return false;
    }

    static public function transformTitleToURI($str)
    {
        $str = Utils::transliterateToAscii($str);








|

|


|
<
<
|
>
>

>
|
|
>
|
|


<
>
>
>
|
>







864
865
866
867
868
869
870
871
872
873
874
875
876


877
878
879
880
881
882
883
884
885
886
887
888

889
890
891
892
893
894
895
896
897
898
899
900
            }
            $h /= 6;
        }

        return array($h * 360, $s, $l);
    }

    static public function HTTPCache(?string $hash, ?int $last_change, int $max_age = 3600): bool
    {
        $etag = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH'], '"\' ') : null;
        $last_modified = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;

        $etag = $etag ? str_replace('-gzip', '', $etag) : null;



        header(sprintf('Cache-Control: private, max-age=%d', $max_age), true);
        header_remove('Expires');

        if ($last_change) {
            header(sprintf('Last-Modified: %s GMT', gmdate('D, d M Y H:i:s', $last_change)), true);
        }

        if ($hash) {
            header(sprintf('Etag: "%s"', $hash), true);
        }


        if (($etag && $etag === $hash) || ($last_modified && $last_modified >= $last_change)) {
            http_response_code(304);
            exit;
        }

        return false;
    }

    static public function transformTitleToURI($str)
    {
        $str = Utils::transliterateToAscii($str);

926
927
928
929
930
931
932
933
934




935
936
937
938
939
940
941
942
943
944
945
946
947

948
949
950
951






952
953
954
955
956
957
958
959
960










961
962
963
964
965
966
967
        $str = str_replace(DIRECTORY_SEPARATOR, '/', $str);
        $str = trim($str, '/');
        $str = substr($str, strrpos($str, '/'));
        $str = trim($str, '/');
        return $str;
    }

    static public function unicodeTransliterate($str): string
    {




        return transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $str);
    }

    static public function unicodeCaseComparison($a, $b): int
    {
        if (!isset(self::$collator) && function_exists('collator_create')) {
            self::$collator = \Collator::create('fr_FR');

            // This is what makes the comparison case insensitive
            // https://www.php.net/manual/en/collator.setstrength.php
            self::$collator->setAttribute(\Collator::STRENGTH, \Collator::SECONDARY);

            // Don't use \Collator::NUMERIC_COLLATION here as it goes against what would feel logic

            // with NUMERIC_COLLATION: 1, 2, 10, 11, 101
            // without: 1, 10, 101, 11, 2
        }







        if (isset(self::$collator)) {
            return (int) self::$collator->compare($a, $b);
        }

        $a = strtoupper(self::transliterateToAscii($a));
        $b = strtoupper(self::transliterateToAscii($b));

        return strcmp($a, $b);
    }











    /**
     * Transforms a unicode string to lowercase AND removes all diacritics
     *
     * @see https://www.matthecat.com/supprimer-les-accents-d-une-chaine-avec-php.html
     */
    static public function unicodeCaseFold(?string $str): string







|

>
>
>
>













>




>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>







931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
        $str = str_replace(DIRECTORY_SEPARATOR, '/', $str);
        $str = trim($str, '/');
        $str = substr($str, strrpos($str, '/'));
        $str = trim($str, '/');
        return $str;
    }

    static public function unicodeTransliterate($str): ?string
    {
        if ($str === null) {
            return null;
        }

        return transliterator_transliterate('Any-Latin; Latin-ASCII; Lower()', $str);
    }

    static public function unicodeCaseComparison($a, $b): int
    {
        if (!isset(self::$collator) && function_exists('collator_create')) {
            self::$collator = \Collator::create('fr_FR');

            // This is what makes the comparison case insensitive
            // https://www.php.net/manual/en/collator.setstrength.php
            self::$collator->setAttribute(\Collator::STRENGTH, \Collator::SECONDARY);

            // Don't use \Collator::NUMERIC_COLLATION here as it goes against what would feel logic
            // for account ordering
            // with NUMERIC_COLLATION: 1, 2, 10, 11, 101
            // without: 1, 10, 101, 11, 2
        }

        // Make sure we have UTF-8
        // If we don't, we may end up with malformed database, eg. "row X missing from index" errors
        // when doing an integrity check
        $a = self::utf8_encode($a);
        $b = self::utf8_encode($b);

        if (isset(self::$collator)) {
            return (int) self::$collator->compare($a, $b);
        }

        $a = strtoupper(self::transliterateToAscii($a));
        $b = strtoupper(self::transliterateToAscii($b));

        return strcmp($a, $b);
    }

    static public function utf8_encode(?string $str): ?string
    {
        if (null === $str) {
            return null;
        }

        // Check if string is already UTF-8 encoded or not
        return !preg_match('//u', $str) ? utf8_encode($str) : $str;
    }

    /**
     * Transforms a unicode string to lowercase AND removes all diacritics
     *
     * @see https://www.matthecat.com/supprimer-les-accents-d-une-chaine-avec-php.html
     */
    static public function unicodeCaseFold(?string $str): string