/** * * {{fmView::fm_tablename::8::template=fm_view::hl=h2&class=myClass&id=jsID}} * * @param $arrSplit * @return string */ private function generateTemplate($arrSplit) { if ($arrSplit[1] && $arrSplit[2]) { // objPage global $objPage; $this->import('FrontendUser', 'User'); // tablename $tablename = $arrSplit[1]; // id $id = $arrSplit[2]; // get parameter & parse parameter $params = $arrSplit[3] ? $arrSplit[3] : ''; parse_str($params, $qRow); $template = $qRow['template'] ? $qRow['template'] : 'fm_view'; $headline = $qRow['hl'] ? $qRow['hl'] : 'h3'; $className = $qRow['class'] ? $qRow['class'] . ' ' : ''; $jsID = $qRow['id'] ? $qRow['id'] : ''; // check if table exist if (!$this->Database->tableExists($tablename)) { return 'table does not exist'; } // get data $qProtectedStr = 'published = "1"'; // check for preview mode if (HelperModel::previewMode()) { $qProtectedStr = ''; } // build query $sqlQuery = 'SELECT * FROM ' . $tablename . '_data WHERE id = ' . $id . ' AND ' . $qProtectedStr . ' LIMIT 1'; if ($id == 'RAND') { $sqlQuery = 'SELECT * FROM ' . $tablename . '_data WHERE ' . $qProtectedStr . ' ORDER BY RAND() LIMIT 1'; } $moduleDB = $this->Database->prepare('SELECT tl_fmodules.id AS moduleID, tl_fmodules.*, tl_fmodules_filters.* FROM tl_fmodules LEFT JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY tl_fmodules_filters.sorting')->execute($tablename); $maps = array(); $widgets = array(); $arrCleanOptions = array(); // search for item $viewDB = $this->Database->prepare($sqlQuery)->execute(); // check if item exist if (!$viewDB->count()) { return 'no item found'; } $item = $this->parseItem($viewDB, $tablename); while ($moduleDB->next()) { $moduleInputFields = $moduleDB->row(); // get map if ($moduleInputFields['type'] == 'map_field') { $maps[] = $this->findMapAndSet($moduleInputFields); } if ($moduleInputFields['type'] == 'widget') { $widgets[] = $this->findWidgetAndSet($moduleInputFields); } // has options if ($moduleInputFields['type'] == 'simple_choice' || $moduleInputFields['type'] == 'multi_choice') { $dcaHelper = new DCAHelper(); // später durch statische methode austauschen! $arrCleanOptions[$moduleInputFields['fieldID']] = $dcaHelper->getOptions($moduleInputFields, $tablename, $item['pid']); } } // prepare for rendering $strTemplate = ''; $objTemplate = new FrontendTemplate($template); // parse css & id $cssClass = $item['cssID'][1] ? $item['cssID'][1] . ' ' : ''; $item['cssClass'] = $cssClass . $className; $item['jsID'] = $jsID ? $jsID : $item['cssID'][0]; $item['templateName'] = $template; $item['tableName'] = $tablename; // parse headline $item['hl'] = $headline; // parse image if ($item['addImage']) { $item['fullsize'] = ''; // disable full size $objTemplate->addImageToTemplate($objTemplate, $item); $item['picture'] = $objTemplate->picture; } // parse Gallery if ($item['addGallery']) { $objGallery = new GalleryGenerator(); $objGallery->id = $item['id']; $objGallery->sortBy = $item['sortBy']; $objGallery->orderSRC = $item['orderSRC']; $objGallery->metaIgnore = $item['metaIgnore']; $objGallery->numberOfItems = $item['numberOfItems']; $objGallery->perPage = $item['perPageGallery']; $objGallery->perRow = $item['perRow']; $objGallery->size = $item['size']; $objGallery->fullsize = $item['fullsize']; $objGallery->galleryTpl = $item['galleryTpl']; $objGallery->getAllImages($item['multiSRC']); $item['gallery'] = $objGallery->renderGallery(); } // parse enclosure $objTemplate->enclosure = array(); if ($item['addEnclosure']) { $objTemplate->addEnclosuresToTemplate($objTemplate, $item); } $item['enclosure'] = $objTemplate->enclosure; // parse map if (!empty($maps)) { foreach ($maps as $map) { $objMapTemplate = new FrontendTemplate($map['template']); $item['mapSettings'] = $map; $objMapTemplate->setData($item); $item[$map['fieldID']] = $objMapTemplate->parse(); } } // field if (!empty($widgets)) { $arrayAsValue = array('list.blank', 'list.keyValue', 'table.blank'); foreach ($widgets as $widget) { $id = $widget['fieldID']; $tplName = $widget['widgetTemplate']; $type = $widget['widgetType']; $value = $item[$id]; if (in_array($type, $arrayAsValue)) { $value = deserialize($value); } // unserialize $objFieldTemplate = new FrontendTemplate($tplName); $objFieldTemplate->setData(array('value' => $value, 'type' => $type, 'item' => $item)); $item[$id . 'AsTemplate'] = $objFieldTemplate->parse(); } } // set clean options if (!empty($arrCleanOptions)) { $item['cleanOptions'] = $arrCleanOptions; // overwrite clean options foreach ($arrCleanOptions as $fieldID => $options) { if ($item[$fieldID] && is_string($item[$fieldID])) { $arrValues = explode(',', $item[$fieldID]); $arrTemp = array(); if (is_array($arrValues)) { foreach ($arrValues as $val) { $arrTemp[$val] = $options[$val]; } } $item[$fieldID] = $arrTemp; } } } // set data to template $objTemplate->setData($item); // parse template $strTemplate .= $objTemplate->parse(); // set js files if ($this->loadMapScript) { $language = $objPage->language ? $objPage->language : 'en'; $GLOBALS['TL_HEAD']['mapJS'] = DiverseFunction::setMapJs($language); } // replace insertTags $strTemplate = $this->replaceInsertTags($strTemplate); // return template return $strTemplate; } return 'no valid arguments'; }