Merge branch 'form' into admin

This commit is contained in:
Manuel Raynaud
2013-06-26 11:03:15 +02:00
43 changed files with 848 additions and 350 deletions

View File

@@ -1,19 +1,67 @@
<?php <?php
/** /*************************************************************************************/
* Created by JetBrains PhpStorm. /* */
* User: manu /* Thelia */
* Date: 20/06/13 /* */
* Time: 12:05 /* Copyright (c) OpenStudio */
* To change this template use File | Settings | File Templates. /* email : info@thelia.net */
*/ /* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Admin\Controller; namespace Thelia\Admin\Controller;
use Symfony\Component\HttpFoundation\Response;
use Thelia\Form\AdminLogin;
class AdminController extends BaseAdminController { class AdminController extends BaseAdminController {
public function indexAction() public function indexAction()
{ {
return $this->render("login.html");
$form = $this->getLoginForm();
$request = $this->getRequest();
if($request->isMethod("POST")) {
$form->bind($request);
if($form->isValid()) {
echo "valid"; exit;
}
}
return $this->render("login.html", array(
"form" => $form->createView()
));
}
protected function getLoginForm()
{
$form = $this->getFormBuilder();
$adminLogin = new AdminLogin();
return $adminLogin->buildForm($form, array())->getForm();
}
public function lostAction()
{
return new Response(
$this->renderRaw("404.html"),
404
);
} }
} }

View File

@@ -24,6 +24,10 @@ namespace Thelia\Admin\Controller;
use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RequestContext;
use Symfony\Component\DependencyInjection\ContainerAware; 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()) public function render($templateName, $args = array())
{ {
$args = array('lang' => 'fr'); $args = array_merge($args, array('lang' => 'fr'));
$response = new Response(); $response = new Response();
@@ -53,7 +57,7 @@ class BaseAdminController extends ContainerAware
public function renderRaw($templateName, $args = array()) public function renderRaw($templateName, $args = array())
{ {
$args = array('lang' => 'fr'); $args = array_merge($args, array('lang' => 'fr'));
return $this->getParser()->render($templateName, $args); return $this->getParser()->render($templateName, $args);
} }
@@ -76,5 +80,15 @@ class BaseAdminController extends ContainerAware
return $parser; 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");
}
} }

View File

@@ -21,6 +21,10 @@
--> -->
</templateDirectives> </templateDirectives>
<forms>
<form name="thelia.customer.creation" class="Thelia\Form\CustomerCreation"/>
</forms>
<commands> <commands>
<command class="Thelia\Command\CacheClear"/> <command class="Thelia\Command\CacheClear"/>
@@ -72,6 +76,15 @@
</call> </call>
</service> </service>
<service id="smart.plugin.form" class="Thelia\Core\Template\Smarty\Plugins\Form" scope="request">
<tag name="thelia.parser.register_plugin"/>
<argument type="service" id="request"/>
<call method="setFormDefinition">
<argument>%thelia.parser.forms%</argument>
</call>
</service>
<service id="smarty.plugin.translation" class="Thelia\Core\Template\Smarty\Plugins\Translation" > <service id="smarty.plugin.translation" class="Thelia\Core\Template\Smarty\Plugins\Translation" >
<tag name="thelia.parser.register_plugin"/> <tag name="thelia.parser.register_plugin"/>
</service> </service>

View File

@@ -7,4 +7,11 @@
<route id="admin" path="/admin"> <route id="admin" path="/admin">
<default key="_controller">Thelia\Admin\Controller\AdminController::indexAction</default> <default key="_controller">Thelia\Admin\Controller\AdminController::indexAction</default>
</route> </route>
<route id="admin.login" path="/admin/login">
<default key="_controller">Thelia\Admin\Controller\AdminController::loginAction</default>
</route>
<route id="admin.lost" path="/admin/{everything}">
<default key="_controller">Thelia\Admin\Controller\AdminController::lostAction</default>
<requirement key="everything">.*</requirement>
</route>
</routes> </routes>

View File

@@ -29,7 +29,6 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
class Application extends BaseApplication class Application extends BaseApplication
{ {
@@ -68,8 +67,7 @@ class Application extends BaseApplication
$container = $this->kernel->getContainer(); $container = $this->kernel->getContainer();
foreach($container->getParameter("command.definition") as $command) foreach ($container->getParameter("command.definition") as $command) {
{
$r = new \ReflectionClass($command); $r = new \ReflectionClass($command);
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) { if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
@@ -77,6 +75,5 @@ class Application extends BaseApplication
} }
} }
} }
} }

View File

@@ -24,7 +24,6 @@ namespace Thelia\Core\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Scope; use Symfony\Component\DependencyInjection\Scope;
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass; use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;

View File

@@ -1,6 +1,5 @@
<?php <?php
namespace Thelia\Core\Controller; namespace Thelia\Core\Controller;
use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver; use Symfony\Component\HttpKernel\Controller\ControllerResolver as BaseControllerResolver;
@@ -21,14 +20,14 @@ class ControllerResolver extends BaseControllerResolver
/** /**
* Constructor. * Constructor.
* *
* @param ContainerInterface $container A ContainerInterface instance * @param ContainerInterface $container A ContainerInterface instance
* @param LoggerInterface $logger A LoggerInterface instance * @param LoggerInterface $logger A LoggerInterface instance
*/ */
public function __construct(ContainerInterface $container, LoggerInterface $logger = null) public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
{ {
$this->container = $container; $this->container = $container;
parent::__construct($logger); parent::__construct($logger);
} }
/** /**
@@ -38,7 +37,7 @@ class ControllerResolver extends BaseControllerResolver
* *
* @return mixed A PHP callable * @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 * @throws \InvalidArgumentException When the controller class does not exist
*/ */
protected function createController($controller) protected function createController($controller)

View File

@@ -23,7 +23,6 @@
namespace Thelia\Core\DependencyInjection\Compiler; namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference; 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. * You can modify the container here before it is dumped to PHP code.
* *

View File

@@ -24,12 +24,12 @@
namespace Thelia\Core\DependencyInjection\Loader; namespace Thelia\Core\DependencyInjection\Loader;
use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader as XmlLoader;
use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\SimpleXMLElement; use Symfony\Component\DependencyInjection\SimpleXMLElement;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -63,6 +63,8 @@ class XmlFileLoader extends FileLoader
$this->parseCommands($xml); $this->parseCommands($xml);
$this->parseForms($xml);
$this->parseDefinitions($xml, $path); $this->parseDefinitions($xml, $path);
} }
@@ -73,7 +75,7 @@ class XmlFileLoader extends FileLoader
} }
try { try {
$commandConfig = $this->container->getParameter("command.definition"); $commandConfig = $this->container->getParameter("command.definition");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { } catch (ParameterNotFoundException $e) {
$commandConfig = array(); $commandConfig = array();
} }
@@ -111,7 +113,7 @@ class XmlFileLoader extends FileLoader
} }
try { try {
$loopConfig = $this->container->getParameter("Thelia.parser.loops"); $loopConfig = $this->container->getParameter("Thelia.parser.loops");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { } catch (ParameterNotFoundException $e) {
$loopConfig = array(); $loopConfig = array();
} }
@@ -122,6 +124,25 @@ class XmlFileLoader extends FileLoader
$this->container->setParameter("Thelia.parser.loops", $loopConfig); $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')] = $form->getAttributeAsPhp('class');
}
$this->container->setParameter('Thelia.parser.forms', $formConfig);
}
/** /**
* parse Filters property * parse Filters property
* *
@@ -134,7 +155,7 @@ class XmlFileLoader extends FileLoader
} }
try { try {
$filterConfig = $this->container->getParameter("Thelia.parser.filters"); $filterConfig = $this->container->getParameter("Thelia.parser.filters");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { } catch (ParameterNotFoundException $e) {
$filterConfig = array(); $filterConfig = array();
} }
@@ -157,7 +178,7 @@ class XmlFileLoader extends FileLoader
} }
try { try {
$baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives"); $baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives");
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { } catch (ParameterNotFoundException $e) {
$baseParamConfig = array(); $baseParamConfig = array();
} }
@@ -334,7 +355,7 @@ EOF
/** /**
* Returns true if this class supports the given resource. * 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 * @param string $type The resource type
* *
* @return Boolean true if this class supports the given resource, false otherwise * @return Boolean true if this class supports the given resource, false otherwise

View File

@@ -15,6 +15,7 @@
<xsd:element name="services" type="services" /> <xsd:element name="services" type="services" />
<xsd:element name="parameters" type="parameters"/> <xsd:element name="parameters" type="parameters"/>
<xsd:element name="commands" type="commands"/> <xsd:element name="commands" type="commands"/>
<xsd:element name="forms" type="forms" />
</xsd:choice> </xsd:choice>
</xsd:complexType> </xsd:complexType>
@@ -74,6 +75,17 @@
<xsd:attribute name="class" type="xsd:string" use="required" /> <xsd:attribute name="class" type="xsd:string" use="required" />
</xsd:complexType> </xsd:complexType>
<xsd:complexType name="forms">
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
<xsd:element name="form" type="form" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="form">
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="class" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="filters"> <xsd:complexType name="filters">
<xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="filter" type="filter" /> <xsd:element name="filter" type="filter" />

View File

@@ -50,9 +50,10 @@ abstract class ActionEvent extends Event
/** /**
* *
* @param \Symfony\Component\HttpFoundation\Request $request * @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->request = $request;
$this->action = $action; $this->action = $action;
} }

View File

@@ -11,6 +11,6 @@ namespace Thelia\Core\Event;
use Thelia\Core\Event\ActionEvent; use Thelia\Core\Event\ActionEvent;
class DefaultActionEvent extends ActionEvent { class DefaultActionEvent extends ActionEvent
{
} }

View File

@@ -25,10 +25,8 @@ namespace Thelia\Core\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Factory\ActionEventFactory; use Thelia\Core\Factory\ActionEventFactory;
/** /**
* *
* Action are dispatch here. * Action are dispatch here.
@@ -41,7 +39,6 @@ use Thelia\Core\Factory\ActionEventFactory;
class ControllerListener implements EventSubscriberInterface class ControllerListener implements EventSubscriberInterface
{ {
public function onKernelController(FilterControllerEvent $event) public function onKernelController(FilterControllerEvent $event)
{ {
$dispatcher = $event->getDispatcher(); $dispatcher = $event->getDispatcher();

View File

@@ -78,7 +78,7 @@ class ViewListener implements EventSubscriberInterface
} else { } else {
$event->setResponse(new Response($content, $parser->getStatus() ?: 200)); $event->setResponse(new Response($content, $parser->getStatus() ?: 200));
} }
} catch(ResourceNotFoundException $e) { } catch (ResourceNotFoundException $e) {
$event->setResponse(new Response($e->getMessage(), 404)); $event->setResponse(new Response($e->getMessage(), 404));
} }

View File

@@ -24,8 +24,6 @@
namespace Thelia\Core\Factory; namespace Thelia\Core\Factory;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Event\ActionEventClass;
class ActionEventFactory class ActionEventFactory
{ {

View File

@@ -37,22 +37,22 @@ use Assetic\Cache\FilesystemCache;
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
*/ */
class AsseticHelper { class AsseticHelper
{
/** /**
* Generates assets from $asset_path in $output_path, using $filters. * 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 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_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 $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 $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 $filters a list of filters, as defined below (see switch($filter_name) ...)
* @param unknown $debug true / false * @param unknown $debug true / false
* @throws \InvalidArgumentException if an invalid filter name is found * @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_name = basename($asset_path);
$asset_dir = dirname($asset_path); $asset_dir = dirname($asset_path);
@@ -62,11 +62,11 @@ class AsseticHelper {
if (! empty($filters)) { if (! empty($filters)) {
$filter_list = explode(',', $filters); $filter_list = explode(',', $filters);
foreach($filter_list as $filter_name) { foreach ($filter_list as $filter_name) {
$filter_name = trim($filter_name); $filter_name = trim($filter_name);
switch($filter_name) { switch ($filter_name) {
case 'less' : case 'less' :
$fm->set('less', new Filter\LessphpFilter()); $fm->set('less', new Filter\LessphpFilter());
break; break;
@@ -92,8 +92,7 @@ class AsseticHelper {
break; break;
} }
} }
} } else {
else {
$filter_list = array(); $filter_list = array();
} }

View File

@@ -37,4 +37,3 @@ class Secure extends BaseParam
} }
} }
} }

View File

@@ -23,9 +23,8 @@
namespace Thelia\Core\Template\Element; namespace Thelia\Core\Template\Element;
class LoopResultRow
class LoopResultRow { {
protected $substitution = array(); protected $substitution = array();
public function set($key, $value) public function set($key, $value)

View File

@@ -22,7 +22,6 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Exception; namespace Thelia\Core\Template\Exception;
class ResourceNotFoundException extends \RuntimeException
class ResourceNotFoundException extends \RuntimeException { {
} }

View File

@@ -21,16 +21,16 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace Thelia\Core\Template\Loop; namespace Thelia\Core\Template\Loop;
use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResult;
use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
use Thelia\Type\TypeCollection; use Thelia\Type\TypeCollection;
use Thelia\Type; use Thelia\Type;
@@ -65,8 +65,8 @@ use Thelia\Type;
* @package Thelia\Core\Template\Loop * @package Thelia\Core\Template\Loop
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class Category extends BaseLoop { class Category extends BaseLoop
{
public $id; public $id;
public $parent; public $parent;
public $current; public $current;
@@ -169,13 +169,13 @@ class Category extends BaseLoop {
$search->filterById(explode(',', $this->id), \Criteria::IN); $search->filterById(explode(',', $this->id), \Criteria::IN);
} }
if(!is_null($this->parent)) { if (!is_null($this->parent)) {
$search->filterByParent($this->parent); $search->filterByParent($this->parent);
} }
if($this->current == 1) { if ($this->current == 1) {
$search->filterById($this->request->get("category_id")); $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); $search->filterById($this->request->get("category_id"), \Criteria::NOT_IN);
} }
@@ -187,14 +187,13 @@ class Category extends BaseLoop {
$search->filterByLink($this->link); $search->filterByLink($this->link);
} }
if($this->limit > -1) { if ($this->limit > -1) {
$search->limit($this->limit); $search->limit($this->limit);
} }
$search->filterByVisible($this->visible); $search->filterByVisible($this->visible);
$search->offset($this->offset); $search->offset($this->offset);
switch ($this->order) {
switch($this->order) {
case "alpha": case "alpha":
$search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE); $search->addAscendingOrderByColumn(\Thelia\Model\CategoryI18nPeer::TITLE);
break; break;
@@ -209,7 +208,7 @@ class Category extends BaseLoop {
break; break;
} }
if($this->random == 1) { if ($this->random == 1) {
$search->clearOrderByColumns(); $search->clearOrderByColumns();
$search->addAscendingOrderByColumn('RAND()'); $search->addAscendingOrderByColumn('RAND()');
} }

View File

@@ -25,8 +25,8 @@ namespace Thelia\Core\Template\Smarty\Assets;
use Thelia\Core\Template\Assets\AsseticHelper; use Thelia\Core\Template\Assets\AsseticHelper;
class SmartyAssetsManager { class SmartyAssetsManager
{
const ASSET_TYPE_AUTO = ''; const ASSET_TYPE_AUTO = '';
private $assetic_manager; private $assetic_manager;
@@ -37,50 +37,49 @@ class SmartyAssetsManager {
/** /**
* Creates a new SmartyAssetsManager instance * Creates a new SmartyAssetsManager instance
* *
* @param string $web_root the disk path to the web root * @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 $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->web_root = $web_root;
$this->path_relative_to_web_root = $path_relative_to_web_root; $this->path_relative_to_web_root = $path_relative_to_web_root;
$this->assetic_manager = new AsseticHelper(); $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) // Opening tag (first call only)
if ($repeat) { if ($repeat) {
$file = $params['file']; $file = $params['file'];
$filters = isset($params['filters']) ? $params['filters'] : ''; $filters = isset($params['filters']) ? $params['filters'] : '';
$debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false; $debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
// Get template base path // Get template base path
$tpl_path = $template->source->filepath; $tpl_path = $template->source->filepath;
// Get basedir // Get basedir
$tpl_dir = dirname($tpl_path); $tpl_dir = dirname($tpl_path);
// Create absolute dir path // Create absolute dir path
$asset_dir = realpath($tpl_dir.'/'.dirname($file)); $asset_dir = realpath($tpl_dir.'/'.dirname($file));
$asset_file = basename($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( $url = $this->assetic_manager->asseticize(
$asset_dir.'/'.$asset_file, $asset_dir.'/'.$asset_file,
$this->web_root."/".$this->path_relative_to_web_root, $this->web_root."/".$this->path_relative_to_web_root,
$this->path_relative_to_web_root, $this->path_relative_to_web_root,
$assetType, $assetType,
$filters, $filters,
$debug $debug
); );
$template->assign('asset_url', $url); $template->assign('asset_url', $url);
} } elseif (isset($content)) {
else if (isset($content)) { return $content;
return $content;
} }
} }
} }

View File

@@ -23,26 +23,23 @@
namespace Thelia\Core\Template\Smarty\Plugins; namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\SmartyPluginInterface;
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager; use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
class Assetic implements SmartyPluginInterface
class Assetic implements SmartyPluginInterface { {
public $asset_manager; public $asset_manager;
public function __construct() public function __construct()
{ {
$web_root = THELIA_WEB_DIR; $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); $this->asset_manager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root);
} }
public function theliaBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat) public function theliaBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
{ {
return $this->asset_manager->processSmartyPluginCall('js', $params, $content, $template, $repeat); return $this->asset_manager->processSmartyPluginCall('js', $params, $content, $template, $repeat);

View File

@@ -0,0 +1,199 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
use Thelia\Log\Tlog;
class Form implements SmartyPluginInterface
{
protected $request;
protected $form;
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, \Smarty_Internal_Template $template, &$repeat)
{
if ($repeat) {
if (empty($params['name'])) {
throw new \InvalidArgumentException("Missing 'name' parameter in form arguments");
}
$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;
}
}
public function formRender($params, $content, \Smarty_Internal_Template $template, &$repeat)
{
if ($repeat) {
$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");
}
$template->assign("options", $form->vars);
$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);
}
$template->assign("attr", implode(" ", $attr));
$form->setRendered();
} else {
return $content;
}
}
public function formRenderHidden($params, \Smarty_Internal_Template $template)
{
$form = $params["form"];
$field = '<input type="hidden" name="%s" value="%s">';
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) && $row->isRendered() === false) {
$return .= sprintf($field, $row->vars["full_name"], $row->vars["value"]);
}
}
return $return;
}
protected function isHidden(FormView $formView)
{
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_enctype function must be an instance of
Symfony\Component\Form\FormView");
}
if ($form->vars["multipart"]) {
return sprintf('%s="%s"',"enctype", "multipart/form-data");
}
}
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])) {
throw new ElementNotFoundException(sprintf("%s form does not exists", $name));
}
return new $this->formDefinition[$name];
}
/**
* @return an array of SmartyPluginDescriptor
*/
public function getPluginDescriptors()
{
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_enctype", $this, "formEnctype"),
new SmartyPluginDescriptor("block", "form_error", $this, "formError")
);
}
}

View File

@@ -23,17 +23,16 @@
namespace Thelia\Core\Template\Smarty\Plugins; namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\SmartyPluginInterface;
class Module implements SmartyPluginInterface { class Module implements SmartyPluginInterface
{
/** /**
* Process theliaModule template inclusion function * Process theliaModule template inclusion function
* *
* @param unknown $params * @param unknown $params
* @param unknown $smarty * @param unknown $smarty
* @return string * @return string
*/ */
public function theliaModule($params, &$smarty) public function theliaModule($params, &$smarty)

View File

@@ -51,46 +51,44 @@ class TheliaLoop implements SmartyPluginInterface
/** /**
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block * Process {loop name="loop name" type="loop type" ... } ... {/loop} block
* *
* @param unknown $params * @param unknown $params
* @param unknown $content * @param unknown $content
* @param unknown $template * @param unknown $template
* @param unknown $repeat * @param unknown $repeat
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return string * @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'])) if (empty($params['type']))
throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments"); 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); $template->assignByRef($name, $loopResults);
} } else {
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);
} }
@@ -100,22 +98,21 @@ class TheliaLoop implements SmartyPluginInterface
$repeat = $loopResults->valid(); $repeat = $loopResults->valid();
} }
if ($content !== null) {
if ($loopResults->isEmpty()) $content = ""; if ($content !== null) {
return $content; if ($loopResults->isEmpty()) $content = "";
} return $content;
}
} }
/** /**
* Process {elseloop rel="loopname"} ... {/elseloop} block * Process {elseloop rel="loopname"} ... {/elseloop} block
* *
* @param unknown $params * @param unknown $params
* @param unknown $content * @param unknown $content
* @param unknown $template * @param unknown $template
* @param unknown $repeat * @param unknown $repeat
* @return Ambigous <string, unknown> * @return Ambigous <string, unknown>
*/ */
public function theliaElseloop($params, $content, $template, &$repeat) public function theliaElseloop($params, $content, $template, &$repeat)
@@ -127,14 +124,13 @@ class TheliaLoop implements SmartyPluginInterface
} }
} }
/** /**
* Process {ifloop rel="loopname"} ... {/ifloop} block * Process {ifloop rel="loopname"} ... {/ifloop} block
* *
* @param unknown $params * @param unknown $params
* @param unknown $content * @param unknown $content
* @param unknown $template * @param unknown $template
* @param unknown $repeat * @param unknown $repeat
* @return Ambigous <string, unknown> * @return Ambigous <string, unknown>
*/ */
public function theliaIfLoop($params, $content, $template, &$repeat) public function theliaIfLoop($params, $content, $template, &$repeat)
@@ -150,32 +146,33 @@ class TheliaLoop implements SmartyPluginInterface
* Check if a loop has returned results. The loop shoud have been executed before, or an * Check if a loop has returned results. The loop shoud have been executed before, or an
* InvalidArgumentException is thrown * InvalidArgumentException is thrown
* *
* @param unknown $params * @param unknown $params
* @param unknown $template * @param unknown $template
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
protected function checkEmptyLoop($params, $template) protected function checkEmptyLoop($params, $template)
{ {
if (empty($params['rel'])) if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments"); throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
$loopName = $params['rel']; $loopName = $params['rel'];
// Find loop results in the current template vars // Find loop results in the current template vars
$loopResults = $template->getTemplateVars($loopName); $loopResults = $template->getTemplateVars($loopName);
if (empty($loopResults)) { if (empty($loopResults)) {
throw new \InvalidArgumentException("Loop $loopName is not defined."); 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 * 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 * @return \Thelia\Core\Template\Element\BaseLoop
* @throws \Thelia\Tpex\Exception\InvalidElementException * @throws \Thelia\Tpex\Exception\InvalidElementException
* @throws \Thelia\Tpex\Exception\ElementNotFoundException * @throws \Thelia\Tpex\Exception\ElementNotFoundException
@@ -183,40 +180,40 @@ class TheliaLoop implements SmartyPluginInterface
protected function createLoopInstance($name) protected function createLoopInstance($name)
{ {
if (! isset($this->loopDefinition[$name])) { if (! isset($this->loopDefinition[$name])) {
throw new ElementNotFoundException(sprintf("%s loop does not exists", $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) { if ($class->isSubclassOf("Thelia\Core\Template\Element\BaseLoop") === false) {
throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop", throw new InvalidElementException(sprintf("%s Loop class have to extends Thelia\Core\Template\Element\BaseLoop",
$name)); $name));
} }
return $class->newInstance( return $class->newInstance(
$this->request, $this->request,
$this->dispatcher $this->dispatcher
); );
} }
/** /**
* Returns the value of a loop argument. * Returns the value of a loop argument.
* *
* @param unknown $loop a BaseLoop instance * @param unknown $loop a BaseLoop instance
* @param unknown $smartyParam * @param unknown $smartyParam
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
protected function getLoopArgument(BaseLoop $loop, $smartyParam) protected function getLoopArgument(BaseLoop $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();
$argumentsCollection = $loop->defineArgs(); $argumentsCollection = $loop->defineArgs();
foreach( $argumentsCollection as $argument ) { foreach( $argumentsCollection as $argument ) {
@@ -253,11 +250,11 @@ class TheliaLoop implements SmartyPluginInterface
$loop->{$argument->name} = $value; $loop->{$argument->name} = $value;
} }
if(!empty($faultActor)){ if (!empty($faultActor)) {
$complement = sprintf('[%s]', implode(', ', $faultDetails)); $complement = sprintf('[%s]', implode(', ', $faultDetails));
throw new \InvalidArgumentException($complement); throw new \InvalidArgumentException($complement);
} }
} }
/** /**
@@ -280,13 +277,13 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
public function setLoopList(array $loopDefinition) public function setLoopList(array $loopDefinition)
{ {
foreach ($loopDefinition as $name => $className) { foreach ($loopDefinition as $name => $className) {
if (array_key_exists($name, $this->loopDefinition)) { if (array_key_exists($name, $this->loopDefinition)) {
throw new \InvalidArgumentException(sprintf("%s loop name already exists for %s class name", $name, $className)); throw new \InvalidArgumentException(sprintf("%s loop name already exists for %s class name", $name, $className));
} }
$this->loopDefinition[$name] = $className; $this->loopDefinition[$name] = $className;
} }
} }
/** /**
@@ -297,6 +294,7 @@ class TheliaLoop implements SmartyPluginInterface
public function getPluginDescriptors() public function getPluginDescriptors()
{ {
return array( return array(
new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'), new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'),
new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'), new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'),
new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop'), new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop'),

View File

@@ -23,32 +23,28 @@
namespace Thelia\Core\Template\Smarty\Plugins; namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\SmartyPluginInterface;
class Translation implements SmartyPluginInterface { class Translation implements SmartyPluginInterface
{
/** /**
* Process translate function * Process translate function
* *
* @param unknown $params * @param unknown $params
* @param unknown $smarty * @param unknown $smarty
* @return string * @return string
*/ */
public function theliaTranslate($params, &$smarty) public function theliaTranslate($params, &$smarty)
{ {
if (isset($params['l'])) { if (isset($params['l'])) {
$string = str_replace('\'', '\\\'', $params['l']); $string = str_replace('\'', '\\\'', $params['l']);
} } else {
else { $string = '';
$string = ''; }
}
// TODO // TODO
return "[$string]";
return "[$string]";
} }
/** /**

View File

@@ -29,10 +29,10 @@ class SmartyParser extends Smarty implements ParserInterface
protected $status = 200; protected $status = 200;
/** /**
* @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* @param bool $template * @param bool $template
* @param string $env Environment define for the kernel application. Used for the cache directory * @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) public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false, $env = "prod", $debug = false)
{ {
@@ -83,107 +83,108 @@ class SmartyParser extends Smarty implements ParserInterface
return $new_source; return $new_source;
} }
public function setTemplate($template_path_from_template_base) { public function setTemplate($template_path_from_template_base)
{
$this->template = $template_path_from_template_base; $this->template = $template_path_from_template_base;
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template); $this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
} }
public function getTemplate() { public function getTemplate()
return $this->template; {
return $this->template;
} }
/** /**
* Return a rendered template file * Return a rendered template file
* *
* @param string $realTemplateName the template name (from the template directory) * @param string $realTemplateName the template name (from the template directory)
* @param array $parameters an associative array of names / value pairs * @param array $parameters an associative array of names / value pairs
* @return string the rendered template text * @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 * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
* *
*/ */
public function getContent() public function getContent()
{ {
return $this->fetch($this->getTemplateFilePath()); return $this->fetch($this->getTemplateFilePath());
} }
/** /**
* *
* set $content with the body of the response or the Response object directly * set $content with the body of the response or the Response object directly
* *
* @param string|Symfony\Component\HttpFoundation\Response $content * @param string|Symfony\Component\HttpFoundation\Response $content
*/ */
public function setContent($content) public function setContent($content)
{ {
$this->content = $content; $this->content = $content;
} }
/** /**
* *
* @return type the status of the response * @return type the status of the response
*/ */
public function getStatus() public function getStatus()
{ {
return $this->status; return $this->status;
} }
/** /**
* *
* status HTTP of the response * status HTTP of the response
* *
* @param int $status * @param int $status
*/ */
public function setStatus($status) public function setStatus($status)
{ {
$this->status = $status; $this->status = $status;
} }
public function addPlugins(SmartyPluginInterface $plugin) public function addPlugins(SmartyPluginInterface $plugin)
{ {
$this->plugins[] = $plugin; $this->plugins[] = $plugin;
} }
public function registerPlugins() public function registerPlugins()
{ {
foreach ($this->plugins as $register_plugin) { foreach ($this->plugins as $register_plugin) {
$plugins = $register_plugin->getPluginDescriptors(); $plugins = $register_plugin->getPluginDescriptors();
if(!is_array($plugins)) { if (!is_array($plugins)) {
$plugins = array($plugins); $plugins = array($plugins);
} }
foreach ($plugins as $plugin) { foreach ($plugins as $plugin) {
$this->registerPlugin( $this->registerPlugin(
$plugin->getType(), $plugin->getType(),
$plugin->getName(), $plugin->getName(),
array( array(
$plugin->getClass(), $plugin->getClass(),
$plugin->getMethod() $plugin->getMethod()
) )
); );
} }
} }
} }
protected function getTemplateFilePath() 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));
} }
} }

View File

@@ -29,8 +29,8 @@ namespace Thelia\Core\Template\Smarty;
* Class SmartyPluginDescriptor * Class SmartyPluginDescriptor
* @package Thelia\Core\Template\Smarty * @package Thelia\Core\Template\Smarty
*/ */
class SmartyPluginDescriptor { class SmartyPluginDescriptor
{
/** /**
* @var string Smarty plugin type (block, function, etc.) * @var string Smarty plugin type (block, function, etc.)
*/ */
@@ -59,35 +59,43 @@ class SmartyPluginDescriptor {
$this->method = $method; $this->method = $method;
} }
public function setType($type) { public function setType($type)
$this->type = $type; {
$this->type = $type;
} }
public function getType() { public function getType()
{
return $this->type; return $this->type;
} }
public function setName($name) { public function setName($name)
$this->name = $name; {
$this->name = $name;
} }
public function getName() { public function getName()
{
return $this->name; return $this->name;
} }
public function setClass($class) { public function setClass($class)
$this->class = $class; {
$this->class = $class;
} }
public function getClass() { public function getClass()
{
return $this->class; return $this->class;
} }
public function setMethod($method) { public function setMethod($method)
$this->method = $method; {
$this->method = $method;
} }
public function getMethod() { public function getMethod()
{
return $this->method; return $this->method;
} }
} }

View File

@@ -30,7 +30,8 @@ namespace Thelia\Core\Template\Smarty;
* Interface SmartyPluginInterface * Interface SmartyPluginInterface
* @package Thelia\Core\Template\Smarty * @package Thelia\Core\Template\Smarty
*/ */
interface SmartyPluginInterface { interface SmartyPluginInterface
{
/** /**
* @return an array of SmartyPluginDescriptor * @return an array of SmartyPluginDescriptor
*/ */

View File

@@ -35,14 +35,9 @@ namespace Thelia\Core;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface; 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\Yaml\Yaml;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Thelia\Core\Bundle; use Thelia\Core\Bundle;
use Thelia\Log\Tlog; use Thelia\Log\Tlog;
use Thelia\Config\DatabaseConfiguration; use Thelia\Config\DatabaseConfiguration;
@@ -64,7 +59,7 @@ class Thelia extends Kernel
public function init() public function init()
{ {
parent::init(); parent::init();
if($this->debug) { if ($this->debug) {
ini_set('display_errors', 1); ini_set('display_errors', 1);
} }
$this->initPropel(); $this->initPropel();
@@ -76,7 +71,7 @@ class Thelia extends Kernel
return ; return ;
} }
if(! Propel::isInit()) { if (! Propel::isInit()) {
$definePropel = new DefinePropel(new DatabaseConfiguration(), $definePropel = new DefinePropel(new DatabaseConfiguration(),
Yaml::parse(THELIA_ROOT . '/local/config/database.yml')); Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
@@ -126,8 +121,7 @@ class Thelia extends Kernel
try { try {
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config")); $loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config"));
$loader->load("config.xml"); $loader->load("config.xml");
} } catch (\InvalidArgumentException $e) {
catch(\InvalidArgumentException $e) {
// FIXME: process module configuration exception // FIXME: process module configuration exception
} }
} }
@@ -166,6 +160,7 @@ class Thelia extends Kernel
$this->loadConfiguration($container); $this->loadConfiguration($container);
$container->customCompile(); $container->customCompile();
return $container; return $container;
} }

View File

@@ -141,7 +141,6 @@ class TheliaHttpKernel extends HttpKernel
$storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config"))); $storage->setOptions(json_decode(Model\ConfigQuery::read("session_config.config")));
} }
$session = new Session\Session($storage); $session = new Session\Session($storage);
$session->start(); $session->start();

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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", array(
"constraints" => array(
new NotBlank(),
new Length(array("min" => 3))
)
))
->add("password", "password");
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return "admin_login";
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 {
/**
* @param Request $request
* @return \Symfony\Component\Form\FormFactoryInterface
*/
public static function getFormFactory(Request $request, $secret = null)
{
$validator = Validation::createValidator();
$form = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->addExtension(
new CsrfExtension(
new SessionCsrfProvider(
$request->getSession(),
$secret ?: ConfigQuery::read("form.secret", md5(__DIR__))
)
)
)
->addExtension(new ValidatorExtension($validator))
->getFormFactory();
return $form;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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", array(
"attr" => array(
"class" => "field"
),
"label" => "email"
)
)
->add('age', 'integer');
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return "customer creation";
}
}

View File

@@ -0,0 +1,14 @@
{$page_title={intl l='Thelia'}}
{include file='includes/header.inc.html'}
<div class="brandbar container">
<a class="brand" href="index.php">{images file='assets/img/logo-thelia-34px.png'}<img src="{$asset_url}" alt="{intl l='Thelia, solution e-commerce libre'}" />{/images}</a>
</div>
<div id="wrapper" class="container">
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "404 Not Found".</h2>
</div>
{include file='includes/footer.inc.html'}

View File

@@ -15,9 +15,17 @@
<div class="hero-unit"> <div class="hero-unit">
<h1>{intl l='Thelia Back Office'}</h1> <h1>{intl l='Thelia Back Office'}</h1>
<form action="/admin/login" method="post" class="well form-inline"> <form action="/admin" method="post" class="well form-inline" {form_enctype form=$form}>
<input type="text" class="input" placeholder="{intl l='E-mail address'}" name="username" /> {form_field_hidden form=$form}
<input type="password" class="input" placeholder="{intl l='Password'}" name="password" /> {form_field form=$form.username}
{form_error form=$form.username}
{$message}
{/form_error}
<input type="text" class="input" placeholder="{intl l='E-mail address'}" name="{$name}" />
{/form_field}
{form_field form=$form.password}
<input type="password" class="input" placeholder="{intl l='Password'}" name="{$name}" />
{/form_field}
<label class="checkbox"> <input type="checkbox" name="remember" value="yes"> {intl l='Remember me'}</label> <label class="checkbox"> <input type="checkbox" name="remember" value="yes"> {intl l='Remember me'}</label>

View File

@@ -7,7 +7,22 @@ An image from asset directory :
<div> <div>
{intl l='An internationalized string'} {intl l='An internationalized string'}
</div> </div>
{form name="thelia.customer.creation"}
<form method="post" action="index_dev.php" {form_enctype form=$form} >
{form_field_hidden form=$form}
{form_field form=$form.email}
{intl l="{$label}"} : <input type="text" name="{$name}" {$attr} >
{/form_field}
{form_field form=$form.name}
{intl l='name'} : <input type="text" name="{$name}" >
{/form_field}
{form_field form=$form.age}
{intl l='age'} : <input type="text" name="{$name}">
{/form_field}
</form>
{/form}
<div> <div>
jQuery data: <span id="jquery_block"></span> jQuery data: <span id="jquery_block"></span>
</div> </div>

View File

@@ -1,4 +1,4 @@
Options +FollowSymlinks Options +FollowSymlinks -Indexes
AddDefaultCharset UTF-8 AddDefaultCharset UTF-8
@@ -8,5 +8,5 @@ AddDefaultCharset UTF-8
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin(/.*)?$ index_dev.php/admin/$1 [L,QSA] RewriteRule ^(.*)$ index_dev.php [L,QSA]
</IfModule> </IfModule>