/** * Compile the current element */ protected function compile() { $config = deserialize($this->bootstrap_navbarModules, true); $modules = array(); $ids = array(); // get ids foreach ($config as $index => $module) { $ids[$index] = intval($module['module']); } // prefetch modules, so only 1 query is required $ids = implode(',', $ids); $collection = \ModuleModel::findBy(array('tl_module.id IN(' . $ids . ')'), array()); $models = array(); if ($collection) { while ($collection->next()) { $model = $collection->current(); $model->bootstrap_inNavbar = true; $models[$model->id] = $model; } } foreach ($config as $module) { $id = $module['module']; if ($id != '' && array_key_exists($id, $models)) { $modules[] = $this->generateModule($module, $models[$id]); } } if ($this->cssID[1] == '') { $cssID = $this->cssID; $cssID[1] = 'navbar-default'; $this->cssID = $cssID; } $this->Template->modules = $modules; }
public function getModules($mcw) { // Get all modules from DB $modules = array($GLOBALS['TL_LANG']['merger2']['legend_article'] => array('article' => $GLOBALS['TL_LANG']['merger2']['article'], 'inherit_articles' => $GLOBALS['TL_LANG']['merger2']['inherit_articles'], 'inherit_all_articles' => $GLOBALS['TL_LANG']['merger2']['inherit_all_articles'], 'inherit_articles_fallback' => $GLOBALS['TL_LANG']['merger2']['inherit_articles_fallback'], 'inherit_all_articles_fallback' => $GLOBALS['TL_LANG']['merger2']['inherit_all_articles_fallback'])); $themeCollection = \ThemeModel::findAll(array('order' => 'name')); while ($themeCollection->next()) { $modules[$themeCollection->name] = array(); $moduleCollection = \ModuleModel::findBy('pid', $themeCollection->id, array('order' => 'name')); if ($moduleCollection) { while ($moduleCollection->next()) { $modules[$themeCollection->name][$moduleCollection->id] = $moduleCollection->name; } } } return $modules; }
/** * Prefetch modules. * * @param array $config Navbar config. * * @return array */ protected function prefetchModules($config) { $ids = $this->extractModuleIds($config); $models = array(); if ($ids) { // prefetch modules, so only 1 query is required $ids = implode(',', $ids); $collection = \ModuleModel::findBy(array('tl_module.id IN(' . $ids . ')'), array()); if ($collection) { while ($collection->next()) { $model = $collection->current(); $model->bootstrap_inNavbar = true; $models[$model->id] = $model; } } } return $models; }
public function templates($obj) { $template = $obj->getName(); switch ($template) { case 'fe_page': case 'fe_page_multitoggle': //custom $obj->setName($template . '_gc'); //gc = grid controll only $obj->__get("layout")->__set("gridCSS", (array) $this->getGridArr($obj->layout)); break; case 'form': $obj->setName($template . '_' . \Config::get('co_grid_prefix')); break; default: } // `-,-´ ContentElements if ($obj->__get('typePrefix') == 'ce_' && strpos($template, 'ce_row_start') === FALSE) { $strClass = $this->findContentElement($obj->__get('type')); if ($strClass !== NULL && $strClass != '') { $objModel = \ContentModel::findBy('id', $obj->__get('id')); if ($objModel !== NULL) { $objEl = new $strClass($objModel); $objEl = $this->design_elements($objEl); $obj->__set('ftc_classes', $objEl->ftc_classes); $obj->__set('ftcID', $objEl->ftcID); $obj->__set('data_attr', $this->splitArr($objEl->data_attr)); $obj->__set('class', $objEl->ftc_classes); $obj->__set('cssID', $objEl->ftcID); } } } if (strpos($template, 'ce_row_start') !== FALSE) { $obj->__set('row_data_attr_ftc', $this->splitArr($obj->row_data_attr_ftc)); } // `-,-´ Article if (strpos($template, 'mod_article') !== FALSE) { $objModel = \ArticleModel::findBy('id', $obj->__get('id')); if ($objModel !== NULL) { $objEl = new \ModuleArticle($objModel); $objEl = $this->design_articles($objEl); $obj->__set('class', '' . $objEl->ftc_classes); $obj->__set('cssID', $objEl->ftcID . ' '); //.$objEl->data_attr.' ' } } // `-,-´ Module if ($obj->__get('typePrefix') == 'mod_') { $strClass = \Module::findClass($obj->__get('type')); if ($strClass !== NULL && $strClass != '') { $objModel = \ModuleModel::findBy('id', $obj->__get('id')); if ($objModel !== NULL) { $objEl = new $strClass($objModel); $co_grid = $this->design_modules($objEl); $obj->__set('class', $co_grid['class'] . ' ' . $co_grid['co_grid_classes']); // $obj->__set('cssID',$co_grid['ftcID'].' '.$co_grid['data_attr'].' '); $obj->__set('ftc_classes', $co_grid['class'] . ' ' . $co_grid['co_grid_classes']); $obj->__set('ftcID', $co_grid['ftcID'] . ' '); $obj->__set('ftc_data_attr', $co_grid['data_attr']); } } } }
/** * Generate the module * * @return string */ public function run() { $objTemplate = new \BackendTemplate('be_rsce_convert'); $objTemplate->isActive = $this->isActive(); $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex']; // Rebuild the index if (\Input::get('act') === 'rsce_convert') { // Check the request token if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) { $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request')); $this->redirect('contao/confirm.php'); } $this->import('Database'); $failedElements = array(); $elementsCount = 0; $contentElements = \ContentModel::findBy(array(\ContentModel::getTable() . '.type LIKE ?'), 'rsce_%'); while ($contentElements && $contentElements->next()) { $html = $this->getHtmlFromElement($contentElements); if (!$html) { $failedElements[] = array('content', $contentElements->id, $contentElements->type); } else { $this->createInitialVersion(\ContentModel::getTable(), $contentElements->id); $this->Database->prepare('UPDATE ' . \ContentModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $contentElements->id); $elementsCount++; $this->createNewVersion(\ContentModel::getTable(), $contentElements->id); $this->log('A new version of record "' . \ContentModel::getTable() . '.id=' . $contentElements->id . '" has been created', __METHOD__, TL_GENERAL); } } $moduleElements = \ModuleModel::findBy(array(\ModuleModel::getTable() . '.type LIKE ?'), 'rsce_%'); while ($moduleElements && $moduleElements->next()) { $html = $this->getHtmlFromElement($moduleElements); if (!$html) { $failedElements[] = array('module', $moduleElements->id, $moduleElements->type); } else { $this->createInitialVersion(\ModuleModel::getTable(), $moduleElements->id); $this->Database->prepare('UPDATE ' . \ModuleModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $moduleElements->id); $elementsCount++; $this->createNewVersion(\ModuleModel::getTable(), $moduleElements->id); $this->log('A new version of record "' . \ModuleModel::getTable() . '.id=' . $moduleElements->id . '" has been created', __METHOD__, TL_GENERAL); } } $formElements = \FormFieldModel::findBy(array(\FormFieldModel::getTable() . '.type LIKE ?'), 'rsce_%'); while ($formElements && $formElements->next()) { $html = $this->getHtmlFromElement($formElements); if (!$html) { $failedElements[] = array('form', $formElements->id, $formElements->type); } else { $this->createInitialVersion(\FormFieldModel::getTable(), $formElements->id); $this->Database->prepare('UPDATE ' . \FormFieldModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $formElements->id); $elementsCount++; $this->createNewVersion(\FormFieldModel::getTable(), $formElements->id); $this->log('A new version of record "' . \FormFieldModel::getTable() . '.id=' . $formElements->id . '" has been created', __METHOD__, TL_GENERAL); } } foreach ($failedElements as $element) { $this->log('Failed to convert ' . $element[0] . ' element ID ' . $element[1] . ' (' . $element[2] . ') to a standard HTML element', __METHOD__, TL_ERROR); } $this->log('Converted ' . $elementsCount . ' RockSolid Custom Elements to standard HTML elements', __METHOD__, TL_GENERAL); $objTemplate->elementsCount = $elementsCount; $objTemplate->failedElements = $failedElements; } $this->loadLanguageFile('rocksolid_custom_elements'); return $objTemplate->parse(); }
/** * Convert IDs for theme import * * @param \DOMDocument $xml theme.xml * @param \ZipWriter $zipArchive CTO file * @param int $themeId * @param array $idMappingData ID mapping for imported database rows * @return void */ public function extractThemeFilesHook($xml, $zipArchive, $themeId, $idMappingData) { $modules = \ModuleModel::findBy(array('tl_module.pid = ? AND tl_module.type LIKE \'rsce_%\''), $themeId); if (!$modules || !count($modules)) { return; } foreach ($modules as $module) { if (substr($module->type, 0, 5) !== 'rsce_') { continue; } $rsceDataConverted = $this->convertDataForImportExport(true, $module->type, $module->rsce_data, $idMappingData); if (!$rsceDataConverted || strtolower($rsceDataConverted) === 'null' || $rsceDataConverted === '{}' || $rsceDataConverted === '[]' || $rsceDataConverted === $module->rsce_data) { continue; } $module->rsce_data = $rsceDataConverted; $module->save(); } }