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