/** * Liefert das passende Template für die aktuelle Seite */ protected function getPageString($currentPage, $pointer, $pageId, &$templates, &$formatter, $pbConfId, $pbMarker) { $rec = array(); $rec['number'] = $currentPage + 1; $pageTemplate = $templates[$pageId]; $pageConfId = $pbConfId . 'page.' . $pageId . '.'; $pageMarker = $pbMarker . '_' . strtoupper($pageId) . '_PAGE_'; $pageMarkerArray = $formatter->getItemMarkerArrayWrapped($rec, $pageConfId, 0, $pageMarker); $pageSubpartArray = array(); if ($this->link) { $this->link->parameters(array($this->pageBrowser->getParamName('pointer') => $currentPage)); $pageWrappedSubpartArray['###' . $pageMarker . 'LINK###'] = explode($this->token, $this->link->makeTag()); $pageMarkerArray['###' . $pageMarker . 'LINKURL###'] = $this->link->makeUrl(); } else { $pageWrappedSubpartArray['###' . $pageMarker . 'LINK###'] = $noLink; $pageMarkerArray['###' . $pageMarker . 'LINKURL###'] = ''; } $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($pageTemplate, $pageMarkerArray, $pageSubpartArray, $pageWrappedSubpartArray); return $out; }
/** * Typoscript USER function for rendering DAM images. * This is a minimal Setup: * <pre> * yourObject.imagecol = USER * yourObject.imagecol { * userFunc=tx_rnbase_util_TSDAM->printImages * refField=imagecol * refTable=tx_yourextkey_tablename * template = EXT:rn_base/res/simplegallery.html * # media is the dam record * media { * # field file contains the complete image path * file = IMAGE * file.file.import.field = file * } * # Optional setting for limit * # limit = 1 * } * </pre> * There are three additional fields in media record: file, file1 and thumbnail containing the complete * image path. * The output is rendered via HTML template with ListBuilder. Have a look at EXT:rn_base/res/simplegallery.html * Possible Typoscript options: * refField: DAM reference field of the media records (defined in TCA and used to locate the record in MM-Table) * refTable: should be the tablename where the DAM record is referenced to * template: Full path to HTML template file. * media: Formatting options of the DAM record. Have a look at tx_dam to find all column names * limit: Limits the number of medias * offset: Start media output with an offset * forcedIdField: force another refernce column (other than UID or _LOCALIZED_UID) * * * @param string $content * @param array $tsConf * @return string */ function printImages($content, $tsConf) { if (!tx_rnbase_util_Extensions::isLoaded('dam')) { return ''; } $conf = $this->createConf($tsConf); $file = $conf->get('template'); $file = $file ? $file : 'EXT:rn_base/res/simplegallery.html'; $subpartName = $conf->get('subpartName'); $subpartName = $subpartName ? $subpartName : '###DAM_IMAGES###'; $templateCode = tx_rnbase_util_Templates::getSubpartFromFile($file, $subpartName); if (!$templateCode) { return '<!-- NO TEMPLATE OR SUBPART ' . $subpartName . ' FOUND -->'; } // Is there a customized language field configured $langField = DEFAULT_LOCAL_FIELD; $locUid = $conf->getCObj()->data[$langField]; // Save original uid if ($conf->get('forcedIdField')) { $langField = $conf->get('forcedIdField'); // Copy localized UID $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $conf->getCObj()->data[$langField]; } // Check if there is a valid uid given. $parentUid = intval($conf->getCObj()->data[DEFAULT_LOCAL_FIELD] ? $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] : $conf->getCObj()->data['uid']); if (!$parentUid) { return '<!-- Invalid data record given -->'; } $damPics = $this->fetchFileList($tsConf, $conf->getCObj()); $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $locUid; // Reset UID $offset = intval($conf->get('offset')); $limit = intval($conf->get('limit')); if (!$limit && $offset && count($damPics)) { $damPics = array_slice($damPics, $offset); } elseif ($limit && count($damPics)) { $damPics = array_slice($damPics, $offset, $limit); } $damDb = tx_rnbase::makeInstance('tx_dam_db'); $medias = array(); while (list($uid, $baseRecord) = each($damPics)) { $mediaObj = tx_rnbase::makeInstance('tx_rnbase_model_media', $baseRecord['uid']); // Localize data (DAM 1.1.0) if (method_exists($damDb, 'getRecordOverlay')) { $loc = $damDb->getRecordOverlay('tx_dam', $mediaObj->getRecord(), array('sys_language_uid' => $GLOBALS['TSFE']->sys_language_uid)); if ($loc) { $mediaObj->setProperty($loc); } } $mediaObj->setParentuid($parentUid); $medias[] = $mediaObj; } $listBuilder = tx_rnbase::makeInstance('tx_rnbase_util_ListBuilder'); $out = $listBuilder->render($medias, FALSE, $templateCode, 'tx_rnbase_util_MediaMarker', 'media.', 'MEDIA', $conf->getFormatter()); // Now set the identifier $markerArray['###MEDIA_PARENTUID###'] = $parentUid; $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray); return $out; }
/** * Render an array of data entries with an html template. The html template should look like this: * ###DATAS### * ###DATA### * ###DATA_UID### * ###DATA### * ###DATAEMPTYLIST### * Shown if list is empty * ###DATAEMPTYLIST### * ###DATAS### * We have some conventions here: * The given parameter $marker should be named 'DATA' for this example. The the list subpart * is experted to be named '###'.$marker.'S###'. Please notice the trailing S! * If you want to render a pagebrowser add it to the $viewData with key 'pagebrowser'. * A filter will be detected and rendered too. It should be available in $viewData with key 'filter'. * * @param array|Traversable $dataArr entries * @param string $template * @param string $markerClassname item-marker class * @param string $confId ts-Config for data entries like team. * @param string $marker name of marker like TEAM * @param tx_rnbase_util_FormatUtil $formatter * @param array $markerParams array of settings for itemmarker * @return string */ function render(&$dataArr, $viewData, $template, $markerClassname, $confId, $marker, $formatter, $markerParams = NULL) { $viewData = is_object($viewData) ? $viewData : new ArrayObject(); $debugKey = $formatter->getConfigurations()->get($confId . '_debuglb'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $mem = memory_get_usage(); $wrapTime = tx_rnbase_util_FormatUtil::$time; $wrapMem = tx_rnbase_util_FormatUtil::$mem; } $outerMarker = $this->getOuterMarker($marker, $template); $htmlParser = tx_rnbase_util_Typo3Classes::getHtmlParserClass(); while ($templateList = $htmlParser::getSubpart($template, '###' . $outerMarker . 'S###')) { if ((is_array($dataArr) || $dataArr instanceof Traversable) && count($dataArr)) { /* @var $listMarker tx_rnbase_util_ListMarker */ $listMarker = tx_rnbase::makeInstance('tx_rnbase_util_ListMarker', $this->info->getListMarkerInfo()); $templateEntry = $htmlParser::getSubpart($templateList, '###' . $marker . '###'); $offset = 0; $pageBrowser = $viewData->offsetGet('pagebrowser'); if ($pageBrowser) { $state = $pageBrowser->getState(); $offset = $state['offset']; } $markerArray = $subpartArray = array(); $listMarker->addVisitors($this->visitors); $out = $listMarker->render($dataArr, $templateEntry, $markerClassname, $confId, $marker, $formatter, $markerParams, $offset); $subpartArray['###' . $marker . '###'] = $out; $subpartArray['###' . $marker . 'EMPTYLIST###'] = ''; // Das Menu für den PageBrowser einsetzen if ($pageBrowser) { $subpartArray['###PAGEBROWSER###'] = tx_rnbase_util_BaseMarker::fillPageBrowser($htmlParser::getSubpart($template, '###PAGEBROWSER###'), $pageBrowser, $formatter, $confId . 'pagebrowser.'); $listSize = $pageBrowser->getListSize(); } else { $listSize = count($dataArr); } $markerArray['###' . $marker . 'COUNT###'] = $formatter->wrap($listSize, $confId . 'count.'); // charbrowser $pagerData = $viewData->offsetGet('pagerData'); $charPointer = $viewData->offsetGet('charpointer'); $subpartArray['###CHARBROWSER###'] = tx_rnbase_util_BaseMarker::fillCharBrowser(tx_rnbase_util_Templates::getSubpart($template, '###CHARBROWSER###'), $markerArray, $pagerData, $charPointer, $formatter->getConfigurations(), $confId . 'charbrowser.'); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($templateList, $markerArray, $subpartArray); } else { // Support für EMPTYLIST-Block if (tx_rnbase_util_BaseMarker::containsMarker($template, $marker . 'EMPTYLIST')) { $out = $htmlParser::getSubpart($template, '###' . $marker . 'EMPTYLIST###'); } else { $out = $this->info->getEmptyListMessage($confId, $viewData, $formatter->getConfigurations()); } } $template = tx_rnbase_util_Templates::substituteSubpart($template, '###' . $outerMarker . 'S###', $out, 0); } $markerArray = array(); $subpartArray = array(); // Muss ein Formular mit angezeigt werden // Zuerst auf einen Filter prüfen $filter = $viewData->offsetGet('filter'); if ($filter) { $template = $filter->getMarker()->parseTemplate($template, $formatter, $confId . 'filter.', $marker); } // Jetzt noch die alte Variante $markerArray['###SEARCHFORM###'] = ''; $seachform = $viewData->offsetGet('searchform'); if ($seachform) { $markerArray['###SEARCHFORM###'] = $seachform; } $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($template, $markerArray, $subpartArray); if ($debug) { tx_rnbase::load('class.tx_rnbase_util_Misc.php'); $wrapTime = tx_rnbase_util_FormatUtil::$time - $wrapTime; $wrapMem = tx_rnbase_util_FormatUtil::$mem - $wrapMem; tx_rnbase_util_Debug::debug(array('Rows' => count($dataArr), 'Execustion time' => microtime(TRUE) - $time, 'WrapTime' => $wrapTime, 'WrapMem' => $wrapMem, 'Memory start' => $mem, 'Memory consumed' => memory_get_usage() - $mem), 'ListBuilder Statistics for: ' . $confId . ' Key: ' . $debugKey); } return $out; }
/** * Typoscript USER function for rendering DAM images. * This is a minimal Setup: * <pre> * yourObject.imagecol = USER * yourObject.imagecol { * userFunc=tx_rnbase_util_TSFAL->printImages * includeLibs = EXT:rn_base/util/class.tx_rnbase_util_TSFAL.php * refField=imagecol * refTable=tx_yourextkey_tablename * template = EXT:rn_base/res/simplegallery.html * # media is the fal reference record * media { * # field file contains the complete image path * file = IMAGE * file.file.import.field = file * } * # Optional setting for limit * # limit = 1 * } * </pre> * There are three additional fields in media record: file, file1 and thumbnail containing the complete * image path. * The output is rendered via HTML template with ListBuilder. Have a look at EXT:rn_base/res/simplegallery.html * Possible Typoscript options: * refField: DAM reference field of the media records (defined in TCA and used to locate the record in MM-Table) * refTable: should be the tablename where the DAM record is referenced to * template: Full path to HTML template file. * media: Formatting options of the DAM record. Have a look at tx_dam to find all column names * limit: Limits the number of medias * offset: Start media output with an offset * forcedIdField: force another reference column (other than UID or _LOCALIZED_UID) * * * @param string $content * @param array $tsConf * @return string */ public function printImages($content, $tsConf) { tx_rnbase::load('tx_rnbase_util_Templates'); $conf = $this->createConf($tsConf); $file = $conf->get('template'); $file = $file ? $file : 'EXT:rn_base/res/simplegallery.html'; $subpartName = $conf->get('subpartName'); $subpartName = $subpartName ? $subpartName : '###DAM_IMAGES###'; $templateCode = tx_rnbase_util_Templates::getSubpartFromFile($file, $subpartName); if (!$templateCode) { return '<!-- NO TEMPLATE OR SUBPART ' . $subpartName . ' FOUND -->'; } // Is there a customized language field configured $langField = DEFAULT_LOCAL_FIELD; $locUid = $conf->getCObj()->data[$langField]; // Save original uid if ($conf->get('forcedIdField')) { $langField = $conf->get('forcedIdField'); // Copy localized UID $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $conf->getCObj()->data[$langField]; } // Check if there is a valid uid given. $parentUid = intval($conf->getCObj()->data[DEFAULT_LOCAL_FIELD] ? $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] : $conf->getCObj()->data['uid']); if (!$parentUid) { return '<!-- Invalid data record given -->'; } $medias = self::fetchFilesByTS($conf, $conf->getCObj()); $listBuilder = tx_rnbase::makeInstance('tx_rnbase_util_ListBuilder'); $out = $listBuilder->render($medias, FALSE, $templateCode, 'tx_rnbase_util_MediaMarker', 'media.', 'MEDIA', $conf->getFormatter()); // Now set the identifier $markerArray = array('###MEDIA_PARENTUID###' => $parentUid); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray); return $out; }
/** * 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); }