當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TemplateLoader::getFiles方法代碼示例

本文整理匯總了PHP中TemplateLoader::getFiles方法的典型用法代碼示例。如果您正苦於以下問題:PHP TemplateLoader::getFiles方法的具體用法?PHP TemplateLoader::getFiles怎麽用?PHP TemplateLoader::getFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TemplateLoader的用法示例。


在下文中一共展示了TemplateLoader::getFiles方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: compareTemplate

 /**
  * Compares the current to the original template
  *
  * @param DataContainer $dc
  *
  * @return string
  */
 public function compareTemplate(DataContainer $dc)
 {
     $strCurrentPath = $dc->id;
     $strName = pathinfo($strCurrentPath, PATHINFO_FILENAME);
     $strExtension = pathinfo($strCurrentPath, PATHINFO_EXTENSION);
     $arrTemplates = TemplateLoader::getFiles();
     $blnOverridesAnotherTpl = isset($arrTemplates[$strName]);
     $strPrefix = '';
     if (($pos = strpos($strName, '_')) !== false) {
         $strPrefix = substr($strName, 0, $pos + 1);
     }
     $strBuffer = '';
     $strCompareName = null;
     $strComparePath = null;
     // By default it's the original template to compare against
     if ($blnOverridesAnotherTpl) {
         $strCompareName = $strName;
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
         if ($strComparePath !== null) {
             $strBuffer .= '<p class="tl_info" style="margin-bottom:1em">' . sprintf($GLOBALS['TL_LANG']['tl_templates']['overridesAnotherTpl'], $strComparePath) . '</p>';
         }
     }
     // User selected template to compare against
     if (\Input::post('from') && isset($arrTemplates[\Input::post('from')])) {
         $strCompareName = \Input::post('from');
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
     }
     if ($strComparePath !== null) {
         $objCurrentFile = new \File($strCurrentPath, true);
         $objCompareFile = new \File($strComparePath, true);
         // Abort if one file is missing
         if (!$objCurrentFile->exists() || !$objCompareFile->exists()) {
             $this->redirect('contao/main.php?act=error');
         }
         $objDiff = new Diff($objCompareFile->getContentAsArray(), $objCurrentFile->getContentAsArray());
         $strDiff = $objDiff->Render(new DiffRenderer(array('field' => $strCurrentPath)));
         // Identical versions
         if ($strDiff == '') {
             $strBuffer .= '<p>' . $GLOBALS['TL_LANG']['MSC']['identicalVersions'] . '</p>';
         } else {
             $strBuffer .= $strDiff;
         }
     } else {
         $strBuffer .= '<p class="tl_info">' . $GLOBALS['TL_LANG']['tl_templates']['pleaseSelect'] . '</p>';
     }
     // Templates to compare against
     $arrComparable = array();
     $intPrefixLength = strlen($strPrefix);
     foreach ($arrTemplates as $k => $v) {
         if (substr($k, 0, $intPrefixLength) === $strPrefix) {
             $arrComparable[$k] = array('version' => $k, 'info' => $k . '.' . $strExtension);
         }
     }
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_diff');
     // Template variables
     $objTemplate->staticTo = $strCurrentPath;
     $objTemplate->versions = $arrComparable;
     $objTemplate->from = $strCompareName;
     $objTemplate->showLabel = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->content = $strBuffer;
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->charset = \Config::get('characterSet');
     \Config::set('debugMode', false);
     $objTemplate->output();
     exit;
 }
開發者ID:StephenGWills,項目名稱:sample-contao-app,代碼行數:77,代碼來源:tl_templates.php

示例2: compareTemplate

 /**
  * Compares the current to the original template
  *
  * @param DataContainer $dc
  *
  * @return string
  *
  * @throws Contao\CoreBundle\Exception\InternalServerErrorException
  */
 public function compareTemplate(DataContainer $dc)
 {
     $objCurrentFile = new File($dc->id);
     $strName = $objCurrentFile->filename;
     $strExtension = $objCurrentFile->extension;
     $arrTemplates = TemplateLoader::getFiles();
     $blnOverridesAnotherTpl = isset($arrTemplates[$strName]);
     $strPrefix = '';
     if (($pos = strpos($strName, '_')) !== false) {
         $strPrefix = substr($strName, 0, $pos + 1);
     }
     $strBuffer = '';
     $strCompareName = null;
     $strComparePath = null;
     // By default it's the original template to compare against
     if ($blnOverridesAnotherTpl) {
         $strCompareName = $strName;
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
         if ($strComparePath !== null) {
             $strBuffer .= '<p class="tl_info" style="margin-bottom:1em">' . sprintf($GLOBALS['TL_LANG']['tl_templates']['overridesAnotherTpl'], $strComparePath) . '</p>';
         }
     } else {
         // Try to find the base template by strippig suffixes
         while (strpos($strName, '_') !== false) {
             $strName = substr($strName, 0, strrpos($strName, '_'));
             if (isset($arrTemplates[$strName])) {
                 $strCompareName = $strName;
                 $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
                 break;
             }
         }
     }
     // User selected template to compare against
     if (Input::post('from') && isset($arrTemplates[Input::post('from')])) {
         $strCompareName = Input::post('from');
         $strComparePath = $arrTemplates[$strCompareName] . '/' . $strCompareName . '.' . $strExtension;
     }
     if ($strComparePath !== null) {
         $objCompareFile = new File($strComparePath);
         // Abort if one file is missing
         if (!$objCurrentFile->exists() || !$objCompareFile->exists()) {
             throw new Contao\CoreBundle\Exception\InternalServerErrorException('The source or target file does not exist.');
         }
         $objDiff = new Diff($objCompareFile->getContentAsArray(), $objCurrentFile->getContentAsArray());
         $strDiff = $objDiff->render(new DiffRenderer(array('field' => $dc->id)));
         // Identical versions
         if ($strDiff == '') {
             $strBuffer .= '<p>' . $GLOBALS['TL_LANG']['MSC']['identicalVersions'] . '</p>';
         } else {
             $strBuffer .= $strDiff;
         }
     } else {
         $strBuffer .= '<p class="tl_info">' . $GLOBALS['TL_LANG']['tl_templates']['pleaseSelect'] . '</p>';
     }
     // Templates to compare against
     $arrComparable = array();
     $intPrefixLength = strlen($strPrefix);
     foreach ($arrTemplates as $k => $v) {
         if (substr($k, 0, $intPrefixLength) === $strPrefix) {
             $arrComparable[$k] = array('version' => $k, 'info' => $k . '.' . $strExtension);
         }
     }
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new BackendTemplate('be_diff');
     // Template variables
     $objTemplate->staticTo = $dc->id;
     $objTemplate->versions = $arrComparable;
     $objTemplate->from = $strCompareName;
     $objTemplate->showLabel = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->content = $strBuffer;
     $objTemplate->theme = Backend::getTheme();
     $objTemplate->base = Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']);
     $objTemplate->charset = Config::get('characterSet');
     Config::set('debugMode', false);
     throw new Contao\CoreBundle\Exception\ResponseException($objTemplate->getResponse());
 }
開發者ID:qzminski,項目名稱:contao-core-bundle,代碼行數:87,代碼來源:tl_templates.php


注:本文中的TemplateLoader::getFiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。