Skip to content

Commit

Permalink
OM PR 4242
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Oct 16, 2024
1 parent 8152a23 commit 391e8eb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 32 deletions.
18 changes: 10 additions & 8 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getCustomerLog()
public function getCreateDate()
{
return ($date = $this->getCustomer()->getCreatedAt())
? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
? $this->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
: null;
}

Expand All @@ -79,15 +79,17 @@ public function getCreateDate()
*/
public function getStoreCreateDate()
{
if (!$this->getCustomer()->getCreatedAt()) {
$date = $this->getCustomer()->getCreatedAtTimestamp();
if (!$date) {
return null;
}
$date = Mage::app()->getLocale()->storeDate(
$this->getCustomer()->getStoreId(),
$this->getCustomer()->getCreatedAtTimestamp(),
true

return $this->formatTimezoneDate(
$date,
Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM,
true,
false
);
return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
}

public function getStoreCreateDateTimezone()
Expand All @@ -104,7 +106,7 @@ public function getStoreCreateDateTimezone()
public function getLastLoginDate()
{
return ($date = $this->getCustomerLog()->getLoginAtTimestamp())
? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
? $this->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false)
: Mage::helper('customer')->__('Never');
}

Expand Down
29 changes: 22 additions & 7 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1106,17 +1106,32 @@ public function helper($name)
/**
* Retrieve formatting date
*
* @param string $date
* @param string $format
* @param bool $showTime
* @param bool $useTimezone
* @return string
* @param string|int|Zend_Date|null $date
* @param string $format
* @param bool $showTime
* @return string
*/
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true)
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
{
/** @var Mage_Core_Helper_Data $helper */
$helper = $this->helper('core');
return $helper->formatDate($date, $format, $showTime, $useTimezone);
return $helper->formatDate($date, $format, $showTime);
}

/**
* Retrieve formatting timezone date
*
* @param string|int|Zend_Date|null $date
*/
public function formatTimezoneDate(
$date = null,
string $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT,
bool $showTime = false,
bool $useTimezone = true
): string {
/** @var Mage_Core_Helper_Data $helper */
$helper = $this->helper('core');
return $helper->formatTimezoneDate($date, $format, $showTime, $useTimezone);
}

/**
Expand Down
64 changes: 48 additions & 16 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,33 +143,48 @@ public function formatPrice($price, $includeContainer = true)
/**
* Format date using current locale options and time zone.
*
* @param string|Zend_Date|null $date If empty, return current datetime.
* @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
* @param bool $showTime Whether to include time
* @param bool $useTimezone Convert to local datetime?
* @param string|int|Zend_Date|null $date If empty, return current datetime.
* @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
* @param bool $showTime Whether to include time
* @return string
*/
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true)
public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
{
return $this->formatTimezoneDate($date, $format, $showTime);
}

/**
* Format date using current locale options and time zone.
*
* @param string|int|Zend_Date|null $date If empty, return current locale datetime.
* @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
* @param bool $showTime Whether to include time
* @param bool $useTimezone Convert to local datetime?
*/
public function formatTimezoneDate(
$date = null,
string $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT,
bool $showTime = false,
bool $useTimezone = true
): string {
if (!in_array($format, $this->_allowedFormats, true)) {
return $date;
}

$locale = Mage::app()->getLocale();
if (empty($date)) {
$date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null, $useTimezone);
$date = $locale->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null, $useTimezone);
} elseif (is_int($date)) {
$date = Mage::app()->getLocale()->date($date, null, null, $useTimezone);
$date = $locale->date($date, null, null, $useTimezone);
} elseif (!$date instanceof Zend_Date) {
if (($time = strtotime($date)) !== false) {
$date = Mage::app()->getLocale()->date($time, null, null, $useTimezone);
$date = $locale->date($time, null, null, $useTimezone);
} else {
return '';
}
}

$format = $showTime
? Mage::app()->getLocale()->getDateTimeFormat($format)
: Mage::app()->getLocale()->getDateFormat($format);

$format = $showTime ? $locale->getDateTimeFormat($format) : $locale->getDateFormat($format);
return $date->toString($format);
}

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

$locale = Mage::app()->getLocale();
if (is_null($time)) {
$date = Mage::app()->getLocale()->date(time());
$date = $locale->date(time());
} elseif ($time instanceof Zend_Date) {
$date = $time;
} else {
$date = Mage::app()->getLocale()->date(strtotime($time));
$date = $locale->date(strtotime($time));
}

if ($showDate) {
$format = Mage::app()->getLocale()->getDateTimeFormat($format);
$format = $locale->getDateTimeFormat($format);
} else {
$format = Mage::app()->getLocale()->getTimeFormat($format);
$format = $locale->getTimeFormat($format);
}

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

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

// convert string from default database format (UTF-8)
// to encoding which replacement arrays made with (ISO-8859-1)
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
if ($s = @iconv('UTF-8', 'ISO-8859-1', $string)) {
$string = $s;
}
Expand Down Expand Up @@ -568,6 +586,7 @@ public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = fal
* @param mixed $value
* @param bool $dontSkip
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private function _decorateArrayObject($element, $key, $value, $dontSkip)
{
if ($dontSkip) {
Expand Down Expand Up @@ -613,6 +632,7 @@ public function assocToXml(array $array, $rootName = '_')
* @return SimpleXMLElement
* @throws Exception
*/
// phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError
private function _assocToXml(array $array, $rootName, SimpleXMLElement &$xml)
{
$hasNumericKey = false;
Expand Down Expand Up @@ -762,14 +782,18 @@ public function mergeFiles(
// check whether merger is required
$shouldMerge = $mustMerge || !$targetFile;
if (!$shouldMerge) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (!file_exists($targetFile)) {
$shouldMerge = true;
} else {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$targetMtime = filemtime($targetFile);
foreach ($srcFiles as $file) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (!file_exists($file)) {
// no translation intentionally
Mage::logException(new Exception(sprintf('File %s not found.', $file)));
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged,Ecg.Security.ForbiddenFunction.Found
} elseif (@filemtime($file) > $targetMtime) {
$shouldMerge = true;
break;
Expand All @@ -780,8 +804,10 @@ public function mergeFiles(

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

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

$data = '';
foreach ($srcFiles as $file) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if (!file_exists($file)) {
continue;
}
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$contents = file_get_contents($file) . "\n";
if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$contents = call_user_func($beforeMergeCallback, $file, $contents);
}
$data .= $contents;
Expand All @@ -820,6 +850,7 @@ public function mergeFiles(
throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles)));
}
if ($targetFile) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
file_put_contents($targetFile, $data, LOCK_EX);
} else {
return $data; // no need to write to file, just return data
Expand Down Expand Up @@ -875,6 +906,7 @@ public function getPublicFilesValidPath()
public function checkLfiProtection($name)
{
if (preg_match('#\.\.[\\\/]#', $name)) {
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
throw new Mage_Core_Exception($this->__('Requested file may not include parent directory traversal ("../", "..\\" notation)'));
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
* @category design
* @package default_default
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
* @copyright Copyright (c) 2021-2022 The OpenMage Contributors (https://openmage.org)
* @copyright Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
* @copyright Copyright (c) 2024 Maho (https://mahocommerce.com)
* @license https://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* Template for block Mage_Adminhtml_Block_Customer_Edit_Tab_View
*
* @see Mage_Adminhtml_Block_Customer_Edit_Tab_View
* @var Mage_Adminhtml_Block_Customer_Edit_Tab_View $this
*/
?>
<?php
Expand Down

0 comments on commit 391e8eb

Please sign in to comment.