/** * 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)); }
/** * Check the Isotope config directory for a particular template * @param string * @return string * @throws Exception */ protected function getTemplate($strTemplate, $strFormat = 'html5') { $arrAllowed = trimsplit(',', $GLOBALS['TL_CONFIG']['templateFiles']); if (is_array($GLOBALS['TL_CONFIG']['templateFiles']) && !in_array($strFormat, $arrAllowed)) { throw new Exception("Invalid output format {$strFormat}"); } $strKey = $strTemplate . '.' . $strFormat; $strPath = TL_ROOT . '/templates'; $strTemplate = basename($strTemplate); // Check the templates subfolder if (TL_MODE == 'FE') { global $objPage; $strTemplateGroup = str_replace(array('../', 'templates/'), '', $this->Isotope->Config->templateGroup); if ($strTemplateGroup != '') { $strFile = $strPath . '/' . $strTemplateGroup . '/' . $strKey; if (file_exists($strFile)) { return $strFile; } // Also check for .tpl files (backwards compatibility) $strFile = $strPath . '/' . $strTemplateGroup . '/' . $strTemplate . '.tpl'; if (file_exists($strFile)) { return $strFile; } } } return parent::getTemplate($strTemplate, $strFormat); }
/** * Check the Isotope config directory for a particular template * * @param string $strTemplate * @param string $strFormat * * @return string */ public static function getTemplate($strTemplate, $strFormat = 'html5') { $arrAllowed = trimsplit(',', $GLOBALS['TL_CONFIG']['templateFiles']); if (is_array($GLOBALS['TL_CONFIG']['templateFiles']) && !in_array($strFormat, $arrAllowed)) { throw new \InvalidArgumentException("Invalid output format {$strFormat}"); } $strKey = $strTemplate . '.' . $strFormat; $strPath = TL_ROOT . '/templates'; $strTemplate = basename($strTemplate); // Check the templates subfolder $strTemplateGroup = str_replace(array('../', 'templates/'), '', Isotope::getConfig()->templateGroup); if ($strTemplateGroup != '') { $strFile = $strPath . '/' . $strTemplateGroup . '/' . $strKey; if (file_exists($strFile)) { return $strFile; } if (file_exists($strFile)) { return $strFile; } } return parent::getTemplate($strTemplate, $strFormat); }