initial commit
This commit is contained in:
65
Classes/Utility/CanonicalUtility.php
Normal file
65
Classes/Utility/CanonicalUtility.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace A2G\A2gProducts\Utility;
|
||||
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
|
||||
/**
|
||||
* Description of Canonical
|
||||
*
|
||||
* @author Raphael Martin raphael@web-crossing.com
|
||||
*/
|
||||
class CanonicalUtility {
|
||||
|
||||
/**
|
||||
* objectManager
|
||||
*
|
||||
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
|
||||
* @Extbase\Inject
|
||||
*/
|
||||
protected $objectManager = null;
|
||||
|
||||
/**
|
||||
* plugin
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static private $plugin = 'tx_a2gproducts_a2gproductsdetail';
|
||||
|
||||
|
||||
/**
|
||||
* uidParamName
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static private $uidParamName = 'resource';
|
||||
|
||||
/**
|
||||
* setCanonical
|
||||
*
|
||||
* @param type $href
|
||||
*/
|
||||
public function setCanonical(&$href) {
|
||||
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
$main = GeneralUtility::_GET(self::$plugin);
|
||||
if ($main[self::$uidParamName]) {
|
||||
$uriBuilder = $this->objectManager->get(UriBuilder::class);
|
||||
$uriBuilder->setCreateAbsoluteUri(true);
|
||||
$uriBuilder->setArguments([self::$plugin => [self::$uidParamName => $main[self::$uidParamName]]]);
|
||||
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
|
||||
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
|
||||
if (isset($settings['plugin.'][self::$plugin.'.']['settings.']['canonical']) && $settings['plugin.'][self::$plugin.'.']['settings.']['canonical'] !== 0) {
|
||||
$uriBuilder->setTargetPageUid($settings['plugin.'][self::$plugin.'.']['settings.']['canonical']);
|
||||
$href = $uriBuilder->build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
Classes/Utility/EvalcoordinatesUtility.php
Normal file
95
Classes/Utility/EvalcoordinatesUtility.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace A2G\A2gTravelBlog\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 float $coordinate
|
||||
* @return float evaluated and well-formed coordinate
|
||||
*/
|
||||
public static function formatLongitude(float $coordinate)
|
||||
{
|
||||
return self::validate((string)$coordinate, self::LONGITUDE_UPPER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $coordinate
|
||||
* @return float evaluated and well-formed coordinate
|
||||
*/
|
||||
public static function formatLatitude(float $coordinate)
|
||||
{
|
||||
return self::validate((string)$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;
|
||||
}
|
||||
}
|
237
Classes/Utility/MapConfigUtility.php
Normal file
237
Classes/Utility/MapConfigUtility.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace A2G\A2gTravelBlog\Utility;
|
||||
|
||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Description of Canonical
|
||||
*
|
||||
* @author Raphael Martin raphael@web-crossing.com
|
||||
*/
|
||||
class MapConfigUtility {
|
||||
|
||||
/**
|
||||
* uidParamName
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static private $mapLayerConfigs = [
|
||||
1 => [
|
||||
"layer" => "osm",
|
||||
"config" => [
|
||||
|
||||
],
|
||||
"label"=>"osm_map_layer"
|
||||
],
|
||||
10 => [
|
||||
"layer" => "stamen",
|
||||
"config" => [
|
||||
"layer" => "terrain"
|
||||
],
|
||||
"label" => "stamen_map_terrain"
|
||||
],
|
||||
11 => [
|
||||
"layer" => "stamen",
|
||||
"config" => [
|
||||
"layer" => "watercolor"
|
||||
],
|
||||
"label" => "stamen_map_watercolor"
|
||||
],
|
||||
12 => [
|
||||
"layer" => "stamen",
|
||||
"config" => [
|
||||
"layer" => "toner"
|
||||
],
|
||||
"label" => "stamen_map_toner"
|
||||
],
|
||||
100 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "cycle"
|
||||
],
|
||||
"label" => "thunderforest_map_cycle"
|
||||
],
|
||||
101 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "transport"
|
||||
],
|
||||
"label" => "thunderforest_map_transport"
|
||||
],
|
||||
102 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "landscape"
|
||||
],
|
||||
"label" => "thunderforest_map_landscape"
|
||||
],
|
||||
103 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "outdoors"
|
||||
],
|
||||
"label" => "thunderforest_map_outdoors"
|
||||
],
|
||||
104 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "atlas"
|
||||
],
|
||||
"label" => "thunderforest_map_atlas"
|
||||
],
|
||||
105 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "transport-dark"
|
||||
],
|
||||
"label" => "thunderforest_map_transport-dark"
|
||||
],
|
||||
106 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "spinal-map"
|
||||
],
|
||||
"label" => "thunderforest_map_spinal"
|
||||
],
|
||||
107 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "pioneer"
|
||||
],
|
||||
"label" => "thunderforest_map_pioneer"
|
||||
],
|
||||
108 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "neighbourhood"
|
||||
],
|
||||
"label" => "thunderforest_map_neighbourhood"
|
||||
],
|
||||
109 => [
|
||||
"layer" => "thunderforest",
|
||||
"config" => [
|
||||
"layer" => "mobile-atlas"
|
||||
],
|
||||
"label" => "thunderforest_map_mobile-atlas"
|
||||
],
|
||||
200 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "basic"
|
||||
],
|
||||
"label" => "maptiler_map_basic"
|
||||
],
|
||||
201 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "basic-4326"
|
||||
],
|
||||
"label" => "maptiler_map_basic-4326"
|
||||
],
|
||||
202 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "bright"
|
||||
],
|
||||
"label" => "maptiler_map_bright"
|
||||
],
|
||||
203 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "openstreetmap"
|
||||
],
|
||||
"label" => "maptiler_map_openstreetmap"
|
||||
],
|
||||
204 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "outdoor"
|
||||
],
|
||||
"label" => "maptiler_map_outdoor"
|
||||
],
|
||||
205 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "pastel"
|
||||
],
|
||||
"label" => "maptiler_map_pastel"
|
||||
],
|
||||
206 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "hybrid"
|
||||
],
|
||||
"label" => "maptiler_map_hybrid"
|
||||
],
|
||||
207 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "streets"
|
||||
],
|
||||
"label" => "maptiler_map_streets"
|
||||
],
|
||||
208 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "toner"
|
||||
],
|
||||
"label" => "maptiler_map_toner"
|
||||
],
|
||||
209 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "topo"
|
||||
],
|
||||
"label" => "maptiler_map_topo"
|
||||
],
|
||||
210 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "topographique"
|
||||
],
|
||||
"label" => "maptiler_map_topographique"
|
||||
],
|
||||
211 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "voyager"
|
||||
],
|
||||
"label" => "maptiler_map_voyager"
|
||||
],
|
||||
212 => [
|
||||
"layer" => "maptiler",
|
||||
"config" => [
|
||||
"layer" => "winter"
|
||||
],
|
||||
"label" => "maptiler_map_winter"
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* setCanonical
|
||||
*
|
||||
* @param type $href
|
||||
*/
|
||||
public static function getMapLayerConfig(array $mapLayerConfigIds) {
|
||||
$out = [];
|
||||
foreach($mapLayerConfigIds as $id){
|
||||
$out[]=self::$mapLayerConfigs[$id];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user