Пример #1
0
 /**
  * Check if a template definition is the current active template
  *
  * @param  TemplateDefinition $tplDefinition
  * @return bool               true is the given template is the active template
  */
 public function isActive(TemplateDefinition $tplDefinition)
 {
     switch ($tplDefinition->getType()) {
         case TemplateDefinition::FRONT_OFFICE:
             $tplVar = 'active-front-template';
             break;
         case TemplateDefinition::BACK_OFFICE:
             $tplVar = 'active-admin-template';
             break;
         case TemplateDefinition::PDF:
             $tplVar = 'active-pdf-template';
             break;
         case TemplateDefinition::EMAIL:
             $tplVar = 'active-mail-template';
             break;
     }
     return $tplDefinition->getName() == ConfigQuery::read($tplVar, 'default');
 }
Пример #2
0
 /**
  * @param TemplateDefinition $templateDefinition
  */
 public function setTemplateDefinition(TemplateDefinition $templateDefinition)
 {
     $this->templateDefinition = $templateDefinition;
     /* init template directories */
     $this->setTemplateDir(array());
     /* define config directory */
     $configDirectory = THELIA_TEMPLATE_DIR . $this->getTemplate() . '/configs';
     $this->addConfigDir($configDirectory, 0);
     /* add modules template directories */
     $this->addTemplateDirectory($templateDefinition->getType(), $templateDefinition->getName(), THELIA_TEMPLATE_DIR . $this->getTemplate(), '0', true);
     /* do not pass array directly to addTemplateDir since we cant control on keys */
     if (isset($this->templateDirectories[$templateDefinition->getType()][$templateDefinition->getName()])) {
         foreach ($this->templateDirectories[$templateDefinition->getType()][$templateDefinition->getName()] as $key => $directory) {
             $this->addTemplateDir($directory, $key);
             $this->addConfigDir($directory . "/configs", $key);
         }
     }
 }
Пример #3
0
 /**
  * @param TemplateDefinition $templateDefinition
  */
 public function setTemplateDefinition(TemplateDefinition $templateDefinition, $useFallback = false)
 {
     $this->templateDefinition = $templateDefinition;
     /* init template directories */
     $this->setTemplateDir(array());
     /* define config directory */
     $configDirectory = THELIA_TEMPLATE_DIR . $this->getTemplatePath() . DS . 'configs';
     $this->addConfigDir($configDirectory, self::TEMPLATE_ASSETS_KEY);
     /* add modules template directories */
     $this->addTemplateDirectory($templateDefinition->getType(), $templateDefinition->getName(), THELIA_TEMPLATE_DIR . $this->getTemplatePath(), self::TEMPLATE_ASSETS_KEY, true);
     $type = $templateDefinition->getType();
     $name = $templateDefinition->getName();
     /* do not pass array directly to addTemplateDir since we cant control on keys */
     if (isset($this->templateDirectories[$type][$name])) {
         foreach ($this->templateDirectories[$type][$name] as $key => $directory) {
             $this->addTemplateDir($directory, $key);
             $this->addConfigDir($directory . DS . 'configs', $key);
         }
     }
     // fallback on default template
     if ($useFallback && 'default' !== $name) {
         if (isset($this->templateDirectories[$type]['default'])) {
             foreach ($this->templateDirectories[$type]['default'] as $key => $directory) {
                 if (null === $this->getTemplateDir($key)) {
                     $this->addTemplateDir($directory, $key);
                     $this->addConfigDir($directory . DS . 'configs', $key);
                 }
             }
         }
     }
 }
Пример #4
0
 /**
  * Retrieve asset URL
  *
  * @param string                    $assetType js|css|image
  * @param array                     $params    Parameters
  *                                             - file File path in the default template
  *                                             - source module asset
  *                                             - filters filter to apply
  *                                             - debug
  *                                             - template if you want to load asset from another template
  * @param \Smarty_Internal_Template $template  Smarty Template
  *
  * @return string
  * @throws \Exception
  */
 public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template)
 {
     $assetUrl = "";
     $file = $params['file'];
     // The 'file' parameter is mandatory
     if (empty($file)) {
         throw new \InvalidArgumentException("The 'file' parameter is missing in an asset directive (type is '{$assetType}')");
     }
     $assetOrigin = isset($params['source']) ? $params['source'] : SmartyParser::TEMPLATE_ASSETS_KEY;
     $filters = isset($params['filters']) ? $params['filters'] : '';
     $debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
     $templateName = isset($params['template']) ? $params['template'] : false;
     Tlog::getInstance()->debug("Searching asset {$file} in source {$assetOrigin}, with template {$templateName}");
     /** @var \TheliaSmarty\Template\SmartyParser $smartyParser */
     $smartyParser = $template->smarty;
     if (false !== $templateName) {
         // We have to be sure that this external template assets have been properly prepared.
         // We will assume the following:
         //   1) this template have the same type as the current template,
         //   2) this template assets have the same structure as the current template
         //     (which is in self::$assetsDirectory)
         $currentTemplate = $smartyParser->getTemplateDefinition();
         $templateDefinition = new TemplateDefinition($templateName, $currentTemplate->getType());
         /* Add this templates directory to the current list */
         $smartyParser->addTemplateDirectory($templateDefinition->getType(), $templateDefinition->getName(), THELIA_TEMPLATE_DIR . $templateDefinition->getPath(), SmartyParser::TEMPLATE_ASSETS_KEY);
         $this->prepareTemplateAssets($templateDefinition, self::$assetsDirectory, $smartyParser);
     }
     $assetSource = $this->assetsResolver->resolveAssetSourcePath($assetOrigin, $templateName, $file, $smartyParser);
     if (null !== $assetSource) {
         $assetUrl = $this->assetsResolver->resolveAssetURL($assetOrigin, $file, $assetType, $smartyParser, $filters, $debug, self::$assetsDirectory, $templateName);
     } else {
         // Log the problem
         Tlog::getInstance()->addError("Failed to find asset source file " . $params['file']);
     }
     return $assetUrl;
 }