/** * 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; }
/** * Return all newsletter content element templates as array * @return array */ public function getNewsletterElementTemplates() { $strPrefix = 'nl_'; $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']; } } // 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; }
/** * Return all template files of a particular group as array * * @param string $strPrefix The template name prefix (e.g. "ce_") * @param integer $intTheme The ID of the theme * * @return array An array of template names */ public static function getTemplateGroup($strPrefix, $intTheme = 0) { $strTplFolder = 'templates'; $arrTemplates = \TemplateLoader::getPrefixedFiles($strPrefix); // Check for a theme templates folder if ($intTheme > 0) { $objTheme = \ThemeModel::findByPk($intTheme); if ($objTheme !== null && $objTheme->templates != '') { $strTplFolder = $objTheme->templates; } } // Scan the templates directory $arrFiles = array_values(preg_grep('/^' . $strPrefix . '/', scan(TL_ROOT . '/' . $strTplFolder))); if (!empty($arrFiles)) { foreach ($arrFiles as $strFile) { $arrTemplates[] = basename($strFile, strrchr($strFile, '.')); } } natcasesort($arrTemplates); $arrTemplates = array_values(array_unique($arrTemplates)); return $arrTemplates; }
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; }
/** * 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; }