[TASK] Deprecate ContentObjectRenderer::fileResource 98/49498/17
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 16 Aug 2016 15:40:10 +0000 (17:40 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 7 Dec 2016 11:52:07 +0000 (12:52 +0100)
Deprecate the mentioned method which does too many
mixed things.

Resolves: #77524
Releases: master
Change-Id: Ib0e3d6d4a4441afb836292070b92f559cac96fb3
Reviewed-on: https://review.typo3.org/49498
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/compatibility7/Classes/Controller/SearchFormController.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-77524-DeprecatedMethodFileResourceOfContentObjectRenderer.rst [new file with mode: 0644]
typo3/sysext/felogin/Classes/Controller/FrontendLoginController.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/ContentObject/FileContentObject.php

index e0966af..7deafb2 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Html\HtmlParser;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 use TYPO3\CMS\IndexedSearch\Utility;
 
 /**
@@ -375,7 +376,10 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
             $this->wholeSiteIdList = implode(',', GeneralUtility::intExplode(',', $this->conf['search.']['rootPidList']));
         }
         // Load the template
-        $this->templateCode = $this->cObj->fileResource($this->conf['templateFile']);
+        $template = $this->getTypoScriptFrontendController()->tmpl->getFileName($this->conf['templateFile']);
+        if ($template !== null && file_exists($template)) {
+            $this->templateCode = file_get_contents($template);
+        }
         // Add search languages:
         $res = $this->databaseConnection->exec_SELECTquery('*', 'sys_language', '1=1' . $this->cObj->enableFields('sys_language'));
         while (false !== ($data = $this->databaseConnection->sql_fetch_assoc($res))) {
@@ -2655,4 +2659,14 @@ class SearchFormController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         );
         $this->conf['results.']['hrefInSummaryCropSignifier'] = $this->cObj->stdWrap($this->conf['results.']['hrefInSummaryCropSignifier'], $this->conf['results.']['hrefInSummaryCropSignifier.']);
     }
+
+    /**
+     * Get TypoScriptFrontendController
+     *
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-77524-DeprecatedMethodFileResourceOfContentObjectRenderer.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-77524-DeprecatedMethodFileResourceOfContentObjectRenderer.rst
new file mode 100644 (file)
index 0000000..7c7624b
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+=============================================================================
+Deprecation: #77524 - Deprecated method fileResource of ContentObjectRenderer
+=============================================================================
+
+See :issue:`77524`
+
+Description
+===========
+
+The method :php:`ContentObjectRenderer::fileResource` has been marked as deprecated.
+
+
+Impact
+======
+
+Using the mentioned method will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Instances that use the method.
+
+
+Migration
+=========
+
+Migrate your code to use :php:`file_get_contents`. Use a call to :php:`$GLOBALS['TSFE']->tmpl->getFileName($fileName)` for substituting strings like `EXT`.
+
+.. index:: Frontend
index 2e60383..e163a68 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Plugin 'Website User Login' for the 'felogin' extension.
@@ -141,7 +142,10 @@ class FrontendLoginController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         $this->redirectUrl = $this->validateRedirectUrl($this->redirectUrl);
         // Get Template
         $templateFile = $this->conf['templateFile'] ?: 'EXT:felogin/Resources/Private/Templates/FrontendLogin.html';
-        $this->template = $this->cObj->fileResource($templateFile);
+        $template = $this->getTypoScriptFrontendController()->tmpl->getFileName($templateFile);
+        if ($template !== null && file_exists($template)) {
+            $this->template = file_get_contents($template);
+        }
         // Is user logged in?
         $this->userIsLoggedIn = $this->frontendController->loginUser;
         // Redirect
@@ -1103,4 +1107,14 @@ class FrontendLoginController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin
         }
         return false;
     }
+
+    /**
+     * Get TypoScriptFrontendController
+     *
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }
index e6880b4..430ea9e 100644 (file)
@@ -1496,9 +1496,11 @@ class ContentObjectRenderer
      * @param string $addParams Additional parameters (attributes). Default is empty alt and title tags.
      * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
      * @see FILE()
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use file_get_contents() directly
      */
     public function fileResource($fName, $addParams = 'alt="" title=""')
     {
+        GeneralUtility::logDeprecatedFunction();
         $tsfe = $this->getTypoScriptFrontendController();
         $incFile = $tsfe->tmpl->getFileName($fName);
         if ($incFile && file_exists($incFile)) {
index ce9e967..6b98a64 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
  * Contains FILE class object.
@@ -27,8 +29,21 @@ class FileContentObject extends AbstractContentObject
      */
     public function render($conf = [])
     {
+        $theValue = '';
         $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
-        $theValue = $this->cObj->fileResource($file, trim($this->cObj->getAltParam($conf, false)));
+        $file = $this->getTypoScriptFrontendController()->tmpl->getFileName($file);
+        if ($file !== null && file_exists($file)) {
+            $fileInfo = GeneralUtility::split_fileref($file);
+            $extension = $fileInfo['fileext'];
+            if ($extension === 'jpg' || $extension === 'jpeg' || $extension === 'gif' || $extension === 'png') {
+                $imgInfo = @getimagesize($file);
+                $altParameters = trim($this->cObj->getAltParam($conf, false));
+                $theValue = '<img src="' . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . $file) . '" width="' . (int)$imgInfo[0] . '" height="' . (int)$imgInfo[1] . '"' . $this->cObj->getBorderAttr(' border="0"') . ' ' . $altParameters . ' />';
+            } elseif (filesize($file) < 1024 * 1024) {
+                $theValue = file_get_contents($file);
+            }
+        }
+
         $linkWrap = isset($conf['linkWrap.']) ? $this->cObj->stdWrap($conf['linkWrap'], $conf['linkWrap.']) : $conf['linkWrap'];
         if ($linkWrap) {
             $theValue = $this->cObj->linkWrap($theValue, $linkWrap);
@@ -42,4 +57,12 @@ class FileContentObject extends AbstractContentObject
         }
         return $theValue;
     }
+
+    /**
+     * @return TypoScriptFrontendController
+     */
+    protected function getTypoScriptFrontendController()
+    {
+        return $GLOBALS['TSFE'];
+    }
 }