Skip to content

Commit 391e8eb

Browse files
committed
1 parent 8152a23 commit 391e8eb

File tree

4 files changed

+84
-32
lines changed

4 files changed

+84
-32
lines changed

app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getCustomerLog()
7070
public function getCreateDate()
7171
{
7272
return ($date = $this->getCustomer()->getCreatedAt())
73-
? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
73+
? $this->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
7474
: null;
7575
}
7676

@@ -79,15 +79,17 @@ public function getCreateDate()
7979
*/
8080
public function getStoreCreateDate()
8181
{
82-
if (!$this->getCustomer()->getCreatedAt()) {
82+
$date = $this->getCustomer()->getCreatedAtTimestamp();
83+
if (!$date) {
8384
return null;
8485
}
85-
$date = Mage::app()->getLocale()->storeDate(
86-
$this->getCustomer()->getStoreId(),
87-
$this->getCustomer()->getCreatedAtTimestamp(),
88-
true
86+
87+
return $this->formatTimezoneDate(
88+
$date,
89+
Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM,
90+
true,
91+
false
8992
);
90-
return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
9193
}
9294

9395
public function getStoreCreateDateTimezone()
@@ -104,7 +106,7 @@ public function getStoreCreateDateTimezone()
104106
public function getLastLoginDate()
105107
{
106108
return ($date = $this->getCustomerLog()->getLoginAtTimestamp())
107-
? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
109+
? $this->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
108110
: Mage::helper('customer')->__('Never');
109111
}
110112

app/code/core/Mage/Core/Block/Abstract.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,32 @@ public function helper($name)
11061106
/**
11071107
* Retrieve formatting date
11081108
*
1109-
* @param string $date
1110-
* @param string $format
1111-
* @param bool $showTime
1112-
* @param bool $useTimezone
1113-
* @return string
1109+
* @param string|int|Zend_Date|null $date
1110+
* @param string $format
1111+
* @param bool $showTime
1112+
* @return string
11141113
*/
1115-
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true)
1114+
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
11161115
{
11171116
/** @var Mage_Core_Helper_Data $helper */
11181117
$helper = $this->helper('core');
1119-
return $helper->formatDate($date, $format, $showTime, $useTimezone);
1118+
return $helper->formatDate($date, $format, $showTime);
1119+
}
1120+
1121+
/**
1122+
* Retrieve formatting timezone date
1123+
*
1124+
* @param string|int|Zend_Date|null $date
1125+
*/
1126+
public function formatTimezoneDate(
1127+
$date = null,
1128+
string $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT,
1129+
bool $showTime = false,
1130+
bool $useTimezone = true
1131+
): string {
1132+
/** @var Mage_Core_Helper_Data $helper */
1133+
$helper = $this->helper('core');
1134+
return $helper->formatTimezoneDate($date, $format, $showTime, $useTimezone);
11201135
}
11211136

11221137
/**

app/code/core/Mage/Core/Helper/Data.php

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,33 +143,48 @@ public function formatPrice($price, $includeContainer = true)
143143
/**
144144
* Format date using current locale options and time zone.
145145
*
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
150149
* @return string
151150
*/
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)
153152
{
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 {
154170
if (!in_array($format, $this->_allowedFormats, true)) {
155171
return $date;
156172
}
173+
174+
$locale = Mage::app()->getLocale();
157175
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);
159177
} elseif (is_int($date)) {
160-
$date = Mage::app()->getLocale()->date($date, null, null, $useTimezone);
178+
$date = $locale->date($date, null, null, $useTimezone);
161179
} elseif (!$date instanceof Zend_Date) {
162180
if (($time = strtotime($date)) !== false) {
163-
$date = Mage::app()->getLocale()->date($time, null, null, $useTimezone);
181+
$date = $locale->date($time, null, null, $useTimezone);
164182
} else {
165183
return '';
166184
}
167185
}
168186

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);
173188
return $date->toString($format);
174189
}
175190

@@ -187,18 +202,19 @@ public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMA
187202
return $time;
188203
}
189204

205+
$locale = Mage::app()->getLocale();
190206
if (is_null($time)) {
191-
$date = Mage::app()->getLocale()->date(time());
207+
$date = $locale->date(time());
192208
} elseif ($time instanceof Zend_Date) {
193209
$date = $time;
194210
} else {
195-
$date = Mage::app()->getLocale()->date(strtotime($time));
211+
$date = $locale->date(strtotime($time));
196212
}
197213

198214
if ($showDate) {
199-
$format = Mage::app()->getLocale()->getDateTimeFormat($format);
215+
$format = $locale->getDateTimeFormat($format);
200216
} else {
201-
$format = Mage::app()->getLocale()->getTimeFormat($format);
217+
$format = $locale->getTimeFormat($format);
202218
}
203219

204220
return $date->toString($format);
@@ -365,12 +381,14 @@ public function removeAccents($string, $german = false)
365381

366382
$replacements[$german] = [];
367383
foreach ($subst as $k => $v) {
384+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
368385
$replacements[$german][$k < 256 ? chr($k) : '&#' . $k . ';'] = $v;
369386
}
370387
}
371388

372389
// convert string from default database format (UTF-8)
373390
// to encoding which replacement arrays made with (ISO-8859-1)
391+
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
374392
if ($s = @iconv('UTF-8', 'ISO-8859-1', $string)) {
375393
$string = $s;
376394
}
@@ -568,6 +586,7 @@ public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = fal
568586
* @param mixed $value
569587
* @param bool $dontSkip
570588
*/
589+
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
571590
private function _decorateArrayObject($element, $key, $value, $dontSkip)
572591
{
573592
if ($dontSkip) {
@@ -613,6 +632,7 @@ public function assocToXml(array $array, $rootName = '_')
613632
* @return SimpleXMLElement
614633
* @throws Exception
615634
*/
635+
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
616636
private function _assocToXml(array $array, $rootName, SimpleXMLElement &$xml)
617637
{
618638
$hasNumericKey = false;
@@ -762,14 +782,18 @@ public function mergeFiles(
762782
// check whether merger is required
763783
$shouldMerge = $mustMerge || !$targetFile;
764784
if (!$shouldMerge) {
785+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
765786
if (!file_exists($targetFile)) {
766787
$shouldMerge = true;
767788
} else {
789+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
768790
$targetMtime = filemtime($targetFile);
769791
foreach ($srcFiles as $file) {
792+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
770793
if (!file_exists($file)) {
771794
// no translation intentionally
772795
Mage::logException(new Exception(sprintf('File %s not found.', $file)));
796+
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
773797
} elseif (@filemtime($file) > $targetMtime) {
774798
$shouldMerge = true;
775799
break;
@@ -780,8 +804,10 @@ public function mergeFiles(
780804

781805
// merge contents into the file
782806
if ($shouldMerge) {
807+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
783808
if ($targetFile && !is_writable(dirname($targetFile))) {
784809
// no translation intentionally
810+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
785811
throw new Exception(sprintf('Path %s is not writeable.', dirname($targetFile)));
786812
}
787813

@@ -792,6 +818,7 @@ public function mergeFiles(
792818
}
793819
if (!empty($srcFiles)) {
794820
foreach ($srcFiles as $key => $file) {
821+
// phpcs:ignore Ecg.Security.DiscouragedFunction.Discouraged
795822
$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
796823
if (!in_array($fileExt, $extensionsFilter)) {
797824
unset($srcFiles[$key]);
@@ -806,11 +833,14 @@ public function mergeFiles(
806833

807834
$data = '';
808835
foreach ($srcFiles as $file) {
836+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
809837
if (!file_exists($file)) {
810838
continue;
811839
}
840+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
812841
$contents = file_get_contents($file) . "\n";
813842
if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
843+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
814844
$contents = call_user_func($beforeMergeCallback, $file, $contents);
815845
}
816846
$data .= $contents;
@@ -820,6 +850,7 @@ public function mergeFiles(
820850
throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles)));
821851
}
822852
if ($targetFile) {
853+
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
823854
file_put_contents($targetFile, $data, LOCK_EX);
824855
} else {
825856
return $data; // no need to write to file, just return data
@@ -875,6 +906,7 @@ public function getPublicFilesValidPath()
875906
public function checkLfiProtection($name)
876907
{
877908
if (preg_match('#\.\.[\\\/]#', $name)) {
909+
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
878910
throw new Mage_Core_Exception($this->__('Requested file may not include parent directory traversal ("../", "..\\" notation)'));
879911
}
880912
return true;

app/design/adminhtml/default/default/template/customer/tab/view.phtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
* @category design
66
* @package default_default
77
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
8-
* @copyright Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
8+
* @copyright Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
99
* @copyright Copyright (c) 2024 Maho (https://mahocommerce.com)
1010
* @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
1111
*/
1212
?>
1313
<?php
1414
/**
1515
* Template for block Mage_Adminhtml_Block_Customer_Edit_Tab_View
16+
*
17+
* @see Mage_Adminhtml_Block_Customer_Edit_Tab_View
18+
* @var Mage_Adminhtml_Block_Customer_Edit_Tab_View $this
1619
*/
1720
?>
1821
<?php

0 commit comments

Comments
 (0)