/** * Extends the getData()-Method of ContentObjectRenderer to process more/other commands * * @param string $getDataString Full content of getData-request e.g. "TSFE:id // field:title // field:uid * @param array $fields Current field-array * @param string $sectionValue Currently examined section value of the getData request e.g. "field:title * @param string $returnValue Current returnValue that was processed so far by getData * @param ContentObjectRenderer $parentObject Parent content object * * @return string Get data result */ public function getDataExtension($getDataString, array $fields, $sectionValue, $returnValue, ContentObjectRenderer &$parentObject) { $parts = explode(':', $getDataString); if (isset($parts[0]) && isset($parts[1]) && $parts[0] === 'fp') { $fileObject = $parentObject->getCurrentFile(); if (!$fileObject instanceof FileReference) { return $returnValue; } $originalFile = $fileObject->getOriginalFile(); switch ($parts[1]) { case 'x': case 'y': $metaData = $originalFile->_getMetaData(); return $metaData['focus_point_' . $parts[1]] / 100; case 'xp': case 'yp': $metaData = $originalFile->_getMetaData(); return (double) $metaData['focus_point_' . substr($parts[1], 0, 1)]; case 'xp_positive': case 'yp_positive': $metaData = $originalFile->_getMetaData(); return ((double) $metaData['focus_point_' . substr($parts[1], 0, 1)] + 100) / 2; case 'w': case 'h': $fileName = GeneralUtility::getFileAbsFileName($fileObject->getPublicUrl(true)); if (file_exists($fileName)) { $sizes = getimagesize($fileName); return $sizes[$parts[1] == 'w' ? 0 : 1]; } break; } } return $returnValue; }
/** * Renders the application defined cObject FORM * which overrides the TYPO3 default cObject FORM * * Convert FORM to COA_INT - COA_INT.10 = FORM_INT * If FORM_INT is also dedected by the ContentObjectRenderer, and now * the Extbaseplugin "Form" is initalized. At this time the * controller "Frontend" action "execute" do the rest. * * @param string $typoScriptObjectName Name of the object * @param array $typoScript TS configuration for this cObject * @param string $typoScriptKey A string label used for the internal debugging tracking. * @param ContentObjectRenderer $contentObject reference * @return string HTML output */ public function cObjGetSingleExt($typoScriptObjectName, array $typoScript, $typoScriptKey, ContentObjectRenderer $contentObject) { $content = ''; if ($typoScriptObjectName === 'FORM' && !empty($typoScript['useDefaultContentObject']) && ExtensionManagementUtility::isLoaded('compatibility6')) { $content = $contentObject->getContentObject($typoScriptObjectName)->render($typoScript); } elseif ($typoScriptObjectName === 'FORM') { $mergedTypoScript = null; if ($contentObject->data['CType'] === 'mailform') { $bodytext = $contentObject->data['bodytext']; /** @var $typoScriptParser TypoScriptParser */ $typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class); $typoScriptParser->parse($bodytext); $mergedTypoScript = (array) $typoScriptParser->setup; ArrayUtility::mergeRecursiveWithOverrule($mergedTypoScript, $typoScript); // Disables content elements since TypoScript is handled that could contain insecure settings: $mergedTypoScript[Configuration::DISABLE_CONTENT_ELEMENT_RENDERING] = true; } $newTypoScript = array('10' => 'FORM_INT', '10.' => is_array($mergedTypoScript) ? $mergedTypoScript : $typoScript); $content = $contentObject->cObjGetSingle('COA_INT', $newTypoScript); // Only apply stdWrap to TypoScript that was NOT created by the wizard: if (isset($typoScript['stdWrap.'])) { $content = $contentObject->stdWrap($content, $typoScript['stdWrap.']); } } elseif ($typoScriptObjectName === 'FORM_INT') { $extbase = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Core\Bootstrap::class); $content = $extbase->run('', array('pluginName' => 'Form', 'extensionName' => 'Form', 'vendorName' => 'TYPO3\\CMS', 'controller' => 'Frontend', 'action' => 'show', 'settings' => array('typoscript' => $typoScript), 'persistence' => array(), 'view' => array())); } return $content; }
/** * Fetches records from the database as an array * * @param ContentObjectRenderer $cObj The data of the content element or page * @param array $contentObjectConfiguration The configuration of Content Object * @param array $processorConfiguration The configuration of this processor * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) * * @return array the processed data as key/value store */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } // the table to query, if none given, exit $tableName = $cObj->stdWrapValue('table', $processorConfiguration); if (empty($tableName)) { return $processedData; } if (isset($processorConfiguration['table.'])) { unset($processorConfiguration['table.']); } if (isset($processorConfiguration['table'])) { unset($processorConfiguration['table']); } // The variable to be used within the result $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'records'); // Execute a SQL statement to fetch the records $records = $cObj->getRecords($tableName, $processorConfiguration); $processedRecordVariables = array(); foreach ($records as $key => $record) { /** @var ContentObjectRenderer $recordContentObjectRenderer */ $recordContentObjectRenderer = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $recordContentObjectRenderer->start($record, $tableName); $processedRecordVariables[$key] = array('data' => $record); $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]); } $processedData[$targetVariableName] = $processedRecordVariables; return $processedData; }
/** * Generate variable Get string from classMappings array with the same key as the "layout" in the content * * @param ContentObjectRenderer $cObj The data of the content element or page * @param array $contentObjectConfiguration The configuration of Content Object * @param array $processorConfiguration The configuration of this processor * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) * @return array the processed data as key/value store */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } // set targetvariable, default "layoutClass" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'layoutClass'); $processedData[$targetVariableName] = ''; // set fieldname, default "layout" $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'layout'); if (isset($cObj->data[$fieldName]) && is_array($processorConfiguration['classMappings.'])) { $layoutClassMappings = GeneralUtility::removeDotsFromTS($processorConfiguration['classMappings.']); $processedData[$targetVariableName] = $layoutClassMappings[$cObj->data[$fieldName]]; } // if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] if ($targetVariableName == 'settings') { if (is_array($contentObjectConfiguration['settings.'])) { $convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); foreach ($convertedConf as $key => $value) { if (!isset($processedData[$targetVariableName][$key]) || $processedData[$targetVariableName][$key] == false) { $processedData[$targetVariableName][$key] = $value; } } } } return $processedData; }
/** * @test */ public function respectHtmlCanBeDisabled() { $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content')); GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject); $actualResult = $this->viewHelper->render(123, '...', true, false); $this->assertEquals('Cropped Content', $actualResult); }
/** * Process flexform field data to an array * * @param ContentObjectRenderer $cObj The data of the content element or page * @param array $contentObjectConfiguration The configuration of Content Object * @param array $processorConfiguration The configuration of this processor * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) * @return array the processed data as key/value store */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } // set targetvariable, default "flexform" $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'flexform'); // set fieldname, default "pi_flexform" $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'pi_flexform'); // parse flexform $flexformService = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\FlexFormService'); $processedData[$targetVariableName] = $flexformService->convertFlexFormContentToArray($cObj->data[$fieldName]); // if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] if ($targetVariableName == 'settings') { if (is_array($contentObjectConfiguration['settings.'])) { $convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); foreach ($convertedConf as $key => $value) { if (!isset($processedData[$targetVariableName][$key]) || $processedData[$targetVariableName][$key] == false) { $processedData[$targetVariableName][$key] = $value; } } } } return $processedData; }
/** * @param array $files * @param boolean $onlyProperties * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception * @return array|NULL */ public function preprocessImages($files, $onlyProperties = FALSE) { if (TRUE === empty($files)) { return NULL; } if ('BE' === TYPO3_MODE) { $this->simulateFrontendEnvironment(); } $setup = array('width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minWidth'], 'minH' => $this->arguments['minHeight'], 'maxW' => $this->arguments['maxWidth'], 'maxH' => $this->arguments['maxHeight'], 'treatIdAsReference' => FALSE); $images = array(); foreach ($files as $file) { $imageInfo = $this->contentObject->getImgResource($file->getUid(), $setup); $GLOBALS['TSFE']->lastImageInfo = $imageInfo; if (FALSE === is_array($imageInfo)) { throw new Exception('Could not get image resource for "' . htmlspecialchars($file->getCombinedIdentifier()) . '".', 1253191060); } if ((double) substr(TYPO3_version, 0, 3) < 7.1) { $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]); } else { $imageInfo[3] = GraphicalFunctions::pngToGifByImagemagick($imageInfo[3]); } $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]); $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3]; $imageSource = $GLOBALS['TSFE']->absRefPrefix . GeneralUtility::rawUrlEncodeFP($imageInfo[3]); if (TRUE === $onlyProperties) { $file = ResourceUtility::getFileArray($file); } $images[] = array('info' => $imageInfo, 'source' => $imageSource, 'file' => $file); } if ('BE' === TYPO3_MODE) { $this->resetFrontendEnvironment(); } return $images; }
/** * Render URL from typolink configuration * * @param string $parameter * @param array $configuration * @return string Rendered page URI */ public function render($parameter = null, $configuration = array()) { $typoLinkConfiguration = array('parameter' => $parameter ? $parameter : $this->contentObject->data['pid']); if (!empty($configuration)) { ArrayUtility::mergeRecursiveWithOverrule($typoLinkConfiguration, $configuration); } return $this->contentObject->typoLink_URL($typoLinkConfiguration); }
/** * @test */ public function convertsCommaSeparatedListFromValueToSerializedArrayOfTrimmedValues() { $list = 'abc, def, ghi, jkl, mno, pqr, stu, vwx, yz'; $expected = 'a:9:{i:0;s:3:"abc";i:1;s:3:"def";i:2;s:3:"ghi";i:3;s:3:"jkl";i:4;s:3:"mno";i:5;s:3:"pqr";i:6;s:3:"stu";i:7;s:3:"vwx";i:8;s:2:"yz";}'; $this->contentObject->start(array()); $actual = $this->contentObject->cObjGetSingle(\Tx_Solr_contentobject_Multivalue::CONTENT_OBJECT_NAME, array('value' => $list, 'separator' => ',')); $this->assertEquals($expected, $actual); }
/** * Gets closing time from a record * * @param string $table Table name * @param int $uid UID of the record * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj COBJECT * @return int Closing timestamp */ function getCloseTime($table, $uid, &$cObj) { $result = 0; $recs = $this->getDatabaseConnection()->exec_SELECTgetRows('disable_comments,comments_closetime', $table, 'uid=' . intval($uid) . $cObj->enableFields($table)); if (count($recs)) { $result = $recs[0]['disable_comments'] ? 0 : ($recs[0]['comments_closetime'] ? $recs[0]['comments_closetime'] : PHP_INT_MAX); } return $result; }
/** * Function used by TypoScript "parseFunc" to process links in the bodytext. * Extracts the link and shows it in plain text in a parathesis next to the link text. If link was relative the site URL was prepended. * * @param string $content : Empty, ignore. * @param array $conf : TypoScript parameters * * @return string Processed output. * @see parseBody() */ function atag_to_http($content, $conf) { $this->conf = $conf; $theLink = trim($this->cObj->parameters['href']); if (strtolower(substr($theLink, 0, 7)) == 'mailto:') { $theLink = substr($theLink, 7); } return $this->cObj->getCurrentVal() . ' ( ' . $theLink . ' )'; }
/** * Initializes the instance of this class. This constructir sets starting * point for the sitemap to the current page id */ public function __construct() { $this->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $this->cObj->start(array()); $this->offset = max(0, (int) GeneralUtility::_GET('offset')); $this->limit = max(0, (int) GeneralUtility::_GET('limit')); if ($this->limit <= 0) { $this->limit = 50000; } $this->createRenderer(); }
/** * Converts a given unix timestamp to a human readable date * * @param array $arguments * @return string */ public function execute(array $arguments = array()) { $content = ''; if (count($arguments) > 1) { $this->dateFormat['date'] = $arguments[1]; } if (is_numeric($arguments[0])) { $content = $this->contentObject->stdWrap($arguments[0], $this->dateFormat); } return $content; }
/** * Initializes the instance of this class. This constructir sets starting * point for the sitemap to the current page id */ public function __construct() { $this->cObj = GeneralUtility::makeInstance('tslib_cObj'); $this->cObj->start(array()); $this->offset = max(0, intval(GeneralUtility::_GET('offset'))); $this->limit = max(0, intval(GeneralUtility::_GET('limit'))); if ($this->limit <= 0) { $this->limit = 50000; } $this->createRenderer(); }
/** * Manipulate values through TypoScript before rendering * * @param Answer $answer * @param string $type "createAction", "confirmationAction", "sender", "receiver" * @return string */ public function render(Answer $answer, $type) { $value = $this->renderChildren(); if ($answer->getField()) { if (!empty($this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker()])) { $this->contentObjectRenderer->start($answer->_getProperties()); $value = $this->contentObjectRenderer->cObjGetSingle($this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker()], $this->typoScriptContext[$this->typeToTsType[$type] . '.'][$answer->getField()->getMarker() . '.']); } } return $value; }
/** * @param string $name * @param array $configuration * @param string $typoscriptKey * @param ContentObjectRenderer $contentObject * @return string */ public function cObjGetSingleExt($name, array $configuration, $typoscriptKey, $contentObject) { $result = []; foreach ($configuration as $key => $contentObjectName) { if (strpos($key, '.') === false) { $conf = $configuration[$key . '.']; $content = $contentObject->cObjGetSingle($contentObjectName, $conf, $contentObjectName); $result[$key] = str_replace(array("\r", "\n", "\t"), '', $content); } } return json_encode($result); }
/** * Converts a given unix timestamp to a human readable date * * @param array $arguments * @return string */ public function execute(array $arguments = array()) { $content = ''; if (count($arguments) > 1) { $this->dateFormat = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['general.']['dateFormat.']; $this->dateFormat['date'] = $arguments[1]; } if (is_numeric($arguments[0])) { $content = $this->contentObject->stdWrap($arguments[0], $this->dateFormat); } return $content; }
/** * Sets up this testcase */ protected function setUp() { parent::setUp(); // Allow objects until 100 levels deep when executing the stdWrap $GLOBALS['TSFE'] = new \stdClass(); $GLOBALS['TSFE']->cObjectDepthCounter = 100; $this->abstractPlugin = new \TYPO3\CMS\Frontend\Plugin\AbstractPlugin(); $contentObjectRenderer = new ContentObjectRenderer(); $contentObjectRenderer->setContentObjectClassMap(array('TEXT' => TextContentObject::class)); $this->abstractPlugin->cObj = $contentObjectRenderer; $this->defaultPiVars = $this->abstractPlugin->piVars; }
/** * Process data of a record to resolve File objects to the view * * @param ContentObjectRenderer $cObj The data of the content element or page * @param array $contentObjectConfiguration The configuration of Content Object * @param array $processorConfiguration The configuration of this processor * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) * @return array the processed data as key/value store */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } // gather data /** @var FileCollector $fileCollector */ $fileCollector = GeneralUtility::makeInstance(FileCollector::class); $settings = $contentObjectConfiguration['settings.']['display_mode.']; // references / relations if (!empty($processorConfiguration['references.'])) { $referenceConfiguration = $processorConfiguration['references.']; $relationField = $cObj->stdWrapValue('fieldName', $referenceConfiguration); // If no reference fieldName is set, there's nothing to do if (!empty($relationField)) { // Fetch the references of the default element $relationTable = $cObj->stdWrapValue('table', $referenceConfiguration, $cObj->getCurrentTable()); if (!empty($relationTable)) { $fileCollector->addFilesFromRelation($relationTable, $relationField, $cObj->data); } } } // Get files from database-record $files = $fileCollector->getFiles(); if (count($files) > 0) { // Use ImageService for further processing $imageService = self::getImageService(); foreach ($files as $file) { $displayMode = $file->getReferenceProperty('display_mode'); $image = $imageService->getImage(null, $file, true); $processingInstructions = ['crop' => $image->getProperty('crop')]; $maxWidth = intval($contentObjectConfiguration['settings.']['display_mode_maxWidth.'][$displayMode]); if ($maxWidth > 0) { $processingInstructions['maxWidth'] = $maxWidth; } $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); $styleAttribute = 'background-image:url(\'' . $imageService->getImageUri($processedImage) . '\');'; switch ($displayMode) { case '1': $targetVariableName = 'layoutMedia'; break; default: $targetVariableName = 'backgroundMedia'; break; } $processedData[$targetVariableName]['fileReference'] = $file; $processedData[$targetVariableName]['class'] = $settings[$displayMode]; $processedData[$targetVariableName]['style'] = $styleAttribute; } } //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($files, '$files'); return $processedData; }
/** * Set up */ protected function setUp() { /** @var TypoScriptFrontendController $tsfe */ $tsfe = $this->getMock(TypoScriptFrontendController::class, array('dummy'), array(), '', false); $tsfe->tmpl = $this->getMock(TemplateService::class, array('dummy')); $tsfe->config = array(); $tsfe->page = array(); $tsfe->sys_page = $this->getMock(PageRepository::class, array('getRawRecord')); $GLOBALS['TSFE'] = $tsfe; $contentObjectRenderer = new ContentObjectRenderer(); $contentObjectRenderer->setContentObjectClassMap(array('CASE' => CaseContentObject::class, 'TEXT' => TextContentObject::class)); $this->subject = new CaseContentObject($contentObjectRenderer); }
/** * @param int $startPage * @param array $basePages * @param SitemapController $obj * * @return array */ public function getRecords($startPage, $basePages, SitemapController $obj) { $nodes = array(); foreach ($basePages as $uid) { if ($this->currentLanguageUid) { $fields = $this->cObject->enableFields('pages_language_overlay'); $overlay = $this->database->exec_SELECTgetSingleRow('uid', 'pages_language_overlay', ' pid=' . intval($uid) . ' AND sys_language_uid=' . $this->currentLanguageUid . $fields); if (!is_array($overlay)) { continue; } } // Build URL $url = $obj->getUriBuilder()->setTargetPageUid($uid)->build(); // can't generate a valid url if (!strlen($url)) { continue; } // Get Record $record = BackendUtility::getRecord('pages', $uid); // exclude Doctypes if (in_array($record['doktype'], array(4))) { continue; } // Check FE Access if ($record['fe_group'] != 0) { continue; } $rootLineList = $GLOBALS['TSFE']->sys_page->getRootLine($record['uid']); $addToNode = true; foreach ($rootLineList as $rootPage) { if ($rootPage['extendToSubpages'] == 1 && $rootPage['fe_group'] != 0) { $addToNode = false; break; } } if ($addToNode == false) { continue; } // Build Node $node = new Node(); $node->setLoc($url); $node->setPriority($this->getPriority($startPage, $record)); $node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout'])); $node->setLastmod($this->getModifiedDate($record)); #$geo = new Geo(); #$geo->setFormat('kml'); #$node->setGeo($geo); $nodes[] = $node; } return $nodes; }
/** * Process field data to split in an array * * @param ContentObjectRenderer $cObj The data of the content element or page * @param array $contentObjectConfiguration The configuration of Content Object * @param array $processorConfiguration The configuration of this processor * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View) * @return array the processed data as key/value store */ public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData) { if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } // The field name to process $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration); if (empty($fieldName)) { return $processedData; } $originalValue = $cObj->data[$fieldName]; // Set the target variable $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $fieldName); // Set the delimiter which is "LF" by default $delimiter = $cObj->stdWrapValue('delimiter', $processorConfiguration, LF); // Filter integers $filterIntegers = (bool) $cObj->stdWrapValue('filterIntegers', $processorConfiguration, false); // Filter unique $filterUnique = (bool) $cObj->stdWrapValue('filterUnique', $processorConfiguration, false); // Remove empty entries $removeEmptyEntries = (bool) $cObj->stdWrapValue('removeEmptyEntries', $processorConfiguration, false); if ($filterIntegers === true) { $processedData[$targetVariableName] = GeneralUtility::intExplode($delimiter, $originalValue, $removeEmptyEntries); } else { $processedData[$targetVariableName] = GeneralUtility::trimExplode($delimiter, $originalValue, $removeEmptyEntries); } if ($filterUnique === true) { $processedData[$targetVariableName] = array_unique($processedData[$targetVariableName]); } return $processedData; }
/** * Set up */ protected function setUp() { $templateService = $this->getMock(TemplateService::class, array('getFileName', 'linkData')); $this->tsfe = $this->getMock(TypoScriptFrontendController::class, array('dummy'), array(), '', false); $this->tsfe->tmpl = $templateService; $this->tsfe->config = array(); $this->tsfe->page = array(); $sysPageMock = $this->getMock(PageRepository::class, array('getRawRecord')); $this->tsfe->sys_page = $sysPageMock; $GLOBALS['TSFE'] = $this->tsfe; $contentObjectRenderer = new ContentObjectRenderer(); $contentObjectRenderer->setContentObjectClassMap(array('FILES' => FilesContentObject::class, 'TEXT' => TextContentObject::class)); $this->subject = $this->getMock(FilesContentObject::class, array('getFileCollector'), array($contentObjectRenderer)); }
/** * Returns the avatar of the user as a <img...> HTML tag * * @param array the user data array * @return string the HTML tag */ function getUserAvatar($userData) { $avatarImg = trim($userData['tx_mmforum_avatar']); $feuserImg = trim($userData['image']); $imgConf = $this->conf['list_posts.']['userinfo.']['avatar_cObj.']; $img = ''; if ($avatarImg || $feuserImg) { if ($avatarImg) { $imgConf['file'] = $this->conf['path_avatar'] . $avatarImg; } else { // only take the first image, if there are multiple ones if (strpos($feuserImg, ',') !== false) { list($feuserImg) = GeneralUtility::trimExplode(',', $feuserImg); } if (file_exists('uploads/pics/' . $feuserImg)) { $imgConf['file'] = 'uploads/pics/' . $feuserImg; } else { if (file_exists('uploads/tx_srfeuserregister/' . $feuserImg)) { $imgConf['file'] = 'uploads/tx_srfeuserregister/' . $feuserImg; } } } $img = $this->cObj->cObjGetSingle($this->conf['list_posts.']['userinfo.']['avatar_cObj'], $imgConf); } return $img; }
/** * Generates a list of content objects with sectionIndex enabled * available on a specific page * * Used for menus with sectionIndex enabled * * @param string $altSortField Alternative sorting field * @param int $pid The page id to search for sections * @throws \UnexpectedValueException if the query to fetch the content elements unexpectedly fails * @return array */ protected function sectionIndex($altSortField, $pid = null) { $pid = (int) ($pid ?: $this->id); $basePageRow = $this->sys_page->getPage($pid); if (!is_array($basePageRow)) { return array(); } $tsfe = $this->getTypoScriptFrontendController(); $configuration = $this->mconf['sectionIndex.']; $useColPos = 0; if (trim($configuration['useColPos']) !== '' || is_array($configuration['useColPos.'])) { $useColPos = $tsfe->cObj->stdWrap($configuration['useColPos'], $configuration['useColPos.']); $useColPos = (int) $useColPos; } $selectSetup = array('pidInList' => $pid, 'orderBy' => $altSortField, 'languageField' => 'sys_language_uid', 'where' => $useColPos >= 0 ? 'colPos=' . $useColPos : ''); if ($basePageRow['content_from_pid']) { // If the page is configured to show content from a referenced page the sectionIndex contains only contents of // the referenced page $selectSetup['pidInList'] = $basePageRow['content_from_pid']; } $resource = $this->parent_cObj->exec_getQuery('tt_content', $selectSetup); if (!$resource) { $message = 'SectionIndex: Query to fetch the content elements failed!'; throw new \UnexpectedValueException($message, 1337334849); } $result = array(); while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { $this->sys_page->versionOL('tt_content', $row); if ($tsfe->sys_language_contentOL && $basePageRow['_PAGES_OVERLAY_LANGUAGE']) { $row = $this->sys_page->getRecordOverlay('tt_content', $row, $basePageRow['_PAGES_OVERLAY_LANGUAGE'], $tsfe->sys_language_contentOL); } if ($this->mconf['sectionIndex.']['type'] !== 'all') { $doIncludeInSectionIndex = $row['sectionIndex'] >= 1; $doHeaderCheck = $this->mconf['sectionIndex.']['type'] === 'header'; $isValidHeader = ((int) $row['header_layout'] !== 100 || !empty($this->mconf['sectionIndex.']['includeHiddenHeaders'])) && trim($row['header']) !== ''; if (!$doIncludeInSectionIndex || $doHeaderCheck && !$isValidHeader) { continue; } } if (is_array($row)) { $uid = $row['uid']; $result[$uid] = $basePageRow; $result[$uid]['title'] = $row['header']; $result[$uid]['nav_title'] = $row['header']; // Prevent false exclusion in filterMenuPages, thus: Always show tt_content records $result[$uid]['nav_hide'] = 0; $result[$uid]['subtitle'] = $row['subheader']; $result[$uid]['starttime'] = $row['starttime']; $result[$uid]['endtime'] = $row['endtime']; $result[$uid]['fe_group'] = $row['fe_group']; $result[$uid]['media'] = $row['media']; $result[$uid]['header_layout'] = $row['header_layout']; $result[$uid]['bodytext'] = $row['bodytext']; $result[$uid]['image'] = $row['image']; $result[$uid]['sectionIndex_uid'] = $uid; } } $this->getDatabaseConnection()->sql_free_result($resource); return $result; }
/** * Make content object * * @return string */ protected function makeContentObject($isSent) { $message = NULL; $type = NULL; if ($this->typoScript['messages.'][$isSent]) { $type = $this->typoScript['messages.'][$isSent]; } if ($this->typoScript['messages.'][$isSent . '.']) { $message = $this->typoScript['messages.'][$isSent . '.']; } if (empty($message)) { if (!empty($type)) { $message = $type; $type = 'TEXT'; } else { $type = 'TEXT'; $message = $this->getLocalLanguageLabel($isSent); } $value['value'] = $message; $value['wrap'] = '<p>|</p>'; } elseif (!is_array($message)) { $value['value'] = $message; $value['wrap'] = '<p>|</p>'; } else { $value = $message; } return $this->localCobj->cObjGetSingle($type, $value); }
/** * Adds an edit icon to the content string. The edit icon links to EditDocumentController with proper parameters for editing the table/fields of the context. * This implements TYPO3 context sensitive editing facilities. Only backend users will have access (if properly configured as well). * * @param string $content The content to which the edit icons should be appended * @param string $params The parameters defining which table and fields to edit. Syntax is [tablename]:[fieldname],[fieldname],[fieldname],... OR [fieldname],[fieldname],[fieldname],... (basically "[tablename]:" is optional, default table is the one of the "current record" used in the function). The fieldlist is sent as "&columnsOnly=" parameter to EditDocumentController * @param array $conf TypoScript properties for configuring the edit icons. * @param string $currentRecord The "table:uid" of the record being shown. If empty string then $this->currentRecord is used. For new records (set by $conf['newRecordFromTable']) it's auto-generated to "[tablename]:NEW * @param array $dataArr Alternative data array to use. Default is $this->data * @param string $addUrlParamStr Additional URL parameters for the link pointing to EditDocumentController * @param string $table * @param int $editUid * @param string $fieldList * @return string The input content string, possibly with edit icons added (not necessarily in the end but just after the last string of normal content. */ public function editIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArr = array(), $addUrlParamStr = '', $table, $editUid, $fieldList) { // Special content is about to be shown, so the cache must be disabled. $this->frontendController->set_no_cache('Display frontend edit icons', TRUE); $iconTitle = $this->cObj->stdWrap($conf['iconTitle'], $conf['iconTitle.']); $optionsArray = array('title' => htmlspecialchars($iconTitle, ENT_COMPAT, 'UTF-8', FALSE), 'class' => 'frontEndEditIcons', 'style' => $conf['styleAttribute'] ? htmlspecialchars($conf['styleAttribute']) : ''); $iconImg = $conf['iconImg'] ? $conf['iconImg'] : IconUtility::getSpriteIcon('actions-document-open', $optionsArray); $nV = GeneralUtility::_GP('ADMCMD_view') ? 1 : 0; $url = BackendUtility::getModuleUrl('record_edit', array('edit[' . $table . '][' . $editUid . ']' => 'edit', 'columnsOnly' => $fieldList, 'noView' => $nV)) . $addUrlParamStr; $icon = $this->editPanelLinkWrap_doWrap($iconImg, $url); if ($conf['beforeLastTag'] < 0) { $content = $icon . $content; } elseif ($conf['beforeLastTag'] > 0) { $cBuf = rtrim($content); $secureCount = 30; while ($secureCount && substr($cBuf, -1) == '>' && substr($cBuf, -4) != '</a>') { $cBuf = rtrim(preg_replace('/<[^<]*>$/', '', $cBuf)); $secureCount--; } $content = strlen($cBuf) && $secureCount ? substr($content, 0, strlen($cBuf)) . $icon . substr($content, strlen($cBuf)) : ($content = $icon . $content); } else { $content .= $icon; } return $content; }
/** * @test * @author Alexander Schnitzler <*****@*****.**> */ public function overrideStoragePidIfStartingPointIsSetOverridesCorrectly() { $this->mockContentObject->expects($this->any())->method('getTreeList')->will($this->returnValue('1,2,3')); $this->mockContentObject->data = array('pages' => '0', 'recursive' => 1); $frameworkConfiguration = array('persistence' => array('storagePid' => '98')); $this->assertSame(array('persistence' => array('storagePid' => '0,1,2,3')), $this->frontendConfigurationManager->_call('overrideStoragePidIfStartingPointIsSet', $frameworkConfiguration)); }
/** * Renders Lorem Ipsum paragraphs. If $lipsum is provided it * will be used as source text. If not provided as an argument * or as inline argument, $lipsum is fetched from TypoScript settings. * * @param string $lipsum String of paragraphs file path or EXT:myext/path/to/file * @return string */ public function render($lipsum = null) { if (strlen($lipsum) === 0) { $lipsum = $this->lipsum; } if (strlen($lipsum) < 255 && !preg_match('/[^a-z0-9_\\.\\:\\/]/i', $lipsum) || 0 === strpos($lipsum, 'EXT:')) { // argument is most likely a file reference. $sourceFile = GeneralUtility::getFileAbsFileName($lipsum); if (file_exists($sourceFile)) { $lipsum = file_get_contents($sourceFile); } else { GeneralUtility::sysLog('Vhs LipsumViewHelper was asked to load Lorem Ipsum from a file which does not exist. ' . 'The file was: ' . $sourceFile, 'vhs', GeneralUtility::SYSLOG_SEVERITY_WARNING); $lipsum = $this->lipsum; } } $lipsum = preg_replace('/[\\r\\n]{1,}/i', "\n", $lipsum); $paragraphs = explode("\n", $lipsum); $paragraphs = array_slice($paragraphs, 0, intval($this->arguments['paragraphs'])); foreach ($paragraphs as $index => $paragraph) { $length = $this->arguments['wordsPerParagraph'] + rand(0 - intval($this->arguments['skew']), intval($this->arguments['skew'])); $words = explode(' ', $paragraph); $paragraphs[$index] = implode(' ', array_slice($words, 0, $length)); } $lipsum = implode("\n", $paragraphs); if ($this->arguments['html']) { $tsParserPath = $this->arguments['parseFuncTSPath'] ? '< ' . $this->arguments['parseFuncTSPath'] : null; $lipsum = $this->contentObject->parseFunc($lipsum, [], $tsParserPath); } return $lipsum; }
/** * Initialize * * @return void */ public function initializeFinisher() { $this->contentObject = $this->configurationManager->getContentObject(); $this->contentObject->start($this->mailRepository->getVariablesWithMarkersFromMail($this->mail)); $typoScript = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); $this->configuration = $typoScript['plugin.']['tx_powermail.']['settings.']['setup.']['marketing.']['sendPost.']; }