本文整理汇总了PHP中TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer类的典型用法代码示例。如果您正苦于以下问题:PHP ContentObjectRenderer类的具体用法?PHP ContentObjectRenderer怎么用?PHP ContentObjectRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentObjectRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDataExtension
/**
* 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;
}
示例2: cObjGetSingleExt
/**
* 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;
}
示例3: process
/**
* 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;
}
示例4: process
/**
* 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;
}
示例5: respectHtmlCanBeDisabled
/**
* @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);
}
示例6: process
/**
* 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;
}
示例7: getCloseTime
/**
* 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;
}
示例8: __construct
/**
* 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();
}
示例9: cObjGetSingleExt
/**
* @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);
}
示例10: setUp
/**
* 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;
}
示例11: process
/**
* 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;
}
示例12: setUp
/**
* 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);
}
示例13: preprocessImages
/**
* @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;
}
示例14: render
/**
* 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);
}
示例15: convertsCommaSeparatedListFromValueToSerializedArrayOfTrimmedValues
/**
* @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);
}