Merge branch 'master' of github.com:thelia/thelia
Conflicts: core/lib/Thelia/Config/Resources/config.xml
This commit is contained in:
@@ -56,8 +56,6 @@ class Customer implements EventSubscriberInterface
|
||||
|
||||
public function create(ActionEvent $event)
|
||||
{
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $event);
|
||||
|
||||
$request = $event->getRequest();
|
||||
|
||||
$customerCreationForm = new CustomerCreation($request);
|
||||
@@ -71,8 +69,11 @@ class Customer implements EventSubscriberInterface
|
||||
if ($form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$customer = new CustomerModel();
|
||||
|
||||
try {
|
||||
$customer->createOrUpdate(
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $event);
|
||||
|
||||
$customer->createOrUpdate(
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
@@ -120,8 +121,6 @@ class Customer implements EventSubscriberInterface
|
||||
|
||||
public function modify(ActionEvent $event)
|
||||
{
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $event);
|
||||
|
||||
$request = $event->getRequest();
|
||||
|
||||
$customerModification = new CustomerModification($request);
|
||||
@@ -137,7 +136,10 @@ class Customer implements EventSubscriberInterface
|
||||
|
||||
$customer = CustomerQuery::create()->findPk(1);
|
||||
try {
|
||||
$data = $form->getData();
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $event);
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$customer->createOrUpdate(
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
|
||||
@@ -37,6 +37,7 @@ use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -133,10 +134,21 @@ class BaseAdminController extends ContainerAware
|
||||
return $this->container->get('request');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a Thelia event to modules
|
||||
*
|
||||
* @param string $eventName a TheliaEvent name, as defined in TheliaEvents class
|
||||
* @param ActionEvent $event the event
|
||||
*/
|
||||
protected function dispatch($eventName, ActionEvent $event = null) {
|
||||
|
||||
$this->container->get("event_dispatcher")->dispatch($eventName, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session from the current request
|
||||
*
|
||||
* @return Ambigous <NULL, \Symfony\Component\HttpFoundation\Session\SessionInterface>
|
||||
* @return \Symfony\Component\HttpFoundation\Session\SessionInterface
|
||||
*/
|
||||
protected function getSession() {
|
||||
|
||||
@@ -146,8 +158,7 @@ class BaseAdminController extends ContainerAware
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a ParserInterface instance parser, as configured.
|
||||
* @return a ParserInterface instance parser
|
||||
*/
|
||||
protected function getParser()
|
||||
{
|
||||
@@ -159,16 +170,6 @@ class BaseAdminController extends ContainerAware
|
||||
return $parser;
|
||||
}
|
||||
|
||||
protected function getFormFactory()
|
||||
{
|
||||
return BaseForm::getFormFactory($this->getRequest(), ConfigQuery::read("form.secret.admin", md5(__DIR__)));
|
||||
}
|
||||
|
||||
protected function getFormBuilder()
|
||||
{
|
||||
return $this->getFormFactory()->createBuilder("form");
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards the request to another controller.
|
||||
*
|
||||
|
||||
@@ -31,6 +31,7 @@ use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Tools\Redirect;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
class SessionController extends BaseAdminController {
|
||||
|
||||
@@ -41,6 +42,8 @@ class SessionController extends BaseAdminController {
|
||||
|
||||
public function checkLogoutAction()
|
||||
{
|
||||
$this->dispatch(TheliaEvents::ADMIN_LOGOUT);
|
||||
|
||||
$this->getSecurityContext()->clear();
|
||||
|
||||
// Go back to login page.
|
||||
@@ -64,6 +67,8 @@ class SessionController extends BaseAdminController {
|
||||
// Log authentication success
|
||||
AdminLog::append("Authentication successuful", $request, $user);
|
||||
|
||||
$this->dispatch(TheliaEvents::ADMIN_LOGIN);
|
||||
|
||||
// Redirect to the success URL
|
||||
return Redirect::exec($adminLoginForm->getSuccessUrl());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
<loop class="Thelia\Core\Template\Loop\Auth" name="auth"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Customer" name="customer"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Order" name="order"/>
|
||||
<loop class="Thelia\Core\Template\Loop\OrderStatus" name="order-status"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Product" name="product"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Feed" name="feed"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Title" name="title"/>
|
||||
@@ -133,6 +135,12 @@
|
||||
<argument type="service" id="thelia.securityContext" />
|
||||
</service>
|
||||
|
||||
<service id="smarty.plugin.dataAccess" class="Thelia\Core\Template\Smarty\Plugins\DataAccessFunctions" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
<argument type="service" id="thelia.securityContext" />
|
||||
<argument type="service" id="thelia.parser.context"/>
|
||||
</service>
|
||||
|
||||
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
||||
<argument type="service" id="event_dispatcher" />
|
||||
<argument type="service" id="service_container" />
|
||||
|
||||
@@ -25,8 +25,7 @@ namespace Thelia\Core\Event;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class containing all Thelia events name using in Thelia Core
|
||||
*
|
||||
* This class contains all Thelia events identifiers used by Thelia Core
|
||||
*
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
@@ -37,25 +36,56 @@ final class TheliaEvents
|
||||
/**
|
||||
* ACTION event
|
||||
*
|
||||
* Send if no action are already present in Thelia action process ( see Thelia\Routing\Matcher\ActionMatcher)
|
||||
* Sent 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
|
||||
* Sent before starting thelia inclusion
|
||||
*/
|
||||
const INCLUSION = "thelia.include";
|
||||
|
||||
/**
|
||||
* Sent before the logout of the customer.
|
||||
*/
|
||||
const CUSTOMER_LOGOUT = "action.customer_logout";
|
||||
/**
|
||||
* Sent once the customer is successfully logged in.
|
||||
*/
|
||||
const CUSTOMER_LOGIN = "action.customer_login";
|
||||
|
||||
/**
|
||||
* Sent before the logout of the administrator.
|
||||
*/
|
||||
const ADMIN_LOGOUT = "action.admin_logout";
|
||||
/**
|
||||
* Sent once the administrator is successfully logged in.
|
||||
*/
|
||||
const ADMIN_LOGIN = "action.admin_login";
|
||||
|
||||
/**
|
||||
* Sent once the customer creation form has been successfully validated, and before customer insertion in the database.
|
||||
*/
|
||||
const BEFORE_CREATECUSTOMER = "action.before_createcustomer";
|
||||
|
||||
/**
|
||||
* Sent just after a successful insert of a new customer in the database.
|
||||
*/
|
||||
const AFTER_CREATECUSTOMER = "action.after_createcustomer";
|
||||
|
||||
/**
|
||||
* Sent once the customer change form has been successfully validated, and before customer update in the database.
|
||||
*/
|
||||
const BEFORE_CHANGECUSTOMER = "action.before_changecustomer";
|
||||
/**
|
||||
* Sent just after a successful update of a customer in the database.
|
||||
*/
|
||||
const AFTER_CHANGECUSTOMER = "action.after_changecustomer";
|
||||
|
||||
/**
|
||||
* Sent before customer insertion, to allow modules to create a custom customer reference.
|
||||
*/
|
||||
const CREATECUSTOMER_CUSTOMREF = "customer.creation.customref";
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,8 @@ class SecurityContext {
|
||||
}
|
||||
|
||||
$this->context = $context;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContext($exception_if_context_undefined = false) {
|
||||
@@ -133,7 +135,7 @@ class SecurityContext {
|
||||
// Get permissions from profile
|
||||
// $userPermissions = $user->getPermissions();
|
||||
|
||||
echo "TODO: Finalize permissions system !";
|
||||
// TODO: Finalize permissions system !;
|
||||
|
||||
$userPermissions = array('*'); // FIXME !
|
||||
|
||||
|
||||
59
core/lib/Thelia/Core/Template/Loop/Order.php
Normal file
59
core/lib/Thelia/Core/Template/Loop/Order.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Loop;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Order extends BaseLoop
|
||||
{
|
||||
public function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
// TODO : a coder !
|
||||
return new LoopResult();
|
||||
}
|
||||
}
|
||||
59
core/lib/Thelia/Core/Template/Loop/OrderStatus.php
Normal file
59
core/lib/Thelia/Core/Template/Loop/OrderStatus.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Loop;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class OrderStatus extends BaseLoop
|
||||
{
|
||||
public function getArgDefinitions()
|
||||
{
|
||||
return new ArgumentCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec(&$pagination)
|
||||
{
|
||||
// TODO : a coder !
|
||||
return new LoopResult();
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ class ParserContext implements \IteratorAggregate
|
||||
->set('BASE_URL' , ConfigQuery::read('base_url', '/'))
|
||||
->set('INDEX_PAGE' , URL::getIndexPage())
|
||||
->set('RETURN_TO_URL' , URL::absoluteUrl($request->getSession()->getReturnToUrl()))
|
||||
->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,34 @@ namespace Thelia\Core\Template\Smarty;
|
||||
|
||||
/**
|
||||
*
|
||||
* this interface must be implements when you want to add plugin to smarty using config process
|
||||
* The class all Smarty Thelia plugin shoud extend
|
||||
*
|
||||
* Interface SmartyPluginInterface
|
||||
* Class AbstractSmartyPlugin
|
||||
* @package Thelia\Core\Template\Smarty
|
||||
*/
|
||||
interface SmartyPluginInterface
|
||||
abstract class AbstractSmartyPlugin
|
||||
{
|
||||
/**
|
||||
* Explode a comma separated list in a array, trimming all array elements
|
||||
*
|
||||
* @param unknown $commaSeparatedValues
|
||||
* @return multitype:
|
||||
*/
|
||||
protected function _explode($commaSeparatedValues)
|
||||
{
|
||||
$array = explode(',', $commaSeparatedValues);
|
||||
|
||||
if (array_walk($array, function(&$item) {
|
||||
$item = strtoupper(trim($item));
|
||||
})) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of SmartyPluginDescriptor
|
||||
*/
|
||||
public function getPluginDescriptors();
|
||||
public abstract function getPluginDescriptors();
|
||||
}
|
||||
@@ -50,10 +50,7 @@ class SmartyAssetsManager
|
||||
$this->assetic_manager = new AsseticHelper();
|
||||
}
|
||||
|
||||
public function processSmartyPluginCall($assetType, $params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
// Opening tag (first call only)
|
||||
if ($repeat) {
|
||||
public function computeAssetUrl($assetType, $params, \Smarty_Internal_Template $template) {
|
||||
$file = $params['file'];
|
||||
$filters = isset($params['filters']) ? $params['filters'] : '';
|
||||
$debug = isset($params['debug']) ? trim(strtolower($params['debug'])) == 'true' : false;
|
||||
@@ -79,7 +76,17 @@ class SmartyAssetsManager
|
||||
$debug
|
||||
);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function processSmartyPluginCall($assetType, $params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
// Opening tag (first call only)
|
||||
if ($repeat) {
|
||||
$url = $this->computeAssetUrl($assetType, $params, $template);
|
||||
|
||||
$template->assign('asset_url', $url);
|
||||
|
||||
} elseif (isset($content)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
|
||||
|
||||
class Assetic implements SmartyPluginInterface
|
||||
class Assetic extends AbstractSmartyPlugin
|
||||
{
|
||||
public $asset_manager;
|
||||
public $assetManager;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -37,22 +37,27 @@ class Assetic implements SmartyPluginInterface
|
||||
|
||||
$asset_dir_from_web_root = 'assets/admin/default'; // FIXME
|
||||
|
||||
$this->asset_manager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root);
|
||||
$this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root);
|
||||
}
|
||||
|
||||
public function theliaBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
public function blockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
return $this->asset_manager->processSmartyPluginCall('js', $params, $content, $template, $repeat);
|
||||
return $this->assetManager->processSmartyPluginCall('js', $params, $content, $template, $repeat);
|
||||
}
|
||||
|
||||
public function theliaBlockImages($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
public function blockImages($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
return $this->asset_manager->processSmartyPluginCall(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $content, $template, $repeat);
|
||||
return $this->assetManager->processSmartyPluginCall(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $content, $template, $repeat);
|
||||
}
|
||||
|
||||
public function theliaBlockStylesheets($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
public function blockStylesheets($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
return $this->asset_manager->processSmartyPluginCall('css', $params, $content, $template, $repeat);
|
||||
return $this->assetManager->processSmartyPluginCall('css', $params, $content, $template, $repeat);
|
||||
}
|
||||
|
||||
public function functionImage($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
return $this->assetManager->computeAssetUrl(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $template);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,9 +68,10 @@ class Assetic implements SmartyPluginInterface
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('block', 'stylesheets', $this, 'theliaBlockStylesheets'),
|
||||
new SmartyPluginDescriptor('block', 'javascripts', $this, 'theliaBlockJavascripts'),
|
||||
new SmartyPluginDescriptor('block', 'images' , $this, 'theliaBlockImages')
|
||||
new SmartyPluginDescriptor('block' , 'stylesheets', $this, 'blockStylesheets'),
|
||||
new SmartyPluginDescriptor('block' , 'javascripts', $this, 'blockJavascripts'),
|
||||
new SmartyPluginDescriptor('block' , 'images' , $this, 'blockImages'),
|
||||
new SmartyPluginDescriptor('function', 'image' , $this, 'functionImage')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?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 Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
/**
|
||||
* Implementation of data access to main Thelia objects (users, cart, etc.)
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*
|
||||
*/
|
||||
class DataAccessFunctions extends AbstractSmartyPlugin
|
||||
{
|
||||
private $securityContext;
|
||||
protected $parserContext;
|
||||
|
||||
public function __construct(SecurityContext $securityContext, ParserContext $parserContext)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current logged administrator attributes using the accessors.
|
||||
*
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string the value of the requested attribute
|
||||
*/
|
||||
public function adminDataAccess($params, &$smarty)
|
||||
{
|
||||
return $this->userDataAccess("Admin User", SecurityContext::CONTEXT_BACK_OFFICE, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the current logged customer attributes throught the accessor
|
||||
*
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string the value of the requested attribute
|
||||
*/
|
||||
public function customerDataAccess($params, &$smarty)
|
||||
{
|
||||
return $this->userDataAccess("Customer User", SecurityContext::CONTEXT_FRONT_OFFICE, $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Provides access to user attributes using the accessors.
|
||||
*
|
||||
* @param array $params
|
||||
* @param unknown $smarty
|
||||
* @return string the value of the requested attribute
|
||||
* @throws InvalidArgumentException if the object does not have the requested attribute.
|
||||
*/
|
||||
protected function userDataAccess($objectLabel, $context, $params)
|
||||
{
|
||||
$attribute = $params['attr'];
|
||||
|
||||
if (! empty($attribute)) {
|
||||
$user = $this->securityContext->setContext($context)->getUser();
|
||||
|
||||
if (null != $user) {
|
||||
$getter = sprintf("get%s", ucfirst(strtolower($attribute)));
|
||||
|
||||
if (method_exists($user, $getter)) {
|
||||
return $user->$getter();
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf("%s has no '%s' attribute", $objectLabel, $attribute));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* Define the various smarty plugins hendled by this class
|
||||
*
|
||||
* @return an array of smarty plugin descriptors
|
||||
*/
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'admin', $this, 'adminDataAccess'),
|
||||
new SmartyPluginDescriptor('function', 'customer', $this, 'customerDataAccess')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ 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\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
|
||||
@@ -55,7 +55,7 @@ use Thelia\Core\Template\ParserContext;
|
||||
* Class Form
|
||||
* @package Thelia\Core\Template\Smarty\Plugins
|
||||
*/
|
||||
class Form implements SmartyPluginInterface
|
||||
class Form extends AbstractSmartyPlugin
|
||||
{
|
||||
|
||||
protected $request;
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
|
||||
class Module implements SmartyPluginInterface
|
||||
class Module extends AbstractSmartyPlugin
|
||||
{
|
||||
/**
|
||||
* Process theliaModule template inclusion function
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\Assets\SmartyAssetsManager;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
|
||||
class Security implements SmartyPluginInterface
|
||||
class Security extends AbstractSmartyPlugin
|
||||
{
|
||||
private $securityContext;
|
||||
|
||||
@@ -38,19 +38,6 @@ class Security implements SmartyPluginInterface
|
||||
$this->securityContext = $securityContext;
|
||||
}
|
||||
|
||||
private function _explode($commaSeparatedValues)
|
||||
{
|
||||
$array = explode(',', $commaSeparatedValues);
|
||||
|
||||
if (array_walk($array, function(&$item) {
|
||||
$item = strtoupper(trim($item));
|
||||
})) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process security check function
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
|
||||
use Thelia\Core\Template\Element\Exception\ElementNotFoundException;
|
||||
@@ -34,7 +34,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
|
||||
class TheliaLoop implements SmartyPluginInterface
|
||||
class TheliaLoop extends AbstractSmartyPlugin
|
||||
{
|
||||
protected static $pagination = null;
|
||||
|
||||
@@ -68,6 +68,23 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the count function: executes a loop and return the number of items found
|
||||
*/
|
||||
public function theliaCount($params, $template) {
|
||||
|
||||
if (empty($params['type']))
|
||||
throw new \InvalidArgumentException("Missing 'type' parameter in count arguments");
|
||||
|
||||
$loop = $this->createLoopInstance($params);
|
||||
|
||||
$dummy = null;
|
||||
|
||||
$loopResults = $loop->exec($dummy);
|
||||
|
||||
return $loopResults->valid() ? $loopResults->getCount() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block
|
||||
*
|
||||
@@ -343,10 +360,11 @@ class TheliaLoop implements SmartyPluginInterface
|
||||
{
|
||||
return array(
|
||||
|
||||
new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'),
|
||||
new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'),
|
||||
new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop'),
|
||||
new SmartyPluginDescriptor('block', 'pageloop' , $this, 'theliaPageLoop'),
|
||||
new SmartyPluginDescriptor('function', 'count' , $this, 'theliaCount'),
|
||||
new SmartyPluginDescriptor('block' , 'loop' , $this, 'theliaLoop'),
|
||||
new SmartyPluginDescriptor('block' , 'elseloop' , $this, 'theliaElseloop'),
|
||||
new SmartyPluginDescriptor('block' , 'ifloop' , $this, 'theliaIfLoop'),
|
||||
new SmartyPluginDescriptor('block' , 'pageloop' , $this, 'theliaPageLoop'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
|
||||
/**
|
||||
* Class TheliaSyntax
|
||||
@@ -31,7 +31,7 @@ use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class TheliaSyntax implements SmartyPluginInterface
|
||||
class TheliaSyntax extends AbstractSmartyPlugin
|
||||
{
|
||||
public function dieseCancel($value, $diese)
|
||||
{
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class Translation implements SmartyPluginInterface
|
||||
class Translation extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $translator;
|
||||
|
||||
@@ -44,7 +44,15 @@ class Translation implements SmartyPluginInterface
|
||||
*/
|
||||
public function translate($params, &$smarty)
|
||||
{
|
||||
return $this->translator->trans($params['l'], isset($params['p']) ? $params['p'] : array());
|
||||
// All parameters other than 'l' are supposed to be variables. Build an array of var => value pairs
|
||||
// and pass it to the translator
|
||||
$vars = array();
|
||||
|
||||
foreach($params as $name => $value) {
|
||||
$vars["%$name"] = $value;
|
||||
}
|
||||
|
||||
return $this->translator->trans($params['l'], $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Tools\URL;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
|
||||
class UrlGenerator implements SmartyPluginInterface
|
||||
class UrlGenerator extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $request;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use \Smarty;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
@@ -177,7 +177,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function addPlugins(SmartyPluginInterface $plugin)
|
||||
public function addPlugins(AbstractSmartyPlugin $plugin)
|
||||
{
|
||||
$this->plugins[] = $plugin;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class SmartyPluginDescriptor
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var SmartyPluginInterface plugin implmentation class
|
||||
* @var AbstractSmartyPlugin plugin implmentation class
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user