[TASK] Initial commit 96/45296/2 3.2.0
authorMatthias Toscanelli <m.toscanelli@code-source.ch>
Tue, 15 Dec 2015 23:52:52 +0000 (00:52 +0100)
committerMatthias Toscanelli <m.toscanelli@code-source.ch>
Wed, 16 Dec 2015 01:02:27 +0000 (02:02 +0100)
Commit all existing files into git repository

Change-Id: I25b26cce4a3c46b20dcba0a7dc08b95868c7c332
Reviewed-on: https://review.typo3.org/45296
Reviewed-by: Matthias Toscanelli <m.toscanelli@code-source.ch>
Tested-by: Matthias Toscanelli <m.toscanelli@code-source.ch>
ChangeLog [new file with mode: 0644]
Classes/CdsrcBaseurlTmplHooks.php [new file with mode: 0644]
README.txt [new file with mode: 0644]
ext_emconf.php [new file with mode: 0644]
ext_icon.gif [new file with mode: 0644]
ext_localconf.php [new file with mode: 0644]
ext_tables.php [new file with mode: 0644]
ext_tables.sql [new file with mode: 0644]
locallang_db.xml [new file with mode: 0644]

diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..f41478f
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,41 @@
+2015-07-02 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 3.2.0
+    * Bug fix: When a page was cached and has INT-scripts in it, the process to recreate the config from cache may cause problems in the rendering. (Thanks to Nils Blattner)
+    * Bug fix: All domains are taken regardless of configuration
+    * Added possibility to desactivate Hook from TypoScript configuration "config.tx_cdsrcbaseurl_disabled" (stdWrap)
+
+2015-03-04 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 3.1.0
+    * TYPO3 7.x compatibility fix
+
+2014-03-25 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 3.0.1
+    * Code cleanup
+
+2014-03-25 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 3.0.0
+    * TYPO3 6.2 compatibility fix
+
+2013-04-18 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 1.2.0
+    * Code cleanup
+    * Comments added
+
+2010-09-02 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 1.0.2
+    * Bug fix: Added final "/" to be more compatible with extensions
+
+2010-04-03 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Stable 1.0.1
+    * Added multidomain cache management
+
+2010-03-10 Matthias Toscanelli  <m.toscanelli@code-source.ch>
+
+    * Initial release
diff --git a/Classes/CdsrcBaseurlTmplHooks.php b/Classes/CdsrcBaseurlTmplHooks.php
new file mode 100644 (file)
index 0000000..2ca7e36
--- /dev/null
@@ -0,0 +1,142 @@
+<?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/README.txt b/README.txt
new file mode 100644 (file)
index 0000000..2b9aebe
--- /dev/null
@@ -0,0 +1,2 @@
+
+Feel free to add some documentation or simply add a link to the online manual.
diff --git a/ext_emconf.php b/ext_emconf.php
new file mode 100644 (file)
index 0000000..ff08e44
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/***************************************************************
+ * Extension Manager/Repository config file for ext "cdsrc_baseurl".
+ *
+ * Auto generated 02-07-2015 11:01
+ *
+ * Manual updates:
+ * Only the data in the array - everything else is removed by next
+ * 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 (
+               ),
+       ),
+);
+
diff --git a/ext_icon.gif b/ext_icon.gif
new file mode 100644 (file)
index 0000000..5ab1d35
Binary files /dev/null and b/ext_icon.gif differ
diff --git a/ext_localconf.php b/ext_localconf.php
new file mode 100644 (file)
index 0000000..d1aa17a
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+
+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
diff --git a/ext_tables.php b/ext_tables.php
new file mode 100644 (file)
index 0000000..c30d19d
--- /dev/null
@@ -0,0 +1,25 @@
+<?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/ext_tables.sql b/ext_tables.sql
new file mode 100644 (file)
index 0000000..a80b1f5
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Table structure for table 'sys_domain'
+#
+CREATE TABLE sys_domain (
+       tx_cdsrcbaseurl_to_baseurl tinyint(3) DEFAULT '1' NOT NULL
+);
\ No newline at end of file
diff --git a/locallang_db.xml b/locallang_db.xml
new file mode 100644 (file)
index 0000000..086a48e
--- /dev/null
@@ -0,0 +1,15 @@
+<?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