Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
|
||||
|
||||
/**
|
||||
* Class CacheUtility handles cache tags
|
||||
*/
|
||||
class CacheUtility
|
||||
{
|
||||
/**
|
||||
* Adds cache tags to page cache by tt_address-records.
|
||||
*
|
||||
* TYPO3 has a built-in mechanism which flushes the page cache
|
||||
* when editing a record. This is done by a tag that looks
|
||||
* like [table]_[record:uid]
|
||||
*
|
||||
* @param array $addressRecords array with address records
|
||||
*/
|
||||
public static function addCacheTagsByAddressRecords(array $addressRecords)
|
||||
{
|
||||
$prefix = 'tt_address_';
|
||||
$cacheTags = [];
|
||||
foreach ($addressRecords as $addressRecord) {
|
||||
if (!$addressRecord instanceof Address) {
|
||||
continue;
|
||||
}
|
||||
// cache tag for each addressRecord record
|
||||
$cacheTags[] = $prefix . $addressRecord->getUid();
|
||||
|
||||
if ($addressRecord->_getProperty('_localizedUid') != $addressRecord->getUid()) {
|
||||
$cacheTags[] = $prefix . $addressRecord->_getProperty('_localizedUid');
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['TSFE']->addCacheTags($cacheTags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class EvalcoordinatesUtility
|
||||
*/
|
||||
class EvalcoordinatesUtility
|
||||
{
|
||||
const LATITUDE_UPPER = '90.00000000';
|
||||
const LONGITUDE_UPPER = '180.00000000';
|
||||
|
||||
/**
|
||||
* @param string $coordinate
|
||||
* @return float evaluated and well-formed coordinate
|
||||
*/
|
||||
public static function formatLongitude(string $coordinate)
|
||||
{
|
||||
return self::validate($coordinate, self::LONGITUDE_UPPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $coordinate
|
||||
* @return float evaluated and well-formed coordinate
|
||||
*/
|
||||
public static function formatLatitude(string $coordinate)
|
||||
{
|
||||
return self::validate($coordinate, self::LATITUDE_UPPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $coordinate
|
||||
* @param string $upperRange
|
||||
* @return string
|
||||
*/
|
||||
protected static function validate($coordinate, string $upperRange): string
|
||||
{
|
||||
if ($coordinate === '') {
|
||||
return '.00000000';
|
||||
}
|
||||
|
||||
// test if value is negative
|
||||
$negative = '';
|
||||
if ($coordinate[0] === '-') {
|
||||
$negative = '-';
|
||||
}
|
||||
// remove all chars not being digits and point
|
||||
// therefore we will get a number
|
||||
$coordinate = preg_replace("/[^\d\.]/", '', $coordinate);
|
||||
|
||||
// split up string at first occurrence decimal point without losing data
|
||||
$integerPart = strstr($coordinate, '.', true);
|
||||
$decimalPart = strstr($coordinate, '.');
|
||||
|
||||
// if coordinate is given as integer (no decimal point)
|
||||
if ($integerPart === false) {
|
||||
$integerPart = $coordinate;
|
||||
}
|
||||
if ($decimalPart === false) {
|
||||
$decimalPart = '00';
|
||||
}
|
||||
|
||||
// remove all points from decimal-part
|
||||
$decimalPart = preg_replace("/[^\d]/", '', $decimalPart);
|
||||
|
||||
// fill up with zeros or shorten to match our goal of decimal(latitude: 10,8 and longitude: 11,8) in DB
|
||||
if (\strlen($decimalPart) >= 8) {
|
||||
$decimalPart = substr($decimalPart, 0, 8);
|
||||
} else {
|
||||
$decimalPart = str_pad($decimalPart, 8, '0', STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
// concatenate the whole string to a well-formed longitude and return
|
||||
$coordinate = $integerPart . '.' . $decimalPart;
|
||||
|
||||
// test if value is in the possible range. longitude can be -180 to +180.
|
||||
// latitude can be -90 to +90
|
||||
// At this point, our minus, if there, is stored to 'negative'
|
||||
// therefore we just test if integerpart is bigger than 90
|
||||
if ($coordinate > $upperRange) {
|
||||
$coordinate = $upperRange;
|
||||
}
|
||||
|
||||
// reapply signed/unsigned and return
|
||||
return $negative . $coordinate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Modify properties of the address model
|
||||
*/
|
||||
class PropertyModification
|
||||
{
|
||||
/**
|
||||
* Get cleaned number of a given telephone, fax or mobile number.
|
||||
* It removes all chars which are not possible to enter on your cell phone.
|
||||
*
|
||||
* @param string $number
|
||||
* @return string
|
||||
*/
|
||||
public static function getCleanedNumber(string $number): string
|
||||
{
|
||||
$number = trim($number);
|
||||
|
||||
// Remove 0 on +49(0)221, but keep 0 on (0)221
|
||||
if (strpos($number, '(0)') > 0) {
|
||||
$number = str_replace('(0)', '', $number);
|
||||
}
|
||||
|
||||
return preg_replace('/[^0-9#+*]/', '', $number);
|
||||
}
|
||||
|
||||
public static function getCleanedDomain(string $domain): string
|
||||
{
|
||||
$domain = trim($domain);
|
||||
if (!$domain) {
|
||||
return '';
|
||||
}
|
||||
$parts = str_replace(['\\\\', '\\"'], ['\\', '"'], str_getcsv($domain, ' '));
|
||||
return $parts[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Utility;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* TypoScript Utility class
|
||||
*/
|
||||
class TypoScript
|
||||
{
|
||||
/**
|
||||
* @param array $previousData
|
||||
* @param array $tsData
|
||||
* @return array
|
||||
*/
|
||||
public function override(array $previousData, array $tsData)
|
||||
{
|
||||
$validFields = GeneralUtility::trimExplode(',', $tsData['settings']['overrideFlexformSettingsIfEmpty'], true);
|
||||
foreach ($validFields as $fieldName) {
|
||||
// Multilevel field
|
||||
if (strpos($fieldName, '.') !== false) {
|
||||
$keyAsArray = explode('.', $fieldName);
|
||||
|
||||
$foundInCurrentTs = $this->getValue($previousData, $keyAsArray);
|
||||
|
||||
if (is_string($foundInCurrentTs) && strlen($foundInCurrentTs) === 0) {
|
||||
$foundInOriginal = $this->getValue($tsData['settings'], $keyAsArray);
|
||||
if ($foundInOriginal) {
|
||||
$previousData = $this->setValue($previousData, $keyAsArray, $foundInOriginal);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($fieldName === 'sortBy' && (($previousData['sortBy'] ?? '') === 'default') && (($tsData['settings']['sortBy'] ?? '') !== '')) {
|
||||
unset($previousData['sortBy']);
|
||||
}
|
||||
// if flexform setting is empty and value is available in TS
|
||||
if (((!isset($previousData[$fieldName]) || (string)$previousData[$fieldName] === '') || (strlen($previousData[$fieldName]) === 0))
|
||||
&& isset($tsData['settings'][$fieldName])
|
||||
) {
|
||||
$previousData[$fieldName] = $tsData['settings'][$fieldName];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $previousData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value from array by path
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $path
|
||||
* @return array|null
|
||||
*/
|
||||
protected function getValue(array $data, array $path)
|
||||
{
|
||||
$found = true;
|
||||
|
||||
for ($x = 0; $x < count($path) && $found; $x++) {
|
||||
$key = $path[$x];
|
||||
|
||||
if (isset($data[$key])) {
|
||||
$data = $data[$key];
|
||||
} else {
|
||||
$found = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value in array by path
|
||||
*
|
||||
* @param array $array
|
||||
* @param $path
|
||||
* @param $value
|
||||
* @return array
|
||||
*/
|
||||
protected function setValue(array $array, $path, $value)
|
||||
{
|
||||
$this->setValueByReference($array, $path, $value);
|
||||
|
||||
return array_merge_recursive([], $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value by reference
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $path
|
||||
* @param $value
|
||||
*/
|
||||
private function setValueByReference(array &$array, array $path, $value)
|
||||
{
|
||||
while (count($path) > 1) {
|
||||
$key = array_shift($path);
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
$key = reset($path);
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user