Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the code with typo3-rector for TYPO3 11 and PHP 8.1 #100

Merged
merged 3 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2022-11-27 Alexander Bigga <alexander@bigga.de>
* fix show_popup for click and hover with OpenLayers and Leaflet
* Show map on EXT:calendarize event detail if location is geo referenced
* Cleanup the code with typo3-rector for TYPO3 11 and PHP 8.1

2022-10-03 Alexander Bigga <alexander@bigga.de>
* Update to OpenLayers 7.1.0
* Update to Leaflet 1.9.1
Expand Down
70 changes: 55 additions & 15 deletions Classes/Controller/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

namespace Bobosch\OdsOsm\Controller;

use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
use Bobosch\OdsOsm\Div;
use Bobosch\OdsOsm\Provider\BaseProvider;
use Doctrine\DBAL\FetchMode;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Page\PageRepository;
use TYPO3\CMS\Core\Resource\FileRepository;

/**
Expand All @@ -41,8 +42,22 @@
* @package TYPO3
* @subpackage tx_odsosm
*/
class PluginController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
class PluginController extends AbstractPlugin
{
/**
* Same as class name
*
* @var string
*/
public $prefixId = 'tx_odsosm_pi1';

/**
* The extension key.
*
* @var string
*/
public $extKey = 'ods_osm';

var $config;
var $hooks;
var $lats = [];
Expand Down Expand Up @@ -124,20 +139,20 @@ function init($conf)
}
}
}
if ($flex['library'] != 'staticmap') {
$flex['layer'] = $flex['base_layer'];
} else {
if ($flex['library'] == 'staticmap' && !empty($flex['staticmap_layer'])) {
$flex['layer'] = $flex['staticmap_layer'];
} else if (!empty($flex['base_layer'])) {
$flex['layer'] = $flex['base_layer'];
}

$this->config = array_merge(Div::getConfig(), $conf, $flex);
if (!is_array($this->config['marker'])) {
if (!is_array($this->config['marker'] ?? null)) {
$this->config['marker'] = [];
}
if (is_array($conf['marker.'])) {
foreach ($conf['marker.'] as $name => $value) {
if (is_string($value) && !empty($value)) {
if (!is_array($this->config['marker'][$name])) {
if (!is_array($this->config['marker'][$name] ?? null)) {
$this->config['marker'][$name] = [];
}
$this->config['marker'][$name] = array_merge($this->config['marker'][$name], explode(',', $value));
Expand Down Expand Up @@ -178,7 +193,31 @@ function init($conf)
}
}

$this->config['id'] = 'osm_' . $this->cObj->data['uid'];
// If EXT:calendarize is installed and the single view is called, we try to fetch the right event.
if (ExtensionManagementUtility::isLoaded('calendarize') &&
GeneralUtility::_GP('tx_calendarize_calendar')['index'] ?? false) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_calendarize_domain_model_index');

$result = $queryBuilder
->select('foreign_uid')
->from('tx_calendarize_domain_model_index')
->where(
$queryBuilder->expr()->eq(
'tx_calendarize_domain_model_index.uid',
$queryBuilder->createNamedParameter((int) GeneralUtility::_GP('tx_calendarize_calendar')['index'], Connection::PARAM_INT)
)
)
->setMaxResults(1)
->execute();

if ($row = $result->fetch()) {
$this->config['marker']['tx_calendarize_domain_model_event'][] = $row['foreign_uid'];
}
}

$this->config['id'] = 'osm_' . ($this->cObj->data['uid'] ? : uniqid()) ;

$this->config['marker'] = $this->extractGroup($this->config['marker']);

// Show this marker's popup intially
Expand Down Expand Up @@ -278,7 +317,7 @@ private function extractGroup($record_ids)
// get marker records from db
$records = [];
foreach ($record_ids as $table => $items) {
$tc = $tables[$table];
$tc = $tables[$table] ?? [];
$connection = $this->connectionPool->getConnectionForTable($table);
foreach ($items as $item) {
$item = intval($item);
Expand All @@ -301,7 +340,7 @@ private function extractGroup($record_ids)

if ($row = $result->fetch()) {
// Group with relation to a field
if (is_array($tc['FIND_IN_SET'])) {
if (is_array($tc['FIND_IN_SET'] ?? null)) {
foreach ($tc['FIND_IN_SET'] as $t => $f) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
Expand Down Expand Up @@ -333,7 +372,7 @@ private function extractGroup($record_ids)
}

// Group with mm relation
if (is_array($tc['MM'])) {
if (is_array($tc['MM'] ?? null)) {
foreach ($tc['MM'] as $t => $f) {
$local = $f['local'];
$mm = $f['mm'];
Expand Down Expand Up @@ -385,7 +424,7 @@ private function extractGroup($record_ids)
}

// Special element
if ($tc === true) {
if ($tc === true && $row) {
$records[$table][$item] = $row;
}
}
Expand Down Expand Up @@ -458,8 +497,8 @@ function getMap()
$local_cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
foreach ($markers as $table => &$items) {
foreach ($items as $key => &$item) {
$popup = is_string($this->config['popup.'][$table]) && is_array($this->config['popup.'][$table . '.']) && $this->config['show_popups'];
$icon = is_string($this->config['icon.'][$table]) && is_array($this->config['icon.'][$table . '.']);
$popup = is_string($this->config['popup.'][$table] ?? null) && is_array($this->config['popup.'][$table . '.'] ?? null) && $this->config['show_popups'];
$icon = is_string($this->config['icon.'][$table] ?? null) && is_array($this->config['icon.'][$table . '.'] ?? null);
if ($popup || $icon) {
$local_cObj->start($item, $table);
}
Expand All @@ -470,7 +509,7 @@ function getMap()
}

// Add icon information
if ($item['tx_odsosm_marker']) {
if ($item['tx_odsosm_marker'] ?? null) {
$fileRepository = GeneralUtility::makeInstance(FileRepository::class);
$fileObjects = $fileRepository->findByRelation('tx_odsosm_marker', 'icon', $item['tx_odsosm_marker']);
if ($fileObjects) {
Expand Down Expand Up @@ -542,6 +581,7 @@ function getMap()

while ($resArray = $result->fetch()) {
$baselayers[$resArray['uid']] = $resArray;
$baselayers[$resArray['uid']]['visible'] = false;
}

// set visible flag
Expand Down
33 changes: 23 additions & 10 deletions Classes/Div.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Bobosch\OdsOsm;

use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Log\Logger;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use TYPO3\CMS\Core\Context\Context;
Expand All @@ -20,7 +24,7 @@ class Div
const RESOURCE_BASE_PATH = 'EXT:ods_osm/Resources/Public/';

public static function getConstraintsForQueryBuilder($table, ContentObjectRenderer $cObj,
\TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder) : array
QueryBuilder $queryBuilder) : array
{
$constraints = [];

Expand All @@ -34,7 +38,7 @@ public static function getConstraintsForQueryBuilder($table, ContentObjectRender
$queryBuilder->expr()->gte($table . '.pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT));

// Translation
if ($ctrl['languageField']) {
if ($ctrl['languageField'] ?? null) {
$orConstraints = [
$queryBuilder->expr()->eq($table . '.' . $ctrl['languageField'], $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq($table . '.' . $ctrl['languageField'], $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT))
Expand All @@ -58,7 +62,7 @@ public static function getConstraintsForQueryBuilder($table, ContentObjectRender

public static function addJsFiles($scripts, $doc)
{
$pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
foreach ($scripts as $script) {
$pageRenderer->addJsFooterFile(
$script['src'],
Expand Down Expand Up @@ -216,7 +220,7 @@ public static function searchAddress(&$address, $service = 0)
'timeout' => 60,
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'TYPO3 extension ods_osm/' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('ods_osm')
'User-Agent' => 'TYPO3 extension ods_osm/' . ExtensionManagementUtility::getExtensionVersion('ods_osm')
],
];

Expand All @@ -233,7 +237,7 @@ public static function searchAddress(&$address, $service = 0)
self::flashMessage(
(string)$result['status']['message'],
'GeoNames message',
\TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
AbstractMessage::WARNING
);
}

Expand Down Expand Up @@ -336,7 +340,7 @@ protected static function searchAddressNominatim($query, &$address)
'timeout' => 60,
'headers' => [
'Accept' => 'application/json',
'User-Agent' => 'TYPO3 extension ods_osm/' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionVersion('ods_osm')
'User-Agent' => 'TYPO3 extension ods_osm/' . ExtensionManagementUtility::getExtensionVersion('ods_osm')
],
];

Expand Down Expand Up @@ -383,7 +387,7 @@ public static function flashMessage($message, $title, $status)
{
/** @var FlashMessage $flashMessage */
$flashMessage = GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Messaging\FlashMessage::class,
FlashMessage::class,
$message,
$title,
$status
Expand Down Expand Up @@ -468,7 +472,7 @@ public static function getConfig($values = [])
}

if ($config === false || count($getDefault)) {
$default = parse_ini_file(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('ods_osm') . 'ext_conf_template.txt');
$default = parse_ini_file(ExtensionManagementUtility::extPath('ods_osm') . 'ext_conf_template.txt');
if ($config === false) {
return $default;
} else {
Expand Down Expand Up @@ -517,6 +521,15 @@ public static function getTableConfig($table = false)
];

// load configuration for tt_address only if extension is loaded
if (ExtensionManagementUtility::isLoaded('calendarize')) {
$tables['tx_calendarize_domain_model_event'] = [
'FORMAT' => '%01.6f',
'lon' => 'tx_odsosm_lon',
'lat' => 'tx_odsosm_lat',
'address' => 'location',
];
}
// load configuration for tt_address only if extension is loaded
if (ExtensionManagementUtility::isLoaded('tt_address')) {
$tables['tt_address'] = [
'FORMAT' => '%01.11f',
Expand All @@ -538,7 +551,7 @@ public static function getTableConfig($table = false)
}

/**
* @return \TYPO3\CMS\Core\Log\Logger
* @return Logger
*/
protected static function getLogger()
{
Expand All @@ -554,7 +567,7 @@ public function isExtensionLoaded($params = [])
{
$isLoaded = false;

if ( \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('tt_address') ) {
if ( ExtensionManagementUtility::isLoaded('tt_address') ) {
$isLoaded = true;
}

Expand Down
81 changes: 81 additions & 0 deletions Classes/Domain/Model/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2022 Alexander Bigga <alexander@bigga.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

declare(strict_types=1);

namespace Bobosch\OdsOsm\Domain\Model;

/**
* Event (Default) for the calendarize function.
*
* @DatabaseTable
*/
class Event extends \HDNET\Calendarize\Domain\Model\Event
{
/**
* Title.
*
* @var float
*/
protected $txOdsosmLon = '';

/**
* Slug.
*
* @var float
*/
protected $txOdsosmLat = '';

/**
* @return float
*/
public function getTxOdsosmLon(): ?float
{
return $this->txOdsosmLon;
}

/**
* @param float $slug
*/
public function SetTxOdsosmLon(string $txOdsosmLon): void
{
$this->txOdsosmLon = $txOdsosmLon;
}

/**
* @return float
*/
public function getTxOdsosmLat(): ?float
{
return $this->txOdsosmLat;
}

/**
* @param float $slug
*/
public function SetTxOdsosmLat(string $txOdsosmLat): void
{
$this->txOdsosmLat = $txOdsosmLat;
}
}
8 changes: 7 additions & 1 deletion Classes/Provider/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bobosch\OdsOsm\Provider;

use TYPO3\CMS\Core\Information\Typo3Version;
use Bobosch\OdsOsm\Div;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -207,10 +208,15 @@ protected function getTileUrl($layer)
protected function getAbsRefPrefix()
{
$absRefPrefix = '';
$versionInformation = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() == 10) {
$absRefPrefix = $GLOBALS['TSFE']->absRefPrefix;
}
return $absRefPrefix;
}

public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
{
$this->cObj = $cObj;
}
}
Loading