From a0f894d70f9fbc274f9ef9c98b04bce36eb6710f Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 5 Sep 2013 17:54:04 +0200 Subject: [PATCH 1/3] customer substitutions --- .../Template/Smarty/Plugins/DataAccessFunctions.php | 12 ++++++------ templates/default/debug.html | 13 ++----------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index ee65f34b3..a2fd10c15 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -68,14 +68,14 @@ class DataAccessFunctions extends AbstractSmartyPlugin } /** - * Provides access to user attributes using the accessors. + * @param $objectLabel + * @param $user + * @param $params * - * @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. + * @return string + * @throws \InvalidArgumentException */ - protected function userDataAccess($objectLabel, $user, $params) + protected function userDataAccess($objectLabel, $user, $params) { $attribute = $this->getNormalizedParam($params, array('attribute', 'attrib', 'attr')); diff --git a/templates/default/debug.html b/templates/default/debug.html index 461e8eed7..1c54c05a4 100755 --- a/templates/default/debug.html +++ b/templates/default/debug.html @@ -1,11 +1,2 @@ -

ALL ATTRIBUTES

- - \ No newline at end of file +::{customer attr="firstname"};; +::{customer attr="titleId"};; \ No newline at end of file From b95218295db1283b18e8d4fa82c3ad39261efaa2 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 6 Sep 2013 08:59:06 +0200 Subject: [PATCH 2/3] rewriting router --- .../Controller/Front/DefaultController.php | 20 +++++++++---------- .../Thelia/Core/Routing/RewritingRouter.php | 7 ++++--- .../Template/Smarty/Plugins/UrlGenerator.php | 2 +- .../Thelia/Rewriting/RewritingResolver.php | 2 ++ .../Thelia/Rewriting/RewritingRetriever.php | 2 ++ core/lib/Thelia/Tools/URL.php | 8 ++++---- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Controller/Front/DefaultController.php b/core/lib/Thelia/Controller/Front/DefaultController.php index 58501ebb0..fe7e1aede 100755 --- a/core/lib/Thelia/Controller/Front/DefaultController.php +++ b/core/lib/Thelia/Controller/Front/DefaultController.php @@ -46,16 +46,6 @@ class DefaultController extends BaseFrontController */ public function noAction(Request $request) { - if(ConfigQuery::isRewritingEnable()) { - - /* Does the query GET parameters match a rewritten URL ? */ - $rewrittenUrl = URL::getInstance()->retrieveCurrent($request); - if($rewrittenUrl->rewrittenUrl !== null) { - /* 301 redirection to rewritten URL */ - $this->redirect($rewrittenUrl->rewrittenUrl, 301); - } - } - $view = null; if (! $view = $request->query->get('view')) { @@ -71,5 +61,15 @@ class DefaultController extends BaseFrontController $request->attributes->set("_view", "index"); } + if(ConfigQuery::isRewritingEnable()) { + if($request->attributes->get('_rewritten', false) === false) { + /* Does the query GET parameters match a rewritten URL ? */ + $rewrittenUrl = URL::getInstance()->retrieveCurrent($request); + if($rewrittenUrl->rewrittenUrl !== null) { + /* 301 redirection to rewritten URL */ + $this->redirect($rewrittenUrl->rewrittenUrl, 301); + } + } + } } } diff --git a/core/lib/Thelia/Core/Routing/RewritingRouter.php b/core/lib/Thelia/Core/Routing/RewritingRouter.php index 570372f60..79d5dc80b 100644 --- a/core/lib/Thelia/Core/Routing/RewritingRouter.php +++ b/core/lib/Thelia/Core/Routing/RewritingRouter.php @@ -43,6 +43,7 @@ use Thelia\Tools\URL; * Class RewritingRouter * @package Thelia\Core\Routing * @author Manuel Raynaud + * @author Etienne Roudeix */ class RewritingRouter implements RouterInterface, RequestMatcherInterface { @@ -170,7 +171,6 @@ class RewritingRouter implements RouterInterface, RequestMatcherInterface if(ConfigQuery::isRewritingEnable()) { try { $rewrittenUrlData = URL::getInstance()->resolve($request->getPathInfo()); - var_dump($rewrittenUrlData); exit; } catch(UrlRewritingException $e) { switch($e->getCode()) { case UrlRewritingException::URL_NOT_FOUND : @@ -205,13 +205,14 @@ class RewritingRouter implements RouterInterface, RequestMatcherInterface return array ( '_controller' => 'Thelia\\Controller\\Front\\DefaultController::noAction', - '_route' => 'rewrite' + '_route' => 'rewrite', + '_rewritten' => true, ); } throw new ResourceNotFoundException(); } - protected function redirect($url, $code = 302) + protected function redirect($url, $status = 302) { Redirect::exec($url, $status); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index 72b3b88fb..f6c20ecfb 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -169,7 +169,7 @@ class UrlGenerator extends AbstractSmartyPlugin protected function getCurrentUrl() { - return URL::getInstance()->retrieveCurrent()->toString(); + return URL::getInstance()->retrieveCurrent($this->request)->toString(); } protected function getReturnToUrl() diff --git a/core/lib/Thelia/Rewriting/RewritingResolver.php b/core/lib/Thelia/Rewriting/RewritingResolver.php index 900442db9..4c8bcba40 100755 --- a/core/lib/Thelia/Rewriting/RewritingResolver.php +++ b/core/lib/Thelia/Rewriting/RewritingResolver.php @@ -58,6 +58,8 @@ class RewritingResolver public function load($rewrittenUrl) { + $rewrittenUrl = ltrim($rewrittenUrl, '/'); + $this->search = $this->rewritingUrlQuery->getResolverSearch($rewrittenUrl); if($this->search->count() == 0) { diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index dfbe63517..8289942f2 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -66,6 +66,7 @@ class RewritingRetriever $allParametersWithoutView[$view . '_id'] = $viewId; } + $this->rewrittenUrl = null; $this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView); if($this->search !== null) { $this->rewrittenUrl = $this->search->getUrl(); @@ -93,6 +94,7 @@ class RewritingRetriever $allParametersWithoutView[$view . '_id'] = $viewId; } + $this->rewrittenUrl = null; $this->url = URL::getInstance()->viewUrl($view, $allParametersWithoutView); if($this->search !== null) { $this->rewrittenUrl = $this->search->getUrl(); diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 152f82895..161175bbf 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -204,20 +204,20 @@ class URL public function retrieveCurrent(Request $request) { if(ConfigQuery::isRewritingEnable()) { - $view = $request->query->get('view', null); + $view = $request->attributes->get('_view', null); $viewLocale = $request->query->get('locale', null); $viewId = $view === null ? null : $request->query->get($view . '_id', null); $allOtherParameters = $request->query->all(); if($view !== null) { unset($allOtherParameters['view']); + if($viewId !== null) { + unset($allOtherParameters[$view . '_id']); + } } if($viewLocale !== null) { unset($allOtherParameters['locale']); } - if($viewId !== null) { - unset($allOtherParameters[$view . '_id']); - } $this->retriever->loadSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); } From 9655ce3c72704fc5ccd48104f3f2e6121d57265f Mon Sep 17 00:00:00 2001 From: franck Date: Fri, 6 Sep 2013 09:56:39 +0200 Subject: [PATCH 3/3] Added a 'development mode' to assetic smarty plugin --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Core/Template/Assets/AsseticHelper.php | 18 +++++++++--------- .../Smarty/Assets/SmartyAssetsManager.php | 13 +++++++++---- .../Core/Template/Smarty/Plugins/Assetic.php | 4 ++-- templates/admin/default/assets/less/main.less | 4 +--- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 96e5941cd..198c49228 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -129,6 +129,7 @@ + %kernel.environment% diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php index fbb93440a..cd7f06ac8 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticHelper.php @@ -43,15 +43,16 @@ class AsseticHelper * Generates assets from $asset_path in $output_path, using $filters. * * @param string $asset_path the full path to the asset file (or file collection) - * @param unknown $output_path the full disk path to the output directory (shoud be visible to web server) - * @param unknown $output_url the URL to the generated asset directory - * @param unknown $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension. - * @param unknown $filters a list of filters, as defined below (see switch($filter_name) ...) - * @param unknown $debug true / false + * @param string $output_path the full disk path to the output directory (shoud be visible to web server) + * @param string $output_url the URL to the generated asset directory + * @param string $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 array $filters a list of filters, as defined below (see switch($filter_name) ...) + * @param boolean $debug true / false + * @param boolean $dev_mode true / false. If true, assets are not cached and always compiled. * @throws \InvalidArgumentException if an invalid filter name is found * @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, $dev_mode = false) { $asset_name = basename($asset_path); $asset_dir = dirname($asset_path); @@ -112,6 +113,7 @@ class AsseticHelper $asset = $factory->createAsset($asset_name); $asset_target_path = $asset->getTargetPath(); + $target_file = sprintf("%s/%s", $output_path, $asset_target_path); // As it seems that assetic cannot handle a real file cache, let's do the job ourselves. @@ -124,7 +126,7 @@ class AsseticHelper // // before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files. // - if (! file_exists($target_file)) { + if ($dev_mode == true || ! file_exists($target_file)) { // Delete previous version of the file list($commonPart, $dummy) = explode('-', $asset_target_path); @@ -143,8 +145,6 @@ class AsseticHelper } } - //$cache = new AssetCache($asset, new FilesystemCache($output_path)); - $writer = new AssetWriter($output_path); $writer->writeAsset($asset); diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 17fe122d3..f19eded95 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -34,18 +34,22 @@ class SmartyAssetsManager private $web_root; private $path_relative_to_web_root; + private $developmentMode; /** * Creates a new SmartyAssetsManager instance * - * @param string $web_root the disk path to the web root - * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated + * @param string $web_root the disk path to the web root + * @param string $path_relative_to_web_root the path (relative to web root) where the assets will be generated + * @param boolean $developmentMode true / false. If true, assets are not cached, and always generated. */ - public function __construct($web_root, $path_relative_to_web_root) + public function __construct($web_root, $path_relative_to_web_root, $developmentMode) { $this->web_root = $web_root; $this->path_relative_to_web_root = $path_relative_to_web_root; + $this->developmentMode = $developmentMode; + $this->assetic_manager = new AsseticHelper(); } @@ -73,7 +77,8 @@ class SmartyAssetsManager URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */), $assetType, $filters, - $debug + $debug, + $this->developmentMode ); return $url; diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php index f8ea1c2ef..b7bb95b83 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Assetic.php @@ -32,13 +32,13 @@ class Assetic extends AbstractSmartyPlugin { public $assetManager; - public function __construct() + public function __construct($developmentMode) { $web_root = THELIA_WEB_DIR; $asset_dir_from_web_root = ConfigQuery::read('asset_dir_from_web_root', 'assets'); - $this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root); + $this->assetManager = new SmartyAssetsManager($web_root, $asset_dir_from_web_root, $developmentMode == 'dev'); } public function blockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat) diff --git a/templates/admin/default/assets/less/main.less b/templates/admin/default/assets/less/main.less index 862810f6d..7ad14e013 100644 --- a/templates/admin/default/assets/less/main.less +++ b/templates/admin/default/assets/less/main.less @@ -3,6 +3,4 @@ /* Thelia Admin */ @import "thelia/thelia.less"; -// @import "thelia/responsive.less"; - -//mmm \ No newline at end of file +// @import "thelia/responsive.less"; \ No newline at end of file