From 2edc71e9c3959b811e9d4879d55d634738347f41 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 24 Jun 2013 10:21:59 +0200 Subject: [PATCH 01/14] fix CS and add start Form plugin for smarty --- core/lib/Thelia/Core/Application.php | 7 +- core/lib/Thelia/Core/Bundle/TheliaBundle.php | 1 - .../Core/Controller/ControllerResolver.php | 11 +- .../Compiler/RegisterListenersPass.php | 2 +- .../Compiler/RegisterParserPluginPass.php | 7 +- .../Loader/XmlFileLoader.php | 5 +- .../Loader/schema/dic/config/thelia-1.0.xsd | 12 + core/lib/Thelia/Core/Event/ActionEvent.php | 27 +- .../Thelia/Core/Event/DefaultActionEvent.php | 6 +- core/lib/Thelia/Core/Event/TheliaEvents.php | 16 +- .../Core/EventListener/ControllerListener.php | 3 - .../Core/EventListener/ViewListener.php | 2 +- .../Core/Factory/ActionEventFactory.php | 4 +- .../Core/Template/Assets/AsseticHelper.php | 31 +-- .../Thelia/Core/Template/BaseParam/Secure.php | 3 +- .../Core/Template/Element/LoopResult.php | 2 +- .../Core/Template/Element/LoopResultRow.php | 7 +- .../Exception/ResourceNotFoundException.php | 7 +- .../Thelia/Core/Template/Loop/Category.php | 22 +- .../Smarty/Assets/SmartyAssetsManager.php | 63 +++-- .../Core/Template/Smarty/Plugins/Assetic.php | 9 +- .../Core/Template/Smarty/Plugins/Form.php | 66 +++++ .../Core/Template/Smarty/Plugins/Module.php | 11 +- .../Template/Smarty/Plugins/TheliaLoop.php | 258 +++++++++--------- .../Template/Smarty/Plugins/Translation.php | 28 +- .../Core/Template/Smarty/SmartyParser.php | 151 +++++----- .../Smarty/SmartyPluginDescriptor.php | 38 ++- .../Template/Smarty/SmartyPluginInterface.php | 5 +- .../Thelia/Core/Template/TestLoop/Equal.php | 2 +- core/lib/Thelia/Core/Thelia.php | 13 +- .../Thelia/Core/TheliaContainerBuilder.php | 2 +- core/lib/Thelia/Core/TheliaHttpKernel.php | 3 +- 32 files changed, 436 insertions(+), 388 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php diff --git a/core/lib/Thelia/Core/Application.php b/core/lib/Thelia/Core/Application.php index 1a47fa263..b6b07614c 100755 --- a/core/lib/Thelia/Core/Application.php +++ b/core/lib/Thelia/Core/Application.php @@ -29,7 +29,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpKernel\KernelInterface; - class Application extends BaseApplication { @@ -68,8 +67,7 @@ class Application extends BaseApplication $container = $this->kernel->getContainer(); - foreach($container->getParameter("command.definition") as $command) - { + foreach ($container->getParameter("command.definition") as $command) { $r = new \ReflectionClass($command); if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { @@ -77,6 +75,5 @@ class Application extends BaseApplication } } - } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index a016dc193..9fb4ec37e 100755 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -24,7 +24,6 @@ namespace Thelia\Core\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Scope; use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass; diff --git a/core/lib/Thelia/Core/Controller/ControllerResolver.php b/core/lib/Thelia/Core/Controller/ControllerResolver.php index deb23b1b7..ac7fb37c4 100755 --- a/core/lib/Thelia/Core/Controller/ControllerResolver.php +++ b/core/lib/Thelia/Core/Controller/ControllerResolver.php @@ -1,6 +1,5 @@ container = $container; + $this->container = $container; - parent::__construct($logger); + parent::__construct($logger); } /** @@ -38,7 +37,7 @@ class ControllerResolver extends BaseControllerResolver * * @return mixed A PHP callable * - * @throws \LogicException When the name could not be parsed + * @throws \LogicException When the name could not be parsed * @throws \InvalidArgumentException When the controller class does not exist */ protected function createController($controller) diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterListenersPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterListenersPass.php index d6d73eeea..786093e15 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterListenersPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterListenersPass.php @@ -74,4 +74,4 @@ class RegisterListenersPass implements CompilerPassInterface $definition->addMethodCall('addSubscriberService', array($id, $class)); } } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterParserPluginPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterParserPluginPass.php index 3c1d0f35f..80c3ba933 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterParserPluginPass.php +++ b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterParserPluginPass.php @@ -23,7 +23,6 @@ namespace Thelia\Core\DependencyInjection\Compiler; - use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -34,8 +33,8 @@ use Symfony\Component\DependencyInjection\Reference; * * */ -class RegisterParserPluginPass implements CompilerPassInterface { - +class RegisterParserPluginPass implements CompilerPassInterface +{ /** * You can modify the container here before it is dumped to PHP code. * @@ -57,4 +56,4 @@ class RegisterParserPluginPass implements CompilerPassInterface { $smarty->addMethodCall("registerPlugins"); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index 58c81a64a..8bc0feb98 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -24,7 +24,6 @@ namespace Thelia\Core\DependencyInjection\Loader; use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader as XmlLoader; use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -334,7 +333,7 @@ EOF /** * Returns true if this class supports the given resource. * - * @param mixed $resource A resource + * @param mixed $resource A resource * @param string $type The resource type * * @return Boolean true if this class supports the given resource, false otherwise @@ -343,4 +342,4 @@ EOF { // TODO: Implement supports() method. } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd index 33f563040..ef33d400a 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd @@ -15,6 +15,7 @@ + @@ -74,6 +75,17 @@ + + + + + + + + + + + diff --git a/core/lib/Thelia/Core/Event/ActionEvent.php b/core/lib/Thelia/Core/Event/ActionEvent.php index 5af624240..b2d1d7b77 100755 --- a/core/lib/Thelia/Core/Event/ActionEvent.php +++ b/core/lib/Thelia/Core/Event/ActionEvent.php @@ -26,48 +26,49 @@ namespace Thelia\Core\Event; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpFoundation\Request; /** - * + * * Class thrown on Thelia.action event - * + * * call setAction if action match yours - * + * */ abstract class ActionEvent extends Event { - + /** * * @var Symfony\Component\HttpFoundation\Request */ protected $request; - + /** * * @var string */ protected $action; - + /** - * + * * @param \Symfony\Component\HttpFoundation\Request $request - * @param string $action + * @param string $action */ - public function __construct(Request $request, $action) { + public function __construct(Request $request, $action) + { $this->request = $request; $this->action = $action; } - + /** - * + * * @return string */ public function getAction() { return $this->action; } - + /** - * + * * @return \Symfony\Component\HttpFoundation\Request */ public function getRequest() diff --git a/core/lib/Thelia/Core/Event/DefaultActionEvent.php b/core/lib/Thelia/Core/Event/DefaultActionEvent.php index a4599fa6a..0f041dfeb 100755 --- a/core/lib/Thelia/Core/Event/DefaultActionEvent.php +++ b/core/lib/Thelia/Core/Event/DefaultActionEvent.php @@ -11,6 +11,6 @@ namespace Thelia\Core\Event; use Thelia\Core\Event\ActionEvent; -class DefaultActionEvent extends ActionEvent { - -} \ No newline at end of file +class DefaultActionEvent extends ActionEvent +{ +} diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 7b6c9e178..3ffac068f 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -24,27 +24,27 @@ namespace Thelia\Core\Event; /** - * + * * Class containing all Thelia events name using in Thelia Core - * - * + * + * * @author Manuel Raynaud */ final class TheliaEvents { - + /** * ACTION event - * + * * Send if no action are already present in Thelia action process ( see Thelia\Routing\Matcher\ActionMatcher) */ const ACTION = "thelia.action"; - + /** * INCLUDE event - * + * * Send before starting thelia inclusion */ const INCLUSION = "thelia.include"; -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/EventListener/ControllerListener.php b/core/lib/Thelia/Core/EventListener/ControllerListener.php index 193621d27..607c2a44d 100755 --- a/core/lib/Thelia/Core/EventListener/ControllerListener.php +++ b/core/lib/Thelia/Core/EventListener/ControllerListener.php @@ -25,10 +25,8 @@ namespace Thelia\Core\EventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; -use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Factory\ActionEventFactory; - /** * * Action are dispatch here. @@ -41,7 +39,6 @@ use Thelia\Core\Factory\ActionEventFactory; class ControllerListener implements EventSubscriberInterface { - public function onKernelController(FilterControllerEvent $event) { $dispatcher = $event->getDispatcher(); diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index 894428760..50acd044d 100755 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -78,7 +78,7 @@ class ViewListener implements EventSubscriberInterface } else { $event->setResponse(new Response($content, $parser->getStatus() ?: 200)); } - } catch(ResourceNotFoundException $e) { + } catch (ResourceNotFoundException $e) { $event->setResponse(new Response($e->getMessage(), 404)); } diff --git a/core/lib/Thelia/Core/Factory/ActionEventFactory.php b/core/lib/Thelia/Core/Factory/ActionEventFactory.php index 667997f09..7cda0a083 100755 --- a/core/lib/Thelia/Core/Factory/ActionEventFactory.php +++ b/core/lib/Thelia/Core/Factory/ActionEventFactory.php @@ -24,8 +24,6 @@ namespace Thelia\Core\Factory; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Thelia\Core\Event\ActionEventClass; class ActionEventFactory { @@ -74,4 +72,4 @@ class ActionEventFactory return $class->newInstance($this->request, $this->action); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php index 6826e373d..c5995e3de 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php @@ -37,22 +37,22 @@ use Assetic\Cache\FilesystemCache; * * @author Franck Allimant */ -class AsseticHelper { - +class AsseticHelper +{ /** * Generates assets from $asset_path in $output_path, using $filters. * - * @param string $asset_path the full path to the asset file (or file collection) - * @param unknown $output_path the full disk path to the output directory (shoud be visible to web server) - * @param unknown $output_url the URL to the generated asset directory - * @param unknown $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension. - * @param unknown $filters a list of filters, as defined below (see switch($filter_name) ...) - * @param unknown $debug true / false + * @param string $asset_path the full path to the asset file (or file collection) + * @param unknown $output_path the full disk path to the output directory (shoud be visible to web server) + * @param unknown $output_url the URL to the generated asset directory + * @param unknown $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension. + * @param unknown $filters a list of filters, as defined below (see switch($filter_name) ...) + * @param unknown $debug true / false * @throws \InvalidArgumentException if an invalid filter name is found - * @return string The URL to the generated asset file. + * @return string The URL to the generated asset file. */ - public function asseticize($asset_path, $output_path, $output_url, $asset_type, $filters, $debug) { - + public function asseticize($asset_path, $output_path, $output_url, $asset_type, $filters, $debug) + { $asset_name = basename($asset_path); $asset_dir = dirname($asset_path); @@ -62,11 +62,11 @@ class AsseticHelper { if (! empty($filters)) { $filter_list = explode(',', $filters); - foreach($filter_list as $filter_name) { + foreach ($filter_list as $filter_name) { $filter_name = trim($filter_name); - switch($filter_name) { + switch ($filter_name) { case 'less' : $fm->set('less', new Filter\LessphpFilter()); break; @@ -92,8 +92,7 @@ class AsseticHelper { break; } } - } - else { + } else { $filter_list = array(); } @@ -120,4 +119,4 @@ class AsseticHelper { return rtrim($output_url, '/').'/'.$asset->getTargetPath(); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/BaseParam/Secure.php b/core/lib/Thelia/Core/Template/BaseParam/Secure.php index efb01389a..43713b150 100755 --- a/core/lib/Thelia/Core/Template/BaseParam/Secure.php +++ b/core/lib/Thelia/Core/Template/BaseParam/Secure.php @@ -31,10 +31,9 @@ class Secure extends BaseParam public function exec() { $request = $this->getRequest(); - + if (!$request->getSession()->get('connected') && $this->baseParamValue) { Redirect::unauthorize(); } } } - diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php index a1d713c01..f01c74210 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResult.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -105,4 +105,4 @@ class LoopResult implements \Iterator { $this->position = 0; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php index 24e14afab..4a14521c7 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php @@ -23,9 +23,8 @@ namespace Thelia\Core\Template\Element; - -class LoopResultRow { - +class LoopResultRow +{ protected $substitution = array(); public function set($key, $value) @@ -43,4 +42,4 @@ class LoopResultRow { return $this->substitution; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php b/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php index c3d627123..87b41ebc5 100644 --- a/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php +++ b/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php @@ -22,7 +22,6 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Exception; - -class ResourceNotFoundException extends \RuntimeException { - -} \ No newline at end of file +class ResourceNotFoundException extends \RuntimeException +{ +} diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 6a996d813..66ef3f084 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -21,14 +21,11 @@ /* */ /*************************************************************************************/ - namespace Thelia\Core\Template\Loop; - use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; -use Thelia\Log\Tlog; use Thelia\Model\CategoryQuery; /** @@ -61,8 +58,8 @@ use Thelia\Model\CategoryQuery; * @package Thelia\Core\Template\Loop * @author Manuel Raynaud */ -class Category extends BaseLoop { - +class Category extends BaseLoop +{ public $id; public $parent; public $current; @@ -105,13 +102,13 @@ class Category extends BaseLoop { $search->filterById(explode(',', $this->id), \Criteria::IN); } - if(!is_null($this->parent)) { + if (!is_null($this->parent)) { $search->filterByParent($this->parent); } - if($this->current == 1) { + if ($this->current == 1) { $search->filterById($this->request->get("category_id")); - } else if (null !== $this->current && $this->current == 0) { + } elseif (null !== $this->current && $this->current == 0) { $search->filterById($this->request->get("category_id"), \Criteria::NOT_IN); } @@ -123,14 +120,13 @@ class Category extends BaseLoop { $search->filterByLink($this->link); } - if($this->limit > -1) { + if ($this->limit > -1) { $search->limit($this->limit); } $search->filterByVisible($this->visible); $search->offset($this->offset); - - switch($this->order) { + switch ($this->order) { case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE); break; @@ -145,7 +141,7 @@ class Category extends BaseLoop { break; } - if($this->random == 1) { + if ($this->random == 1) { $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); } @@ -182,4 +178,4 @@ class Category extends BaseLoop { return $loopResult; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 69a611b3e..10cfefec7 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -25,8 +25,8 @@ namespace Thelia\Core\Template\Smarty\Assets; use Thelia\Core\Template\Assets\AsseticHelper; -class SmartyAssetsManager { - +class SmartyAssetsManager +{ const ASSET_TYPE_AUTO = ''; private $assetic_manager; @@ -37,50 +37,49 @@ class SmartyAssetsManager { /** * Creates a new SmartyAssetsManager instance * - * @param string $web_root the disk path to the web root - * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated + * @param string $web_root the disk path to the web root + * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated */ - public function __construct($web_root, $path_relative_to_web_root) { - + public function __construct($web_root, $path_relative_to_web_root) + { $this->web_root = $web_root; $this->path_relative_to_web_root = $path_relative_to_web_root; $this->assetic_manager = new AsseticHelper(); } - public function processSmartyPluginCall($assetType, $params, $content, \Smarty_Internal_Template $template, &$repeat) { - + public function processSmartyPluginCall($assetType, $params, $content, \Smarty_Internal_Template $template, &$repeat) + { // Opening tag (first call only) if ($repeat) { - $file = $params['file']; - $filters = isset($params['filters']) ? $params['filters'] : ''; - $debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false; + $file = $params['file']; + $filters = isset($params['filters']) ? $params['filters'] : ''; + $debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false; - // Get template base path - $tpl_path = $template->source->filepath; + // Get template base path + $tpl_path = $template->source->filepath; - // Get basedir - $tpl_dir = dirname($tpl_path); + // Get basedir + $tpl_dir = dirname($tpl_path); - // Create absolute dir path - $asset_dir = realpath($tpl_dir.'/'.dirname($file)); - $asset_file = basename($file); + // Create absolute dir path + $asset_dir = realpath($tpl_dir.'/'.dirname($file)); + $asset_file = basename($file); - if ($asset_dir === false) throw new \Exception("Failed to get real path of '".$tpl_dir.'/'.dirname($file)."'"); + if ($asset_dir === false) throw new \Exception("Failed to get real path of '".$tpl_dir.'/'.dirname($file)."'"); - $url = $this->assetic_manager->asseticize( - $asset_dir.'/'.$asset_file, - $this->web_root."/".$this->path_relative_to_web_root, - $this->path_relative_to_web_root, - $assetType, - $filters, - $debug - ); + $url = $this->assetic_manager->asseticize( + $asset_dir.'/'.$asset_file, + $this->web_root."/".$this->path_relative_to_web_root, + $this->path_relative_to_web_root, + $assetType, + $filters, + $debug + ); - $template->assign('asset_url', $url); - } - else if (isset($content)) { - return $content; + $template->assign('asset_url', $url); + } elseif (isset($content)) { + return $content; } } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php index 7b24b78be..4418bd50c 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php @@ -23,14 +23,12 @@ namespace Thelia\Core\Template\Smarty\Plugins; - use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager; - -class Assetic implements SmartyPluginInterface { - +class Assetic implements SmartyPluginInterface +{ public $asset_manager; public function __construct() @@ -42,7 +40,6 @@ class Assetic implements SmartyPluginInterface { $this->asset_manager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root); } - public function theliaBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat) { return $this->asset_manager->processSmartyPluginCall('js', $params, $content, $template, $repeat); @@ -71,4 +68,4 @@ class Assetic implements SmartyPluginInterface { new SmartyPluginDescriptor('block', 'images' , $this, 'theliaBlockImages') ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php new file mode 100644 index 000000000..c994d9cfa --- /dev/null +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -0,0 +1,66 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\Template\Smarty\Plugins; + +use Symfony\Component\HttpFoundation\Request; +use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; +use Thelia\Core\Template\Smarty\SmartyPluginInterface; + +class Form implements SmartyPluginInterface +{ + + protected $request; + protected $formDefinition = array(); + + public function __construct(Request $request) + { + $this->request = $request; + } + + public function setFormDefinition($formDefinition) + { + foreach ($formDefinition as $name => $className) { + if (array_key_exists($name, $this->formDefinition)) { + throw new \InvalidArgumentException(sprintf("%s form name already exists for %s class", $name, + $className)); + } + + $this->formDefinition[$name] = $className; + } + } + + public function generateForm($params, $content, $template, &$repeat) + { + + } + + /** + * @return an array of SmartyPluginDescriptor + */ + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor("block", "form", $this, "generateForm") + ); + } +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php index bf2a26ca9..99080ce70 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php @@ -23,17 +23,16 @@ namespace Thelia\Core\Template\Smarty\Plugins; - use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginInterface; -class Module implements SmartyPluginInterface { - +class Module implements SmartyPluginInterface +{ /** * Process theliaModule template inclusion function * - * @param unknown $params - * @param unknown $smarty + * @param unknown $params + * @param unknown $smarty * @return string */ public function theliaModule($params, &$smarty) @@ -53,4 +52,4 @@ class Module implements SmartyPluginInterface { new SmartyPluginDescriptor('function', 'module_include', $this, 'theliaModule'), ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index d8b1abd9a..461b44a86 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -32,15 +32,16 @@ use Thelia\Core\Template\Element\Exception\InvalidElementException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -class TheliaLoop implements SmartyPluginInterface { - +class TheliaLoop implements SmartyPluginInterface +{ protected $loopDefinition = array(); protected $request; protected $dispatcher; - public function __construct(Request $request, EventDispatcherInterface $dispatcher) { + public function __construct(Request $request, EventDispatcherInterface $dispatcher) + { $this->request = $request; $this->dispatcher = $dispatcher; } @@ -48,128 +49,125 @@ class TheliaLoop implements SmartyPluginInterface { /** * Process {loop name="loop name" type="loop type" ... } ... {/loop} block * - * @param unknown $params - * @param unknown $content - * @param unknown $template - * @param unknown $repeat + * @param unknown $params + * @param unknown $content + * @param unknown $template + * @param unknown $repeat * @throws \InvalidArgumentException * @return string */ - public function theliaLoop($params, $content, $template, &$repeat) { + public function theliaLoop($params, $content, $template, &$repeat) + { + if (empty($params['name'])) + throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments"); - if (empty($params['name'])) - throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments"); + if (empty($params['type'])) + throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments"); - if (empty($params['type'])) - throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments"); + $name = $params['name']; - $name = $params['name']; + if ($content === null) { - if ($content === null) { + $loop = $this->createLoopInstance(strtolower($params['type'])); - $loop = $this->createLoopInstance(strtolower($params['type'])); + $this->getLoopArgument($loop, $params); - $this->getLoopArgument($loop, $params); + $loopResults = $loop->exec(); - $loopResults = $loop->exec(); + $template->assignByRef($name, $loopResults); + } else { - $template->assignByRef($name, $loopResults); - } - else { + $loopResults = $template->getTemplateVars($name); - $loopResults = $template->getTemplateVars($name); + $loopResults->next(); + } - $loopResults->next(); - } + if ($loopResults->valid()) { - if ($loopResults->valid()) { + $loopResultRow = $loopResults->current(); - $loopResultRow = $loopResults->current(); + foreach ($loopResultRow->getVarVal() as $var => $val) { - foreach($loopResultRow->getVarVal() as $var => $val) { + $template->assign(substr($var, 1), $val); - $template->assign(substr($var, 1), $val); + $template->assign('__COUNT__', 1 + $loopResults->key()); + $template->assign('__TOTAL__', $loopResults->getCount()); + } - $template->assign('__COUNT__', 1 + $loopResults->key()); - $template->assign('__TOTAL__', $loopResults->getCount()); - } + $repeat = $loopResults->valid(); + } - $repeat = $loopResults->valid(); - } + if ($content !== null) { - if ($content !== null) { - - if ($loopResults->isEmpty()) $content = ""; - - return $content; - } + if ($loopResults->isEmpty()) $content = ""; + return $content; + } } - /** * Process {elseloop rel="loopname"} ... {/elseloop} block * - * @param unknown $params - * @param unknown $content - * @param unknown $template - * @param unknown $repeat + * @param unknown $params + * @param unknown $content + * @param unknown $template + * @param unknown $repeat * @return Ambigous */ - public function theliaElseloop($params, $content, $template, &$repeat) { - - // When encoutering close tag, check if loop has results. - if ($repeat === false) { - return $this->checkEmptyLoop($params, $template) ? $content : ''; - } + public function theliaElseloop($params, $content, $template, &$repeat) + { + // When encoutering close tag, check if loop has results. + if ($repeat === false) { + return $this->checkEmptyLoop($params, $template) ? $content : ''; + } } - /** * Process {ifloop rel="loopname"} ... {/ifloop} block * - * @param unknown $params - * @param unknown $content - * @param unknown $template - * @param unknown $repeat + * @param unknown $params + * @param unknown $content + * @param unknown $template + * @param unknown $repeat * @return Ambigous */ - public function theliaIfLoop($params, $content, $template, &$repeat) { - - // When encountering close tag, check if loop has results. - if ($repeat === false) { - return $this->checkEmptyLoop($params, $template) ? '' : $content; - } + public function theliaIfLoop($params, $content, $template, &$repeat) + { + // When encountering close tag, check if loop has results. + if ($repeat === false) { + return $this->checkEmptyLoop($params, $template) ? '' : $content; + } } /** * Check if a loop has returned results. The loop shoud have been executed before, or an * InvalidArgumentException is thrown * - * @param unknown $params - * @param unknown $template + * @param unknown $params + * @param unknown $template * @throws \InvalidArgumentException */ - protected function checkEmptyLoop($params, $template) { - if (empty($params['rel'])) - throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments"); + protected function checkEmptyLoop($params, $template) + { + if (empty($params['rel'])) + throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments"); - $loopName = $params['rel']; + $loopName = $params['rel']; - // Find loop results in the current template vars - $loopResults = $template->getTemplateVars($loopName); + // Find loop results in the current template vars + $loopResults = $template->getTemplateVars($loopName); - if (empty($loopResults)) { - throw new \InvalidArgumentException("Loop $loopName is not defined."); - } + if (empty($loopResults)) { + throw new \InvalidArgumentException("Loop $loopName is not defined."); + } - return $loopResults->isEmpty(); + return $loopResults->isEmpty(); } /** * * find the loop class with his name and construct an instance of this class * - * @param string $name + * @param string $name * @return \Thelia\Core\Template\Element\BaseLoop * @throws \Thelia\Tpex\Exception\InvalidElementException * @throws \Thelia\Tpex\Exception\ElementNotFoundException @@ -177,76 +175,74 @@ class TheliaLoop implements SmartyPluginInterface { protected function createLoopInstance($name) { - if (! isset($this->loopDefinition[$name])) { - throw new ElementNotFoundException(sprintf("%s loop does not exists", $name)); - } + if (! isset($this->loopDefinition[$name])) { + throw new ElementNotFoundException(sprintf("%s loop does not exists", $name)); + } - $class = new \ReflectionClass($this->loopDefinition[$name]); + $class = new \ReflectionClass($this->loopDefinition[$name]); - if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) { - throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop", - $name)); - } + if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) { + throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop", + $name)); + } - return $class->newInstance( - $this->request, - $this->dispatcher - ); + return $class->newInstance( + $this->request, + $this->dispatcher + ); } - /** * Returns the value of a loop argument. * - * @param unknown $loop a BaseLoop instance - * @param unknown $smartyParam + * @param unknown $loop a BaseLoop instance + * @param unknown $smartyParam * @throws \InvalidArgumentException */ protected function getLoopArgument($loop, $smartyParam) { - $defaultItemsParams = array('required' => true); + $defaultItemsParams = array('required' => true); - $shortcutItemParams = array('optional' => array('required' => false)); + $shortcutItemParams = array('optional' => array('required' => false)); - $errorCode = 0; - $faultActor = array(); - $faultDetails = array(); + $errorCode = 0; + $faultActor = array(); + $faultDetails = array(); - foreach($loop->defineArgs() as $name => $param){ - if(is_integer($name)){ - $name = $param; - $param = $defaultItemsParams; - } + foreach ($loop->defineArgs() as $name => $param) { + if (is_integer($name)) { + $name = $param; + $param = $defaultItemsParams; + } - if(is_string($param) && array_key_exists($param, $shortcutItemParams)){ - $param = $shortcutItemParams[$param]; - } + if (is_string($param) && array_key_exists($param, $shortcutItemParams)) { + $param = $shortcutItemParams[$param]; + } - if(!is_array($param)){ - $param = array('default' => $param); - } + if (!is_array($param)) { + $param = array('default' => $param); + } - $value = isset($smartyParam[$name]) ? $smartyParam[$name] : null; + $value = isset($smartyParam[$name]) ? $smartyParam[$name] : null; - if($value == null){ - if(isset($param['default'])){ - $value = $param['default']; - } - else if($param['required'] === true){ - $faultActor[] = $name; - $faultDetails[] = sprintf('"%s" parameter is missing', $name); - continue; - } - } + if ($value == null) { + if (isset($param['default'])) { + $value = $param['default']; + } elseif ($param['required'] === true) { + $faultActor[] = $name; + $faultDetails[] = sprintf('"%s" parameter is missing', $name); + continue; + } + } - $loop->{$name} = $value; - } + $loop->{$name} = $value; + } - if(!empty($faultActor)){ + if (!empty($faultActor)) { - $complement = sprintf('[%s]', implode(', ', $faultDetails)); - throw new \InvalidArgumentException($complement); - } + $complement = sprintf('[%s]', implode(', ', $faultDetails)); + throw new \InvalidArgumentException($complement); + } } /** @@ -269,13 +265,13 @@ class TheliaLoop implements SmartyPluginInterface { */ public function setLoopList(array $loopDefinition) { - foreach ($loopDefinition as $name => $className) { - if (array_key_exists($name, $this->loopDefinition)) { - throw new \InvalidArgumentException(sprintf("%s loop name already exists for %s class name", $name, $className)); - } + foreach ($loopDefinition as $name => $className) { + if (array_key_exists($name, $this->loopDefinition)) { + throw new \InvalidArgumentException(sprintf("%s loop name already exists for %s class name", $name, $className)); + } - $this->loopDefinition[$name] = $className; - } + $this->loopDefinition[$name] = $className; + } } /** @@ -286,9 +282,9 @@ class TheliaLoop implements SmartyPluginInterface { public function getPluginDescriptors() { return array( - new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'), - new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'), - new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop') + new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'), + new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'), + new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop') ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php index 36e14b97a..403cfac80 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php @@ -23,32 +23,28 @@ namespace Thelia\Core\Template\Smarty\Plugins; - use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginInterface; -class Translation implements SmartyPluginInterface { - - +class Translation implements SmartyPluginInterface +{ /** * Process translate function * - * @param unknown $params - * @param unknown $smarty + * @param unknown $params + * @param unknown $smarty * @return string */ public function theliaTranslate($params, &$smarty) { - if (isset($params['l'])) { - $string = str_replace('\'', '\\\'', $params['l']); - } - else { - $string = ''; - } + if (isset($params['l'])) { + $string = str_replace('\'', '\\\'', $params['l']); + } else { + $string = ''; + } - // TODO - - return "[$string]"; + // TODO + return "[$string]"; } /** @@ -62,4 +58,4 @@ class Translation implements SmartyPluginInterface { new SmartyPluginDescriptor('function', 'intl', $this, 'theliaTranslate'), ); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 8f0763f3f..1eb7f5a4d 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -8,18 +8,16 @@ use \Symfony\Component\EventDispatcher\EventDispatcherInterface; use \Smarty; use Thelia\Core\Template\ParserInterface; -use Thelia\Core\Template\Loop\Category; use Thelia\Core\Template\Smarty\SmartyPluginInterface; -use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager; use Thelia\Core\Template\Exception\ResourceNotFoundException; /** * * @author Franck Allimant */ -class SmartyParser extends Smarty implements ParserInterface { - +class SmartyParser extends Smarty implements ParserInterface +{ public $plugins = array(); protected $request, $dispatcher; @@ -29,10 +27,10 @@ class SmartyParser extends Smarty implements ParserInterface { protected $status = 200; /** - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher - * @param bool $template - * @param string $env Environment define for the kernel application. Used for the cache directory + * @param bool $template + * @param string $env Environment define for the kernel application. Used for the cache directory */ public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false, $env = "prod", $debug = false) { @@ -68,107 +66,108 @@ class SmartyParser extends Smarty implements ParserInterface { $this->status = 200; } - public function setTemplate($template_path_from_template_base) { - + public function setTemplate($template_path_from_template_base) + { $this->template = $template_path_from_template_base; $this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template); } - public function getTemplate() { - return $this->template; + public function getTemplate() + { + return $this->template; } /** * Return a rendered template file * - * @param string $realTemplateName the template name (from the template directory) - * @param array $parameters an associative array of names / value pairs + * @param string $realTemplateName the template name (from the template directory) + * @param array $parameters an associative array of names / value pairs * @return string the rendered template text */ - public function render($realTemplateName, array $parameters) { + public function render($realTemplateName, array $parameters) + { + $this->assign($parameters); - $this->assign($parameters); - - return $this->fetch($realTemplateName); + return $this->fetch($realTemplateName); } - /** - * - * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response - * - */ - public function getContent() - { - return $this->fetch($this->getTemplateFilePath()); - } + /** + * + * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response + * + */ + public function getContent() + { + return $this->fetch($this->getTemplateFilePath()); + } - /** - * - * set $content with the body of the response or the Response object directly - * - * @param string|Symfony\Component\HttpFoundation\Response $content - */ - public function setContent($content) - { - $this->content = $content; - } + /** + * + * set $content with the body of the response or the Response object directly + * + * @param string|Symfony\Component\HttpFoundation\Response $content + */ + public function setContent($content) + { + $this->content = $content; + } - /** - * - * @return type the status of the response - */ - public function getStatus() - { - return $this->status; - } + /** + * + * @return type the status of the response + */ + public function getStatus() + { + return $this->status; + } - /** - * - * status HTTP of the response - * - * @param int $status - */ - public function setStatus($status) - { - $this->status = $status; - } + /** + * + * status HTTP of the response + * + * @param int $status + */ + public function setStatus($status) + { + $this->status = $status; + } public function addPlugins(SmartyPluginInterface $plugin) { - $this->plugins[] = $plugin; + $this->plugins[] = $plugin; } public function registerPlugins() { - foreach ($this->plugins as $register_plugin) { - $plugins = $register_plugin->getPluginDescriptors(); + foreach ($this->plugins as $register_plugin) { + $plugins = $register_plugin->getPluginDescriptors(); - if(!is_array($plugins)) { - $plugins = array($plugins); - } + if (!is_array($plugins)) { + $plugins = array($plugins); + } - foreach ($plugins as $plugin) { - $this->registerPlugin( - $plugin->getType(), - $plugin->getName(), - array( - $plugin->getClass(), - $plugin->getMethod() - ) - ); - } - } + foreach ($plugins as $plugin) { + $this->registerPlugin( + $plugin->getType(), + $plugin->getName(), + array( + $plugin->getClass(), + $plugin->getMethod() + ) + ); + } + } } protected function getTemplateFilePath() { - $file = $this->request->attributes->get('_view'); + $file = $this->request->attributes->get('_view'); - $fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html"; + $fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html"; - if (file_exists($fileName)) return $fileName; + if (file_exists($fileName)) return $fileName; - throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template)); + throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template)); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php index 6d598b0ce..b22f99577 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php @@ -29,8 +29,8 @@ namespace Thelia\Core\Template\Smarty; * Class SmartyPluginDescriptor * @package Thelia\Core\Template\Smarty */ -class SmartyPluginDescriptor { - +class SmartyPluginDescriptor +{ /** * @var string Smarty plugin type (block, function, etc.) */ @@ -59,35 +59,43 @@ class SmartyPluginDescriptor { $this->method = $method; } - public function setType($type) { - $this->type = $type; + public function setType($type) + { + $this->type = $type; } - public function getType() { + public function getType() + { return $this->type; } - public function setName($name) { - $this->name = $name; + public function setName($name) + { + $this->name = $name; } - public function getName() { + public function getName() + { return $this->name; } - public function setClass($class) { - $this->class = $class; + public function setClass($class) + { + $this->class = $class; } - public function getClass() { + public function getClass() + { return $this->class; } - public function setMethod($method) { - $this->method = $method; + public function setMethod($method) + { + $this->method = $method; } - public function getMethod() { + public function getMethod() + { return $this->method; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php index afbc7741f..e1228c7b1 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php @@ -30,9 +30,10 @@ namespace Thelia\Core\Template\Smarty; * Interface SmartyPluginInterface * @package Thelia\Core\Template\Smarty */ -interface SmartyPluginInterface { +interface SmartyPluginInterface +{ /** * @return an array of SmartyPluginDescriptor */ public function getPluginDescriptors(); -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Template/TestLoop/Equal.php b/core/lib/Thelia/Core/Template/TestLoop/Equal.php index 5e812a7a4..220657158 100755 --- a/core/lib/Thelia/Core/Template/TestLoop/Equal.php +++ b/core/lib/Thelia/Core/Template/TestLoop/Equal.php @@ -48,4 +48,4 @@ class Equal extends BaseTestLoop { return $variable == $value; } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 30f2040d8..72a72f4f9 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -35,14 +35,9 @@ namespace Thelia\Core; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Config\Definition\Processor; -use Symfony\Component\Config\ConfigCache; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\Yaml\Yaml; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; - use Thelia\Core\Bundle; use Thelia\Log\Tlog; use Thelia\Config\DatabaseConfiguration; @@ -64,7 +59,7 @@ class Thelia extends Kernel public function init() { parent::init(); - if($this->debug) { + if ($this->debug) { ini_set('display_errors', 1); } $this->initPropel(); @@ -76,7 +71,7 @@ class Thelia extends Kernel return ; } - if(! Propel::isInit()) { + if (! Propel::isInit()) { $definePropel = new DefinePropel(new DatabaseConfiguration(), Yaml::parse(THELIA_ROOT . '/local/config/database.yml')); @@ -126,8 +121,7 @@ class Thelia extends Kernel try { $loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config")); $loader->load("config.xml"); - } - catch(\InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { // FIXME: process module configuration exception } } @@ -166,6 +160,7 @@ class Thelia extends Kernel $this->loadConfiguration($container); $container->customCompile(); + return $container; } diff --git a/core/lib/Thelia/Core/TheliaContainerBuilder.php b/core/lib/Thelia/Core/TheliaContainerBuilder.php index 997f29a40..fb765ebb2 100755 --- a/core/lib/Thelia/Core/TheliaContainerBuilder.php +++ b/core/lib/Thelia/Core/TheliaContainerBuilder.php @@ -35,4 +35,4 @@ class TheliaContainerBuilder extends ContainerBuilder parent::compile(); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index e8d78751d..c315662e0 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -141,7 +141,6 @@ class TheliaHttpKernel extends HttpKernel $storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config"))); } - $session = new Session\Session($storage); $session->start(); @@ -149,4 +148,4 @@ class TheliaHttpKernel extends HttpKernel return $request; } -} \ No newline at end of file +} From f699686d13827e25a663c8fdd458838755c5fd78 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 24 Jun 2013 10:34:34 +0200 Subject: [PATCH 02/14] create first class form and adapt config for injecting form process in Smarty --- core/lib/Thelia/Config/Resources/config.xml | 13 ++++++++ .../Loader/XmlFileLoader.php | 30 ++++++++++++++++--- core/lib/Thelia/Form/CustomerCreation.php | 25 ++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 core/lib/Thelia/Form/CustomerCreation.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 710cfabfd..d1e6569fa 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -21,6 +21,10 @@ --> + +
+ + @@ -72,6 +76,15 @@ + + + + + + %thelia.parser.forms% + + + diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index 8bc0feb98..baae8c487 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\SimpleXMLElement; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -62,6 +63,8 @@ class XmlFileLoader extends FileLoader $this->parseCommands($xml); + $this->parseForms($xml); + $this->parseDefinitions($xml, $path); } @@ -72,7 +75,7 @@ class XmlFileLoader extends FileLoader } try { $commandConfig = $this->container->getParameter("command.definition"); - } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { + } catch (ParameterNotFoundException $e) { $commandConfig = array(); } @@ -110,7 +113,7 @@ class XmlFileLoader extends FileLoader } try { $loopConfig = $this->container->getParameter("Thelia.parser.loops"); - } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { + } catch (ParameterNotFoundException $e) { $loopConfig = array(); } @@ -121,6 +124,25 @@ class XmlFileLoader extends FileLoader $this->container->setParameter("Thelia.parser.loops", $loopConfig); } + protected function parseForms(SimpleXMLElement $xml) + { + if (false === $forms = $xml->xpath('//config:forms/config:form')) { + return; + } + + try { + $formConfig = $this->container->getParameter("Thelia.parser.forms"); + } catch (ParameterNotFoundException $e) { + $formConfig = array(); + } + + foreach ($forms as $form) { + $formConfig[$form->getAttributeAsPhp('name')] = $formConfig->getAttributeAsPhp('class'); + } + + $this->container->setParameter('Thelia.parser.forms', $formConfig); + } + /** * parse Filters property * @@ -133,7 +155,7 @@ class XmlFileLoader extends FileLoader } try { $filterConfig = $this->container->getParameter("Thelia.parser.filters"); - } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { + } catch (ParameterNotFoundException $e) { $filterConfig = array(); } @@ -156,7 +178,7 @@ class XmlFileLoader extends FileLoader } try { $baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives"); - } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { + } catch (ParameterNotFoundException $e) { $baseParamConfig = array(); } diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php new file mode 100644 index 000000000..e160702d5 --- /dev/null +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -0,0 +1,25 @@ +. */ +/* */ +/*************************************************************************************/ +class CustomerCreation { + +} \ No newline at end of file From 84bc1a826842448c52bf2c96d2c518c4fce7e64a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 24 Jun 2013 14:50:06 +0200 Subject: [PATCH 03/14] generate a FormView --- .../Loader/XmlFileLoader.php | 2 +- .../Core/Template/Smarty/Plugins/Form.php | 26 ++++++++ core/lib/Thelia/Form/BaseForm.php | 59 +++++++++++++++++++ core/lib/Thelia/Form/CustomerCreation.php | 25 +++++++- templates/smarty-sample/index.html | 4 +- 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 core/lib/Thelia/Form/BaseForm.php diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index baae8c487..8de39f095 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -137,7 +137,7 @@ class XmlFileLoader extends FileLoader } foreach ($forms as $form) { - $formConfig[$form->getAttributeAsPhp('name')] = $formConfig->getAttributeAsPhp('class'); + $formConfig[$form->getAttributeAsPhp('name')] = $form->getAttributeAsPhp('class'); } $this->container->setParameter('Thelia.parser.forms', $formConfig); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index c994d9cfa..f9f488c3c 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -22,6 +22,8 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Smarty\Plugins; +use Thelia\Form\BaseForm; +use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginInterface; @@ -30,11 +32,13 @@ class Form implements SmartyPluginInterface { protected $request; + protected $form; protected $formDefinition = array(); public function __construct(Request $request) { $this->request = $request; + } public function setFormDefinition($formDefinition) @@ -51,7 +55,29 @@ class Form implements SmartyPluginInterface public function generateForm($params, $content, $template, &$repeat) { + if (empty($params['name'])) { + throw new \InvalidArgumentException("Missing 'name' parameter in form arguments"); + } + $form = new BaseForm($this->request); + $formBuilder = $form->getFormBuilder()->createBuilder(); + + $instance = $this->getInstance($params['name']); + $instance = $instance->buildForm($formBuilder, array()); + + var_dump($instance->getForm()->createView()); exit; + $template->assign("form", $instance->getForm()->createView()); + + } + + public function getInstance($name) + { + if (!isset($this->formDefinition[$name])) { + throw new ElementNotFoundException(sprintf("%s form does not exists", $name)); + } + + + return new $this->formDefinition[$name]; } /** diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php new file mode 100644 index 000000000..e16106c1b --- /dev/null +++ b/core/lib/Thelia/Form/BaseForm.php @@ -0,0 +1,59 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + +use Symfony\Component\Form\Forms; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension; +use Symfony\Component\Form\Extension\Csrf\CsrfExtension; +use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider; +use Thelia\Model\ConfigQuery; + +class BaseForm { + + protected $request; + + public function __construct(Request $request) + { + $this->request = $request; + } + + + public function getFormBuilder() + { + $form = Forms::createFormFactoryBuilder() + ->addExtension(new HttpFoundationExtension()) + ->addExtension( + new CsrfExtension( + new SessionCsrfProvider( + $this->request->getSession(), + ConfigQuery::read("form.secret", md5(__DIR__)) + ) + ) + )->getFormFactory(); + + return $form; + } +} + diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index e160702d5..4c70a0177 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -20,6 +20,29 @@ /* along with this program. If not, see . */ /* */ /*************************************************************************************/ -class CustomerCreation { +namespace Thelia\Form; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; + + +class CustomerCreation extends AbstractType +{ + + public function buildForm(FormBuilderInterface $builder, array $options) + { + return $builder->add("name", "text") + ->add("email", "email") + ->add('age', 'integer'); + } + + /** + * Returns the name of this type. + * + * @return string The name of this type + */ + public function getName() + { + return "customer creation"; + } } \ No newline at end of file diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index f93dd3876..0aa78f442 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -7,7 +7,9 @@ An image from asset directory :
{intl l='An internationalized string'}
- +{form name="thelia.customer.creation"} + {$form.name} +{/form}
jQuery data:
From e29dafdd08e5c095321de42bf1591982058c5707 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 24 Jun 2013 16:13:43 +0200 Subject: [PATCH 04/14] render form field basic info (name and value) --- .../Core/Template/Smarty/Plugins/Form.php | 43 ++++++++++++++----- templates/smarty-sample/index.html | 14 +++++- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index f9f488c3c..ff5d298cf 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -27,6 +27,7 @@ use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginInterface; +use Thelia\Log\Tlog; class Form implements SmartyPluginInterface { @@ -53,21 +54,42 @@ class Form implements SmartyPluginInterface } } - public function generateForm($params, $content, $template, &$repeat) + public function generateForm($params, $content, \Smarty_Internal_Template $template, &$repeat) { - if (empty($params['name'])) { - throw new \InvalidArgumentException("Missing 'name' parameter in form arguments"); + if ($repeat) { + if (empty($params['name'])) { + throw new \InvalidArgumentException("Missing 'name' parameter in form arguments"); + } + + $form = new BaseForm($this->request); + $formBuilder = $form->getFormBuilder()->createBuilder(); + + $instance = $this->getInstance($params['name']); + $instance = $instance->buildForm($formBuilder, array()); + + $template->assign("form", $instance->getForm()->createView()); + } else { + return $content; } + } - $form = new BaseForm($this->request); - $formBuilder = $form->getFormBuilder()->createBuilder(); + public function formRender($params, $content, \Smarty_Internal_Template $template, &$repeat) + { + if ($repeat) { - $instance = $this->getInstance($params['name']); - $instance = $instance->buildForm($formBuilder, array()); + $form = $params["form"]; - var_dump($instance->getForm()->createView()); exit; - $template->assign("form", $instance->getForm()->createView()); + if (! $form instanceof \Symfony\Component\Form\FormView) { + throw new \InvalidArgumentException("form parameter in form_render block must be an instance of + Symfony\Component\Form\FormView"); + } + $template->assign("name", $form->vars["name"]); + $template->assign("value", $form->vars["data"]); + + } else { + return $content; + } } public function getInstance($name) @@ -86,7 +108,8 @@ class Form implements SmartyPluginInterface public function getPluginDescriptors() { return array( - new SmartyPluginDescriptor("block", "form", $this, "generateForm") + new SmartyPluginDescriptor("block", "form", $this, "generateForm"), + new SmartyPluginDescriptor("block", "form_render", $this, "formRender") ); } } diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 0aa78f442..0e3e45efc 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -7,9 +7,21 @@ An image from asset directory :
{intl l='An internationalized string'}
+ {form name="thelia.customer.creation"} - {$form.name} + {form_render form=$form._token} + + {/form_render} + + {form_render form=$form.email} + {intl l='email'} : + {/form_render} + + {form_render form=$form.name} + {intl l='name'} : + {/form_render} {/form} +
jQuery data:
From fe92cc546aec71df79f59183b5feb28bb4878a29 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 10:35:00 +0200 Subject: [PATCH 05/14] create smarty function for displaying hidden form fields --- .../Core/Template/Smarty/Plugins/Form.php | 43 ++++++++++++++++--- .../Template/Smarty/Plugins/TheliaLoop.php | 4 +- core/lib/Thelia/Form/BaseForm.php | 16 +++---- core/lib/Thelia/Form/CustomerCreation.php | 3 +- templates/smarty-sample/index.html | 16 +++---- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index ff5d298cf..0dbfb5f01 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Core\Template\Smarty\Plugins; +use Symfony\Component\Form\FormView; use Thelia\Form\BaseForm; use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; @@ -57,16 +58,16 @@ class Form implements SmartyPluginInterface public function generateForm($params, $content, \Smarty_Internal_Template $template, &$repeat) { if ($repeat) { + if (empty($params['name'])) { throw new \InvalidArgumentException("Missing 'name' parameter in form arguments"); } - $form = new BaseForm($this->request); - $formBuilder = $form->getFormBuilder()->createBuilder(); + $form = BaseForm::getFormFactory($this->request); + $formBuilder = $form->createBuilder('form'); $instance = $this->getInstance($params['name']); $instance = $instance->buildForm($formBuilder, array()); - $template->assign("form", $instance->getForm()->createView()); } else { return $content; @@ -80,18 +81,47 @@ class Form implements SmartyPluginInterface $form = $params["form"]; if (! $form instanceof \Symfony\Component\Form\FormView) { - throw new \InvalidArgumentException("form parameter in form_render block must be an instance of + throw new \InvalidArgumentException("form parameter in form_field block must be an instance of Symfony\Component\Form\FormView"); } $template->assign("name", $form->vars["name"]); - $template->assign("value", $form->vars["data"]); + $template->assign("value", $form->vars["value"]); + + $form->setRendered(); } else { return $content; } } + public function formRenderHidden($params, $template) + { + $form = $params["form"]; + + $field = ''; + + if (! $form instanceof \Symfony\Component\Form\FormView) { + throw new \InvalidArgumentException("form parameter in form_field_hidden function must be an instance of + Symfony\Component\Form\FormView"); + } + + $return = ""; + + foreach ($form->getIterator() as $row) { + if ($this->isHidden($row)) { + $return .= sprintf($field, $row->vars["name"], $row->vars["value"]); + } + } + + return $return; + } + + protected function isHidden(FormView $formView) + { + return array_search("hidden", $formView->vars["block_prefixes"]); + } + public function getInstance($name) { if (!isset($this->formDefinition[$name])) { @@ -109,7 +139,8 @@ class Form implements SmartyPluginInterface { return array( new SmartyPluginDescriptor("block", "form", $this, "generateForm"), - new SmartyPluginDescriptor("block", "form_render", $this, "formRender") + new SmartyPluginDescriptor("block", "form_field", $this, "formRender"), + new SmartyPluginDescriptor("function", "form_field_hidden", $this, "formRenderHidden") ); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 3258f36c5..24a7ad609 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -86,9 +86,9 @@ class TheliaLoop implements SmartyPluginInterface } if ($loopResults->valid()) { + $loopResultRow = $loopResults->current(); - - foreach($loopResultRow->getVarVal() as $var => $val) { + foreach($loopResultRow->getVarVal() as $var => $val) { $template->assign(substr($var, 1), $val); } diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index e16106c1b..bd5dbdaef 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -32,22 +32,18 @@ use Thelia\Model\ConfigQuery; class BaseForm { - protected $request; - - public function __construct(Request $request) - { - $this->request = $request; - } - - - public function getFormBuilder() + /** + * @param Request $request + * @return \Symfony\Component\Form\FormFactoryInterface + */ + public static function getFormFactory(Request $request) { $form = Forms::createFormFactoryBuilder() ->addExtension(new HttpFoundationExtension()) ->addExtension( new CsrfExtension( new SessionCsrfProvider( - $this->request->getSession(), + $request->getSession(), ConfigQuery::read("form.secret", md5(__DIR__)) ) ) diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index 4c70a0177..f6215387e 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -33,7 +33,8 @@ class CustomerCreation extends AbstractType { return $builder->add("name", "text") ->add("email", "email") - ->add('age', 'integer'); + ->add('age', 'integer') + ; } /** diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index be5e00a24..ac4ae2a0d 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -9,17 +9,17 @@ An image from asset directory :
{form name="thelia.customer.creation"} - {form_render form=$form._token} - - {/form_render} - - {form_render form=$form.email} + {form_field_hidden form=$form} + {form_field form=$form.email} {intl l='email'} : - {/form_render} + {/form_field} - {form_render form=$form.name} + {form_field form=$form.name} {intl l='name'} : - {/form_render} + {/form_field} + {form_field form=$form.age} + {intl l='age'} : + {/form_field} {/form}
From 2fb6ec2a7d6ba39e8cba848a0ef19025b0b9a132 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 10:48:30 +0200 Subject: [PATCH 06/14] add smarty function form_enctype --- .../Core/Template/Smarty/Plugins/Form.php | 20 +++++++++++++++++-- core/lib/Thelia/Form/CustomerCreation.php | 3 +-- templates/smarty-sample/index.html | 5 +++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 0dbfb5f01..0ddd5229b 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -85,6 +85,7 @@ class Form implements SmartyPluginInterface Symfony\Component\Form\FormView"); } + $template->assign("name", $form->vars["name"]); $template->assign("value", $form->vars["value"]); @@ -95,7 +96,7 @@ class Form implements SmartyPluginInterface } } - public function formRenderHidden($params, $template) + public function formRenderHidden($params, \Smarty_Internal_Template $template) { $form = $params["form"]; @@ -122,6 +123,20 @@ class Form implements SmartyPluginInterface return array_search("hidden", $formView->vars["block_prefixes"]); } + public function formEnctype($params, \Smarty_Internal_Template $template) + { + $form = $params["form"]; + + if (! $form instanceof \Symfony\Component\Form\FormView) { + throw new \InvalidArgumentException("form parameter in form_field block must be an instance of + Symfony\Component\Form\FormView"); + } + + if ($form->vars["multipart"]) { + return sprintf('%s="%s"',"enctype", "multipart/form-data"); + } + } + public function getInstance($name) { if (!isset($this->formDefinition[$name])) { @@ -140,7 +155,8 @@ class Form implements SmartyPluginInterface return array( new SmartyPluginDescriptor("block", "form", $this, "generateForm"), new SmartyPluginDescriptor("block", "form_field", $this, "formRender"), - new SmartyPluginDescriptor("function", "form_field_hidden", $this, "formRenderHidden") + new SmartyPluginDescriptor("function", "form_field_hidden", $this, "formRenderHidden"), + new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype") ); } } diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index f6215387e..4c70a0177 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -33,8 +33,7 @@ class CustomerCreation extends AbstractType { return $builder->add("name", "text") ->add("email", "email") - ->add('age', 'integer') - ; + ->add('age', 'integer'); } /** diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index ac4ae2a0d..89b1c63d6 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -7,8 +7,9 @@ An image from asset directory :
{intl l='An internationalized string'}
-
{form name="thelia.customer.creation"} + + {form_field_hidden form=$form} {form_field form=$form.email} {intl l='email'} : @@ -20,8 +21,8 @@ An image from asset directory : {form_field form=$form.age} {intl l='age'} : {/form_field} -{/form}
+{/form}
jQuery data:
From 3d7262b3ea76ce81afcc83bf492a92e80561a0b7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 11:32:53 +0200 Subject: [PATCH 07/14] iallow to display labek and attribute into form_field block --- core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php | 10 +++++++++- core/lib/Thelia/Form/CustomerCreation.php | 8 +++++++- templates/smarty-sample/index.html | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 0ddd5229b..407606604 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -68,6 +68,7 @@ class Form implements SmartyPluginInterface $instance = $this->getInstance($params['name']); $instance = $instance->buildForm($formBuilder, array()); + $template->assign("form", $instance->getForm()->createView()); } else { return $content; @@ -86,8 +87,15 @@ class Form implements SmartyPluginInterface } + $template->assign("options", $form->vars); $template->assign("name", $form->vars["name"]); $template->assign("value", $form->vars["value"]); + $template->assign("label", $form->vars["label"]); + $attr = array(); + foreach ($form->vars["attr"] as $key => $value) { + $attr[] = sprintf('%s="%s"', $key, $value); + } + $template->assign("attr", implode(" ", $attr)); $form->setRendered(); @@ -110,7 +118,7 @@ class Form implements SmartyPluginInterface $return = ""; foreach ($form->getIterator() as $row) { - if ($this->isHidden($row)) { + if ($this->isHidden($row) && $row->isRendered() === false) { $return .= sprintf($field, $row->vars["name"], $row->vars["value"]); } } diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index 4c70a0177..98e3dd0eb 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -32,7 +32,13 @@ class CustomerCreation extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { return $builder->add("name", "text") - ->add("email", "email") + ->add("email", "email", array( + "attr" => array( + "class" => "field" + ), + "label" => "toto" + ) + ) ->add('age', 'integer'); } diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 89b1c63d6..1aaa0b9e6 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -12,11 +12,11 @@ An image from asset directory : {form_field_hidden form=$form} {form_field form=$form.email} - {intl l='email'} : + {intl l='{$label}'} : {/form_field} {form_field form=$form.name} - {intl l='name'} : + {intl l='name'} : {/form_field} {form_field form=$form.age} {intl l='age'} : From 1fc1482ac403c7718e27dbd1a27a5482a752fb91 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 11:43:07 +0200 Subject: [PATCH 08/14] change label in form test --- core/lib/Thelia/Form/CustomerCreation.php | 2 +- templates/smarty-sample/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index 98e3dd0eb..120be2f41 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -36,7 +36,7 @@ class CustomerCreation extends AbstractType "attr" => array( "class" => "field" ), - "label" => "toto" + "label" => "email" ) ) ->add('age', 'integer'); diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 1aaa0b9e6..2332aa5ff 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -12,7 +12,7 @@ An image from asset directory : {form_field_hidden form=$form} {form_field form=$form.email} - {intl l='{$label}'} : + {intl l="{$label}"} : {/form_field} {form_field form=$form.name} From 7bc1b4f5138fd94c2e557193df87ac75e668c9c9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 14:30:35 +0200 Subject: [PATCH 09/14] integrate form into admin part --- .../Admin/Controller/AdminController.php | 52 ++++++++++++++++--- .../Admin/Controller/BaseAdminController.php | 18 ++++++- .../Core/Template/Smarty/Plugins/Form.php | 6 +-- core/lib/Thelia/Form/BaseForm.php | 4 +- templates/admin/default/login.html | 11 ++-- 5 files changed, 73 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Admin/Controller/AdminController.php b/core/lib/Thelia/Admin/Controller/AdminController.php index 27d0ef707..bef1b1288 100755 --- a/core/lib/Thelia/Admin/Controller/AdminController.php +++ b/core/lib/Thelia/Admin/Controller/AdminController.php @@ -1,19 +1,55 @@ . */ +/* */ +/*************************************************************************************/ namespace Thelia\Admin\Controller; +use Thelia\Form\AdminLogin; class AdminController extends BaseAdminController { public function indexAction() { - return $this->render("login.html"); + + $form = $this->getFormBuilder(); + + $adminLogin = new AdminLogin(); + + $form = $adminLogin->buildForm($form, array())->getForm(); + + $request = $this->getRequest(); + + if($request->isMethod("POST")) { + $form->bind($request); + + if($form->isValid()) { + //TODO + } else { + //TODO + } + } + + return $this->render("login.html", array( + "form" => $form->createView() + )); } } \ No newline at end of file diff --git a/core/lib/Thelia/Admin/Controller/BaseAdminController.php b/core/lib/Thelia/Admin/Controller/BaseAdminController.php index 47ec7a476..3aa0e9281 100755 --- a/core/lib/Thelia/Admin/Controller/BaseAdminController.php +++ b/core/lib/Thelia/Admin/Controller/BaseAdminController.php @@ -24,6 +24,10 @@ namespace Thelia\Admin\Controller; use Symfony\Component\Routing\RequestContext; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\HttpFoundation\Response; + +use Thelia\Form\BaseForm; +use Thelia\Model\ConfigQuery; /** * @@ -44,7 +48,7 @@ class BaseAdminController extends ContainerAware */ public function render($templateName, $args = array()) { - $args = array('lang' => 'fr'); + $args = array_merge($args, array('lang' => 'fr')); $response = new Response(); @@ -53,7 +57,7 @@ class BaseAdminController extends ContainerAware public function renderRaw($templateName, $args = array()) { - $args = array('lang' => 'fr'); + $args = array_merge($args, array('lang' => 'fr')); return $this->getParser()->render($templateName, $args); } @@ -76,5 +80,15 @@ class BaseAdminController extends ContainerAware return $parser; } + public function getFormFactory() + { + return BaseForm::getFormFactory($this->getRequest(), ConfigQuery::read("form.secret.admin", md5(__DIR__))); + } + + public function getFormBuilder() + { + return $this->getFormFactory()->createBuilder("form"); + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 407606604..ea44af4a4 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -88,7 +88,7 @@ class Form implements SmartyPluginInterface $template->assign("options", $form->vars); - $template->assign("name", $form->vars["name"]); + $template->assign("name", $form->vars["full_name"]); $template->assign("value", $form->vars["value"]); $template->assign("label", $form->vars["label"]); $attr = array(); @@ -119,7 +119,7 @@ class Form implements SmartyPluginInterface foreach ($form->getIterator() as $row) { if ($this->isHidden($row) && $row->isRendered() === false) { - $return .= sprintf($field, $row->vars["name"], $row->vars["value"]); + $return .= sprintf($field, $row->vars["full_name"], $row->vars["value"]); } } @@ -136,7 +136,7 @@ class Form implements SmartyPluginInterface $form = $params["form"]; if (! $form instanceof \Symfony\Component\Form\FormView) { - throw new \InvalidArgumentException("form parameter in form_field block must be an instance of + throw new \InvalidArgumentException("form parameter in form_enctype function must be an instance of Symfony\Component\Form\FormView"); } diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index bd5dbdaef..1f3f15d79 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -36,7 +36,7 @@ class BaseForm { * @param Request $request * @return \Symfony\Component\Form\FormFactoryInterface */ - public static function getFormFactory(Request $request) + public static function getFormFactory(Request $request, $secret = null) { $form = Forms::createFormFactoryBuilder() ->addExtension(new HttpFoundationExtension()) @@ -44,7 +44,7 @@ class BaseForm { new CsrfExtension( new SessionCsrfProvider( $request->getSession(), - ConfigQuery::read("form.secret", md5(__DIR__)) + $secret ?: ConfigQuery::read("form.secret", md5(__DIR__)) ) ) )->getFormFactory(); diff --git a/templates/admin/default/login.html b/templates/admin/default/login.html index b059bb222..879c76cda 100755 --- a/templates/admin/default/login.html +++ b/templates/admin/default/login.html @@ -15,9 +15,14 @@

{intl l='Thelia Back Office'}

-
- - + + {form_field_hidden form=$form} + {form_field form=$form.username} + + {/form_field} + {form_field form=$form.password} + + {/form_field} From 21280569e6f86b6fd91eabc6eb345c5bb72e2e88 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 14:47:01 +0200 Subject: [PATCH 10/14] add AdminLogin file --- .../Admin/Controller/AdminController.php | 1 + core/lib/Thelia/Form/AdminLogin.php | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core/lib/Thelia/Form/AdminLogin.php diff --git a/core/lib/Thelia/Admin/Controller/AdminController.php b/core/lib/Thelia/Admin/Controller/AdminController.php index bef1b1288..6965858eb 100755 --- a/core/lib/Thelia/Admin/Controller/AdminController.php +++ b/core/lib/Thelia/Admin/Controller/AdminController.php @@ -43,6 +43,7 @@ class AdminController extends BaseAdminController { if($form->isValid()) { //TODO + } else { //TODO } diff --git a/core/lib/Thelia/Form/AdminLogin.php b/core/lib/Thelia/Form/AdminLogin.php new file mode 100644 index 000000000..2284cba91 --- /dev/null +++ b/core/lib/Thelia/Form/AdminLogin.php @@ -0,0 +1,47 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Form; + + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; + +class AdminLogin extends AbstractType { + + public function buildForm(FormBuilderInterface $builder, array $options) + { + return $builder + ->add("username", "text") + ->add("password", "password"); + } + + /** + * Returns the name of this type. + * + * @return string The name of this type + */ + public function getName() + { + return "admin_login"; + } +} \ No newline at end of file From b2ee3c3ef8c6e1de9e3e3995be4883bf8122936c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 15:30:29 +0200 Subject: [PATCH 11/14] Use Validator component for form Validation --- core/lib/Thelia/Form/AdminLogin.php | 9 ++++++++- core/lib/Thelia/Form/BaseForm.php | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Form/AdminLogin.php b/core/lib/Thelia/Form/AdminLogin.php index 2284cba91..2bd2debac 100644 --- a/core/lib/Thelia/Form/AdminLogin.php +++ b/core/lib/Thelia/Form/AdminLogin.php @@ -25,13 +25,20 @@ namespace Thelia\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Validator\Constraints\Length; +use Symfony\Component\Validator\Constraints\NotBlank; class AdminLogin extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { return $builder - ->add("username", "text") + ->add("username", "text", array( + "constraints" => array( + new NotBlank(), + new Length(array("min" => 3)) + ) + )) ->add("password", "password"); } diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index 1f3f15d79..da6689f24 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -22,12 +22,14 @@ /*************************************************************************************/ namespace Thelia\Form; +use Symfony\Component\Form\Extension\Validator\ValidatorExtension; use Symfony\Component\Form\Forms; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension; use Symfony\Component\Form\Extension\Csrf\CsrfExtension; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider; +use Symfony\Component\Validator\Validation; use Thelia\Model\ConfigQuery; class BaseForm { @@ -38,6 +40,8 @@ class BaseForm { */ public static function getFormFactory(Request $request, $secret = null) { + $validator = Validation::createValidator(); + $form = Forms::createFormFactoryBuilder() ->addExtension(new HttpFoundationExtension()) ->addExtension( @@ -47,7 +51,9 @@ class BaseForm { $secret ?: ConfigQuery::read("form.secret", md5(__DIR__)) ) ) - )->getFormFactory(); + ) + ->addExtension(new ValidatorExtension($validator)) + ->getFormFactory(); return $form; } From 8dd43d6779c340f7c97534698b70e9e30aa7df8a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 25 Jun 2013 16:54:42 +0200 Subject: [PATCH 12/14] add form_error block --- .../Admin/Controller/AdminController.php | 20 +++++++------ .../Thelia/Config/Resources/routing/admin.xml | 3 ++ .../Core/Template/Smarty/Plugins/Form.php | 30 ++++++++++++++++++- templates/admin/default/login.html | 3 ++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/core/lib/Thelia/Admin/Controller/AdminController.php b/core/lib/Thelia/Admin/Controller/AdminController.php index 6965858eb..39cdfb4fc 100755 --- a/core/lib/Thelia/Admin/Controller/AdminController.php +++ b/core/lib/Thelia/Admin/Controller/AdminController.php @@ -30,11 +30,7 @@ class AdminController extends BaseAdminController { public function indexAction() { - $form = $this->getFormBuilder(); - - $adminLogin = new AdminLogin(); - - $form = $adminLogin->buildForm($form, array())->getForm(); + $form = $this->getLoginForm(); $request = $this->getRequest(); @@ -42,10 +38,7 @@ class AdminController extends BaseAdminController { $form->bind($request); if($form->isValid()) { - //TODO - - } else { - //TODO + echo "valid"; exit; } } @@ -53,4 +46,13 @@ class AdminController extends BaseAdminController { "form" => $form->createView() )); } + + protected function getLoginForm() + { + $form = $this->getFormBuilder(); + + $adminLogin = new AdminLogin(); + + return $adminLogin->buildForm($form, array())->getForm(); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 68510a84c..171763f56 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -7,4 +7,7 @@ Thelia\Admin\Controller\AdminController::indexAction + + Thelia\Admin\Controller\AdminController::loginAction + \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index ea44af4a4..3c90ec4d8 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -145,6 +145,33 @@ class Form implements SmartyPluginInterface } } + public function formError($params, $content, \Smarty_Internal_Template $template, &$repeat) + { + + $form = $params["form"]; + if (! $form instanceof \Symfony\Component\Form\FormView) { + throw new \InvalidArgumentException("form parameter in form_error block must be an instance of + Symfony\Component\Form\FormView"); + } + + if (empty($form->vars["errors"])) { + return ""; + } + + if ($repeat) { + + $error = $form->vars["errors"]; + + $template->assign("message", $error[0]->getMessage()); + $template->assign("parameters", $error[0]->getMessageParameters()); + $template->assign("pluralization", $error[0]->getMessagePluralization()); + + + } else { + return $content; + } + } + public function getInstance($name) { if (!isset($this->formDefinition[$name])) { @@ -164,7 +191,8 @@ class Form implements SmartyPluginInterface new SmartyPluginDescriptor("block", "form", $this, "generateForm"), new SmartyPluginDescriptor("block", "form_field", $this, "formRender"), new SmartyPluginDescriptor("function", "form_field_hidden", $this, "formRenderHidden"), - new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype") + new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype"), + new SmartyPluginDescriptor("block", "form_error", $this, "formError") ); } } diff --git a/templates/admin/default/login.html b/templates/admin/default/login.html index 879c76cda..5c33d742e 100755 --- a/templates/admin/default/login.html +++ b/templates/admin/default/login.html @@ -18,6 +18,9 @@ {form_field_hidden form=$form} {form_field form=$form.username} + {form_error form=$form.username} + {$message} + {/form_error} {/form_field} {form_field form=$form.password} From 83318ccd2fb6bfa39477454f5f29b85e6898ccb2 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 26 Jun 2013 09:19:32 +0200 Subject: [PATCH 13/14] add error variable in form_field block --- core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 3c90ec4d8..d1ef26244 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -91,6 +91,7 @@ class Form implements SmartyPluginInterface $template->assign("name", $form->vars["full_name"]); $template->assign("value", $form->vars["value"]); $template->assign("label", $form->vars["label"]); + $template->assign("error", empty($form->vars["errors"]) ? false : true); $attr = array(); foreach ($form->vars["attr"] as $key => $value) { $attr[] = sprintf('%s="%s"', $key, $value); From 200ace2fc02327afc2dfe6cd2d7b4963c0719164 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 26 Jun 2013 10:45:43 +0200 Subject: [PATCH 14/14] add 404 rule in admin --- .../Thelia/Admin/Controller/AdminController.php | 9 +++++++++ core/lib/Thelia/Config/Resources/routing/admin.xml | 4 ++++ .../Core/Template/Smarty/Plugins/Assetic.php | 2 +- templates/admin/default/404.html | 14 ++++++++++++++ web/.htaccess | 4 ++-- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 templates/admin/default/404.html diff --git a/core/lib/Thelia/Admin/Controller/AdminController.php b/core/lib/Thelia/Admin/Controller/AdminController.php index 39cdfb4fc..bb5536c7e 100755 --- a/core/lib/Thelia/Admin/Controller/AdminController.php +++ b/core/lib/Thelia/Admin/Controller/AdminController.php @@ -23,6 +23,7 @@ namespace Thelia\Admin\Controller; +use Symfony\Component\HttpFoundation\Response; use Thelia\Form\AdminLogin; class AdminController extends BaseAdminController { @@ -55,4 +56,12 @@ class AdminController extends BaseAdminController { return $adminLogin->buildForm($form, array())->getForm(); } + + public function lostAction() + { + return new Response( + $this->renderRaw("404.html"), + 404 + ); + } } \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 171763f56..90ecd0c1a 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -10,4 +10,8 @@ Thelia\Admin\Controller\AdminController::loginAction + + Thelia\Admin\Controller\AdminController::lostAction + .* + \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php index 4418bd50c..f79f98a1a 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php @@ -35,7 +35,7 @@ class Assetic implements SmartyPluginInterface { $web_root = THELIA_WEB_DIR; - $asset_dir_from_web_root = 'assets/admin/default'; // FIXME + $asset_dir_from_web_root = '/assets/admin/default'; // FIXME $this->asset_manager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root); } diff --git a/templates/admin/default/404.html b/templates/admin/default/404.html new file mode 100644 index 000000000..5704c8125 --- /dev/null +++ b/templates/admin/default/404.html @@ -0,0 +1,14 @@ +{$page_title={intl l='Thelia'}} +{include file='includes/header.inc.html'} + + + +
+

Oops! An Error Occurred

+

The server returned a "404 Not Found".

+
+ + +{include file='includes/footer.inc.html'} \ No newline at end of file diff --git a/web/.htaccess b/web/.htaccess index 4336ad269..57b1cf491 100755 --- a/web/.htaccess +++ b/web/.htaccess @@ -1,4 +1,4 @@ -Options +FollowSymlinks +Options +FollowSymlinks -Indexes AddDefaultCharset UTF-8 @@ -8,5 +8,5 @@ AddDefaultCharset UTF-8 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^admin(/.*)?$ index_dev.php/admin/$1 [L,QSA] + RewriteRule ^(.*)$ index_dev.php [L,QSA] \ No newline at end of file