[CLEANUP] Replace count with empty in multiple extensions
[Packages/TYPO3.CMS.git] / typo3 / sysext / css_styled_content / Classes / Controller / CssStyledContentController.php
index fea7c9b..e4de3b6 100644 (file)
@@ -1,33 +1,21 @@
 <?php
 namespace TYPO3\CMS\CssStyledContent\Controller;
 
-/***************************************************************
- *  Copyright notice
+/*
+ * This file is part of the TYPO3 CMS project.
  *
- *  (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
- *  All rights reserved
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  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.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  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!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 
 /**
  * Plugin class - instantiated from TypoScript.
@@ -40,26 +28,26 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
        /**
         * Same as class name
         *
-        * @todo Define visibility
+        * @var string
         */
        public $prefixId = 'tx_cssstyledcontent_pi1';
 
        /**
         * Path to this script relative to the extension dir.
         *
-        * @todo Define visibility
+        * @var string
         */
-       public $scriptRelPath = 'pi1/class.tx_cssstyledcontent_pi1.php';
+       public $scriptRelPath = 'Classes/Controller/CssStyledContentController.php';
 
        /**
         * The extension key
         *
-        * @todo Define visibility
+        * @var string
         */
        public $extKey = 'css_styled_content';
 
        /**
-        * @todo Define visibility
+        * @var array
         */
        public $conf = array();
 
@@ -73,8 +61,10 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * @param string $content Content input. Not used, ignore.
         * @param array $conf TypoScript configuration
         * @return string HTML output.
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, is done by default in pure TypoScript
         */
        public function render_bullets($content, $conf) {
+               GeneralUtility::logDeprecatedFunction();
                // Look for hook before running default code for function
                if ($hookObj = $this->hookRequest('render_bullets')) {
                        return $hookObj->render_bullets($content, $conf);
@@ -82,7 +72,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        // Get bodytext field content, returning blank if empty:
                        $field = isset($conf['field']) && trim($conf['field']) ? trim($conf['field']) : 'bodytext';
                        $content = trim($this->cObj->data[$field]);
-                       if (!strcmp($content, '')) {
+                       if ($content === '') {
                                return '';
                        }
                        // Split into single lines:
@@ -92,7 +82,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        unset($val);
                        // Set header type:
-                       $type = intval($this->cObj->data['layout']);
+                       $type = (int)$this->cObj->data['layout'];
                        // Compile list:
                        $out = '
                                <ul class="csc-bulletlist csc-bulletlist-' . $type . '">' . implode('', $lines) . '
@@ -119,7 +109,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        // Get bodytext field content
                        $field = isset($conf['field']) && trim($conf['field']) ? trim($conf['field']) : 'bodytext';
                        $content = trim($this->cObj->data[$field]);
-                       if (!strcmp($content, '')) {
+                       if ($content === '') {
                                return '';
                        }
                        // get flexform values
@@ -130,13 +120,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        $tableClass = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_tableclass');
                        $delimiter = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_delimiter', 's_parsing'));
                        if ($delimiter) {
-                               $delimiter = chr(intval($delimiter));
+                               $delimiter = chr((int)$delimiter);
                        } else {
                                $delimiter = '|';
                        }
                        $quotedInput = trim($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tableparsing_quote', 's_parsing'));
                        if ($quotedInput) {
-                               $quotedInput = chr(intval($quotedInput));
+                               $quotedInput = chr((int)$quotedInput);
                        } else {
                                $quotedInput = '';
                        }
@@ -148,21 +138,17 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        reset($rows);
                        // Find number of columns to render:
                        $cols = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(
-                               $this->cObj->data['cols'] ? $this->cObj->data['cols'] : count(explode($delimiter, current($rows))),
+                               $this->cObj->data['cols'] ? $this->cObj->data['cols'] : count(str_getcsv(current($rows), $delimiter, $quotedInput)),
                                0,
                                100
                        );
                        // Traverse rows (rendering the table here)
                        $rCount = count($rows);
                        foreach ($rows as $k => $v) {
-                               $cells = explode($delimiter, $v);
+                               $cells = str_getcsv($v, $delimiter, $quotedInput);
                                $newCells = array();
                                for ($a = 0; $a < $cols; $a++) {
-                                       // Remove quotes if needed
-                                       if ($quotedInput && substr($cells[$a], 0, 1) == $quotedInput && substr($cells[$a], -1, 1) == $quotedInput) {
-                                               $cells[$a] = substr($cells[$a], 1, -1);
-                                       }
-                                       if (!strcmp(trim($cells[$a]), '')) {
+                                       if (trim($cells[$a]) === '') {
                                                $cells[$a] = '&nbsp;';
                                        }
                                        $cellAttribs = $noStyles ? '' : ($a > 0 && $cols - 1 == $a ? ' class="td-last td-' . $a . '"' : ' class="td-' . $a . '"');
@@ -213,7 +199,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        $tableContents .= $tmpTable;
                        // Set header type:
-                       $type = intval($this->cObj->data['layout']);
+                       $type = (int)$this->cObj->data['layout'];
                        // Table tag params.
                        $tableTagParams = $this->getTableAttributes($conf, $type);
                        if (!$noStyles) {
@@ -236,8 +222,10 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * @param string $content Content input. Not used, ignore.
         * @param array $conf TypoScript configuration
         * @return string HTML output.
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, is done by default in pure TypoScript
         */
        public function render_uploads($content, $conf) {
+               GeneralUtility::logDeprecatedFunction();
                // Look for hook before running default code for function
                if ($hookObj = $this->hookRequest('render_uploads')) {
                        return $hookObj->render_uploads($content, $conf);
@@ -246,7 +234,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        $this->pi_loadLL();
                        $out = '';
                        // Set layout type:
-                       $type = intval($this->cObj->data['layout']);
+                       $type = (int)$this->cObj->data['layout'];
                        // See if the file path variable is set, this takes precedence
                        $filePathConf = $this->cObj->stdWrap($conf['filePath'], $conf['filePath.']);
                        if ($filePathConf) {
@@ -254,7 +242,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                list($path) = explode('|', $filePathConf);
                        } else {
                                // Get the list of files from the field
-                               $field = trim($conf['field']) ? trim($conf['field']) : 'media';
+                               $field = trim($conf['field']) ?: 'media';
                                $fileList = $this->cObj->data[$field];
                                $path = 'uploads/media/';
                                if (
@@ -267,9 +255,9 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        $path = trim($path);
                        // Explode into an array:
-                       $fileArray = GeneralUtility::trimExplode(',', $fileList, 1);
+                       $fileArray = GeneralUtility::trimExplode(',', $fileList, TRUE);
                        // If there were files to list...:
-                       if (count($fileArray)) {
+                       if (!empty($fileArray)) {
                                // Get the descriptions for the files (if any):
                                $descriptions = GeneralUtility::trimExplode(LF, $this->cObj->data['imagecaption']);
                                // Get the titles for the files (if any)
@@ -318,6 +306,8 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                                $filesData[$key]['filesize'] = filesize($absPath);
                                                $filesData[$key]['fileextension'] = strtolower($fI['extension']);
                                                $filesData[$key]['description'] = trim($descriptions[$key]);
+                                               $filesData[$key]['titletext'] = trim($titles[$key]);
+                                               $filesData[$key]['alttext'] = trim($altTexts[$key]);
                                                $conf['linkProc.']['title'] = trim($titles[$key]);
                                                if (isset($altTexts[$key]) && !empty($altTexts[$key])) {
                                                        $altText = trim($altTexts[$key]);
@@ -326,12 +316,15 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                                }
                                                $conf['linkProc.']['altText'] = ($conf['linkProc.']['iconCObject.']['altText'] = $altText);
                                                $this->cObj->setCurrentVal($currentPath);
-                                               $GLOBALS['TSFE']->register['ICON_REL_PATH'] = $currentPath . $fileName;
-                                               $GLOBALS['TSFE']->register['filename'] = $filesData[$key]['filename'];
-                                               $GLOBALS['TSFE']->register['path'] = $filesData[$key]['path'];
-                                               $GLOBALS['TSFE']->register['fileSize'] = $filesData[$key]['filesize'];
-                                               $GLOBALS['TSFE']->register['fileExtension'] = $filesData[$key]['fileextension'];
-                                               $GLOBALS['TSFE']->register['description'] = $filesData[$key]['description'];
+                                               $this->frontendController->register['ICON_REL_PATH'] = $currentPath . $fileName;
+                                               $this->frontendController->register['filename'] = $filesData[$key]['filename'];
+                                               $this->frontendController->register['path'] = $filesData[$key]['path'];
+                                               $this->frontendController->register['fileSize'] = $filesData[$key]['filesize'];
+                                               $this->frontendController->register['fileExtension'] = $filesData[$key]['fileextension'];
+                                               $this->frontendController->register['description'] = $filesData[$key]['description'];
+                                               $this->frontendController->register['titleText'] = $filesData[$key]['titletext'];
+                                               $this->frontendController->register['altText'] = $filesData[$key]['alttext'];
+
                                                $filesData[$key]['linkedFilenameParts'] = $this->beautifyFileLink(
                                                        explode('//**//', $this->cObj->filelink($fileName, $conf['linkProc.'])),
                                                        $fileName,
@@ -341,17 +334,19 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                        }
                                }
                                // optionSplit applied to conf to allow differnt settings per file
-                               $splitConf = $GLOBALS['TSFE']->tmpl->splitConfArray($conf, count($filesData));
+                               $splitConf = $this->frontendController->tmpl->splitConfArray($conf, count($filesData));
                                // Now, lets render the list!
                                $outputEntries = array();
                                foreach ($filesData as $key => $fileData) {
-                                       $GLOBALS['TSFE']->register['linkedIcon'] = $fileData['linkedFilenameParts'][0];
-                                       $GLOBALS['TSFE']->register['linkedLabel'] = $fileData['linkedFilenameParts'][1];
-                                       $GLOBALS['TSFE']->register['filename'] = $fileData['filename'];
-                                       $GLOBALS['TSFE']->register['path'] = $fileData['path'];
-                                       $GLOBALS['TSFE']->register['description'] = $fileData['description'];
-                                       $GLOBALS['TSFE']->register['fileSize'] = $fileData['filesize'];
-                                       $GLOBALS['TSFE']->register['fileExtension'] = $fileData['fileextension'];
+                                       $this->frontendController->register['linkedIcon'] = $fileData['linkedFilenameParts'][0];
+                                       $this->frontendController->register['linkedLabel'] = $fileData['linkedFilenameParts'][1];
+                                       $this->frontendController->register['filename'] = $fileData['filename'];
+                                       $this->frontendController->register['path'] = $fileData['path'];
+                                       $this->frontendController->register['description'] = $fileData['description'];
+                                       $this->frontendController->register['fileSize'] = $fileData['filesize'];
+                                       $this->frontendController->register['fileExtension'] = $fileData['fileextension'];
+                                       $this->frontendController->register['titleText'] = $fileData['titletext'];
+                                       $this->frontendController->register['altText'] = $fileData['alttext'];
                                        $outputEntries[] = $this->cObj->cObjGetSingle($splitConf[$key]['itemRendering'], $splitConf[$key]['itemRendering.']);
                                }
                                if (isset($conf['outerWrap'])) {
@@ -378,7 +373,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * uses "1:1" column relations by default.
         *
         * @param array $conf TS configuration for img
-        * @param integer $colCount number of columns
+        * @param int $colCount number of columns
         * @return array
         */
        protected function getImgColumnRelations($conf, $colCount) {
@@ -392,7 +387,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        if (count($relationParts) >= $colCount) {
                                $out = array();
                                for ($a = 0; $a < $colCount; $a++) {
-                                       $currentRelationValue = intval($relationParts[$a]);
+                                       $currentRelationValue = (int)$relationParts[$a];
                                        if ($currentRelationValue >= 1) {
                                                $out[$a] = $currentRelationValue;
                                        } else {
@@ -413,15 +408,15 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                }
                        }
                }
-               return $relations ? $relations : $equalRelations;
+               return $relations ?: $equalRelations;
        }
 
        /**
         * Returns an array containing the image widths for an image row with $colCount columns.
         *
         * @param array $conf TS configuration of img
-        * @param integer $colCount number of columns
-        * @param integer $netW max usable width for images (without spaces and borders)
+        * @param int $colCount number of columns
+        * @param int $netW max usable width for images (without spaces and borders)
         * @return array
         */
        protected function getImgColumnWidths($conf, $colCount, $netW) {
@@ -441,7 +436,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        // this evenly distributes rounding errors across all images in this row.
                        $suggestedWidth = round($accumDesiredWidth - $accumWidth);
                        // finalImgWidth may not exceed $availableWidth
-                       $finalImgWidth = (int) min($availableWidth, $suggestedWidth);
+                       $finalImgWidth = (int)min($availableWidth, $suggestedWidth);
                        $accumWidth += $finalImgWidth;
                        $columnWidths[$a] = $finalImgWidth;
                }
@@ -449,7 +444,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
        }
 
        /**
-        * Rendering the IMGTEXT content element, called from TypoScript (tt_content.textpic.20)
+        * Rendering the text w/ image content element, called from TypoScript (tt_content.textpic.20)
         *
         * @param string $content Content input. Not used, ignore.
         * @param array $conf TypoScript configuration. See TSRef "IMGTEXT". This function aims to be compatible.
@@ -465,11 +460,16 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                $renderMethod = $this->cObj->stdWrap($conf['renderMethod'], $conf['renderMethod.']);
                // Render using the default IMGTEXT code (table-based)
                if (!$renderMethod || $renderMethod == 'table') {
-                       return $this->cObj->IMGTEXT($conf);
+                       return $this->cObj->cObjGetSingle('IMGTEXT', $conf);
+               }
+               $restoreRegisters = FALSE;
+               if (isset($conf['preRenderRegisters.'])) {
+                       $restoreRegisters = TRUE;
+                       $this->cObj->cObjGetSingle('LOAD_REGISTER', $conf['preRenderRegisters.']);
                }
                // Specific configuration for the chosen rendering method
                if (is_array($conf['rendering.'][$renderMethod . '.'])) {
-                       $conf = $this->cObj->joinTSarrays($conf, $conf['rendering.'][$renderMethod . '.']);
+                       $conf = array_replace_recursive($conf, $conf['rendering.'][$renderMethod . '.']);
                }
                // Image or Text with Image?
                if (is_array($conf['text.'])) {
@@ -478,14 +478,24 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                $imgList = trim($this->cObj->stdWrap($conf['imgList'], $conf['imgList.']));
                if (!$imgList) {
                        // No images, that's easy
+                       if ($restoreRegisters) {
+                               $this->cObj->cObjGetSingle('RESTORE_REGISTER', array());
+                       }
                        return $content;
                }
-               $imgs = GeneralUtility::trimExplode(',', $imgList);
-               $imgStart = intval($this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']));
+               $imgs = GeneralUtility::trimExplode(',', $imgList, TRUE);
+               if (empty($imgs)) {
+                       // The imgList was not empty but did only contain empty values
+                       if ($restoreRegisters) {
+                               $this->cObj->cObjGetSingle('RESTORE_REGISTER', array());
+                       }
+                       return $content;
+               }
+               $imgStart = (int)$this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']);
                $imgCount = count($imgs) - $imgStart;
-               $imgMax = intval($this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']));
+               $imgMax = (int)$this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']);
                if ($imgMax) {
-                       $imgCount = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($imgCount, 0, $imgMax);
+                       $imgCount = MathUtility::forceIntegerInRange($imgCount, 0, $imgMax);
                }
                $imgPath = $this->cObj->stdWrap($conf['imgPath'], $conf['imgPath.']);
                // Does we need to render a "global caption" (below the whole image block)?
@@ -494,14 +504,18 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        // If we just have one image, the caption relates to the image, so it is not "global"
                        $renderGlobalCaption = FALSE;
                }
+               $imgListContainsReferenceUids = (bool)(isset($conf['imgListContainsReferenceUids.'])
+                       ? $this->cObj->stdWrap($conf['imgListContainsReferenceUids'], $conf['imgListContainsReferenceUids.'])
+                       : $conf['imgListContainsReferenceUids']);
                // Use the calculated information (amount of images, if global caption is wanted) to choose a different rendering method for the images-block
-               $GLOBALS['TSFE']->register['imageCount'] = $imgCount;
-               $GLOBALS['TSFE']->register['renderGlobalCaption'] = $renderGlobalCaption;
+               $this->frontendController->register['imageCount'] = $imgCount;
+               $this->frontendController->register['renderGlobalCaption'] = $renderGlobalCaption;
+               $fallbackRenderMethod = '';
                if ($conf['fallbackRendering']) {
                        $fallbackRenderMethod = $this->cObj->cObjGetSingle($conf['fallbackRendering'], $conf['fallbackRendering.']);
                }
                if ($fallbackRenderMethod && is_array($conf['rendering.'][$fallbackRenderMethod . '.'])) {
-                       $conf = $this->cObj->joinTSarrays($conf, $conf['rendering.'][$fallbackRenderMethod . '.']);
+                       $conf = array_replace_recursive($conf, $conf['rendering.'][$fallbackRenderMethod . '.']);
                }
                // Set the accessibility mode which uses a different type of markup, used 4.7+
                $accessibilityMode = FALSE;
@@ -519,24 +533,24 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                $imagePosition = $position & 7;
                // 0,8,16,24 (above,below,intext,intext-wrap)
                $contentPosition = $position & 24;
-               $textMargin = intval($this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.']));
+               $textMargin = (int)$this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.']);
                if (!$conf['textMargin_outOfText'] && $contentPosition < 16) {
                        $textMargin = 0;
                }
-               $colspacing = intval($this->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']));
-               $border = intval($this->cObj->stdWrap($conf['border'], $conf['border.'])) ? 1 : 0;
-               $borderThickness = intval($this->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']));
-               $borderThickness = $borderThickness ? $borderThickness : 1;
-               $borderSpace = $conf['borderSpace'] && $border ? intval($conf['borderSpace']) : 0;
+               $colspacing = (int)$this->cObj->stdWrap($conf['colSpace'], $conf['colSpace.']);
+               $border = (int)$this->cObj->stdWrap($conf['border'], $conf['border.']) ? 1 : 0;
+               $borderThickness = (int)$this->cObj->stdWrap($conf['borderThick'], $conf['borderThick.']);
+               $borderThickness = $borderThickness ?: 1;
+               $borderSpace = $conf['borderSpace'] && $border ? (int)$conf['borderSpace'] : 0;
                // Generate cols
-               $cols = intval($this->cObj->stdWrap($conf['cols'], $conf['cols.']));
+               $cols = (int)$this->cObj->stdWrap($conf['cols'], $conf['cols.']);
                $colCount = $cols > 1 ? $cols : 1;
                if ($colCount > $imgCount) {
                        $colCount = $imgCount;
                }
                $rowCount = ceil($imgCount / $colCount);
                // Generate rows
-               $rows = intval($this->cObj->stdWrap($conf['rows'], $conf['rows.']));
+               $rows = (int)$this->cObj->stdWrap($conf['rows'], $conf['rows.']);
                if ($rows > 1) {
                        $rowCount = $rows;
                        if ($rowCount > $imgCount) {
@@ -545,8 +559,8 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        $colCount = $rowCount > 1 ? ceil($imgCount / $rowCount) : $imgCount;
                }
                // Max Width
-               $maxW = intval($this->cObj->stdWrap($conf['maxW'], $conf['maxW.']));
-               $maxWInText = intval($this->cObj->stdWrap($conf['maxWInText'], $conf['maxWInText.']));
+               $maxW = (int)$this->cObj->stdWrap($conf['maxW'], $conf['maxW.']);
+               $maxWInText = (int)$this->cObj->stdWrap($conf['maxWInText'], $conf['maxWInText.']);
                $fiftyPercentWidthInText = round($maxW / 100 * 50);
                // in Text
                if ($contentPosition >= 16) {
@@ -561,26 +575,35 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                $netW = $maxW - $colspacing * ($colCount - 1) - $colCount * $border * ($borderThickness + $borderSpace) * 2;
                // Specify the maximum width for each column
                $columnWidths = $this->getImgColumnWidths($conf, $colCount, $netW);
-               $image_compression = intval($this->cObj->stdWrap($conf['image_compression'], $conf['image_compression.']));
-               $image_effects = intval($this->cObj->stdWrap($conf['image_effects'], $conf['image_effects.']));
-               $image_frames = intval($this->cObj->stdWrap($conf['image_frames.']['key'], $conf['image_frames.']['key.']));
+               $image_compression = (int)$this->cObj->stdWrap($conf['image_compression'], $conf['image_compression.']);
+               $image_effects = (int)$this->cObj->stdWrap($conf['image_effects'], $conf['image_effects.']);
+               $image_frames = (int)$this->cObj->stdWrap($conf['image_frames.']['key'], $conf['image_frames.']['key.']);
                // EqualHeight
-               $equalHeight = intval($this->cObj->stdWrap($conf['equalH'], $conf['equalH.']));
+               $equalHeight = (int)$this->cObj->stdWrap($conf['equalH'], $conf['equalH.']);
                if ($equalHeight) {
-                       // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
-                       $gifCreator = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Imaging\\GifBuilder');
-                       $gifCreator->init();
                        $relations_cols = array();
                        // contains the individual width of all images after scaling to $equalHeight
                        $imgWidths = array();
                        for ($a = 0; $a < $imgCount; $a++) {
                                $imgKey = $a + $imgStart;
-                               $imgInfo = $gifCreator->getImageDimensions($imgPath . $imgs[$imgKey]);
+
+                               /** @var $file \TYPO3\CMS\Core\Resource\File */
+                               if (MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
+                                       if ($imgListContainsReferenceUids) {
+                                               $file = $this->getResourceFactory()->getFileReferenceObject((int)$imgs[$imgKey])->getOriginalFile();
+                                       } else {
+                                               $file = $this->getResourceFactory()->getFileObject((int)$imgs[$imgKey]);
+                                       }
+
+                               } else {
+                                       $file = $this->getResourceFactory()->getFileObjectFromCombinedIdentifier($imgPath . $imgs[$imgKey]);
+                               }
+
                                // relationship between the original height and the wished height
-                               $rel = $imgInfo[1] / $equalHeight;
+                               $rel = $file->getProperty('height') / $equalHeight;
                                // if relations is zero, then the addition of this value is omitted as the image is not expected to display because of some error.
                                if ($rel) {
-                                       $imgWidths[$a] = $imgInfo[0] / $rel;
+                                       $imgWidths[$a] = $file->getProperty('width') / $rel;
                                        // counts the total width of the row with the new height taken into consideration.
                                        $relations_cols[(int)floor($a / $colCount)] += $imgWidths[$a];
                                }
@@ -589,7 +612,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                // Fetches pictures
                $splitArr = array();
                $splitArr['imgObjNum'] = $conf['imgObjNum'];
-               $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr, $imgCount);
+               $splitArr = $this->frontendController->tmpl->splitConfArray($splitArr, $imgCount);
                // Contains the width of every image row
                $imageRowsFinalWidths = array();
                // Array index of $imgsTag will be the same as in $imgs, but $imgsTag only contains the images that are actually shown
@@ -599,17 +622,18 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                for ($a = 0; $a < $imgCount; $a++) {
                        $imgKey = $a + $imgStart;
                        // If the image cannot be interpreted as integer (therefore filename and no FAL id), add the image path
-                       if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
-                               $totalImagePath = intval($imgs[$imgKey]);
+                       if (MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
+                               $totalImagePath = (int)$imgs[$imgKey];
+                               $this->initializeCurrentFileInContentObjectRenderer($totalImagePath, $imgListContainsReferenceUids);
                        } else {
                                $totalImagePath = $imgPath . $imgs[$imgKey];
                        }
                        // register IMG_NUM is kept for backwards compatibility
-                       $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey;
-                       $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
-                       $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $totalImagePath;
+                       $this->frontendController->register['IMAGE_NUM'] = $imgKey;
+                       $this->frontendController->register['IMAGE_NUM_CURRENT'] = $imgKey;
+                       $this->frontendController->register['ORIG_FILENAME'] = $totalImagePath;
                        $this->cObj->data[$this->cObj->currentValKey] = $totalImagePath;
-                       $imgObjNum = intval($splitArr[$a]['imgObjNum']);
+                       $imgObjNum = (int)$splitArr[$a]['imgObjNum'];
                        $imgConf = $conf[$imgObjNum . '.'];
                        if ($equalHeight) {
                                if ($a % $colCount == 0) {
@@ -637,7 +661,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                // this evenly distributes rounding errors across all images in this row.
                                $suggestedWidth = round($accumDesiredWidth - $accumWidth);
                                // finalImgWidth may not exceed $availableWidth
-                               $finalImgWidth = (int) min($availableWidth, $suggestedWidth);
+                               $finalImgWidth = (int)min($availableWidth, $suggestedWidth);
                                $accumWidth += $finalImgWidth;
                                $imgConf['file.']['width'] = $finalImgWidth;
                                $imgConf['file.']['height'] = round($desiredHeight);
@@ -656,13 +680,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        $titleInLink = $this->cObj->stdWrap($imgConf['titleInLink'], $imgConf['titleInLink.']);
                        $titleInLinkAndImg = $this->cObj->stdWrap($imgConf['titleInLinkAndImg'], $imgConf['titleInLinkAndImg.']);
-                       $oldATagParms = $GLOBALS['TSFE']->ATagParams;
+                       $oldATagParms = $this->frontendController->ATagParams;
                        if ($titleInLink) {
                                // Title in A-tag instead of IMG-tag
                                $titleText = trim($this->cObj->stdWrap($imgConf['titleText'], $imgConf['titleText.']));
                                if ($titleText) {
                                        // This will be used by the IMAGE call later:
-                                       $GLOBALS['TSFE']->ATagParams .= ' title="' . $titleText . '"';
+                                       $this->frontendController->ATagParams .= ' title="' . htmlspecialchars($titleText) . '"';
                                }
                        }
 
@@ -701,9 +725,11 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                        if ($image_compression == 1) {
                                                $tempImport = $imgConf['file.']['import'];
                                                $tempImport_dot = $imgConf['file.']['import.'];
+                                               $tempTreatIdAsReference = $imgConf['file.']['treatIdAsReference'];
                                                unset($imgConf['file.']);
                                                $imgConf['file.']['import'] = $tempImport;
                                                $imgConf['file.']['import.'] = $tempImport_dot;
+                                               $imgConf['file.']['treatIdAsReference'] = $tempTreatIdAsReference;
                                        } elseif (isset($this->cObj->image_compression[$image_compression])) {
                                                $imgConf['file.']['params'] .= ' ' . $this->cObj->image_compression[$image_compression]['params'];
                                                $imgConf['file.']['ext'] = $this->cObj->image_compression[$image_compression]['ext'];
@@ -712,7 +738,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                }
                                if ($titleInLink && !$titleInLinkAndImg) {
                                        // Check if the image will be linked
-                                       $link = $this->cObj->imageLinkWrap('', $totalImagePath, $imgConf['imageLinkWrap.']);
+                                       $link = $this->cObj->imageLinkWrap('', $this->cObj->getCurrentFile() ?: $totalImagePath, $imgConf['imageLinkWrap.']);
                                        if ($link) {
                                                // Title in A-tag only (set above: ATagParams), not in IMG-tag
                                                unset($imgConf['titleText']);
@@ -720,25 +746,25 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                                $imgConf['emptyTitleHandling'] = 'removeAttr';
                                        }
                                }
-                               $imgsTag[$imgKey] = $this->cObj->IMAGE($imgConf);
+                               $imgsTag[$imgKey] = $this->cObj->cObjGetSingle('IMAGE', $imgConf);
                        } else {
                                // currentValKey !!!
-                               $imgsTag[$imgKey] = $this->cObj->IMAGE(array('file' => $totalImagePath));
+                               $imgsTag[$imgKey] = $this->cObj->cObjGetSingle('IMAGE', array('file' => $totalImagePath));
                        }
                        // Restore our ATagParams
-                       $GLOBALS['TSFE']->ATagParams = $oldATagParms;
+                       $this->frontendController->ATagParams = $oldATagParms;
                        // Store the original filepath
-                       $origImages[$imgKey] = $GLOBALS['TSFE']->lastImageInfo;
-                       if ($GLOBALS['TSFE']->lastImageInfo[0] == 0) {
+                       $origImages[$imgKey] = $this->frontendController->lastImageInfo;
+                       if ($this->frontendController->lastImageInfo[0] == 0) {
                                $imageRowsFinalWidths[(int)floor($a / $colCount)] += $this->cObj->data['imagewidth'];
                        } else {
-                               $imageRowsFinalWidths[(int)floor($a / $colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
+                               $imageRowsFinalWidths[(int)floor($a / $colCount)] += $this->frontendController->lastImageInfo[0];
                        }
                }
                // How much space will the image-block occupy?
                $imageBlockWidth = max($imageRowsFinalWidths) + $colspacing * ($colCount - 1) + $colCount * $border * ($borderSpace + $borderThickness) * 2;
-               $GLOBALS['TSFE']->register['rowwidth'] = $imageBlockWidth;
-               $GLOBALS['TSFE']->register['rowWidthPlusTextMargin'] = $imageBlockWidth + $textMargin;
+               $this->frontendController->register['rowwidth'] = $imageBlockWidth;
+               $this->frontendController->register['rowWidthPlusTextMargin'] = $imageBlockWidth + $textMargin;
                // noRows is in fact just one ROW, with the amount of columns specified, where the images are placed in.
                // noCols is just one COLUMN, each images placed side by side on each row
                $noRows = $this->cObj->stdWrap($conf['noRows'], $conf['noRows.']);
@@ -755,7 +781,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                if (!is_array($conf['editIcons.'])) {
                        $conf['editIcons.'] = array();
                }
-               $editIconsHTML = $conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin ? $this->cObj->editIcons('', $conf['editIcons'], $conf['editIcons.']) : '';
+               $editIconsHTML = $conf['editIcons'] && $this->frontendController->beUserLogin ? $this->cObj->editIcons('', $conf['editIcons'], $conf['editIcons.']) : '';
                // If noRows, we need multiple imagecolumn wraps
                $imageWrapCols = 1;
                if ($noRows) {
@@ -776,13 +802,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        if (isset($conf['addClassesCol.'])) {
                                $addClassesCol = $this->cObj->stdWrap($addClassesCol, $conf['addClassesCol.']);
                        }
-                       $addClassesColConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesCol' => $addClassesCol), $colCount);
+                       $addClassesColConf = $this->frontendController->tmpl->splitConfArray(array('addClassesCol' => $addClassesCol), $colCount);
                        // Apply optionSplit to the list of classes that we want to add to each image
                        $addClassesImage = $conf['addClassesImage'];
                        if (isset($conf['addClassesImage.'])) {
                                $addClassesImage = $this->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
                        }
-                       $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $imagesInColumns);
+                       $addClassesImageConf = $this->frontendController->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $imagesInColumns);
                        $rows = array();
                        $currentImage = 0;
                        // Set the class for the caption (split or global)
@@ -807,8 +833,15 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                                // Set the key of the current image
                                                $imageKey = $currentImage + $imgStart;
                                                // Register IMAGE_NUM_CURRENT for the caption
-                                               $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imageKey;
+                                               $this->frontendController->register['IMAGE_NUM_CURRENT'] = $imageKey;
                                                $this->cObj->data[$this->cObj->currentValKey] = $origImages[$imageKey]['origFile'];
+                                               if (MathUtility::canBeInterpretedAsInteger($imgs[$imageKey])) {
+                                                       $this->initializeCurrentFileInContentObjectRenderer((int)$imgs[$imageKey], $imgListContainsReferenceUids);
+                                               } elseif (!isset($imgs[$imageKey])) {
+                                                       // If not all columns in the last row are filled $imageKey gets larger than
+                                                       // the array. In that case we clear the current file.
+                                                       $this->cObj->setCurrentFile(NULL);
+                                               }
                                                // Get the image if not an empty cell
                                                if (isset($imgsTag[$imageKey])) {
                                                        $image = $this->cObj->stdWrap($imgsTag[$imageKey], $conf['imgTagStdWrap.']);
@@ -865,9 +898,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                }
                        }
                        // Set the margin for image + text, no wrap always to avoid multiple stylesheets
-                       $noWrapMargin = (int) (($maxWInText ? $maxWInText : $fiftyPercentWidthInText) + intval(
-                               $this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.'])
-                       ));
+                       $noWrapMargin = (int)(($maxWInText ? $maxWInText : $fiftyPercentWidthInText) + (int)$this->cObj->stdWrap($conf['textMargin'], $conf['textMargin.']));
                        $this->addPageStyle('.csc-textpic-intext-right-nowrap .csc-textpic-text', 'margin-right: ' . $noWrapMargin . 'px;');
                        $this->addPageStyle('.csc-textpic-intext-left-nowrap .csc-textpic-text', 'margin-left: ' . $noWrapMargin . 'px;');
                        // Beside Text where the image block width is not equal to maxW
@@ -884,7 +915,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        // Add the border class if needed
                        if ($border) {
-                               $classes[] = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
+                               $classes[] = $conf['borderClass'] ?: 'csc-textpic-border';
                        }
                        // Add the class for equal height if needed
                        if ($equalHeight) {
@@ -905,7 +936,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        if (isset($conf['addClassesImage.'])) {
                                $addClassesImage = $this->cObj->stdWrap($addClassesImage, $conf['addClassesImage.']);
                        }
-                       $addClassesImageConf = $GLOBALS['TSFE']->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $colCount);
+                       $addClassesImageConf = $this->frontendController->tmpl->splitConfArray(array('addClassesImage' => $addClassesImage), $colCount);
                        // Render the images
                        $images = '';
                        for ($c = 0; $c < $imageWrapCols; $c++) {
@@ -930,12 +961,15 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                        } else {
                                                $imageSpace = $origImages[$imgKey][0] + $border * ($borderSpace + $borderThickness) * 2;
                                        }
-                                       $GLOBALS['TSFE']->register['IMAGE_NUM'] = $imgKey;
-                                       $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $imgKey;
-                                       $GLOBALS['TSFE']->register['ORIG_FILENAME'] = $origImages[$imgKey]['origFile'];
-                                       $GLOBALS['TSFE']->register['imagewidth'] = $origImages[$imgKey][0];
-                                       $GLOBALS['TSFE']->register['imagespace'] = $imageSpace;
-                                       $GLOBALS['TSFE']->register['imageheight'] = $origImages[$imgKey][1];
+                                       $this->frontendController->register['IMAGE_NUM'] = $imgKey;
+                                       $this->frontendController->register['IMAGE_NUM_CURRENT'] = $imgKey;
+                                       $this->frontendController->register['ORIG_FILENAME'] = $origImages[$imgKey]['origFile'];
+                                       $this->frontendController->register['imagewidth'] = $origImages[$imgKey][0];
+                                       $this->frontendController->register['imagespace'] = $imageSpace;
+                                       $this->frontendController->register['imageheight'] = $origImages[$imgKey][1];
+                                       if (MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
+                                               $this->initializeCurrentFileInContentObjectRenderer(intval($imgs[$imgKey]), $imgListContainsReferenceUids);
+                                       }
                                        if ($imageSpace > $maxImageSpace) {
                                                $maxImageSpace = $imageSpace;
                                        }
@@ -958,7 +992,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                        } else {
                                                $allRows .= $thisImage;
                                        }
-                                       $GLOBALS['TSFE']->register['columnwidth'] = $maxImageSpace + $tmpColspacing;
+                                       $this->frontendController->register['columnwidth'] = $maxImageSpace + $tmpColspacing;
                                        // Close this row at the end (colCount), or the last row at the final end
                                        if ($separateRows && $i + 1 == count($imgsTag)) {
                                                // Close the very last row with either normal configuration or lastRow stdWrap
@@ -999,7 +1033,7 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        }
                        $borderClass = '';
                        if ($border) {
-                               $borderClass = $conf['borderClass'] ? $conf['borderClass'] : 'csc-textpic-border';
+                               $borderClass = $conf['borderClass'] ?: 'csc-textpic-border';
                        }
                        // Multiple classes with all properties, to be styled in CSS
                        $class = '';
@@ -1023,20 +1057,55 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                                $imgWrapWidth = $imageBlockWidth;
                        }
                        // Wrap around the whole image block
-                       $GLOBALS['TSFE']->register['totalwidth'] = $imgWrapWidth;
+                       $this->frontendController->register['totalwidth'] = $imgWrapWidth;
                        if ($imgWrapWidth) {
                                $images = $this->cObj->stdWrap($images, $conf['imageStdWrap.']);
                        } else {
                                $images = $this->cObj->stdWrap($images, $conf['imageStdWrapNoWidth.']);
                        }
                }
-               $output = $this->cObj->cObjGetSingle($conf['layout'], $conf['layout.']);
-               $output = str_replace('###TEXT###', $content, $output);
-               $output = str_replace('###IMAGES###', $images, $output);
-               $output = str_replace('###CLASSES###', $class, $output);
+
+               $output = str_replace(
+                       array(
+                               '###TEXT###',
+                               '###IMAGES###',
+                               '###CLASSES###'
+                       ),
+                       array(
+                               $content,
+                               $images,
+                               $class
+                       ),
+                       $this->cObj->cObjGetSingle($conf['layout'], $conf['layout.'])
+               );
+
+               if ($restoreRegisters) {
+                       $this->cObj->cObjGetSingle('RESTORE_REGISTER', array());
+               }
+
                return $output;
        }
 
+       /**
+        * Loads the file / file reference object and sets it in the
+        * currentFile property of the ContentObjectRenderer.
+        *
+        * This makes the file data available during image rendering.
+        *
+        * @param int $fileUid The UID of the file or file reference (depending on $treatAsReference) that should be loaded.
+        * @param bool $treatAsReference If TRUE the given UID will be used to load a file reference otherwise it will be used to load a regular file.
+        * @return void
+        */
+       protected function initializeCurrentFileInContentObjectRenderer($fileUid, $treatAsReference) {
+               $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
+               if ($treatAsReference) {
+                       $imageFile = $resourceFactory->getFileReferenceObject($fileUid);
+               } else {
+                       $imageFile = $resourceFactory->getFileObject($fileUid);
+               }
+               $this->cObj->setCurrentFile($imageFile);
+       }
+
        /***********************************
         * Rendering of Content Element properties
         ***********************************/
@@ -1057,13 +1126,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                        return $hookObject->renderSpace($content, $configuration);
                }
                if (isset($configuration['space']) && in_array($configuration['space'], array('before', 'after'))) {
-                       $constant = (int) $configuration['constant'];
+                       $constant = (int)$configuration['constant'];
                        if ($configuration['space'] === 'before') {
                                $value = $constant + $this->cObj->data['spaceBefore'];
-                               $declaration = 'margin-top: ' . $value . 'px;';
+                               $declaration = 'margin-top: ' . $value . 'px !important;';
                        } else {
                                $value = $constant + $this->cObj->data['spaceAfter'];
-                               $declaration = 'margin-bottom: ' . $value . 'px;';
+                               $declaration = 'margin-bottom: ' . $value . 'px !important;';
                        }
                        if (!empty($value)) {
                                if ($configuration['classStdWrap.']) {
@@ -1090,11 +1159,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         *
         * @param array $links
         * @param string $fileName
-        * @param boolean $useSpaces
-        * @param boolean $cutFileExtension
+        * @param bool $useSpaces
+        * @param bool $cutFileExtension
         * @return array modified array with new link text
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, is done by default in pure TypoScript
         */
        protected function beautifyFileLink(array $links, $fileName, $useSpaces = FALSE, $cutFileExtension = FALSE) {
+               GeneralUtility::logDeprecatedFunction();
                $linkText = $fileName;
                if ($useSpaces) {
                        $linkText = str_replace('_', ' ', $linkText);
@@ -1111,21 +1182,20 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * Returns table attributes for uploads / tables.
         *
         * @param array $conf TypoScript configuration array
-        * @param integer $type The "layout" type
+        * @param int $type The "layout" type
         * @return array Array with attributes inside.
-        * @todo Define visibility
         */
        public function getTableAttributes($conf, $type) {
                // Initializing:
                $tableTagParams_conf = $conf['tableParams_' . $type . '.'];
-               $border = $this->cObj->data['table_border'] ? intval($this->cObj->data['table_border']) : $tableTagParams_conf['border'];
-               $cellSpacing = $this->cObj->data['table_cellspacing'] ? intval($this->cObj->data['table_cellspacing']) : $tableTagParams_conf['cellspacing'];
-               $cellPadding = $this->cObj->data['table_cellpadding'] ? intval($this->cObj->data['table_cellpadding']) : $tableTagParams_conf['cellpadding'];
+               $border = $this->cObj->data['table_border'] ? (int)$this->cObj->data['table_border'] : $tableTagParams_conf['border'];
+               $cellSpacing = $this->cObj->data['table_cellspacing'] ? (int)$this->cObj->data['table_cellspacing'] : $tableTagParams_conf['cellspacing'];
+               $cellPadding = $this->cObj->data['table_cellpadding'] ? (int)$this->cObj->data['table_cellpadding'] : $tableTagParams_conf['cellpadding'];
                $summary = trim(htmlspecialchars($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'acctables_summary')));
                // Create table attributes and classes array:
                $tableTagParams = ($classes = array());
                // Table attributes for all doctypes except HTML5
-               if ($GLOBALS['TSFE']->config['config']['doctype'] !== 'html5') {
+               if ($this->frontendController->config['config']['doctype'] !== 'html5') {
                        $tableTagParams['border'] = $border;
                        $tableTagParams['cellspacing'] = $cellSpacing;
                        $tableTagParams['cellpadding'] = $cellPadding;
@@ -1181,11 +1251,11 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * @return void
         */
        protected function addPageStyle($selector, $declaration) {
-               if (!isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'])) {
-                       $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'] = array();
+               if (!isset($this->frontendController->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'])) {
+                       $this->frontendController->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'] = array();
                }
-               if (!isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector])) {
-                       $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector] = TAB . $selector . ' { ' . $declaration . ' }';
+               if (!isset($this->frontendController->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector])) {
+                       $this->frontendController->tmpl->setup['plugin.']['tx_cssstyledcontent.']['_CSS_PAGE_STYLE'][$selector] = TAB . $selector . ' { ' . $declaration . ' }';
                }
        }
 
@@ -1193,14 +1263,12 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
         * Returns an object reference to the hook object if any
         *
         * @param string $functionName Name of the function you want to call / hook key
-        * @return object Hook object, if any. Otherwise NULL.
-        * @todo Define visibility
+        * @return object|NULL Hook object, if any. Otherwise NULL.
         */
        public function hookRequest($functionName) {
-               global $TYPO3_CONF_VARS;
                // Hook: menuConfig_preProcessModMenu
-               if ($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]) {
-                       $hookObj = GeneralUtility::getUserObj($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]);
+               if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]) {
+                       $hookObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]);
                        if (method_exists($hookObj, $functionName)) {
                                $hookObj->pObj = $this;
                                return $hookObj;
@@ -1208,5 +1276,13 @@ class CssStyledContentController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlug
                }
        }
 
+       /**
+        * Get the ResourceFactory
+        *
+        * @return \TYPO3\CMS\Core\Resource\ResourceFactory
+        */
+       protected function getResourceFactory() {
+               return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
+       }
+
 }
-?>