The class stores template names and automatically loads the files upon their first usage. It uses a mapper array to support complex nesting and arbitrary subfolders to store the template files in. Usage: ClassLoader::addFile('moo_mediabox', 'core/templates');
Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * Initializes the framework.
  */
 private function initializeFramework()
 {
     // Set the error_reporting level
     error_reporting($this->errorLevel);
     $this->includeHelpers();
     $this->includeBasicClasses();
     // Set the container
     System::setContainer($this->container);
     /** @var Config $config */
     $config = $this->getAdapter(Config::class);
     // Preload the configuration (see #5872)
     $config->preload();
     // Register the class loader
     ClassLoader::scanAndRegister();
     $this->initializeLegacySessionAccess();
     $this->setDefaultLanguage();
     // Fully load the configuration
     $config->getInstance();
     $this->validateInstallation();
     Input::initialize();
     TemplateLoader::initialize();
     $this->setTimezone();
     $this->triggerInitializeSystemHook();
     $this->handleRequestToken();
 }