[FEATURE] Update structure to be fully compatible with version 7.x and 8.x 51/50751/2 master
authorMatthias Toscanelli <m.toscanelli@code-source.ch>
Tue, 22 Nov 2016 14:41:03 +0000 (15:41 +0100)
committerMatthias Toscanelli <m.toscanelli@code-source.ch>
Tue, 22 Nov 2016 16:14:47 +0000 (17:14 +0100)
The full structure of the extension has been reviewed to use TYPO3 standards.

Resolves: #78768
Change-Id: Id9f6a4759edd08b5fa89ef3840d32e2c5af25d3f
Reviewed-on: https://review.typo3.org/50751
Reviewed-by: Matthias Toscanelli <m.toscanelli@code-source.ch>
Tested-by: Matthias Toscanelli <m.toscanelli@code-source.ch>
ChangeLog
Classes/CdsrcBaseurlTmplHooks.php [deleted file]
Classes/Hook/BaseUrlHook.php [new file with mode: 0644]
Configuration/TCA/Overrides/sys_domain.php [new file with mode: 0644]
README.txt [deleted file]
Resources/Private/Language/fr.locallang_db.xlf [new file with mode: 0644]
Resources/Private/Language/locallang_db.xlf [new file with mode: 0644]
ext_emconf.php
ext_localconf.php
ext_tables.php [deleted file]
locallang_db.xml [deleted file]

index f41478f..0cbff3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-22 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 4.0.0
+    * Extension structure fully compatible with version 7.x and 8.x standards
+
 2015-07-02 Matthias Toscanelli  <m.toscanelli@code-source.ch>
 
     * Stable 3.2.0
diff --git a/Classes/CdsrcBaseurlTmplHooks.php b/Classes/CdsrcBaseurlTmplHooks.php
deleted file mode 100644 (file)
index 2ca7e36..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-<?php
-
-/* * *************************************************************
- *  Copyright notice
- *
- *  (c) 2013 Matthias Toscanelli <m.toscanelli@code-source.ch>
- *  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!
- * ************************************************************* */
-
-/**
- * Hook for template object
- *
- * @author     Matthias Toscanelli <m.toscanelli@code-source.ch>
- * @package CDSRC
- * @subpackage baseurl
- */
-class CdsrcBaseurlTmplHooks {
-
-    /**
-     * 
-     * @var boolean
-     */
-    protected $versionUsingNamespace = NULL;
-
-    /**
-     * Append baseUrl to TSFE based on loaded domain
-     *
-     * @param array     $config: Reference to configuration array
-     * @param tslib_fe  $tsfe: Reference to TypoScript based Front End object
-     */
-    public function hookInitConfig(&$config, &$tsfe) {
-        if ($this->isEnabled($tsfe)) {
-            if ($this->isVersionUsingNamespace()) {
-                $parts = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
-                if (($domain = \TYPO3\CMS\Backend\Utility\BackendUtility::getDomainStartPage($parts['host'], $parts['path'])) && $domain['tx_cdsrcbaseurl_to_baseurl']) {
-                    $baseURL = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'), '/') . '/';
-                    $this->updateBaseUrl($baseURL, $tsfe);
-                }
-            } else {
-                require_once(PATH_t3lib . 'class.t3lib_befunc.php');
-                require_once(PATH_t3lib . 'class.t3lib_div.php');
-
-                $parts = parse_url(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
-                if (($domain = t3lib_BEfunc::getDomainStartPage($parts['host'], $parts['path'])) && $domain['tx_cdsrcbaseurl_to_baseurl']) {
-                    $baseURL = rtrim(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), '/') . '/';
-                    $this->updateBaseUrl($baseURL, $tsfe);
-                }
-            }
-        }
-    }
-
-    /**
-     * Is current TYPO3 version using Namespace?
-     * 
-     * @return boolean
-     */
-    protected function isVersionUsingNamespace() {
-        if ($this->versionUsingNamespace === NULL) {
-            if (class_exists('\\TYPO3\\CMS\\Core\Utility\\GeneralUtility') && \TYPO3\CMS\Core\Utility\GeneralUtility::compat_version('6.0')) {
-                $this->versionUsingNamespace = TRUE;
-            } else {
-                $this->versionUsingNamespace = FALSE;
-            }
-        }
-        return $this->versionUsingNamespace;
-    }
-
-    /**
-     * Is Hook enable?
-     * @param tslib_fe  $tsfe: Reference to TypoScript based Front End object
-     * 
-     * @return boolean
-     */
-    protected function isEnabled($tsfe) {
-        if (isset($tsfe->config['config']['tx_cdsrcbaseurl_disabled.'])) {
-            if ($this->isVersionUsingNamespace() && class_exists('\\TYPO3\\CMS\\Frontend\ContentObject\\ContentObjectRenderer')) {
-                $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
-            } else {
-                require_once(PATH_t3lib . 'class.t3lib_div.php');
-                require_once(PATH_tslib . 'class.tslib_content.php');
-                $cObj = t3lib_div::makeInstance('tslib_cObj');
-            }
-            return !$cObj->stdWrap($tsfe->config['config']['tx_cdsrcbaseurl_disabled'], $tsfe->config['config']['tx_cdsrcbaseurl_disabled.']);
-        } elseif (isset($tsfe->config['config']['tx_cdsrcbaseurl_disabled'])) {
-            return !$tsfe->config['config']['tx_cdsrcbaseurl_disabled'];
-        }
-        return TRUE;
-    }
-
-    /**
-     * Set or replace baseURL in TSFE
-     * 
-     * @param string $baseURL
-     * @param tslib_fe  $tsfe: Reference to TypoScript based Front End object
-     */
-    protected function updateBaseUrl($baseURL, &$tsfe) {
-        if ($tsfe->cacheContentFlag) {
-            if (!$tsfe->tx_cdsrcbaseurl_tmplhooks_done) {
-                $tsfe->tx_cdsrcbaseurl_tmplhooks_done = 1;
-                // Replace baseURL in TSFE's cached content
-                $matches = array();
-                if (preg_match('#(<base[^>]+href=["\']([^"\']+)["\'][^>]*>(</base>)?)#iu', $tsfe->content, $matches)) {
-                    if ($matches[2] !== $baseURL) {
-                        $submatches = array();
-                        $target = preg_match('#target=["\']([^"\']+)["\']#i', $matches[1], $submatches) ? ' target="' . $submatches[1] . '"' : '';
-                        $tsfe->content = str_replace($matches[1], '<base href="' . $baseURL . '"' . $target . ' />', $tsfe->content);
-                    }
-                } else {
-                    $tsfe->content = preg_replace('#(<head[^>]*>)#iu', '$1<base href="' . $baseURL . '" />', $tsfe->content);
-                }
-            }
-        } elseif (!$tsfe->config['config']['baseURL']) {
-            $tsfe->config['config']['baseURL'] = $baseURL;
-        }
-    }
-
-}
-
-/**
- * TYPO3 4.x branch compatibility fix
- */
-class user_CdsrcBaseurlTmplHooks extends CdsrcBaseurlTmplHooks {
-    
-}
-
-?>
\ No newline at end of file
diff --git a/Classes/Hook/BaseUrlHook.php b/Classes/Hook/BaseUrlHook.php
new file mode 100644 (file)
index 0000000..542bd42
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+namespace CDSRC\CdsrcBaseurl\Hook;
+
+/**
+ * @copyright Copyright (c) 2016 Code-Source
+ */
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+
+/**
+ * Hook for template object
+ *
+ * @author    Matthias Toscanelli <m.toscanelli@code-source.ch>
+ * @package CDSRC
+ * @subpackage baseurl
+ */
+class BaseUrlHook
+{
+
+    /**
+     * Append baseUrl to TSFE based on loaded domain
+     *
+     * @param array $config : Reference to configuration array
+     * @param TypoScriptFrontendController $tsfe : Reference to TypoScript based Front End object
+     */
+    public function execute(array $config, TypoScriptFrontendController $tsfe)
+    {
+        if ($this->isEnabled($config['config'])) {
+            $parts = parse_url(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
+            $domain = BackendUtility::getDomainStartPage($parts['host'], $parts['path']);
+            if ($domain && $domain['tx_cdsrcbaseurl_to_baseurl']) {
+                $baseURL = rtrim(GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'), '/') . '/';
+                $this->updateBaseUrl($baseURL, $tsfe);
+            }
+        }
+    }
+
+    /**
+     * Is Hook enable?
+     *
+     * @param array $config
+     *
+     * @return boolean
+     */
+    protected function isEnabled(array $config)
+    {
+        if (isset($config['tx_cdsrcbaseurl_disabled.'])) {
+            /** @var ContentObjectRenderer $cObj */
+            $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
+
+            return !$cObj->stdWrap($config['tx_cdsrcbaseurl_disabled'], $config['tx_cdsrcbaseurl_disabled.']);
+        } elseif (isset($config['tx_cdsrcbaseurl_disabled'])) {
+            return !$config['tx_cdsrcbaseurl_disabled'];
+        }
+
+        return true;
+    }
+
+    /**
+     * Set or replace baseURL in TSFE
+     *
+     * @param string $baseURL
+     * @param TypoScriptFrontendController $tsfe
+     */
+    protected function updateBaseUrl($baseURL, TypoScriptFrontendController $tsfe)
+    {
+        if ($tsfe->isGeneratePage()) {
+            // Check if baseURL is not set manually
+            if (isset($tsfe->config['config']['baseURL']) && $tsfe->config['config']['baseURL']) {
+                return;
+            }
+            $tsfe->config['config']['baseURL'] = $baseURL;
+        } elseif (!isset($tsfe->config['config']['tx_cdsrcbaseurl_cache_overridden'])) {
+            $tsfe->config['config']['tx_cdsrcbaseurl_cache_overridden'] = 1;
+            // Replace baseURL in TSFE's cached content
+            $matches = [];
+            if (preg_match('#(<base[^>]+href=["\']([^"\']+)["\'][^>]*>(</base>)?)#iu', $tsfe->content, $matches)) {
+                if ($matches[2] !== $baseURL) {
+                    $targetMatches = [];
+                    $hasTarget = preg_match('#target=["\']([^"\']+)["\']#i', $matches[1], $targetMatches);
+                    $target = $hasTarget ? ' target="' . $targetMatches[1] . '"' : '';
+                    $tsfe->content = str_replace(
+                        $matches[1],
+                        '<base href="' . $baseURL . '"' . $target . ' />',
+                        $tsfe->content
+                    );
+                }
+            } else {
+                $tsfe->content = preg_replace(
+                    '#(<head[^>]*>)#iu',
+                    '$1<base href="' . $baseURL . '" />',
+                    $tsfe->content
+                );
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/Configuration/TCA/Overrides/sys_domain.php b/Configuration/TCA/Overrides/sys_domain.php
new file mode 100644 (file)
index 0000000..b865368
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Code-Source
+ */
+
+
+$tempColumns = [
+    'tx_cdsrcbaseurl_to_baseurl' => [
+        'exclude' => 1,
+        'label' => 'LLL:EXT:cdsrc_baseurl/Resources/Private/Language/locallang_db.xlf:sys_domain.tx_cdsrcbaseurl_to_baseurl',
+        'config' => [
+            'type' => 'check',
+            'default' => 1,
+        ],
+    ],
+];
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_domain', $tempColumns);
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_domain', 'tx_cdsrcbaseurl_to_baseurl');
diff --git a/README.txt b/README.txt
deleted file mode 100644 (file)
index 2b9aebe..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-
-Feel free to add some documentation or simply add a link to the online manual.
diff --git a/Resources/Private/Language/fr.locallang_db.xlf b/Resources/Private/Language/fr.locallang_db.xlf
new file mode 100644 (file)
index 0000000..981bbcc
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+       <file source-language="en" target-language="fr" datatype="plaintext" original="messages" date="2016-11-22T14:05:12Z" product-name="cdsrc_baseurl">
+               <header/>
+               <body>
+                       <trans-unit id="sys_domain.tx_cdsrcbaseurl_to_baseurl">
+                               <source>Add base URL for this domain</source>
+                               <target>Ajouter l'URL de base pour ce domaine</target>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>
diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf
new file mode 100644 (file)
index 0000000..091b2f5
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+       <file source-language="en" datatype="plaintext" original="messages" date="2016-11-22T14:05:12Z" product-name="cdsrc_baseurl">
+               <header/>
+               <body>
+                       <trans-unit id="sys_domain.tx_cdsrcbaseurl_to_baseurl">
+                               <source>Add base URL for this domain</source>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>
index ff08e44..83facd6 100644 (file)
  * writing. "version" and "dependencies" must not be touched!
  ***************************************************************/
 
-$EM_CONF[$_EXTKEY] = array (
-       'title' => 'Automatic base url',
-       'description' => 'Add automaticly base url based on current domain',
-       'category' => 'fe',
-       'version' => '3.2.0',
-       'state' => 'stable',
-       'uploadfolder' => true,
-       'createDirs' => '',
-       'clearcacheonload' => true,
-       'author' => 'Matthias Toscanelli',
-       'author_email' => 'm.toscanelli@code-source.ch',
-       'author_company' => 'Code-Source',
-       'constraints' => 
-       array (
-               'depends' => 
-               array (
-                       'typo3' => '4.5.0-7.3.99',
-               ),
-               'conflicts' => 
-               array (
-               ),
-               'suggests' => 
-               array (
-               ),
-       ),
-);
+$EM_CONF[$_EXTKEY] = [
+    'title' => 'Automatic base url',
+    'description' => 'Add automaticly base url based on current domain',
+    'category' => 'fe',
+    'version' => '4.0.0',
+    'state' => 'stable',
+    'uploadfolder' => true,
+    'createDirs' => '',
+    'clearcacheonload' => true,
+    'author' => 'Matthias Toscanelli',
+    'author_email' => 'm.toscanelli@code-source.ch',
+    'author_company' => 'Code-Source',
+    'constraints' => [
+        'depends' => [
+            'typo3' => '7.6.0-8.4.99',
+        ],
+        'conflicts' => [],
+        'suggests' => [],
+    ],
+];
 
index d1aa17a..5d2f927 100644 (file)
@@ -1,11 +1,9 @@
 <?php
 
-if (!defined('TYPO3_MODE'))
+if (!defined('TYPO3_MODE')) {
     die('Access denied.');
+}
 
 
 // Add hook to configuration post processus
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'][$_EXTKEY] = 
-        'EXT:cdsrc_baseurl/Classes/CdsrcBaseurlTmplHooks.php:&user_CdsrcBaseurlTmplHooks->hookInitConfig';
-
-?>
\ No newline at end of file
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'][$_EXTKEY] = 'CDSRC\CdsrcBaseurl\Hook\BaseUrlHook->execute';
diff --git a/ext_tables.php b/ext_tables.php
deleted file mode 100644 (file)
index c30d19d..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-if (!defined('TYPO3_MODE')) die('Access denied.');
-
-
-$tempColumns = Array(
-    'tx_cdsrcbaseurl_to_baseurl' => Array(
-        'exclude' => 1,
-        'label' => 'LLL:EXT:cdsrc_baseurl/locallang_db.xml:sys_domain.tx_cdsrcbaseurl_to_baseurl',
-        'config' => Array(
-            'type' => 'check',
-            'default' => 1,
-        )
-    ),
-);
-
-
-if (class_exists('\\TYPO3\\CMS\\Core\Utility\\GeneralUtility') && \TYPO3\CMS\Core\Utility\GeneralUtility::compat_version('6.0')) {
-    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_domain', $tempColumns);
-    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_domain', 'tx_cdsrcbaseurl_to_baseurl;;;;1-1-1');
-} else {
-    t3lib_div::loadTCA('sys_domain');
-    t3lib_extMgm::addTCAcolumns('sys_domain', $tempColumns, 1);
-    t3lib_extMgm::addToAllTCAtypes('sys_domain', 'tx_cdsrcbaseurl_to_baseurl;;;;1-1-1');
-}
-?>
\ No newline at end of file
diff --git a/locallang_db.xml b/locallang_db.xml
deleted file mode 100644 (file)
index 086a48e..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
-<T3locallang>
-    <meta type="array">
-        <type>database</type>
-        <description>Language labels for database tables/fields belonging to extension 'cdsrc_baseurl'</description>
-    </meta>
-    <data type="array">
-        <languageKey index="default" type="array">
-            <label index="sys_domain.tx_cdsrcbaseurl_to_baseurl">Add base URL for this domain</label>
-        </languageKey>
-        <languageKey index="fr" type="array">
-            <label index="sys_domain.tx_cdsrcbaseurl_to_baseurl">Ajouter l'URL de base pour ce domaine</label>
-        </languageKey>
-    </data>
-</T3locallang>
\ No newline at end of file