33 *
44 * TinyButStrong - Template Engine for Pro and Beginners
55 *
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
88 * @link http://www.tinybutstrong.com Web site
99 * @author http://www.tinybutstrong.com/onlyyou.html
1010 * @license http://opensource.org/licenses/LGPL-3.0 LGPL-3.0
@@ -655,7 +655,7 @@ class clsTinyButStrong {
655655public $ ExtendedMethods = array ();
656656public $ ErrCount = 0 ;
657657// Undocumented (can change at any version)
658- public $ Version = '3.12.0 ' ;
658+ public $ Version = '3.12.1 ' ;
659659public $ Charset = '' ;
660660public $ TurboBlock = true ;
661661public $ VarPrefix = '' ;
@@ -3731,21 +3731,27 @@ function meth_PlugIn_SetEvent($PlugInId, $Event, $NewRef='') {
37313731
37323732}
37333733
3734+ /**
3735+ * Convert any value to a string without specific formating.
3736+ */
37343737static function meth_Misc_ToStr ($ Value ) {
37353738 if (is_string ($ Value )) {
37363739 return $ Value ;
37373740 } elseif (is_object ($ Value )) {
37383741 if (method_exists ($ Value ,'__toString ' )) {
37393742 return $ Value ->__toString ();
37403743 } elseif (is_a ($ Value , 'DateTime ' )) {
3744+ // ISO date-time format
37413745 return $ Value ->format ('c ' );
37423746 }
37433747 }
37443748 return @(string )$ Value ; // (string) is faster than strval() and settype()
37453749}
37463750
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+ */
37473754function 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.
37493755
37503756 $ FrmStr = $ PrmLst ['frm ' ];
37513757 $ CheckNumeric = true ;
@@ -3757,30 +3763,39 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
37573763 // Manage Multi format strings
37583764 if ($ Frm ['type ' ]=='multi ' ) {
37593765
3760- // Select the format
3766+ // Found the format according to the value (positive|negative|zero|null)
3767+
37613768 if (is_numeric ($ Value )) {
3769+ // Numeric:
37623770 if (is_string ($ Value )) $ Value = 0.0 + $ Value ;
37633771 if ($ Value >0 ) {
37643772 $ FrmStr = &$ Frm [0 ];
37653773 } elseif ($ Value <0 ) {
37663774 $ FrmStr = &$ Frm [1 ];
37673775 if ($ Frm ['abs ' ]) $ Value = abs ($ Value );
3768- } else { // zero
3776+ } else {
3777+ // zero
37693778 $ FrmStr = &$ Frm [2 ];
37703779 $ Minus = '' ;
37713780 }
37723781 $ CheckNumeric = false ;
37733782 } else {
3783+ // date|
37743784 $ Value = $ this ->meth_Misc_ToStr ($ Value );
37753785 if ($ Value ==='' ) {
3776- return $ Frm [3 ]; // Null value
3786+ // Null value
3787+ return $ Frm [3 ];
37773788 } else {
3789+ // Date conversion
37783790 $ 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
37803793 return $ Frm [1 ];
3781- } elseif ($ t ===943916400 ) { // Date to zero
3794+ } elseif ($ t ===943916400 ) {
3795+ // Date to zero in some softwares
37823796 return $ Frm [2 ];
3783- } else { // It's a date
3797+ } else {
3798+ // It's a date
37843799 $ Value = $ t ;
37853800 $ FrmStr = &$ Frm [0 ];
37863801 }
@@ -3794,7 +3809,7 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
37943809 }
37953810
37963811 switch ($ Frm ['type ' ]) {
3797- case 'num ' :
3812+ case 'num ' :
37983813 // NUMERIC
37993814 if ($ CheckNumeric ) {
38003815 if (is_numeric ($ Value )) {
@@ -3810,29 +3825,9 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
38103825 $ Value = substr_replace ($ Frm ['Str ' ],$ Value ,$ Frm ['Pos ' ],$ Frm ['Len ' ]);
38113826 return $ Value ;
38123827 break ;
3813- case 'date ' :
3828+ case 'date ' :
38143829 // 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 );
38363831 break ;
38373832 default :
38383833 return $ Frm ['string ' ];
@@ -3841,6 +3836,62 @@ function meth_Misc_Format(&$Value,&$PrmLst) {
38413836
38423837}
38433838
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+
38443895/**
38453896 * Apply combo parameters.
38463897 * @param array $PrmLst The existing list of combo
0 commit comments