/** * Get all found template paths * * @param string $template Template name * @param string $format Format (xhtml or html5) * @return array All template paths for the specified template */ public static function getTemplates($template, $format = 'html5') { $templates = array(); try { $theme = \ThemeModel::findAll(array('order' => 'name')); } catch (\Exception $e) { $theme = null; } while ($theme && $theme->next()) { if ($theme->templates != '') { if (file_exists(TL_ROOT . '/' . $theme->templates . '/' . $template . '.' . $format)) { $templates[] = TL_ROOT . '/' . $theme->templates . '/' . $template . '.' . $format; } } } if (file_exists(TL_ROOT . '/templates/' . $template . '.' . $format)) { $templates[] = TL_ROOT . '/templates/' . $template . '.' . $format; } // Add templates of inactive themes to the bottom of the templates array $allFiles = glob(TL_ROOT . '/templates/*/' . $template . '.' . $format) ?: array(); foreach ($allFiles as $file) { if (!in_array($file, $templates)) { $templates[] = $file; } } if (count($templates)) { return $templates; } return array(parent::getTemplate($template, $format)); }
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; }
/** * prepare */ public function prepare() { // load backenduser $this->import('BackendUser', 'User'); // check permission if ($this->User->isAdmin || $this->User->hasAccess('themes', 'modules')) { // check if table exists if (!$this->Database->tableExists('tl_theme')) { return; } // get all existing themes $objThemes = \ThemeModel::findAll(array('order' => 'name')); // if there is at minimum one theme if (!is_null($objThemes) && $objThemes->count()) { // prepare array return $arrDirectEntry = array(); // set counter $intCounter = 1; // set icons array $arrIcons = array('css' => 'tl_style_sheet', 'modules' => 'tl_module', 'layout' => 'tl_layout'); // do this foreach theme while ($objThemes->next()) { // set the theme url and title $arrDirectEntry[$intCounter]['name']['url'] = 'contao/main.php?do=themes&act=edit&id=' . $objThemes->id; $arrDirectEntry[$intCounter]['name']['title'] = $objThemes->name; $arrDirectEntry[$intCounter]['name']['link'] = strlen($objThemes->name) > 10 ? substr($objThemes->name, 0, 8) . '...' : $objThemes->name; // foreach icons foreach ($arrIcons as $strIcon => $strTableName) { // check detail permissions if ($this->User->isAdmin || $this->User->hasAccess($strIcon, 'themes')) { // set the icon url and title $arrDirectEntry[$intCounter]['icons'][$strIcon]['url'] = 'contao/main.php?do=themes&id=' . $objThemes->id . '&table=' . $strTableName; $arrDirectEntry[$intCounter]['icons'][$strIcon]['title'] = $strIcon; $arrDirectEntry[$intCounter]['icons'][$strIcon]['icon'] = $strIcon; } } // add one to counter $intCounter++; } // add to direcentries service $this->import('DirectEntries'); $this->DirectEntries->addDirectEntry('design', 'themes', $arrDirectEntry); } } }
public static function getTemplateGroup($strPrefix, $intThemeId = null) { $arrTemplates = array(); // Get the default templates foreach (\TemplateLoader::getPrefixedFiles($strPrefix) as $strTemplate) { $arrTemplates[$strTemplate] = $strTemplate; } $arrCustomized = glob(TL_ROOT . '/templates/' . $strPrefix . '*'); // Add the customized templates if (is_array($arrCustomized)) { foreach ($arrCustomized as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[$strTemplate])) { $arrTemplates[$strTemplate] = $strTemplate; } } } // Do not look for back end templates in theme folders (see #5379) if ($strPrefix == 'be_' || $strPrefix == 'mail_') { return $arrTemplates; } $arrDefault = $arrTemplates; $arrTemplates = array('safeTpl' => $arrDefault, 'unsafeTpl' => array()); // Try to select the themes (see #5210) try { $objTheme = \ThemeModel::findAll(array('order' => 'name')); } catch (\Exception $e) { $objTheme = null; } // Add the theme templates if ($objTheme === null) { return $arrTemplates; } while ($objTheme->next()) { $strGroup = $objTheme->id == $intThemeId ? 'safeTpl' : 'unsafeTpl'; if ($objTheme->templates == '') { continue; } $arrThemeTemplates = glob(TL_ROOT . '/' . $objTheme->templates . '/' . $strPrefix . '*'); if (!is_array($arrThemeTemplates)) { continue; } foreach ($arrThemeTemplates as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[$strGroup][$strTemplate])) { $arrTemplates[$strGroup][$strTemplate] = $strTemplate . ' (' . sprintf($GLOBALS['TL_LANG']['MSC']['templatesTheme'], $objTheme->name) . ')'; } else { $arrTemplates[$strGroup][$strTemplate] .= ' (' . sprintf($GLOBALS['TL_LANG']['MSC']['templatesTheme'], $objTheme->name) . ')'; } } } return $arrTemplates; }
/** * Return all template files of a particular group as array * * @param string $strPrefix The template name prefix (e.g. "ce_") * * @return array An array of template names */ public static function getTemplateGroup($strPrefix) { $arrTemplates = array(); // Get the default templates foreach (\TemplateLoader::getPrefixedFiles($strPrefix) as $strTemplate) { $arrTemplates[$strTemplate][] = 'root'; } $arrCustomized = glob(TL_ROOT . '/templates/' . $strPrefix . '*'); // Add the customized templates if (is_array($arrCustomized)) { foreach ($arrCustomized as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); $arrTemplates[$strTemplate][] = $GLOBALS['TL_LANG']['MSC']['global']; } } // Do not look for back end templates in theme folders (see #5379) if ($strPrefix != 'be_' && $strPrefix != 'mail_') { // Try to select the themes (see #5210) try { $objTheme = \ThemeModel::findAll(array('order' => 'name')); } catch (\Exception $e) { $objTheme = null; } // Add the theme templates if ($objTheme !== null) { while ($objTheme->next()) { if ($objTheme->templates != '') { $arrThemeTemplates = glob(TL_ROOT . '/' . $objTheme->templates . '/' . $strPrefix . '*'); if (is_array($arrThemeTemplates)) { foreach ($arrThemeTemplates as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[$strTemplate])) { $arrTemplates[$strTemplate][] = $objTheme->name; } else { $arrTemplates[$strTemplate][] = $objTheme->name; } } } } } } } // Show the template sources (see #6875) foreach ($arrTemplates as $k => $v) { $v = array_filter($v, function ($a) { return $a != 'root'; }); if (empty($v)) { $arrTemplates[$k] = $k; } else { $arrTemplates[$k] = $k . ' (' . implode(', ', $v) . ')'; } } // Sort the template names ksort($arrTemplates); return $arrTemplates; }
private function getTemplatePathes(ContaoTwigConfig $config) { $arrTemplatePaths = array(); // Add the layout templates directory if ($config->isEnableThemeTemplatesLoader() && TL_MODE == 'FE') { global $objPage; $strTemplateGroup = str_replace(array('../', 'templates/'), '', $objPage->templateGroup); if ($strTemplateGroup != '') { $arrTemplatePaths[] = TL_ROOT . '/templates/' . $strTemplateGroup; } } else { if (TL_MODE == 'BE') { $themeCollection = \ThemeModel::findAll(); if ($themeCollection) { while ($themeCollection->next()) { if ($themeCollection->templates) { $arrTemplatePaths[] = TL_ROOT . '/' . $themeCollection->templates; } } } } } // Add the global templates directory if ($config->isEnableGlobalTemplatesLoader()) { $arrTemplatePaths[] = TL_ROOT . '/templates'; } $this->addModuleTemplatePathes($config, $arrTemplatePaths); return $arrTemplatePaths; }
/** * List an file * * @param array * * @return string */ public function listFileFor($row, $layoutField = false) { switch ($row['type']) { case 'code': $label = $row['code_snippet_title']; break; case 'url': $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $row['url']); break; case 'file': if ($row['filesource'] == $GLOBALS['TL_CONFIG']['uploadPath'] && version_compare(VERSION, '3', '>=')) { $file = version_compare(VERSION, '3.2', '>=') ? \FilesModel::findByUuid($row['file']) : \FilesModel::findByPk($row['file']); if ($file) { $label = preg_replace('#/([^/]+)$#', '/<strong>$1</strong>', $file->path); break; } } else { $label = preg_replace('#([^/]+)$#', '<strong>$1</strong>', $row['file']); break; } default: $label = '?'; } if ($row['inline']) { \Controller::loadLanguageFile('tl_theme_plus_file'); $label = sprintf('<span title="%s">‹›</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['inline'], ENT_QUOTES, 'UTF-8'), $label); } else { if ($row['standalone']) { \Controller::loadLanguageFile('tl_theme_plus_file'); $label = sprintf('<span title="%s">×</span> %s', htmlentities($GLOBALS['TL_LANG']['tl_theme_plus_file']['standalone'], ENT_QUOTES, 'UTF-8'), $label); } } if (strlen($row['position'])) { $label = '[' . strtoupper($row['position']) . '] ' . $label; } if (strlen($row['cc'])) { $label .= ' <span style="padding-left: 3px; color: #B3B3B3;">[' . $row['cc'] . ']</span>'; } $filterRules = static::renderFilterRules($row); if ($filterRules) { $label .= sprintf('<br><span style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">[%s]</span>', $filterRules); } if ($layoutField) { $assignedLayouts = []; $themes = \ThemeModel::findAll(['order' => 'name']); foreach ($themes as $theme) { $assignedThemeLayouts = []; $layouts = \LayoutModel::findBy('pid', $theme->id, ['order' => 'name']); foreach ($layouts as $layout) { $files = deserialize($layout->{$layoutField}, true); if (in_array($row['id'], $files)) { $assignedThemeLayouts[$layout->id] = $layout->name; } } if (count($assignedThemeLayouts)) { $assignedLayouts[$theme->name] = $assignedThemeLayouts; } } if (count($assignedLayouts)) { $label .= '<ul style="margin-left: 20px; padding-left: 3px; color: #B3B3B3;">'; foreach ($assignedLayouts as $theme => $layouts) { $label .= '<li>'; $label .= sprintf('<strong>%s</strong>', $theme); $label .= '<ul>'; foreach ($layouts as $id => $layout) { $label .= sprintf('<li> ↳ <a href="%s">%s</a></li>', \Backend::addToUrl('table=tl_layout&act=edit&id=' . $id), $layout); } $label .= '</ul>'; $label .= '</li>'; } $label .= '</ul>'; } } $image = 'assets/theme-plus/images/' . $row['type'] . '.png'; return '<div>' . ($image ? $this->generateImage($image, $label, 'style="vertical-align:-3px"') . ' ' : '') . $label . "</div>\n"; }
/** * Generate the html for the toolbar */ protected function generateToolbar($strContent) { // get themes $objThemes = \ThemeModel::findAll(array('order' => 'name')); // vertical or horizontal $id = $this->User->om_toolbar == 1 ? 'toolbar' : 'toolbarHorizontal'; $class = version_compare(VERSION . '.' . BUILD, '3.3.0', '<') ? '' : 'contao33'; // open container $strToolbar = '<div id="' . $id . '" class="' . $class . '"><h1>Tools</h1>'; // add button - id search //$strToolbar .= '<a class="button" href="contao/main.php?do=id_search" title="'.$GLOBALS['TL_LANG']['om_backend']['id_search'].'"><img class="pngfix" src="system/modules/om_backend/html/find.png" width="16" height="16" alt="'.$GLOBALS['TL_LANG']['om_backend']['id_search'].'" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\'ID-Suche\',\'url\':this.href});return false"></a>'; $strToolbar .= '<a class="button" href="contao/main.php?do=id_search" title="' . $GLOBALS['TL_LANG']['om_backend']['id_search'] . '"><img class="pngfix" src="system/modules/om_backend/html/find.png" width="16" height="16" alt="' . $GLOBALS['TL_LANG']['om_backend']['id_search'] . '"></a>'; // add button - update database $strToolbar .= '<a class="button" href="contao/main.php?do=repository_manager&update=database" title="' . $GLOBALS['TL_LANG']['om_backend']['update_database'] . '"><img class="pngfix" src="system/modules/repository/themes/default/images/dbcheck16.png" width="16" height="16" alt="' . $GLOBALS['TL_LANG']['om_backend']['update_database'] . '"></a>'; // add button - new template $strToolbar .= '<a class="button" href="contao/main.php?do=tpl_editor&key=new_tpl&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . $GLOBALS['TL_LANG']['om_backend']['new_template'] . '"><img class="pngfix" src="system/modules/om_backend/assets/icons/page_add.png" width="16" height="16" alt="' . $GLOBALS['TL_LANG']['om_backend']['new_template'] . '"></a>'; // add button - sync $strToolbar .= '<a class="button" href="contao/main.php?do=files&act=sync&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . $GLOBALS['TL_LANG']['om_backend']['sync_files'] . '"><img class="pngfix" src="system/themes/default/images/sync.gif" width="16" height="16" alt="' . $GLOBALS['TL_LANG']['om_backend']['sync_files'] . '"></a>'; // exist a theme? if (is_object($objThemes) && $objThemes->count() > 0) { // add css, modules and layouts while ($objThemes->next()) { // add separator $strToolbar .= '<div class="separator"></div>'; // add buttons $strToolbar .= '<a class="button" href="contao/main.php?do=themes&table=tl_style_sheet&id=' . $objThemes->id . '&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . sprintf($GLOBALS['TL_LANG']['om_backend']['stylesheets'], $objThemes->name) . '"><img src="system/themes/default/images/css.gif" width="17" height="16" alt="Stylesheets"></a>'; $strToolbar .= '<a class="button" href="contao/main.php?do=themes&table=tl_module&id=' . $objThemes->id . '&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . sprintf($GLOBALS['TL_LANG']['om_backend']['modules'], $objThemes->name) . '"><img src="system/themes/default/images/modules.gif" width="16" height="16" alt="Module"></a>'; $strToolbar .= '<a class="button" href="contao/main.php?do=themes&table=tl_layout&id=' . $objThemes->id . '&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . sprintf($GLOBALS['TL_LANG']['om_backend']['layouts'], $objThemes->name) . '"><img src="system/themes/default/images/layout.gif" width="14" height="16" alt="Seitenlayouts"></a>'; if (version_compare(VERSION . '.' . BUILD, '3.4.0', '>=')) { $strToolbar .= '<a class="button" href="contao/main.php?do=themes&table=tl_image_size&id=' . $objThemes->id . '&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . sprintf($GLOBALS['TL_LANG']['om_backend']['image_size'], $objThemes->name) . '"><img src="system/themes/default/images/sizes.gif" width="14" height="16" alt="Bildgrößen"></a>'; } } } // generate save buttons if (strpos($strContent, 'class="tl_submit_container"') !== false && strpos($strContent, 'name="save"') !== FALSE) { // button save if (strpos($strContent, 'name="save"') !== FALSE) { $arrButtons[] = 'save'; } // button save and close if (strpos($strContent, 'name="saveNclose"') !== FALSE) { $arrButtons[] = 'saveNclose'; } // button save and create if (strpos($strContent, 'name="saveNcreate"') !== FALSE) { $arrButtons[] = 'saveNcreate'; } // button save and back if (strpos($strContent, 'name="saveNback"') !== FALSE) { $arrButtons[] = 'saveNback'; } // add alls buttons and separator if (is_array($arrButtons)) { // add separator $strToolbar .= '<div class="separator"></div>'; // add buttons foreach ($arrButtons as $button) { $strToolbar .= '<a class="button" onclick="document.getElementById(\'' . $button . '\').click(); return false;" title="' . $GLOBALS['TL_LANG']['MSC'][$button] . '"><img src="system/modules/om_backend/assets/icons/' . $button . '.png" width="14" height="16" alt="' . $GLOBALS['TL_LANG']['MSC'][$button] . '"></a>'; } } } // edit multiple ? if (strpos($strContent, 'class="header_edit_all"') !== false) { // get parameter $id = strlen(\Input::get('id')) ? '&id' . \Input::get('id') : ''; $table = strlen(\Input::get('table')) ? '&table=' . \Input::get('table') : ''; // add separator and button $strToolbar .= '<div class="separator"></div>'; $strToolbar .= '<a class="button" href="contao/main.php?do=' . \Input::get('do') . $table . $id . '&act=select&rt=' . $_SESSION['REQUEST_TOKEN'] . '" title="' . sprintf($GLOBALS['TL_LANG']['om_backend']['stylesheets'], $objThemes->name) . '"><img src="system/themes/default/images/all.gif" width="17" height="16" alt="Stylesheets"></a>'; } // edit multiple buttons if (strpos($strContent, 'class="tl_submit_container"') !== false && strpos($strContent, 'name="edit"') !== FALSE) { // html button names $arrButtonNames = array('delete', 'cut', 'copy', 'override', 'edit', 'alias'); // check for buttons foreach ($arrButtonNames as $buttonName) { // button save if (strpos($strContent, 'name="' . $buttonName . '"') !== FALSE) { $arrButtons[] = $buttonName; } } // add alls buttons and separator if (is_array($arrButtons)) { // add separator $strToolbar .= '<div class="separator"></div>'; // add buttons foreach ($arrButtons as $button) { $strToolbar .= '<a class="button" onclick="document.getElementById(\'' . $button . '\').click(); return false;" title="' . $GLOBALS['TL_LANG']['om_backend']['button_' . $button] . '"><img src="system/modules/om_backend/assets/icons/folder_' . $button . '.png" width="14" height="16" alt="' . $GLOBALS['TL_LANG']['om_backend']['button_' . $button] . '"></a>'; } } } // close container $strToolbar .= '</div>'; return $strToolbar; }
/** * List template from all themes, show theme name * @param string * @param int * @return array */ public static function getTemplates($strPrefix) { $arrTemplates = array(); // Get the default templates foreach (\TemplateLoader::getPrefixedFiles($strPrefix) as $strTemplate) { $arrTemplates[$strTemplate] = $strTemplate; } $arrCustomized = glob(TL_ROOT . '/templates/' . $strPrefix . '*'); // Add the customized templates if (is_array($arrCustomized)) { foreach ($arrCustomized as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[$strTemplate])) { $arrTemplates[''][$strTemplate] = $strTemplate; } } } // Do not look for back end templates in theme folders (see #5379) if ($strPrefix == 'be_') { return $arrTemplates; } // Try to select the shop configs try { $objConfig = Config::findAll(array('order' => 'name')); } catch (\Exception $e) { $objConfig = null; } // Add the shop config templates if (null !== $objConfig) { while ($objConfig->next()) { if ($objConfig->templateGroup != '') { $strFolder = sprintf($GLOBALS['TL_LANG']['MSC']['templatesConfig'], $objConfig->name); $arrConfigTemplates = glob(TL_ROOT . '/' . $objConfig->templateGroup . '/' . $strPrefix . '*'); if (is_array($arrConfigTemplates)) { foreach ($arrConfigTemplates as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[''][$strTemplate])) { $arrTemplates[$strFolder][$strTemplate] = $strTemplate; } } } } } } // Try to select the themes (see #5210) try { $objTheme = \ThemeModel::findAll(array('order' => 'name')); } catch (\Exception $e) { $objTheme = null; } // Add the theme templates if (null !== $objTheme) { while ($objTheme->next()) { if ($objTheme->templates != '') { $strFolder = sprintf($GLOBALS['TL_LANG']['MSC']['templatesTheme'], $objTheme->name); $arrThemeTemplates = glob(TL_ROOT . '/' . $objTheme->templates . '/' . $strPrefix . '*'); if (is_array($arrThemeTemplates)) { foreach ($arrThemeTemplates as $strFile) { $strTemplate = basename($strFile, strrchr($strFile, '.')); if (!isset($arrTemplates[''][$strTemplate])) { $arrTemplates[$strFolder][$strTemplate] = $strTemplate; } } } } } } return $arrTemplates; }