3
3
*
4
4
* TinyButStrong - Template Engine for Pro and Beginners
5
5
*
6
- * @version 3.12.0 for PHP 5, 7, 8
7
- * @date 2020-10-12
6
+ * @version 3.12.1 for PHP 5, 7, 8
7
+ * @date 2020-10-21
8
8
* @link http://www.tinybutstrong.com Web site
9
9
* @author http://www.tinybutstrong.com/onlyyou.html
10
10
* @license http://opensource.org/licenses/LGPL-3.0 LGPL-3.0
@@ -655,7 +655,7 @@ class clsTinyButStrong {
655
655
public $ ExtendedMethods = array ();
656
656
public $ ErrCount = 0 ;
657
657
// Undocumented (can change at any version)
658
- public $ Version = '3.12.0 ' ;
658
+ public $ Version = '3.12.1 ' ;
659
659
public $ Charset = '' ;
660
660
public $ TurboBlock = true ;
661
661
public $ VarPrefix = '' ;
@@ -3731,21 +3731,27 @@ function meth_PlugIn_SetEvent($PlugInId, $Event, $NewRef='') {
3731
3731
3732
3732
}
3733
3733
3734
+ /**
3735
+ * Convert any value to a string without specific formating.
3736
+ */
3734
3737
static function meth_Misc_ToStr ($ Value ) {
3735
3738
if (is_string ($ Value )) {
3736
3739
return $ Value ;
3737
3740
} elseif (is_object ($ Value )) {
3738
3741
if (method_exists ($ Value ,'__toString ' )) {
3739
3742
return $ Value ->__toString ();
3740
3743
} elseif (is_a ($ Value , 'DateTime ' )) {
3744
+ // ISO date-time format
3741
3745
return $ Value ->format ('c ' );
3742
3746
}
3743
3747
}
3744
3748
return @(string )$ Value ; // (string) is faster than strval() and settype()
3745
3749
}
3746
3750
3751
+ /**
3752
+ * Return the formated representation of a Date/Time or numeric variable using a 'VB like' format syntax instead of the PHP syntax.
3753
+ */
3747
3754
function meth_Misc_Format (&$ Value ,&$ PrmLst ) {
3748
- // This function return the formated representation of a Date/Time or numeric variable using a 'VB like' format syntax instead of the PHP syntax.
3749
3755
3750
3756
$ FrmStr = $ PrmLst ['frm ' ];
3751
3757
$ CheckNumeric = true ;
@@ -3757,30 +3763,39 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
3757
3763
// Manage Multi format strings
3758
3764
if ($ Frm ['type ' ]=='multi ' ) {
3759
3765
3760
- // Select the format
3766
+ // Found the format according to the value (positive|negative|zero|null)
3767
+
3761
3768
if (is_numeric ($ Value )) {
3769
+ // Numeric:
3762
3770
if (is_string ($ Value )) $ Value = 0.0 + $ Value ;
3763
3771
if ($ Value >0 ) {
3764
3772
$ FrmStr = &$ Frm [0 ];
3765
3773
} elseif ($ Value <0 ) {
3766
3774
$ FrmStr = &$ Frm [1 ];
3767
3775
if ($ Frm ['abs ' ]) $ Value = abs ($ Value );
3768
- } else { // zero
3776
+ } else {
3777
+ // zero
3769
3778
$ FrmStr = &$ Frm [2 ];
3770
3779
$ Minus = '' ;
3771
3780
}
3772
3781
$ CheckNumeric = false ;
3773
3782
} else {
3783
+ // date|
3774
3784
$ Value = $ this ->meth_Misc_ToStr ($ Value );
3775
3785
if ($ Value ==='' ) {
3776
- return $ Frm [3 ]; // Null value
3786
+ // Null value
3787
+ return $ Frm [3 ];
3777
3788
} else {
3789
+ // Date conversion
3778
3790
$ t = strtotime ($ Value ); // We look if it's a date
3779
- if (($ t ===-1 ) || ($ t ===false )) { // Date not recognized
3791
+ if (($ t ===-1 ) || ($ t ===false )) {
3792
+ // Date not recognized
3780
3793
return $ Frm [1 ];
3781
- } elseif ($ t ===943916400 ) { // Date to zero
3794
+ } elseif ($ t ===943916400 ) {
3795
+ // Date to zero in some softwares
3782
3796
return $ Frm [2 ];
3783
- } else { // It's a date
3797
+ } else {
3798
+ // It's a date
3784
3799
$ Value = $ t ;
3785
3800
$ FrmStr = &$ Frm [0 ];
3786
3801
}
@@ -3794,7 +3809,7 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
3794
3809
}
3795
3810
3796
3811
switch ($ Frm ['type ' ]) {
3797
- case 'num ' :
3812
+ case 'num ' :
3798
3813
// NUMERIC
3799
3814
if ($ CheckNumeric ) {
3800
3815
if (is_numeric ($ Value )) {
@@ -3810,29 +3825,9 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
3810
3825
$ Value = substr_replace ($ Frm ['Str ' ],$ Value ,$ Frm ['Pos ' ],$ Frm ['Len ' ]);
3811
3826
return $ Value ;
3812
3827
break ;
3813
- case 'date ' :
3828
+ case 'date ' :
3814
3829
// DATE
3815
- if (is_object ($ Value )) {
3816
- $ Value = $ this ->meth_Misc_ToStr ($ Value );
3817
- }
3818
- if (is_string ($ Value )) {
3819
- if ($ Value ==='' ) return '' ;
3820
- $ x = strtotime ($ Value );
3821
- if (($ x ===-1 ) || ($ x ===false )) {
3822
- if (!is_numeric ($ Value )) $ Value = 0 ;
3823
- } else {
3824
- $ Value = &$ x ;
3825
- }
3826
- } else {
3827
- if (!is_numeric ($ Value )) return $ this ->meth_Misc_ToStr ($ Value );
3828
- }
3829
- if ($ Frm ['loc ' ] || isset ($ PrmLst ['locale ' ])) {
3830
- $ x = strftime ($ Frm ['str_loc ' ],$ Value );
3831
- $ this ->meth_Conv_Str ($ x ,false ); // may have accent
3832
- return $ x ;
3833
- } else {
3834
- return date ($ Frm ['str_us ' ],$ Value );
3835
- }
3830
+ return $ this ->meth_Misc_DateFormat ($ Value , $ Frm );
3836
3831
break ;
3837
3832
default :
3838
3833
return $ Frm ['string ' ];
@@ -3841,6 +3836,62 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
3841
3836
3842
3837
}
3843
3838
3839
+ function meth_Misc_DateFormat (&$ Value , $ Frm ) {
3840
+
3841
+ if (is_object ($ Value )) {
3842
+ $ Value = $ this ->meth_Misc_ToStr ($ Value );
3843
+ }
3844
+
3845
+ if ($ Value ==='' ) return '' ;
3846
+
3847
+ // Note : DateTime object is supported since PHP 5.2
3848
+ // So we could simplify this function using only DateTime instead of timestamp.
3849
+
3850
+ // Now we try to get the timestamp
3851
+ if (is_string ($ Value )) {
3852
+ // Any string value is assumed to be a formated date.
3853
+ // If you whant a string value to be a considered to a a time stamp, then use prefixe '@' accordding to the
3854
+ $ x = strtotime ($ Value );
3855
+ // In case of error return false (return -1 for PHP < 5.1.0)
3856
+ if (($ x ===false ) || ($ x ===-1 )) {
3857
+ if (!is_numeric ($ Value )) {
3858
+ // At this point the value is not recognized as a date
3859
+ // Special fix for PHP 32-bit and date > '2038-01-19 03:14:07' => strtotime() failes
3860
+ if (PHP_INT_SIZE === 4 ) { // 32-bit
3861
+ try {
3862
+ $ date = new DateTime ($ Value );
3863
+ return $ date ->format ($ Frm ['str_us ' ]);
3864
+ // 'locale' cannot be supported in this case because strftime() has to equilavent with DateTime
3865
+ } catch (Exception $ e ) {
3866
+ // We take an arbitrary value in order to avoid formating error
3867
+ $ Value = 0 ; // '1970-01-01'
3868
+ // echo $e->getMessage();
3869
+ }
3870
+ } else {
3871
+ // We take an arbirtary value in order to avoid formating error
3872
+ $ Value = 0 ; // '1970-01-01'
3873
+ }
3874
+ }
3875
+ } else {
3876
+ $ Value = &$ x ;
3877
+ }
3878
+ } else {
3879
+ if (!is_numeric ($ Value )) {
3880
+ // It’s not a timestamp, thus we return the non formated value
3881
+ return $ this ->meth_Misc_ToStr ($ Value );
3882
+ }
3883
+ }
3884
+
3885
+ if ($ Frm ['loc ' ] || isset ($ PrmLst ['locale ' ])) {
3886
+ $ x = strftime ($ Frm ['str_loc ' ],$ Value );
3887
+ $ this ->meth_Conv_Str ($ x ,false ); // may have accent
3888
+ return $ x ;
3889
+ } else {
3890
+ return date ($ Frm ['str_us ' ],$ Value );
3891
+ }
3892
+
3893
+ }
3894
+
3844
3895
/**
3845
3896
* Apply combo parameters.
3846
3897
* @param array $PrmLst The existing list of combo
0 commit comments