TYPO3 CMS  TYPO3_6-2
CropViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is part of the TYPO3 project - inspiring people to share! *
6  * *
7  * TYPO3 is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License version 2 as published by *
9  * the Free Software Foundation. *
10  * *
11  * This script is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14  * Public License for more details. *
15  * */
58 
62  protected $contentObject;
63 
67  protected $tsfeBackup;
68 
73 
78  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
79  $this->configurationManager = $configurationManager;
80  $this->contentObject = $this->configurationManager->getContentObject();
81  }
82 
92  public function render($maxCharacters, $append = '...', $respectWordBoundaries = TRUE, $respectHtml = TRUE) {
93  $stringToTruncate = $this->renderChildren();
94  if (TYPO3_MODE === 'BE') {
96  }
97  if ($respectHtml) {
98  $content = $this->contentObject->cropHTML($stringToTruncate, $maxCharacters . '|' . $append . '|' . $respectWordBoundaries);
99  } else {
100  $content = $this->contentObject->crop($stringToTruncate, $maxCharacters . '|' . $append . '|' . $respectWordBoundaries);
101  }
102  if (TYPO3_MODE === 'BE') {
103  $this->resetFrontendEnvironment();
104  }
105  return $content;
106  }
107 
114  protected function simulateFrontendEnvironment() {
115  $this->tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL;
116  $GLOBALS['TSFE'] = new \stdClass();
117  // preparing csConvObj
118  if (!is_object($GLOBALS['TSFE']->csConvObj)) {
119  if (is_object($GLOBALS['LANG'])) {
120  $GLOBALS['TSFE']->csConvObj = $GLOBALS['LANG']->csConvObj;
121  } else {
122  $GLOBALS['TSFE']->csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
123  }
124  }
125  // preparing renderCharset
126  if (!is_object($GLOBALS['TSFE']->renderCharset)) {
127  if (is_object($GLOBALS['LANG'])) {
128  $GLOBALS['TSFE']->renderCharset = $GLOBALS['LANG']->charSet;
129  } else {
130  $GLOBALS['TSFE']->renderCharset = 'utf-8';
131  }
132  }
133  }
134 
141  protected function resetFrontendEnvironment() {
142  $GLOBALS['TSFE'] = $this->tsfeBackup;
143  }
144 }
render($maxCharacters, $append='...', $respectWordBoundaries=TRUE, $respectHtml=TRUE)
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
const TYPO3_MODE
Definition: init.php:40
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]