/** * Konstruktor * @param tx_rnbase_configurations $configurations */ function tx_rnbase_util_FormatUtil($configurations, $cObjClass = 'tslib_cObj') { $this->configurations = $configurations; // t3lib_div::debug($this->configurations->get('tt_content.') , 'util_formatUtil'); $this->cObj = $configurations->getCObj(); // $this->cObj = t3lib_div::makeInstance($cObjClass); // $this->cObj->data = $this->configurations->get('tt_content.'); }
/** * This method is taken from TYPO3\CMS\Frontend\ContentObject\FileContentObject. * It is a good tradition in TYPO3 that code can not be re-used. TYPO3 6.x makes * no difference... * * @param tx_rnbase_configurations $conf * @param $cObj * @param string $confId * @return array */ public static function fetchFilesByTS($conf, $cObj, $confId = '') { /* @var $fileRepository \TYPO3\CMS\Core\Resource\FileRepository */ $fileRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); $fileObjects = array(); $pics = array(); tx_rnbase::load('tx_rnbase_util_Strings'); // Getting the files // Try DAM style if ($conf->get($confId . 'refTable')) { $referencesForeignTable = $conf->getCObj()->stdWrap($conf->get($confId . 'refTable'), $conf->get($confId . 'refTable.')); $referencesFieldName = $conf->getCObj()->stdWrap($conf->get($confId . 'refField'), $conf->get($confId . 'refField.')); $referencesForeignUid = $conf->getCObj()->stdWrap($conf->get($confId . 'refUid'), $conf->get($confId . 'refUid.')); if (!$referencesForeignUid) { $referencesForeignUid = isset($cObj->data['_LOCALIZED_UID']) ? $cObj->data['_LOCALIZED_UID'] : $cObj->data['uid']; } $pics = $fileRepository->findByRelation($referencesForeignTable, $referencesFieldName, $referencesForeignUid); } elseif (is_array($conf->get($confId . 'references.'))) { $refConfId = $confId . 'references.'; /* The TypoScript could look like this:# all items related to the page.media field: references { table = pages uid.data = page:uid fieldName = media }# or: sys_file_references with uid 27: references = 27 */ // It's important that this always stays "fieldName" and not be renamed to "field" as it would otherwise collide with the stdWrap key of that name $referencesFieldName = $conf->getCObj()->stdWrap($conf->get($refConfId . 'fieldName'), $conf->get($refConfId . 'fieldName.')); if ($referencesFieldName) { $table = $cObj->getCurrentTable(); if ($table === 'pages' && isset($cObj->data['_LOCALIZED_UID']) && intval($cObj->data['sys_language_uid']) > 0) { $table = 'pages_language_overlay'; } $referencesForeignTable = $conf->getCObj()->stdWrap($conf->get($refConfId . 'table'), $conf->get($refConfId . 'table.')); $referencesForeignTable = $referencesForeignTable ? $referencesForeignTable : $table; $referencesForeignUid = $conf->getCObj()->stdWrap($conf->get($refConfId . 'uid'), $conf->get($refConfId . 'uid.')); $referencesForeignUid = $referencesForeignUid ? $referencesForeignUid : (isset($cObj->data['_LOCALIZED_UID']) ? $cObj->data['_LOCALIZED_UID'] : $cObj->data['uid']); // Vermutlich kann hier auch nur ein Objekt geliefert werden... $pics = array(); $referencesForeignUid = tx_rnbase_util_Strings::intExplode(',', $referencesForeignUid); foreach ($referencesForeignUid as $refForUid) { if (!$conf->get($refConfId . 'treatIdAsReference')) { $pics[] = $fileRepository->findFileReferenceByUid($refForUid); } else { $pics[] = $fileRepository->findByRelation($referencesForeignTable, $referencesFieldName, $refForUid); } } } elseif ($refUids = $conf->getCObj()->stdWrap($conf->get($refConfId . 'uid'), $conf->get($refConfId . 'uid.'))) { if (!empty($refUids)) { $refUids = tx_rnbase_util_Strings::intExplode(',', $refUids); foreach ($refUids as $refUid) { $pics[] = $fileRepository->findFileReferenceByUid($refUid); } } } } // TODO: Hook tx_rnbase_util_Misc::callHook('rn_base', 'util_TSFal_fetchFilesByTS_appendMedia_hook', array('conf' => $conf, '$confId' => $confId, 'media' => &$pics), null); // gibt es ein Limit/offset $offset = intval($conf->get($confId . 'offset')); $limit = intval($conf->get($confId . 'limit')); if (!empty($pics) && $limit) { $pics = array_slice($pics, $offset, $limit); } elseif (!empty($pics) && $offset) { $pics = array_slice($pics, $offset); } // Die Bilder sollten jetzt noch in ein $fileObjects = self::convertRef2Media($pics); return $fileObjects; }
/** * Konstruktor * @param tx_rnbase_configurations $configurations */ function tx_rnbase_util_FormatUtil($configurations) { $this->configurations = $configurations; $this->cObj = $configurations->getCObj(); }
/** * Init this link by typoscript setup * * @param tx_rnbase_configurations $configurations * @param string $confId * * @return tx_rnbase_util_Link */ public function initByTS($configurations, $confId, $parameterArr) { $parameterArr = is_array($parameterArr) ? $parameterArr : array(); $pid = $configurations->getCObj()->stdWrap($configurations->get($confId . 'pid'), $configurations->get($confId . 'pid.')); $qualifier = $configurations->get($confId . 'qualifier'); if ($qualifier) { $this->designator($qualifier); } $target = $configurations->get($confId . 'target'); if ($target) { $this->target($target); } // feste URL für externen Link if ($fixed = $configurations->get($confId . 'fixedUrl', TRUE)) { $this->destination($fixed); } else { $this->destination($pid ? $pid : $GLOBALS['TSFE']->id); // absolute und ggf. schema url erzeugen if ($absUrl = $configurations->get($confId . 'absurl')) { $this->setAbsUrl(TRUE, $absUrl == 1 || strtolower($absUrl) == 'true' ? '' : $absUrl); } } if (array_key_exists('SECTION', $parameterArr)) { $this->anchor(htmlspecialchars($parameterArr['SECTION'])); unset($parameterArr['SECTION']); } else { $this->anchor((string) $configurations->get($confId . 'section', TRUE)); } $this->parameters($parameterArr); // eigene Parameter für typolink, die einfach weitergegeben werden $typolinkCfg = $configurations->get($confId . 'typolink.'); if (is_array($typolinkCfg)) { foreach ($typolinkCfg as $cfgName => $cfgValue) { $this->addTypolinkParam($cfgName, $cfgValue); } } // Zusätzliche Parameter für den Link $atagParams = $configurations->get($confId . 'atagparams.', TRUE); if (is_array($atagParams)) { // Die Parameter werden jetzt nochmal per TS validiert und können somit dynamisch gesetzt werden $attributes = array(); foreach ($atagParams as $aParam => $lvalue) { if (substr($aParam, strlen($aParam) - 1, 1) == '.') { $aParam = substr($aParam, 0, strlen($aParam) - 1); if (array_key_exists($aParam, $atagParams)) { continue; } } $attributes[$aParam] = $configurations->getCObj()->stdWrap($atagParams[$aParam], $atagParams[$aParam . '.']); } $this->attributes($attributes); } // KeepVars prüfen // Per Default sind die KeepVars nicht aktiviert. Mit useKeepVars == 1 können sie hinzugefügt werden if (!$configurations->get($confId . 'useKeepVars')) { $this->overruled(); } elseif ($keepVarConf = $configurations->get($confId . 'useKeepVars.')) { // Sonderoptionen für KeepVars gesetzt $newKeepVars = array(); // skip empty values? default false! $skipEmpty = !empty($keepVarConf['skipEmpty']); $keepVars = $configurations->getKeepVars(); $allow = $keepVarConf['allow']; $deny = $keepVarConf['deny']; if ($allow) { $allow = tx_rnbase_util_Strings::trimExplode(',', $allow); foreach ($allow as $allowed) { $value = $keepVars->offsetGet($allowed); if ($skipEmpty && empty($value)) { continue; } $newKeepVars[$allowed] = $keepVars->offsetGet($allowed); } } elseif ($deny) { $deny = array_flip(tx_rnbase_util_Strings::trimExplode(',', $deny)); $keepVarsArr = $keepVars->getArrayCopy(); foreach ($keepVarsArr as $key => $value) { if ($skipEmpty && empty($value)) { continue; } if (!array_key_exists($key, $deny)) { $newKeepVars[$key] = $value; } } } $add = $keepVarConf['add']; if ($add) { $add = tx_rnbase_util_Strings::trimExplode(',', $add); foreach ($add as $linkvar) { $linkvar = tx_rnbase_util_Strings::trimExplode('=', $linkvar); if (count($linkvar) < 2) { // tt_news::* or ttnews::id list($qualifier, $name) = tx_rnbase_util_Strings::trimExplode('::', $linkvar[0]); if ($value = tx_rnbase_parameters::getPostOrGetParameter($qualifier)) { if ($name == '*' && is_array($value)) { foreach ($value as $paramName => $paramValue) { if ($skipEmpty && empty($paramValue)) { continue; } if (strpos($paramName, 'NK_') === FALSE) { $newKeepVars[$qualifier . '::' . $paramName] = $paramValue; } } } else { $newKeepVars[$linkvar[0]] = $value[$name]; } } } else { $newKeepVars[$linkvar[0]] = $linkvar[1]; } } } $this->overruled($newKeepVars); } if ($configurations->get($confId . 'noCache')) { $this->noCache(); } // Bei der Linkerzeugung wir normalerweise immer ein cHash angelegt. Bei Plugins, die als USER_INT // ausgeführt werden, ist dies nicht notwendig und geht auf die Performance. Daher wird hier // automatisch der cHash für USER_INT deaktiviert. Per Typocript kann man es aber bei Bedarf manuell // wieder aktivieren if ($configurations->get($confId . 'noHash') || $configurations->get($confId . 'noHash') !== '0' && $configurations->isPluginUserInt()) { $this->noHash(); } return $this; }
/** * render plugin data and additional flexdata * * @param string $templateCode * @param tx_rnbase_configurations $configurations * @return string */ protected function renderPluginData($templateCode, tx_rnbase_configurations $configurations) { // render only, if there is an controller if (!$this->getController()) { return $templateCode; } // check, if there are plugin markers to render if (!tx_rnbase_util_BaseMarker::containsMarker($templateCode, 'PLUGIN_')) { return $templateCode; } $confId = $this->getController()->getConfId(); $markerArray = array(); // build the data to render $pluginData = array_merge((array) $configurations->getCObj()->data, $configurations->getExploded($confId . 'plugin.flexdata.')); // check for unused columns $ignoreColumns = tx_rnbase_util_BaseMarker::findUnusedCols($pluginData, $templateCode, 'PLUGIN'); // create the marker array with the parsed columns $markerArray = $configurations->getFormatter()->getItemMarkerArrayWrapped($pluginData, $confId . 'plugin.', $ignoreColumns, 'PLUGIN_'); return tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($templateCode, $markerArray); }