Example #1
0
 public function main()
 {
     $out = '';
     $conf = $this->getModule()->getConfigurations();
     $file = t3lib_div::getFileAbsFileName($conf->get($this->getConfId() . 'template'));
     $templateCode = t3lib_div::getURL($file);
     if (!$templateCode) {
         return $conf->getLL('msg_template_not_found') . '<br />File: \'' . $file . '\'<br />ConfId: \'' . $this->getConfId() . 'template\'';
     }
     $subpart = '###' . strtoupper($this->getFuncId()) . '###';
     $template = tx_rnbase_util_Templates::getSubpart($templateCode, $subpart);
     if (!$template) {
         return $conf->getLL('msg_subpart_not_found') . ': ' . $subpart;
     }
     $start = microtime(TRUE);
     $memStart = memory_get_usage();
     $out .= $this->getContent($template, $conf, $conf->getFormatter(), $this->getModule()->getFormTool());
     if (tx_rnbase_util_BaseMarker::containsMarker($out, 'MOD_')) {
         $markerArr = array();
         $memEnd = memory_get_usage();
         $markerArr['###MOD_PARSETIME###'] = microtime(TRUE) - $start;
         $markerArr['###MOD_MEMUSED###'] = $memEnd - $memStart;
         $markerArr['###MOD_MEMSTART###'] = $memStart;
         $markerArr['###MOD_MEMEND###'] = $memEnd;
         $out = tx_rnbase_util_Templates::substituteMarkerArrayCached($out, $markerArr);
     }
     return $out;
 }
 /**
  * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
  * This method is taken from tslib_content
  * TODO: cache result
  *
  * @param string The filename, being a TypoScript resource data type or a FAL-Reference (file:123)
  * @param string Additional parameters (attributes). Default is empty alt and title tags.
  * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
  * @see FILE()
  */
 public static function getFileResource($fName, $options = array())
 {
     if (!(is_object($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']->tmpl))) {
         tx_rnbase::load('tx_rnbase_util_Misc');
         tx_rnbase_util_Misc::prepareTSFE(array('force' => TRUE));
     }
     if (self::isFALReference($fName)) {
         /** @var FileRepository $fileRepository */
         $fileRepository = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
         $fileObject = $fileRepository->findByUid(intval(substr($fName, 5)));
         $incFile = is_object($fileObject) ? $fileObject->getForLocalProcessing(FALSE) : FALSE;
     } else {
         $incFile = self::getFileName($fName);
     }
     if ($incFile) {
         // Im BE muss ein absoluter Pfad verwendet werden
         $fullPath = TYPO3_MODE == 'BE' ? PATH_site . $incFile : $incFile;
         $utility = tx_rnbase_util_Typo3Classes::getGeneralUtilityClass();
         $fileinfo = $utility::split_fileref($incFile);
         if ($utility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) {
             $imgFile = $incFile;
             $imgInfo = @getImageSize($imgFile);
             $addParams = isset($options['addparams']) ? $options['addparams'] : 'alt="" title=""';
             $ret = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . self::getBorderAttr(' border="0"') . ' ' . $addParams . ' />';
         } elseif (file_exists($fullPath) && filesize($fullPath) < 1024 * 1024) {
             $ret = @file_get_contents($fullPath);
             $subpart = isset($options['subpart']) ? $options['subpart'] : '';
             if ($subpart) {
                 tx_rnbase::load('tx_rnbase_util_Templates');
                 $ret = tx_rnbase_util_Templates::getSubpart($ret, $subpart);
             }
         }
     }
     return $ret;
 }
 /**
  * Enter description here...
  *
  * @param string $view default name of view
  * @param tx_rnbase_configurations $configurations
  * @return string
  */
 function render($view, &$configurations)
 {
     $this->_init($configurations);
     $templateCode = tx_rnbase_util_Files::getFileResource($this->getTemplate($view, '.html'));
     if (!strlen($templateCode)) {
         tx_rnbase::load('tx_rnbase_util_Misc');
         tx_rnbase_util_Misc::mayday('TEMPLATE NOT FOUND: ' . $this->getTemplate($view, '.html'));
     }
     // Die ViewData bereitstellen
     $viewData =& $configurations->getViewData();
     // Optional kann schon ein Subpart angegeben werden
     $subpart = $this->getMainSubpart($viewData);
     if (!empty($subpart)) {
         $templateCode = tx_rnbase_util_Templates::getSubpart($templateCode, $subpart);
         if (!strlen($templateCode)) {
             tx_rnbase::load('tx_rnbase_util_Misc');
             tx_rnbase_util_Misc::mayday('SUBPART NOT FOUND: ' . $subpart);
         }
     }
     $controller = $this->getController();
     if ($controller) {
         // disable substitution marker cache
         if ($configurations->getBool($controller->getConfId() . '_caching.disableSubstCache')) {
             tx_rnbase_util_Templates::disableSubstCache();
         }
     }
     $out = $templateCode;
     $out = $this->createOutput($templateCode, $viewData, $configurations, $configurations->getFormatter());
     $out = $this->renderPluginData($out, $configurations);
     if ($controller) {
         $params = array();
         $params['confid'] = $controller->getConfId();
         $params['item'] = $controller->getViewData()->offsetGet('item');
         $params['items'] = $controller->getViewData()->offsetGet('items');
         $markerArray = $subpartArray = $wrappedSubpartArray = array();
         tx_rnbase_util_BaseMarker::callModules($out, $markerArray, $subpartArray, $wrappedSubpartArray, $params, $configurations->getFormatter());
         $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray, $subpartArray, $wrappedSubpartArray);
     }
     return $out;
 }
 /**
  * Call services for single markers
  *
  * @param string $template
  * @param array $markerArray
  * @param array $params
  * @param tx_rnbase_util_FormatUtil $formatter
  */
 protected static function callModuleMarkers($template, &$markerArray, &$params, $formatter)
 {
     preg_match_all('!\\<\\!--[a-zA-Z0-9 ]*###([A-Z0-9_\\-|]*)\\###[a-zA-Z0-9 ]*-->!is', $template, $match);
     $allMarkers = array_unique($match[1]);
     preg_match_all('!\\###([A-Z0-9_\\-|]*)\\###!is', $template, $match);
     $allSingleMarkers = array_unique($match[1]);
     $allSingleMarkers = array_diff($allSingleMarkers, $allMarkers);
     $suffixesToTry = self::getSuffixesToTry($formatter->getConfigurations());
     foreach ($allSingleMarkers as $marker) {
         if (preg_match('/MARKERMODULE__([A-Z0-9_\\-])*/', $marker)) {
             $module = tx_rnbase::makeInstanceService('markermodule', substr($marker, 14));
             if (is_object($module)) {
                 $subTemplate = tx_rnbase_util_Templates::getSubpart($template, '###' . $marker . '###');
                 $value = $module->getMarkerValue($params, $formatter);
                 if ($value !== FALSE) {
                     $markerArray['###' . $marker . '###'] = $value;
                 }
             }
         } elseif (preg_match('/LABEL_.*/', $marker)) {
             $markerArray['###' . $marker . '###'] = '';
             // remove marker per default
             foreach ($suffixesToTry as $suffix) {
                 $completeKey = $marker . $suffix;
                 // Hier kommt immer ein leerer String zurück, weil T3 keinen Alternativ-String unterstützt
                 $translation = $formatter->getConfigurations()->getLL(strtolower($completeKey));
                 if ($translation !== '') {
                     $markerArray['###' . $marker . '###'] = $translation;
                     break;
                 }
             }
         }
     }
 }
 public function test_includeSubTemplates()
 {
     $fixture = tx_rnbase_util_Network::getURL(tx_rnbase_util_Extensions::extPath('rn_base', 'tests/fixtures/html/includeSubTemplates.html'));
     $raw = tx_rnbase_util_Templates::getSubpart($fixture, '###TEMPLATE###');
     $expected = tx_rnbase_util_Templates::getSubpart($fixture, '###EXPECTED###');
     $included = tx_rnbase_util_Templates::includeSubTemplates($raw);
     // remove empty lines
     $included = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $included);
     $expected = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $expected);
     $this->assertEquals($expected, $included);
 }
 /**
  * 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;
 }
 private function createContent($template, $conf)
 {
     $formTool = $this->getModule()->getFormTool();
     $out = '';
     // TabMenu initialisieren
     $menuItems = array();
     $menu = $this->initSubMenu($menuItems, $this->getModule()->getFormTool());
     $this->getModule()->setSubMenu($menu['menu']);
     // SubSelectors
     $selectorStr = '';
     $subSels = $this->makeSubSelectors($selectorStr);
     $this->getModule()->setSelector($selectorStr);
     if (is_array($subSels) && count($subSels) == 0) {
         // Abbruch, da kein Wert gewählt
         return $this->handleNoSubSelectorValues();
     } elseif (is_string($subSels)) {
         // Ein String als Ergebnis bedeutet ebenfalls Abbruch.
         return $subSels;
     }
     $args = array();
     //$out .= $this->getContent($template, $conf, $conf->getFormatter(), $formTool);
     $handler = $menuItems[$menu['value']];
     if (is_object($handler)) {
         $subpart = '###' . strtoupper($handler->getSubID()) . '###';
         $templateSub = tx_rnbase_util_Templates::getSubpart($template, $subpart);
         $args[] = $templateSub;
         $args[] = $this->getModule();
         $args[] = array('subSels' => $subSels);
         // Der Handler sollte nicht das gesamte Template bekommen, sondern nur seinen Subpart...
         $subOut = call_user_func_array(array($handler, 'showScreen'), $args);
     }
     // Jetzt noch die COMMON-PARTS
     $content .= $formTool->getTCEForm()->printNeededJSFunctions_top();
     $content .= tx_rnbase_util_Templates::getSubpart($template, '###COMMON_START###');
     $content .= $subOut;
     $content .= tx_rnbase_util_Templates::getSubpart($template, '###COMMON_END###');
     // Den JS-Code für Validierung einbinden
     $content .= $formTool->getTCEForm()->printNeededJSFunctions();
     return $content;
 }
 /**
  * Liefert das Template für den Export
  * eigentlich private, für tests protected
  * @param string $type
  * @return string
  */
 private function getExportTemplate($type)
 {
     $configuration = $this->getConfigurations();
     $confId = $this->getConfId() . 'types.' . $type . '.template.';
     // template laden
     $sAbsPath = t3lib_div::getFileAbsFileName($configuration->get($confId . 'template'));
     $templateCode = t3lib_div::getURL($sAbsPath);
     if (!$templateCode) {
         $this->getModule()->addMessage('Could not find the template "' . $sAbsPath . '"  defined under ' . $confId . 'template' . '.', 'Template not found', 2);
         return FALSE;
     }
     // subpart auslesen
     $subpart = $configuration->get($confId . 'subpart');
     tx_rnbase::load('tx_rnbase_util_Templates');
     $template = tx_rnbase_util_Templates::getSubpart($templateCode, $subpart);
     if (!$template) {
         $this->getModule()->addMessage('Could not find the the subpart "' . $subpart . '" in template "' . $sAbsPath . '".', 'Subpart not found', 2);
         return FALSE;
     }
     return $template;
 }