@@ -143,33 +143,48 @@ public function formatPrice($price, $includeContainer = true)
143
143
/**
144
144
* Format date using current locale options and time zone.
145
145
*
146
- * @param string|Zend_Date|null $date If empty, return current datetime.
147
- * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
148
- * @param bool $showTime Whether to include time
149
- * @param bool $useTimezone Convert to local datetime?
146
+ * @param string|int|Zend_Date|null $date If empty, return current datetime.
147
+ * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
148
+ * @param bool $showTime Whether to include time
150
149
* @return string
151
150
*/
152
- public function formatDate ($ date = null , $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT , $ showTime = false , $ useTimezone = true )
151
+ public function formatDate ($ date = null , $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT , $ showTime = false )
153
152
{
153
+ return $ this ->formatTimezoneDate ($ date , $ format , $ showTime );
154
+ }
155
+
156
+ /**
157
+ * Format date using current locale options and time zone.
158
+ *
159
+ * @param string|int|Zend_Date|null $date If empty, return current locale datetime.
160
+ * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
161
+ * @param bool $showTime Whether to include time
162
+ * @param bool $useTimezone Convert to local datetime?
163
+ */
164
+ public function formatTimezoneDate (
165
+ $ date = null ,
166
+ string $ format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT ,
167
+ bool $ showTime = false ,
168
+ bool $ useTimezone = true
169
+ ): string {
154
170
if (!in_array ($ format , $ this ->_allowedFormats , true )) {
155
171
return $ date ;
156
172
}
173
+
174
+ $ locale = Mage::app ()->getLocale ();
157
175
if (empty ($ date )) {
158
- $ date = Mage:: app ()-> getLocale () ->date (Mage::getSingleton ('core/date ' )->gmtTimestamp (), null , null , $ useTimezone );
176
+ $ date = $ locale ->date (Mage::getSingleton ('core/date ' )->gmtTimestamp (), null , null , $ useTimezone );
159
177
} elseif (is_int ($ date )) {
160
- $ date = Mage:: app ()-> getLocale () ->date ($ date , null , null , $ useTimezone );
178
+ $ date = $ locale ->date ($ date , null , null , $ useTimezone );
161
179
} elseif (!$ date instanceof Zend_Date) {
162
180
if (($ time = strtotime ($ date )) !== false ) {
163
- $ date = Mage:: app ()-> getLocale () ->date ($ time , null , null , $ useTimezone );
181
+ $ date = $ locale ->date ($ time , null , null , $ useTimezone );
164
182
} else {
165
183
return '' ;
166
184
}
167
185
}
168
186
169
- $ format = $ showTime
170
- ? Mage::app ()->getLocale ()->getDateTimeFormat ($ format )
171
- : Mage::app ()->getLocale ()->getDateFormat ($ format );
172
-
187
+ $ format = $ showTime ? $ locale ->getDateTimeFormat ($ format ) : $ locale ->getDateFormat ($ format );
173
188
return $ date ->toString ($ format );
174
189
}
175
190
@@ -187,18 +202,19 @@ public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMA
187
202
return $ time ;
188
203
}
189
204
205
+ $ locale = Mage::app ()->getLocale ();
190
206
if (is_null ($ time )) {
191
- $ date = Mage:: app ()-> getLocale () ->date (time ());
207
+ $ date = $ locale ->date (time ());
192
208
} elseif ($ time instanceof Zend_Date) {
193
209
$ date = $ time ;
194
210
} else {
195
- $ date = Mage:: app ()-> getLocale () ->date (strtotime ($ time ));
211
+ $ date = $ locale ->date (strtotime ($ time ));
196
212
}
197
213
198
214
if ($ showDate ) {
199
- $ format = Mage:: app ()-> getLocale () ->getDateTimeFormat ($ format );
215
+ $ format = $ locale ->getDateTimeFormat ($ format );
200
216
} else {
201
- $ format = Mage:: app ()-> getLocale () ->getTimeFormat ($ format );
217
+ $ format = $ locale ->getTimeFormat ($ format );
202
218
}
203
219
204
220
return $ date ->toString ($ format );
@@ -365,12 +381,14 @@ public function removeAccents($string, $german = false)
365
381
366
382
$ replacements [$ german ] = [];
367
383
foreach ($ subst as $ k => $ v ) {
384
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
368
385
$ replacements [$ german ][$ k < 256 ? chr ($ k ) : '&# ' . $ k . '; ' ] = $ v ;
369
386
}
370
387
}
371
388
372
389
// convert string from default database format (UTF-8)
373
390
// to encoding which replacement arrays made with (ISO-8859-1)
391
+ // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
374
392
if ($ s = @iconv ('UTF-8 ' , 'ISO-8859-1 ' , $ string )) {
375
393
$ string = $ s ;
376
394
}
@@ -568,6 +586,7 @@ public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = fal
568
586
* @param mixed $value
569
587
* @param bool $dontSkip
570
588
*/
589
+ // phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
571
590
private function _decorateArrayObject ($ element , $ key , $ value , $ dontSkip )
572
591
{
573
592
if ($ dontSkip ) {
@@ -613,6 +632,7 @@ public function assocToXml(array $array, $rootName = '_')
613
632
* @return SimpleXMLElement
614
633
* @throws Exception
615
634
*/
635
+ // phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
616
636
private function _assocToXml (array $ array , $ rootName , SimpleXMLElement &$ xml )
617
637
{
618
638
$ hasNumericKey = false ;
@@ -762,14 +782,18 @@ public function mergeFiles(
762
782
// check whether merger is required
763
783
$ shouldMerge = $ mustMerge || !$ targetFile ;
764
784
if (!$ shouldMerge ) {
785
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
765
786
if (!file_exists ($ targetFile )) {
766
787
$ shouldMerge = true ;
767
788
} else {
789
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
768
790
$ targetMtime = filemtime ($ targetFile );
769
791
foreach ($ srcFiles as $ file ) {
792
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
770
793
if (!file_exists ($ file )) {
771
794
// no translation intentionally
772
795
Mage::logException (new Exception (sprintf ('File %s not found. ' , $ file )));
796
+ // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
773
797
} elseif (@filemtime ($ file ) > $ targetMtime ) {
774
798
$ shouldMerge = true ;
775
799
break ;
@@ -780,8 +804,10 @@ public function mergeFiles(
780
804
781
805
// merge contents into the file
782
806
if ($ shouldMerge ) {
807
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
783
808
if ($ targetFile && !is_writable (dirname ($ targetFile ))) {
784
809
// no translation intentionally
810
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
785
811
throw new Exception (sprintf ('Path %s is not writeable. ' , dirname ($ targetFile )));
786
812
}
787
813
@@ -792,6 +818,7 @@ public function mergeFiles(
792
818
}
793
819
if (!empty ($ srcFiles )) {
794
820
foreach ($ srcFiles as $ key => $ file ) {
821
+ // phpcs:ignore Ecg.Security.DiscouragedFunction.Discouraged
795
822
$ fileExt = strtolower (pathinfo ($ file , PATHINFO_EXTENSION ));
796
823
if (!in_array ($ fileExt , $ extensionsFilter )) {
797
824
unset($ srcFiles [$ key ]);
@@ -806,11 +833,14 @@ public function mergeFiles(
806
833
807
834
$ data = '' ;
808
835
foreach ($ srcFiles as $ file ) {
836
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
809
837
if (!file_exists ($ file )) {
810
838
continue ;
811
839
}
840
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
812
841
$ contents = file_get_contents ($ file ) . "\n" ;
813
842
if ($ beforeMergeCallback && is_callable ($ beforeMergeCallback )) {
843
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
814
844
$ contents = call_user_func ($ beforeMergeCallback , $ file , $ contents );
815
845
}
816
846
$ data .= $ contents ;
@@ -820,6 +850,7 @@ public function mergeFiles(
820
850
throw new Exception (sprintf ("No content found in files: \n%s " , implode ("\n" , $ srcFiles )));
821
851
}
822
852
if ($ targetFile ) {
853
+ // phpcs:ignore Ecg.Security.ForbiddenFunction.Found
823
854
file_put_contents ($ targetFile , $ data , LOCK_EX );
824
855
} else {
825
856
return $ data ; // no need to write to file, just return data
@@ -875,6 +906,7 @@ public function getPublicFilesValidPath()
875
906
public function checkLfiProtection ($ name )
876
907
{
877
908
if (preg_match ('#\.\.[ \\\/]# ' , $ name )) {
909
+ // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
878
910
throw new Mage_Core_Exception ($ this ->__ ('Requested file may not include parent directory traversal ("../", ".. \\" notation) ' ));
879
911
}
880
912
return true ;
0 commit comments