Merge branch 'modules'
Conflicts: core/lib/Thelia/Controller/Admin/BaseAdminController.php core/lib/Thelia/Core/Template/Smarty/SmartyParser.php core/lib/Thelia/Core/Thelia.php
This commit is contained in:
@@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
|
|||||||
'Config',
|
'Config',
|
||||||
'Model',
|
'Model',
|
||||||
'Loop',
|
'Loop',
|
||||||
'AdminIncludes'
|
'AdminIncludes',
|
||||||
|
'templates',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected function verifyExistingModule()
|
protected function verifyExistingModule()
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
<argument type="service" id="event_dispatcher"/>
|
<argument type="service" id="event_dispatcher"/>
|
||||||
<argument type="service" id="thelia.parser.context"/>
|
<argument type="service" id="thelia.parser.context"/>
|
||||||
<argument >false</argument> <!-- Template name, or false -->
|
|
||||||
<argument >%kernel.environment%</argument>
|
<argument >%kernel.environment%</argument>
|
||||||
<argument >%kernel.debug%</argument>
|
<argument >%kernel.debug%</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class BaseAdminController extends BaseController
|
|||||||
{
|
{
|
||||||
$parser = $this->container->get("thelia.parser");
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
// Define the template thant shoud be used
|
// Define the template that should be used
|
||||||
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
|
$parser->setTemplate($template ?: TemplateHelper::getInstance()->getActiveAdminTemplate()->getPath());
|
||||||
|
|
||||||
return $parser;
|
return $parser;
|
||||||
|
|||||||
@@ -311,6 +311,11 @@ class BaseController extends ContainerAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* return an instance of SmartyParser
|
||||||
|
*
|
||||||
|
* Caution : maybe there is still not default template defined.
|
||||||
|
*
|
||||||
* @return ParserInterface instance parser
|
* @return ParserInterface instance parser
|
||||||
*/
|
*/
|
||||||
protected function getParser()
|
protected function getParser()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Thelia\Controller\Front;
|
|||||||
use Symfony\Component\Routing\Router;
|
use Symfony\Component\Routing\Router;
|
||||||
use Thelia\Controller\BaseController;
|
use Thelia\Controller\BaseController;
|
||||||
use Thelia\Model\AddressQuery;
|
use Thelia\Model\AddressQuery;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Model\ModuleQuery;
|
use Thelia\Model\ModuleQuery;
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
@@ -83,4 +84,16 @@ class BaseFrontController extends BaseController
|
|||||||
$this->redirectToRoute("order.invoice");
|
$this->redirectToRoute("order.invoice");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ParserInterface instance parser
|
||||||
|
*/
|
||||||
|
protected function getParser()
|
||||||
|
{
|
||||||
|
$parser = $this->container->get("thelia.parser");
|
||||||
|
|
||||||
|
$parser->setTemplate(ConfigQuery::getActiveTemplate());
|
||||||
|
|
||||||
|
return $parser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,15 +23,18 @@
|
|||||||
namespace Thelia\Core\EventListener;
|
namespace Thelia\Core\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Thelia\Core\HttpFoundation\Response;
|
use Thelia\Core\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Router;
|
use Symfony\Component\Routing\Router;
|
||||||
|
use Thelia\Core\HttpKernel\Exception\NotFountHttpException;
|
||||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||||
use Thelia\Core\Template\ParserInterface;
|
use Thelia\Core\Template\ParserInterface;
|
||||||
use Thelia\Exception\OrderException;
|
use Thelia\Exception\OrderException;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
use Thelia\Tools\Redirect;
|
use Thelia\Tools\Redirect;
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||||
@@ -74,9 +77,11 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
$parser = $this->container->get('thelia.parser');
|
$parser = $this->container->get('thelia.parser');
|
||||||
|
$parser->setTemplate(ConfigQuery::getActiveTemplate());
|
||||||
|
$request = $this->container->get('request');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$content = $parser->getContent();
|
$content = $parser->render($request->attributes->get('_view').".html");
|
||||||
|
|
||||||
if ($content instanceof Response) {
|
if ($content instanceof Response) {
|
||||||
$response = $content;$event->setResponse($content);
|
$response = $content;$event->setResponse($content);
|
||||||
@@ -94,7 +99,7 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
} catch (ResourceNotFoundException $e) {
|
} catch (ResourceNotFoundException $e) {
|
||||||
$event->setResponse(new Response($e->getMessage(), 404));
|
throw new NotFoundHttpException();
|
||||||
} catch (AuthenticationException $ex) {
|
} catch (AuthenticationException $ex) {
|
||||||
|
|
||||||
// Redirect to the login template
|
// Redirect to the login template
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ interface ParserInterface
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getContent();
|
public function render($realTemplateName, array $parameters = array());
|
||||||
|
|
||||||
public function setContent($content);
|
public function setContent($content);
|
||||||
|
|
||||||
|
|||||||
@@ -38,13 +38,12 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param EventDispatcherInterface $dispatcher
|
* @param EventDispatcherInterface $dispatcher
|
||||||
* @param ParserContext $parserContext
|
* @param ParserContext $parserContext
|
||||||
* @param bool $template
|
|
||||||
* @param string $env
|
* @param string $env
|
||||||
* @param bool $debug
|
* @param bool $debug
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
|
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
|
||||||
$template = false, $env = "prod", $debug = false)
|
$env = "prod", $debug = false)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
@@ -63,7 +62,6 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->setCompileDir($compile_dir);
|
$this->setCompileDir($compile_dir);
|
||||||
$this->setCacheDir($cache_dir);
|
$this->setCacheDir($cache_dir);
|
||||||
|
|
||||||
$this->setTemplate($template ?: TemplateHelper::getInstance()->getActiveFrontTemplate()->getPath());
|
|
||||||
|
|
||||||
$this->debugging = $debug;
|
$this->debugging = $debug;
|
||||||
|
|
||||||
@@ -79,6 +77,8 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->setForceCompile(false);
|
$this->setForceCompile(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//$this->enableSecurity();
|
||||||
|
|
||||||
|
|
||||||
// The default HTTP status
|
// The default HTTP status
|
||||||
$this->status = 200;
|
$this->status = 200;
|
||||||
@@ -105,7 +105,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
{
|
{
|
||||||
$this->template = $template_path_from_template_base;
|
$this->template = $template_path_from_template_base;
|
||||||
|
|
||||||
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
|
$this->addTemplateDir(THELIA_TEMPLATE_DIR.$this->template, 0);
|
||||||
|
|
||||||
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
|
$config_dir = THELIA_TEMPLATE_DIR.$this->template.'/configs';
|
||||||
|
|
||||||
@@ -126,6 +126,9 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
*/
|
*/
|
||||||
public function render($realTemplateName, array $parameters = array())
|
public function render($realTemplateName, array $parameters = array())
|
||||||
{
|
{
|
||||||
|
if(false === $this->templateExists($realTemplateName)) {
|
||||||
|
throw new ResourceNotFoundException();
|
||||||
|
}
|
||||||
// Assign the parserContext variables
|
// Assign the parserContext variables
|
||||||
foreach ($this->parserContext as $var => $value) {
|
foreach ($this->parserContext as $var => $value) {
|
||||||
$this->assign($var, $value);
|
$this->assign($var, $value);
|
||||||
@@ -133,23 +136,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
|
|
||||||
$this->assign($parameters);
|
$this->assign($parameters);
|
||||||
|
|
||||||
return $this->fetch($realTemplateName);
|
return $this->fetch(sprintf("file:%s", $realTemplateName));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function getContent()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$templateFile = $this->getTemplateFilePath();
|
|
||||||
} catch (\RuntimeException $e) {
|
|
||||||
return new Response($this->render(\Thelia\Model\ConfigQuery::getPageNotFoundView()), "404");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render($templateFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,26 +197,4 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTemplateFilePath()
|
|
||||||
{
|
|
||||||
$file = $this->request->attributes->get('_view');
|
|
||||||
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file;
|
|
||||||
|
|
||||||
$pathFileName = realpath(dirname(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file));
|
|
||||||
$templateDir = realpath(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
|
|
||||||
|
|
||||||
if (strpos($pathFileName, $templateDir) !== 0) {
|
|
||||||
throw new ResourceNotFoundException(sprintf("this view does not exists"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($fileName)) {
|
|
||||||
$fileName .= ".html";
|
|
||||||
|
|
||||||
if (!file_exists($fileName)) {
|
|
||||||
throw new ResourceNotFoundException(sprintf("file not found in %s template", $this->template));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fileName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,8 +124,10 @@ class Thelia extends Kernel
|
|||||||
|
|
||||||
if (defined("THELIA_INSTALL_MODE") === false) {
|
if (defined("THELIA_INSTALL_MODE") === false) {
|
||||||
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
$modules = \Thelia\Model\ModuleQuery::getActivated();
|
||||||
$translator = $container->getDefinition('thelia.translator');
|
|
||||||
$dirs = array();
|
$translationDirs = array();
|
||||||
|
$templateDirs = array();
|
||||||
|
$parser = $container->getDefinition('thelia.parser');
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -139,50 +141,65 @@ class Thelia extends Kernel
|
|||||||
$defintion
|
$defintion
|
||||||
);
|
);
|
||||||
|
|
||||||
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . $module->getConfigPath()));
|
|
||||||
|
$code = ucfirst($module->getCode());
|
||||||
|
|
||||||
|
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . $code . "/Config"));
|
||||||
$loader->load("config.xml");
|
$loader->load("config.xml");
|
||||||
|
|
||||||
if (is_dir($dir = THELIA_MODULE_DIR . $module->getI18nPath())) {
|
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/I18n")) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
|
||||||
|
//$templateDirs[$code] = $dir;
|
||||||
|
$parser->addMethodCall('addTemplateDir', array($dir, $code));
|
||||||
}
|
}
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
// FIXME: process module configuration exception
|
// TODO: process module configuration exception
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load translation from templates
|
// Load translation from templates
|
||||||
//core translation
|
//core translation
|
||||||
$dirs[] = THELIA_ROOT . "core/lib/Thelia/Config/I18n";
|
$translationDirs[] = THELIA_ROOT . "core/lib/Thelia/Config/I18n";
|
||||||
|
|
||||||
// admin template
|
// admin template
|
||||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveAdminTemplate()->getI18nPath())) {
|
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveAdminTemplate()->getI18nPath())) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// front template
|
// front template
|
||||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveFrontTemplate()->getI18nPath())) {
|
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActiveFrontTemplate()->getI18nPath())) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PDF template
|
// PDF template
|
||||||
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActivePdfTemplate()->getI18nPath())) {
|
if (is_dir($dir = THELIA_TEMPLATE_DIR . TemplateHelper::getInstance()->getActivePdfTemplate()->getI18nPath())) {
|
||||||
$dirs[] = $dir;
|
$translationDirs[] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dirs) {
|
if ($translationDirs) {
|
||||||
$finder = Finder::create()
|
$this->loadTranslation($container, $translationDirs);
|
||||||
->files()
|
|
||||||
->depth(0)
|
|
||||||
->in($dirs);
|
|
||||||
|
|
||||||
foreach ($finder as $file) {
|
|
||||||
list($locale, $format) = explode('.', $file->getBaseName(), 2);
|
|
||||||
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadTranslation(ContainerBuilder $container, array $dirs)
|
||||||
|
{
|
||||||
|
$translator = $container->getDefinition('thelia.translator');
|
||||||
|
|
||||||
|
$finder = Finder::create()
|
||||||
|
->files()
|
||||||
|
->depth(0)
|
||||||
|
->in($dirs);
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
list($locale, $format) = explode('.', $file->getBaseName(), 2);
|
||||||
|
$translator->addMethodCall('addResource', array($format, (string) $file, $locale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* initialize session in Request object
|
* initialize session in Request object
|
||||||
|
|||||||
Reference in New Issue
Block a user