[TASK] HTMLArea: Optimize path handling 55/49755/5
authorBenni Mack <benni@typo3.org>
Fri, 2 Sep 2016 13:53:34 +0000 (15:53 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 3 Sep 2016 09:00:54 +0000 (11:00 +0200)
Use Core functionality with absolute paths
instead of own calculations.

Resolves: #77789
Releases: master
Change-Id: Id566eb29a51dc393fb46b85151fa68a616365c2b
Reviewed-on: https://review.typo3.org/49755
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/rtehtmlarea/Classes/Extension/MicroDataSchema.php
typo3/sysext/rtehtmlarea/Classes/Extension/Spellchecker.php
typo3/sysext/rtehtmlarea/Classes/Extension/Typo3Link.php
typo3/sysext/rtehtmlarea/Classes/Form/Element/RichTextElement.php
typo3/sysext/rtehtmlarea/Classes/RteHtmlAreaApi.php

index 8a8fdcf..9421b6c 100644 (file)
@@ -64,8 +64,8 @@ class MicroDataSchema extends RteHtmlAreaApi
                 // Fallback to default schema file if configured file does not exists or is of zero size
                 if (!$fileName || !file_exists($absolutePath) || !filesize($absolutePath)) {
                     $fileName = 'EXT:' . $this->extensionKey . '/Resources/Public/Rdf/MicrodataSchema/SchemaOrgAll.rdf';
+                    $fileName = GeneralUtility::getFileAbsFileName($fileName);
                 }
-                $fileName = $this->getFullFileName($fileName);
                 $rdf = file_get_contents($fileName);
                 if ($rdf) {
                     $this->parseSchema($rdf, $schema);
index d0b301a..81361e3 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Rtehtmlarea\Extension;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
 
 /**
@@ -97,7 +98,7 @@ class Spellchecker extends RteHtmlAreaApi
 
             // Get the eID script or the AJAX path
             if ($this->isFrontend() || $this->isFrontendEditActive()) {
-                $path = ($GLOBALS['TSFE']->absRefPrefix ?: '') . 'index.php?eID=rtehtmlarea_spellchecker';
+                $path = PathUtility::getAbsoluteWebPath('index.php?eID=rtehtmlarea_spellchecker');
             } else {
                 /** @var UriBuilder $uriBuilder */
                 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
index 40a3b71..4fa5c35 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Rtehtmlarea\Extension;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
 
 /**
@@ -100,7 +101,7 @@ class Typo3Link extends RteHtmlAreaApi
                     $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'type : "' . str_replace('"', '', str_replace('\'', '', $conf['type'])) . '"' . LF;
                 }
                 if (trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))) {
-                    $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'image : "' . GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . GeneralUtility::resolveBackPath((TYPO3_mainDir . $this->getFullFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))))) . '"' . LF;
+                    $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'image : "' . GeneralUtility::locationHeaderUrl(PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName(trim(str_replace('\'', '', str_replace('"', '', $conf['image'])))))) . '"' . LF;
                 }
                 $JSClassesAnchorArray .= ($index++ ? ',' : '') . 'addIconAfterLink : ' . ($conf['addIconAfterLink'] ? 'true' : 'false') . LF;
                 if (trim($conf['altText'])) {
index 47970e5..89e7df2 100644 (file)
@@ -19,7 +19,6 @@ use TYPO3\CMS\Backend\Form\InlineStackProcessor;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController;
 use TYPO3\CMS\Core\Html\RteHtmlParser;
 use TYPO3\CMS\Core\Localization\Locales;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
@@ -27,6 +26,7 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\ClientUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Rtehtmlarea\RteHtmlAreaApi;
 
@@ -238,7 +238,7 @@ class RichTextElement extends AbstractFormElement
 
         // Get skin file name from Page TSConfig if any
         $skinFilename = trim($this->processedRteConfiguration['skin']) ?: 'EXT:rtehtmlarea/Resources/Public/Css/Skin/htmlarea.css';
-        $skinFilename = $this->getFullFileName($skinFilename);
+        $skinFilename = PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($skinFilename));
         $skinDirectory = dirname($skinFilename);
 
         // jQuery UI Resizable style sheet and main skin stylesheet
@@ -603,19 +603,20 @@ class RichTextElement extends AbstractFormElement
     protected function getRteInitJsCode()
     {
         $skinFilename = trim($this->processedRteConfiguration['skin']) ?: 'EXT:rtehtmlarea/Resources/Public/Css/Skin/htmlarea.css';
-        $skinFilename = $this->getFullFileName($skinFilename);
+        $skinFilename = GeneralUtility::getFileAbsFileName($skinFilename);
         $skinDirectory = dirname($skinFilename);
         // Editing area style sheet
         $editedContentCSS = GeneralUtility::createVersionNumberedFilename($skinDirectory . '/htmlarea-edited-content.css');
-
+        $editorUrl = GeneralUtility::getFileAbsFileName('EXT:rtehtmlarea/Resources/');
+        $editorUrl = dirname($editorUrl) . '/';
         return 'require(["TYPO3/CMS/Rtehtmlarea/HTMLArea/HTMLArea"], function (HTMLArea) {
                        if (typeof RTEarea === "undefined") {
                                RTEarea = new Object();
                                RTEarea[0] = new Object();
                                RTEarea[0].version = "' . TYPO3_version . '";
-                               RTEarea[0].editorUrl = "' . ExtensionManagementUtility::extRelPath('rtehtmlarea') . '";
-                               RTEarea[0].editorSkin = "' . $skinDirectory . '/";
-                               RTEarea[0].editedContentCSS = "' . $editedContentCSS . '";
+                               RTEarea[0].editorUrl = "' . PathUtility::getAbsoluteWebPath($editorUrl) . '";
+                               RTEarea[0].editorSkin = "' . PathUtility::getAbsoluteWebPath($skinDirectory) . '/";
+                               RTEarea[0].editedContentCSS = "' . PathUtility::getAbsoluteWebPath($editedContentCSS) . '";
                                RTEarea.init = function() {
                                        HTMLArea.init();
                                };
@@ -781,12 +782,12 @@ class RichTextElement extends AbstractFormElement
                 $fileName = trim($contentCssfile);
                 $absolutePath = GeneralUtility::getFileAbsFileName($fileName);
                 if (file_exists($absolutePath) && filesize($absolutePath)) {
-                    $contentCssFiles[$contentCssKey] = $this->getFullFileName($fileName);
+                    $contentCssFiles[$contentCssKey] = PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($fileName));
                 }
             }
         } else {
             // Fallback to default content css file if none of the configured files exists and is not empty
-            $contentCssFiles['default'] = $this->getFullFileName('EXT:rtehtmlarea/Resources/Public/Css/ContentCss/Default.css');
+            $contentCssFiles['default'] = PathUtility::getAbsoluteWebPath('EXT:rtehtmlarea/Resources/Public/Css/ContentCss/Default.css');
         }
         return array_unique($contentCssFiles);
     }
@@ -1083,31 +1084,6 @@ class RichTextElement extends AbstractFormElement
     }
 
     /**
-     * Make a file name relative to the PATH_site or to the PATH_typo3
-     *
-     * @param string $filename: a file name of the form EXT:.... or relative to the PATH_site
-     * @return string the file name relative to the PATH_site if in frontend or relative to the PATH_typo3 if in backend
-     */
-    protected function getFullFileName($filename)
-    {
-        if (strpos($filename, 'EXT:') === 0) {
-            // extension
-            list($extKey, $local) = explode('/', substr($filename, 4), 2);
-            $newFilename = '';
-            if ((string)$extKey !== '' && ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
-                $newFilename = ($this->isFrontendEditActive()
-                        ? ExtensionManagementUtility::siteRelPath($extKey)
-                        : ExtensionManagementUtility::extRelPath($extKey))
-                    . $local;
-            }
-        } else {
-            $path = ($this->isFrontendEditActive() ? '' : '../');
-            $newFilename = $path . ($filename[0] === '/' ? substr($filename, 1) : $filename);
-        }
-        return GeneralUtility::resolveBackPath($newFilename);
-    }
-
-    /**
      * Return the Javascript code for copying the HTML code from the editor into the hidden input field.
      *
      * @return void
@@ -1124,16 +1100,6 @@ class RichTextElement extends AbstractFormElement
     }
 
     /**
-     * Checks if frontend editing is active.
-     *
-     * @return bool TRUE if frontend editing is active
-     */
-    protected function isFrontendEditActive()
-    {
-        return is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->beUserLogin && $GLOBALS['BE_USER']->frontendEdit instanceof FrontendEditingController;
-    }
-
-    /**
      * Client Browser Information
      *
      * @return array Contains keys "user agent", "browser", "version", "system"
index 725a56d..c0d81d0 100644 (file)
@@ -15,8 +15,8 @@ namespace TYPO3\CMS\Rtehtmlarea;
  */
 
 use TYPO3\CMS\Core\FrontendEditing\FrontendEditingController;
-use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Lang\LanguageService;
 
 /**
@@ -273,31 +273,6 @@ abstract class RteHtmlAreaApi
     }
 
     /**
-     * Make a file name relative to the PATH_site or to the PATH_typo3
-     *
-     * @param string $filename: a file name of the form EXT:.... or relative to the PATH_site
-     * @return string the file name relative to the PATH_site if in frontend or relative to the PATH_typo3 if in backend
-     */
-    protected function getFullFileName($filename)
-    {
-        if (strpos($filename, 'EXT:') === 0) {
-            // extension
-            list($extKey, $local) = explode('/', substr($filename, 4), 2);
-            $newFilename = '';
-            if ((string)$extKey !== '' && ExtensionManagementUtility::isLoaded($extKey) && (string)$local !== '') {
-                $newFilename = ($this->isFrontend() || $this->isFrontendEditActive()
-                        ? ExtensionManagementUtility::siteRelPath($extKey)
-                        : ExtensionManagementUtility::extRelPath($extKey))
-                    . $local;
-            }
-        } else {
-            $path = ($this->isFrontend() || $this->isFrontendEditActive() ? '' : '../');
-            $newFilename = $path . ($filename[0] === '/' ? substr($filename, 1) : $filename);
-        }
-        return GeneralUtility::resolveBackPath($newFilename);
-    }
-
-    /**
      * Writes contents in a file in typo3temp and returns the file name
      *
      * @param string $label: A label to insert at the beginning of the name of the file
@@ -320,12 +295,7 @@ abstract class RteHtmlAreaApi
                 throw new \RuntimeException($failure, 1294585668);
             }
         }
-        if ($this->isFrontend() || $this->isFrontendEditActive()) {
-            $fileName = $relativeFilename;
-        } else {
-            $fileName = '../' . $relativeFilename;
-        }
-        return GeneralUtility::resolveBackPath($fileName);
+        return PathUtility::getAbsoluteWebPath($destination);
     }
 
     /**