From 696b871acddc7bc2f979f5ba1c4b6b42b4e8da3e Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 29 Aug 2013 08:49:48 +0200 Subject: [PATCH 1/7] start rewriting --- .../Thelia/Core/Template/Element/BaseLoop.php | 6 +- .../Thelia/Core/Template/Loop/Attribute.php | 2 +- .../Template/Loop/AttributeAvailability.php | 2 +- .../Template/Loop/AttributeCombination.php | 4 +- .../Thelia/Core/Template/Loop/Category.php | 4 +- .../lib/Thelia/Core/Template/Loop/Content.php | 4 +- .../lib/Thelia/Core/Template/Loop/Country.php | 2 +- .../Thelia/Core/Template/Loop/Currency.php | 2 +- .../lib/Thelia/Core/Template/Loop/Feature.php | 2 +- .../Template/Loop/FeatureAvailability.php | 2 +- .../Core/Template/Loop/FeatureValue.php | 2 +- core/lib/Thelia/Core/Template/Loop/Folder.php | 4 +- core/lib/Thelia/Core/Template/Loop/Image.php | 2 +- .../lib/Thelia/Core/Template/Loop/Product.php | 4 +- core/lib/Thelia/Core/Template/Loop/Title.php | 2 +- core/lib/Thelia/Model/Category.php | 4 +- core/lib/Thelia/Model/ConfigQuery.php | 10 ++++ core/lib/Thelia/Model/Content.php | 5 +- core/lib/Thelia/Model/Folder.php | 5 +- core/lib/Thelia/Model/Product.php | 6 +- .../Thelia/Model/Tools/ModelCriteriaTools.php | 8 ++- .../Thelia/Rewriting/RewritingResolver.php | 35 ++++++++++++ .../Thelia/Rewriting/RewritingRetriever.php | 56 +++++++++++++++++++ core/lib/Thelia/Tools/URL.php | 12 ++++ install/insert.sql | 2 + local/config/schema.xml | 25 ++++++--- templates/default/category.html | 4 +- 27 files changed, 173 insertions(+), 43 deletions(-) create mode 100755 core/lib/Thelia/Rewriting/RewritingResolver.php create mode 100755 core/lib/Thelia/Rewriting/RewritingRetriever.php diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 72f782309..9dcff5ab9 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -218,10 +218,10 @@ abstract class BaseLoop } /** - * @param \ModelCriteria $search - * @param $pagination + * @param ModelCriteria $search + * @param $pagination * - * @return array|\PropelModelPager + * @return array|\Propel\Runtime\Util\PropelModelPager */ protected function searchWithPagination(ModelCriteria $search, &$pagination) { diff --git a/core/lib/Thelia/Core/Template/Loop/Attribute.php b/core/lib/Thelia/Core/Template/Loop/Attribute.php index 41721350b..94afc96c7 100755 --- a/core/lib/Thelia/Core/Template/Loop/Attribute.php +++ b/core/lib/Thelia/Core/Template/Loop/Attribute.php @@ -92,7 +92,7 @@ class Attribute extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php index be42f5dab..771058ad1 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeAvailability.php @@ -84,7 +84,7 @@ class AttributeAvailability extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php b/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php index 833f1abb3..97c355763 100755 --- a/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php +++ b/core/lib/Thelia/Core/Template/Loop/AttributeCombination.php @@ -81,7 +81,7 @@ class AttributeCombination extends BaseLoop /* manage attribute translations */ ModelCriteriaTools::getFrontEndI18n( $search, - ConfigQuery::read("default_lang_without_translation", 1), + ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), AttributeTableMap::TABLE_NAME, @@ -91,7 +91,7 @@ class AttributeCombination extends BaseLoop /* manage attributeAv translations */ ModelCriteriaTools::getFrontEndI18n( $search, - ConfigQuery::read("default_lang_without_translation", 1), + ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), AttributeAvTableMap::TABLE_NAME, diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 9b497bb1a..1e959777c 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -103,7 +103,7 @@ class Category extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + $locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); @@ -185,7 +185,7 @@ class Category extends BaseLoop ->set("DESCRIPTION", $category->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $category->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("PARENT", $category->getParent()) - ->set("URL", $category->getUrl()) + ->set("URL", $category->getUrl($locale)) ->set("PRODUCT_COUNT", $category->countChild()) ->set("VISIBLE", $category->getVisible() ? "1" : "0") ->set("POSITION", $category->getPosition()) diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 6632a184c..b5a15f82d 100755 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -93,7 +93,7 @@ class Content extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + $locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); @@ -226,7 +226,7 @@ class Content extends BaseLoop ->set("DESCRIPTION", $content->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $content->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("POSITION", $content->getPosition()) - ->set("URL", $content->getUrl()) + ->set("URL", $content->getUrl($locale)) ; $loopResult->addRow($loopResultRow); diff --git a/core/lib/Thelia/Core/Template/Loop/Country.php b/core/lib/Thelia/Core/Template/Loop/Country.php index c6f7d16de..5064c20b5 100755 --- a/core/lib/Thelia/Core/Template/Loop/Country.php +++ b/core/lib/Thelia/Core/Template/Loop/Country.php @@ -75,7 +75,7 @@ class Country extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/Currency.php b/core/lib/Thelia/Core/Template/Loop/Currency.php index d833ff8ae..50b606220 100755 --- a/core/lib/Thelia/Core/Template/Loop/Currency.php +++ b/core/lib/Thelia/Core/Template/Loop/Currency.php @@ -74,7 +74,7 @@ class Currency extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('NAME')); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('NAME')); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/Feature.php b/core/lib/Thelia/Core/Template/Loop/Feature.php index 85d037080..fdce096c0 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feature.php +++ b/core/lib/Thelia/Core/Template/Loop/Feature.php @@ -89,7 +89,7 @@ class Feature extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php b/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php index ce6f8767a..41645aff7 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureAvailability.php @@ -82,7 +82,7 @@ class FeatureAvailability extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index 8a29d7c74..2a8cac955 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -86,7 +86,7 @@ class FeatureValue extends BaseLoop /* manage featureAv translations */ ModelCriteriaTools::getFrontEndI18n( $search, - ConfigQuery::read("default_lang_without_translation", 1), + ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), FeatureAvTableMap::TABLE_NAME, diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php index c95b0dc42..4db07cc8f 100755 --- a/core/lib/Thelia/Core/Template/Loop/Folder.php +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -85,7 +85,7 @@ class Folder extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + $locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $id = $this->getId(); @@ -168,7 +168,7 @@ class Folder extends BaseLoop ->set("DESCRIPTION", $folder->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $folder->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("PARENT", $folder->getParent()) - ->set("URL", $folder->getUrl()) + ->set("URL", $folder->getUrl($locale)) ->set("CONTENT_COUNT", $folder->countChild()) ->set("VISIBLE", $folder->getVisible() ? "1" : "0") ->set("POSITION", $folder->getPosition()) diff --git a/core/lib/Thelia/Core/Template/Loop/Image.php b/core/lib/Thelia/Core/Template/Loop/Image.php index a1e866cb2..80aa2fb9a 100755 --- a/core/lib/Thelia/Core/Template/Loop/Image.php +++ b/core/lib/Thelia/Core/Template/Loop/Image.php @@ -215,7 +215,7 @@ class Image extends BaseLoop $search->joinWithI18n( $this->request->getSession()->getLocale(), - (ConfigQuery::read("default_lang_without_translation", 1)) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN + (ConfigQuery::getDefaultLangWhenNoTranslationAvailable()) ? Criteria::LEFT_JOIN : Criteria::INNER_JOIN ); $results = $this->search($search, $pagination); diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 10112ef28..7c00c6775 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -143,7 +143,7 @@ class Product extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale()); + $locale = ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale()); $attributeNonStrictMatch = $this->getAttribute_non_strict_match(); $isPSELeftJoinList = array(); @@ -520,7 +520,7 @@ class Product extends BaseLoop ->set("CHAPO", $product->getVirtualColumn('i18n_CHAPO')) ->set("DESCRIPTION", $product->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM", $product->getVirtualColumn('i18n_POSTSCRIPTUM')) - ->set("URL", $product->getUrl()) + ->set("URL", $product->getUrl($locale)) ->set("BEST_PRICE", $product->getVirtualColumn('real_lowest_price')) ->set("IS_PROMO", $product->getVirtualColumn('main_product_is_promo')) ->set("IS_NEW", $product->getVirtualColumn('main_product_is_new')) diff --git a/core/lib/Thelia/Core/Template/Loop/Title.php b/core/lib/Thelia/Core/Template/Loop/Title.php index caa5e7d87..92451e764 100755 --- a/core/lib/Thelia/Core/Template/Loop/Title.php +++ b/core/lib/Thelia/Core/Template/Loop/Title.php @@ -72,7 +72,7 @@ class Title extends BaseLoop $lang = $this->getLang(); /* manage translations */ - ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::read("default_lang_without_translation", 1), $this->request->getSession()->getLocale(), array('SHORT', 'LONG')); + ModelCriteriaTools::getI18n($backendContext, $lang, $search, ConfigQuery::getDefaultLangWhenNoTranslationAvailable(), $this->request->getSession()->getLocale(), array('SHORT', 'LONG')); $id = $this->getId(); diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 88e7cfc10..5f93f247c 100755 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -4,6 +4,7 @@ namespace Thelia\Model; use Thelia\Model\Base\Category as BaseCategory; use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Tools\URL; class Category extends BaseCategory { @@ -15,8 +16,9 @@ class Category extends BaseCategory return CategoryQuery::countChild($this->getId()); } - public function getUrl() + public function getUrl($locale) { + return URL::retrieve('category', $this->getId(), $locale); } /** diff --git a/core/lib/Thelia/Model/ConfigQuery.php b/core/lib/Thelia/Model/ConfigQuery.php index b00ef7d8c..4165f4f7c 100755 --- a/core/lib/Thelia/Model/ConfigQuery.php +++ b/core/lib/Thelia/Model/ConfigQuery.php @@ -22,4 +22,14 @@ class ConfigQuery extends BaseConfigQuery { return $value ? $value->getValue() : $default; } + + public static function getDefaultLangWhenNoTranslationAvailable() + { + return ConfigQuery::read("default_lang_without_translation", 1); + } + + public static function isRewritingEnable() + { + return self::read("rewriting_enable") == 1; + } } // ConfigQuery diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 3b5af9ede..1a797be89 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -3,11 +3,12 @@ namespace Thelia\Model; use Thelia\Model\Base\Content as BaseContent; +use Thelia\Tools\URL; class Content extends BaseContent { - public function getUrl() + public function getUrl($locale) { - + return URL::retrieve('content', $this->getId(), $locale); } } diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index 1179f6e72..05838e939 100755 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -3,6 +3,7 @@ namespace Thelia\Model; use Thelia\Model\Base\Folder as BaseFolder; +use Thelia\Tools\URL; class Folder extends BaseFolder { @@ -14,9 +15,9 @@ class Folder extends BaseFolder return FolderQuery::countChild($this->getId()); } - public function getUrl() + public function getUrl($locale) { - + return URL::retrieve('folder', $this->getId(), $locale); } /** diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index ae693e0aa..e7d0586cc 100755 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -3,12 +3,12 @@ namespace Thelia\Model; use Thelia\Model\Base\Product as BaseProduct; -use Thelia\Model\ProductSaleElements; +use Thelia\Tools\URL; class Product extends BaseProduct { - public function getUrl() + public function getUrl($locale) { - + return URL::retrieve('product', $this->getId(), $locale); } } diff --git a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php index e9323ebfa..47c18a162 100755 --- a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php +++ b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php @@ -109,10 +109,14 @@ class ModelCriteriaTools } } + $askedLocale = $lang === null ? $currentLocale : $localeSearch->getLocale(); + if($backendContext) { - self::getBackEndI18n($search, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey); + self::getBackEndI18n($search, $askedLocale, $columns, $foreignTable, $foreignKey); } else { - self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $lang === null ? $currentLocale : $localeSearch->getLocale(), $columns, $foreignTable, $foreignKey); + self::getFrontEndI18n($search, $defaultLangWithoutTranslation, $askedLocale, $columns, $foreignTable, $foreignKey); } + + return $askedLocale; } } diff --git a/core/lib/Thelia/Rewriting/RewritingResolver.php b/core/lib/Thelia/Rewriting/RewritingResolver.php new file mode 100755 index 000000000..818dbec32 --- /dev/null +++ b/core/lib/Thelia/Rewriting/RewritingResolver.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Rewriting; + +/** + * Class RewritingResolver + * @package Thelia\Rewriting + * @author Etienne Roudeix + * + * This class provides methods to resolve rewritten URL as a query + */ +class RewritingResolver +{ + +} diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php new file mode 100755 index 000000000..5c49c4e2e --- /dev/null +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -0,0 +1,56 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Rewriting; + +use Propel\Runtime\ActiveQuery\Criteria; +use Thelia\Model\Base\RewritingUrlQuery; + +/** + * Class RewritingRetriever + * @package Thelia\Rewriting + * @author Etienne Roudeix + * + * This class provides methods to retrieve a rewritten URL from a query + */ +class RewritingRetriever +{ + public function getViewUrl($view, $viewId, $viewLocale) + { + $url = RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->where('ISNULL(`ra`.REWRITING_URL_ID)') + ->filterByView($view) + ->filterByViewId($viewId) + ->filterByViewLocale($viewLocale) + ->filterByRedirected(null) + ->orderByUpdatedAt(Criteria::DESC) + ->findOne(); + + return $url === null ? null : $url->getUrl(); + } + + /*public function getSpecificUrl($view, $viewId, $viewLocale, $viewOtherParameters = array()) + { + + }*/ +} diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 5a88fa922..01958bc1c 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -24,6 +24,7 @@ namespace Thelia\Tools; use Thelia\Model\ConfigQuery; +use Thelia\Rewriting\RewritingRetriever; class URL { @@ -101,4 +102,15 @@ class URL return self::absoluteUrl($path, $parameters); } + + public static function retrieve($view, $viewId, $viewLocale) + { + $rewrittenUrl = null; + if(ConfigQuery::isRewritingEnable()) { + $retriever = new RewritingRetriever(); + $rewrittenUrl = $retriever->getViewUrl($view, $viewId, $viewLocale); + } + + return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; + } } diff --git a/install/insert.sql b/install/insert.sql index cbb6725f3..4336eaa0c 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -7,6 +7,8 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`created_at`, INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES ('session_config.default', '1', 1, 1, NOW(), NOW()), ('verifyStock', '1', 1, 0, NOW(), NOW()), +('default_lang_without_translation', '1', 1, 0, NOW(), NOW()), +('rewriting_enable', '0', 1, 0, NOW(), NOW()), ('imagine_graphic_driver', 'gd', 1, 0, NOW(), NOW()), ('default_images_quality_percent', '75', 1, 0, NOW(), NOW()), ('original_image_delivery_mode', 'symlink', 1, 0, NOW(), NOW()), diff --git a/local/config/schema.xml b/local/config/schema.xml index 0e20f2562..dbd57314b 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1095,24 +1095,19 @@ - - - - - - + - - - + + +
@@ -1126,4 +1121,16 @@
+ + + + + + + + + + + +
diff --git a/templates/default/category.html b/templates/default/category.html index af4cdcf14..440866a26 100755 --- a/templates/default/category.html +++ b/templates/default/category.html @@ -22,7 +22,7 @@ {loop name="product" type="product" category="#ID"}
-

PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

#TITLE

#DESCRIPTION

@@ -111,7 +111,7 @@ {loop name="product" type="product" category="#ID"}
-

PRODUCT : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

#TITLE

#DESCRIPTION

From 75b456429763840ccf85a44d45e6e2a7c4187600 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 29 Aug 2013 09:20:58 +0200 Subject: [PATCH 2/7] rewriting tables --- local/config/schema.xml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/local/config/schema.xml b/local/config/schema.xml index dbd57314b..0e20f2562 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1095,19 +1095,24 @@ + - + + + + + + + + - - -
@@ -1121,16 +1126,4 @@
- - - - - - - - - - - -
From 4ba16dc2909586e03588cbd2085b5b5620e9afa0 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 30 Aug 2013 09:13:54 +0200 Subject: [PATCH 3/7] sid : rewriting --- .../Thelia/Rewriting/RewritingRetriever.php | 57 +++++++++++++++++-- .../Rewriting/RewritingRetrieverTest.php | 44 ++++++++++++++ core/lib/Thelia/Tests/Tools/URLTest.php | 39 +++++++++++++ core/lib/Thelia/Tools/URL.php | 34 +++++++++++ web/index_dev.php | 2 + 5 files changed, 170 insertions(+), 6 deletions(-) create mode 100755 core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php create mode 100755 core/lib/Thelia/Tests/Tools/URLTest.php diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 5c49c4e2e..546b9d077 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -24,6 +24,7 @@ namespace Thelia\Rewriting; use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\RewritingUrlQuery; +use Thelia\Model\Map\RewritingUrlTableMap; /** * Class RewritingRetriever @@ -36,7 +37,14 @@ class RewritingRetriever { public function getViewUrl($view, $viewId, $viewLocale) { - $url = RewritingUrlQuery::create() + $url = $this->getViewUrlQuery($view, $viewId, $viewLocale); + + return $url === null ? null : $url->getUrl(); + } + + protected function getViewUrlQuery($view, $viewId, $viewLocale) + { + return RewritingUrlQuery::create() ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) ->where('ISNULL(`ra`.REWRITING_URL_ID)') ->filterByView($view) @@ -45,12 +53,49 @@ class RewritingRetriever ->filterByRedirected(null) ->orderByUpdatedAt(Criteria::DESC) ->findOne(); + } + + public function getSpecificUrl($view = null, $viewId = null, $viewLocale = null, $viewOtherParameters = array()) + { + $urlQuery = RewritingUrlQuery::create() + ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) + ->withColumn('`ra`.PARAMETER', 'ra_parameter') + ->withColumn('`ra`.VALUE', 'ra_value') + ->filterByView($view) + ->filterByViewId($viewId) + ->filterByViewLocale($viewLocale) + ->filterByRedirected(null) + ->orderByUpdatedAt(Criteria::DESC); + + $otherParametersCount = count($viewOtherParameters); + if($otherParametersCount > 0) { + $parameterConditions = array(); + foreach($viewOtherParameters as $parameter => $value) { + $conditionName = 'other_parameter_condition_' . count($parameterConditions); + $urlQuery->condition('parameter_condition', '`ra_parameter`= ?', $parameter, \PDO::PARAM_STR) + ->condition('value_condition', '`ra_value` = ?', $value, \PDO::PARAM_STR) + ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); + $parameterConditions[] = $conditionName; + } + + $urlQuery->combine($parameterConditions, Criteria::LOGICAL_OR, 'parameter_full_condition'); + + $urlQuery->groupBy(RewritingUrlTableMap::ID); + + $urlQuery->condition('count_condition', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) + ->combine(array('count_condition', 'parameter_full_condition'), Criteria::LOGICAL_AND, 'full_having_condition'); + + + $urlQuery + ->having(array('full_having_condition')) + //->having('COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) + ; + } else { + $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); + } + + $url = $urlQuery->findOne(); return $url === null ? null : $url->getUrl(); } - - /*public function getSpecificUrl($view, $viewId, $viewLocale, $viewOtherParameters = array()) - { - - }*/ } diff --git a/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php new file mode 100755 index 000000000..741c22b4e --- /dev/null +++ b/core/lib/Thelia/Tests/Rewriting/RewritingRetrieverTest.php @@ -0,0 +1,44 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Rewriting; + +use Thelia\Rewriting\RewritingRetriever; + +/** + * + * @author Etienne Roudeix + * + */ +class RewritingRetrieverTest extends \PHPUnit_Framework_TestCase +{ + public function testGetViewUrl() + { + + } + + public function testGetSpecificUrl() + { + + } +} diff --git a/core/lib/Thelia/Tests/Tools/URLTest.php b/core/lib/Thelia/Tests/Tools/URLTest.php new file mode 100755 index 000000000..0c99651b4 --- /dev/null +++ b/core/lib/Thelia/Tests/Tools/URLTest.php @@ -0,0 +1,39 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Type; + +use Thelia\Tools\URL; + +/** + * + * @author Etienne Roudeix + * + */ +class URLTest extends \PHPUnit_Framework_TestCase +{ + public function testRetrieve() + { + + } +} diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 01958bc1c..267e5554c 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -23,6 +23,7 @@ namespace Thelia\Tools; +use Symfony\Component\HttpFoundation\Request; use Thelia\Model\ConfigQuery; use Thelia\Rewriting\RewritingRetriever; @@ -103,6 +104,13 @@ class URL return self::absoluteUrl($path, $parameters); } + /** + * @param $view + * @param $viewId + * @param $viewLocale + * + * @return null|string + */ public static function retrieve($view, $viewId, $viewLocale) { $rewrittenUrl = null; @@ -113,4 +121,30 @@ class URL return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; } + + public static function retrieveCurrent(Request $request) + { + $rewrittenUrl = null; + if(ConfigQuery::isRewritingEnable()) { + $view = $request->query->get('view', null); + $viewId = $view === null ? null : $request->query->get($view . '_id', null); + $viewLocale = $request->query->get('locale', null); + + $allOtherParameters = $request->query->all(); + if($view !== null) { + unset($allOtherParameters['view']); + } + if($viewId !== null) { + unset($allOtherParameters[$view . '_id']); + } + if($viewLocale !== null) { + unset($allOtherParameters['locale']); + } + + $retriever = new RewritingRetriever(); + $rewrittenUrl = $retriever->getSpecificUrl($view, $viewId, $viewLocale, $allOtherParameters); + } + + return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; + } } diff --git a/web/index_dev.php b/web/index_dev.php index 8991dc4a8..b5a98978a 100755 --- a/web/index_dev.php +++ b/web/index_dev.php @@ -21,6 +21,8 @@ if ( false === in_array($request->getClientIp(), $trustIp)) { $thelia = new Thelia("dev", true); +\Thelia\Tools\URL::retrieveCurrent($request); + $response = $thelia->handle($request)->prepare($request)->send(); $thelia->terminate($request, $response); From 3c71aa613f9a10347dfa003699ea476b0eb67ee5 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 30 Aug 2013 14:30:33 +0200 Subject: [PATCH 4/7] url global substitution --- .../Core/Template/Loop/FeatureValue.php | 3 +- .../Thelia/Core/Template/ParserContext.php | 6 +- .../Template/Smarty/Plugins/UrlGenerator.php | 65 ++++++++- .../Thelia/Model/Map/RewritingUrlTableMap.php | 4 +- .../Thelia/Model/Tools/ModelCriteriaTools.php | 14 +- .../Thelia/Rewriting/RewritingRetriever.php | 13 +- core/lib/Thelia/Tools/URL.php | 26 ++-- install/thelia.sql | 4 +- local/config/schema.xml | 4 +- .../admin/default/includes/header.inc.html | 2 +- templates/default/cart.html | 2 +- templates/default/category.html | 137 +++--------------- templates/default/connexion.html | 4 +- templates/default/login.html | 6 +- web/index_dev.php | 2 - 15 files changed, 126 insertions(+), 166 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index 2a8cac955..62f9ceb47 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -90,7 +90,8 @@ class FeatureValue extends BaseLoop $this->request->getSession()->getLocale(), array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), FeatureAvTableMap::TABLE_NAME, - 'FEATURE_AV_ID' + 'FEATURE_AV_ID', + true ); $feature = $this->getFeature(); diff --git a/core/lib/Thelia/Core/Template/ParserContext.php b/core/lib/Thelia/Core/Template/ParserContext.php index 03c3cf45f..af12018e6 100755 --- a/core/lib/Thelia/Core/Template/ParserContext.php +++ b/core/lib/Thelia/Core/Template/ParserContext.php @@ -40,11 +40,7 @@ class ParserContext implements \IteratorAggregate public function __construct(Request $request) { // Setup basic variables - $this - ->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')) + $this->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined')) ; } diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php index b3814f088..33e699c43 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/UrlGenerator.php @@ -47,14 +47,15 @@ class UrlGenerator extends AbstractSmartyPlugin public function generateUrlFunction($params, &$smarty) { // the path to process - $path = $this->getParam($params, 'path'); + $path = $this->getParam($params, 'path'); - $target = $this->getParam($params, 'target', null); + $target = $this->getParam($params, 'target', null); - $url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target'))); + $url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target'))); - if ($target != null) $url .= '#'.$target; - return $url; + if ($target != null) $url .= '#'.$target; + + return $url; } /** @@ -81,6 +82,15 @@ class UrlGenerator extends AbstractSmartyPlugin return $this->generateViewUrlFunction($params, true); } + public function navigateToUrlFunction($params, &$smarty) + { + $to = $this->getParam($params, 'to', null); + + $toMethod = $this->getNavigateToMethod($to); + + return $this->$toMethod(); + } + protected function generateViewUrlFunction($params, $forAdmin) { // the view name (without .html) @@ -125,7 +135,50 @@ class UrlGenerator extends AbstractSmartyPlugin return array( new SmartyPluginDescriptor('function', 'url', $this, 'generateUrlFunction'), new SmartyPluginDescriptor('function', 'viewurl', $this, 'generateFrontViewUrlFunction'), - new SmartyPluginDescriptor('function', 'admin_viewurl', $this, 'generateAdminViewUrlFunction') + new SmartyPluginDescriptor('function', 'admin_viewurl', $this, 'generateAdminViewUrlFunction'), + new SmartyPluginDescriptor('function', 'navigate', $this, 'navigateToUrlFunction'), ); } + + /** + * @return array sur le format "to_value" => "method_name" + */ + protected function getNavigateToValues() + { + return array( + "current" => "getCurrentUrl", + "return_to" => "getReturnToUrl", + "index" => "getIndexUrl", + ); + } + + protected function getNavigateToMethod($to) + { + if($to === null) { + throw new \InvalidArgumentException("Missing 'to' parameter in `navigate` substitution."); + } + + $navigateToValues = $this->getNavigateToValues(); + + if(!array_key_exists($to, $navigateToValues)) { + throw new \InvalidArgumentException("Incorrect value for parameter `to` in `navigate` substitution."); + } + + return $navigateToValues[$to]; + } + + protected function getCurrentUrl() + { + return URL::retrieveCurrent($this->request); + } + + protected function getReturnToUrl() + { + return URL::absoluteUrl($this->request->getSession()->getReturnToUrl()); + } + + protected function getIndexUrl() + { + return Url::getIndexPage(); + } } diff --git a/core/lib/Thelia/Model/Map/RewritingUrlTableMap.php b/core/lib/Thelia/Model/Map/RewritingUrlTableMap.php index c6d5e5473..1d6129ed8 100644 --- a/core/lib/Thelia/Model/Map/RewritingUrlTableMap.php +++ b/core/lib/Thelia/Model/Map/RewritingUrlTableMap.php @@ -162,9 +162,9 @@ class RewritingUrlTableMap extends TableMap // columns $this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null); $this->addColumn('URL', 'Url', 'VARCHAR', true, 255, null); - $this->addColumn('VIEW', 'View', 'VARCHAR', false, 255, null); + $this->addColumn('VIEW', 'View', 'VARCHAR', true, 255, null); $this->addColumn('VIEW_ID', 'ViewId', 'VARCHAR', false, 255, null); - $this->addColumn('VIEW_LOCALE', 'ViewLocale', 'VARCHAR', false, 255, null); + $this->addColumn('VIEW_LOCALE', 'ViewLocale', 'VARCHAR', true, 255, null); $this->addForeignKey('REDIRECTED', 'Redirected', 'INTEGER', 'rewriting_url', 'ID', false, null, null); $this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null); $this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null); diff --git a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php index 47c18a162..209006988 100755 --- a/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php +++ b/core/lib/Thelia/Model/Tools/ModelCriteriaTools.php @@ -23,7 +23,7 @@ class ModelCriteriaTools * @param null $foreignTable * @param string $foreignKey */ - public static function getFrontEndI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID') + public static function getFrontEndI18n(ModelCriteria &$search, $defaultLangWithoutTranslation, $askedLocale, $columns = array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'), $foreignTable = null, $foreignKey = 'ID', $forceReturn = false) { if($foreignTable === null) { $foreignTable = $search->getTableMap()->getName(); @@ -32,13 +32,13 @@ class ModelCriteriaTools $aliasPrefix = $foreignTable . '_'; } - $askedLocaleI18nAlias = 'asked_locale_i18n'; - $defaultLocaleI18nAlias = 'default_locale_i18n'; + $askedLocaleI18nAlias = $aliasPrefix . 'asked_locale_i18n'; + $defaultLocaleI18nAlias = $aliasPrefix . 'default_locale_i18n'; if($defaultLangWithoutTranslation == 0) { $askedLocaleJoin = new Join(); $askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias); - $askedLocaleJoin->setJoinType(Criteria::INNER_JOIN); + $askedLocaleJoin->setJoinType($forceReturn === false ? Criteria::INNER_JOIN : Criteria::LEFT_JOIN); $search->addJoinObject($askedLocaleJoin, $askedLocaleI18nAlias) ->addJoinCondition($askedLocaleI18nAlias ,'`' . $askedLocaleI18nAlias . '`.LOCALE = ?', $askedLocale, null, \PDO::PARAM_STR); @@ -67,7 +67,9 @@ class ModelCriteriaTools $search->withColumn('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.`ID`)', $aliasPrefix . 'IS_TRANSLATED'); - $search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)'); + if(!$forceReturn) { + $search->where('NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID)')->_or()->where('NOT ISNULL(`' . $defaultLocaleI18nAlias . '`.ID)'); + } foreach($columns as $column) { $search->withColumn('CASE WHEN NOT ISNULL(`' . $askedLocaleI18nAlias . '`.ID) THEN `' . $askedLocaleI18nAlias . '`.`' . $column . '` ELSE `' . $defaultLocaleI18nAlias . '`.`' . $column . '` END', $aliasPrefix . 'i18n_' . $column); @@ -84,7 +86,7 @@ class ModelCriteriaTools $aliasPrefix = $foreignTable . '_'; } - $askedLocaleI18nAlias = 'asked_locale_i18n'; + $askedLocaleI18nAlias = $aliasPrefix . 'asked_locale_i18n'; $askedLocaleJoin = new Join(); $askedLocaleJoin->addExplicitCondition($search->getTableMap()->getName(), $foreignKey, null, $foreignTable . '_i18n', 'ID', $askedLocaleI18nAlias); diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 546b9d077..73b09dd2c 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -35,7 +35,7 @@ use Thelia\Model\Map\RewritingUrlTableMap; */ class RewritingRetriever { - public function getViewUrl($view, $viewId, $viewLocale) + public function getViewUrl($view, $viewLocale, $viewId) { $url = $this->getViewUrlQuery($view, $viewId, $viewLocale); @@ -48,22 +48,22 @@ class RewritingRetriever ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) ->where('ISNULL(`ra`.REWRITING_URL_ID)') ->filterByView($view) - ->filterByViewId($viewId) ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) ->filterByRedirected(null) ->orderByUpdatedAt(Criteria::DESC) ->findOne(); } - public function getSpecificUrl($view = null, $viewId = null, $viewLocale = null, $viewOtherParameters = array()) + public function getSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array()) { $urlQuery = RewritingUrlQuery::create() ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) ->withColumn('`ra`.PARAMETER', 'ra_parameter') ->withColumn('`ra`.VALUE', 'ra_value') ->filterByView($view) - ->filterByViewId($viewId) ->filterByViewLocale($viewLocale) + ->filterByViewId($viewId) ->filterByRedirected(null) ->orderByUpdatedAt(Criteria::DESC); @@ -86,10 +86,7 @@ class RewritingRetriever ->combine(array('count_condition', 'parameter_full_condition'), Criteria::LOGICAL_AND, 'full_having_condition'); - $urlQuery - ->having(array('full_having_condition')) - //->having('COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) - ; + $urlQuery->having(array('full_having_condition')); } else { $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); } diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 267e5554c..1bf0e566c 100755 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -53,7 +53,11 @@ class URL // Already absolute ? if (substr($path, 0, 4) != 'http') { - $root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : self::getIndexPage(); + /** + * @etienne : can't be done here for it's already done in ::viewUrl / ::adminViewUrl + */ + //$root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : self::getIndexPage(); + $root = $path_only == self::PATH_TO_FILE ? ConfigQuery::read('base_url', '/') : ''; $base = rtrim($root, '/') . '/' . ltrim($path, '/'); } else @@ -116,7 +120,7 @@ class URL $rewrittenUrl = null; if(ConfigQuery::isRewritingEnable()) { $retriever = new RewritingRetriever(); - $rewrittenUrl = $retriever->getViewUrl($view, $viewId, $viewLocale); + $rewrittenUrl = $retriever->getViewUrl($view, $viewLocale, $viewId); } return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; @@ -127,24 +131,26 @@ class URL $rewrittenUrl = null; if(ConfigQuery::isRewritingEnable()) { $view = $request->query->get('view', null); - $viewId = $view === null ? null : $request->query->get($view . '_id', null); $viewLocale = $request->query->get('locale', null); + $viewId = $view === null ? null : $request->query->get($view . '_id', null); - $allOtherParameters = $request->query->all(); + $allParameters = $request->query->all(); + $allParametersWithoutView = $allParameters; if($view !== null) { - unset($allOtherParameters['view']); + unset($allParametersWithoutView['view']); + } + $allOtherParameters = $allParametersWithoutView; + if($viewLocale !== null) { + unset($allOtherParameters['locale']); } if($viewId !== null) { unset($allOtherParameters[$view . '_id']); } - if($viewLocale !== null) { - unset($allOtherParameters['locale']); - } $retriever = new RewritingRetriever(); - $rewrittenUrl = $retriever->getSpecificUrl($view, $viewId, $viewLocale, $allOtherParameters); + $rewrittenUrl = $retriever->getSpecificUrl($view, $viewLocale, $viewId, $allOtherParameters); } - return $rewrittenUrl === null ? self::viewUrl($view, array($view . '_id' => $viewId, 'locale' => $viewLocale)) : $rewrittenUrl; + return $rewrittenUrl === null ? self::viewUrl($view, $allParametersWithoutView) : $rewrittenUrl; } } diff --git a/install/thelia.sql b/install/thelia.sql index 1993ee084..99b18513e 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -1443,9 +1443,9 @@ CREATE TABLE `rewriting_url` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `url` VARCHAR(255) NOT NULL, - `view` VARCHAR(255), + `view` VARCHAR(255) NOT NULL, `view_id` VARCHAR(255), - `view_locale` VARCHAR(255), + `view_locale` VARCHAR(255) NOT NULL, `redirected` INTEGER, `created_at` DATETIME, `updated_at` DATETIME, diff --git a/local/config/schema.xml b/local/config/schema.xml index 0e20f2562..17fcf612f 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -1096,9 +1096,9 @@ - + - + diff --git a/templates/admin/default/includes/header.inc.html b/templates/admin/default/includes/header.inc.html index 65500f05a..05578de6b 100755 --- a/templates/admin/default/includes/header.inc.html +++ b/templates/admin/default/includes/header.inc.html @@ -67,7 +67,7 @@ {/loop} - + diff --git a/templates/default/cart.html b/templates/default/cart.html index 03ec8e3ee..5597d28ad 100755 --- a/templates/default/cart.html +++ b/templates/default/cart.html @@ -8,7 +8,7 @@ {form name="thelia.cart.add" } -{* We use $INDEX_PAGE as form action to avoid mixing post and get data *} +{* We use {navigate to="index"} as form action to avoid mixing post and get data *}
{* diff --git a/templates/default/category.html b/templates/default/category.html index 440866a26..dd5c6a20a 100755 --- a/templates/default/category.html +++ b/templates/default/category.html @@ -22,34 +22,10 @@ {loop name="product" type="product" category="#ID"}
-

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

#TITLE

#DESCRIPTION

- {ifloop rel="acc"} -
Accessories
-
    - {loop name="acc" type="accessory" product="#ID" order="accessory"} -
  • #REF
  • - {/loop} -
- {/ifloop} - {elseloop rel="acc"} -
No accessory
- {/elseloop} - - {ifloop rel="prod_ass_cont"} -
Associated Content
-
    - {loop name="prod_ass_cont" type="associated_content" product="#ID" order="associated_content"} -
  • #TITLE
  • - {/loop} -
- {/ifloop} - {elseloop rel="prod_ass_cont"} -
No associated content
- {/elseloop} - {ifloop rel="ft"}
Features
    @@ -67,29 +43,6 @@ {elseloop rel="ft"}
    No feature
    {/elseloop} - -
    Product sale elements
    - - {assign var=current_product value=#ID} - {loop name="pse" type="product_sale_elements" product="#ID"} -
    - {loop name="combi" type="attribute_combination" product_sale_elements="#ID"} - #ATTRIBUTE_TITLE = #ATTRIBUTE_AVAILABILITY_TITLE
    - {/loop} -
    #WEIGHT g -
    {if #IS_PROMO == 1} #PROMO_PRICE € (instead of #PRICE) {else} #PRICE € {/if} -

    - Add - - to my cart -
-
- {/loop} - {/loop} {loop name="catgory1" type="category" parent="#ID"} @@ -110,75 +63,29 @@ {loop name="product" type="product" category="#ID"} -
-

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

-

#TITLE

-

#DESCRIPTION

+
+

PRODUCT #ID : #REF (#LOOP_COUNT / #LOOP_TOTAL)

+

#TITLE

+

#DESCRIPTION

- {ifloop rel="acc"} -
Accessories
-
    - {loop name="acc" type="accessory" product="#ID" order="accessory"} -
  • #REF
  • - {/loop} -
- {/ifloop} - {elseloop rel="acc"} -
No accessory
- {/elseloop} - - {ifloop rel="prod_ass_cont"} -
Associated Content
-
    - {loop name="prod_ass_cont" type="associated_content" product="#ID" order="associated_content"} -
  • #TITLE
  • - {/loop} -
- {/ifloop} - {elseloop rel="prod_ass_cont"} -
No associated content
- {/elseloop} - - {ifloop rel="ft"} -
Features
-
    - {loop name="ft" type="feature" order="manual" product="#ID"} -
  • - #TITLE : - {loop name="ft_v" type="feature_value" product="{$current_product}" feature="#ID"} - #TITLE / #PERSONAL_VALUE + {ifloop rel="ft"} +
    Features
    +
      + {assign var=current_product value=#ID} + {loop name="ft" type="feature" order="manual" product="#ID"} +
    • + #TITLE : + {loop name="ft_v" type="feature_value" product="{$current_product}" feature="#ID"} + #TITLE / #PERSONAL_VALUE + {/loop} +
    • {/loop} - - {/loop} -
    - {/ifloop} - {elseloop rel="ft"} -
    No feature
    - {/elseloop} - -
    Product sale elements
    - - {assign var=current_product value=#ID} - {loop name="pse" type="product_sale_elements" product="#ID"} -
    - {loop name="combi" type="attribute_combination" product_sale_elements="#ID"} - #ATTRIBUTE_TITLE = #ATTRIBUTE_AVAILABILITY_TITLE
    - {/loop} -
    #WEIGHT g -
    {if #IS_PROMO == 1} #PROMO_PRICE € (instead of #PRICE) {else} #PRICE € {/if} -

    - Add - - to my cart -
-
- {/loop} - -
+ + {/ifloop} + {elseloop rel="ft"} +
No feature
+ {/elseloop} + {/loop} {/loop} diff --git a/templates/default/connexion.html b/templates/default/connexion.html index e3109e8b3..a6a2cc665 100755 --- a/templates/default/connexion.html +++ b/templates/default/connexion.html @@ -1,7 +1,7 @@ {include file="includes/header.html"} {form name="thelia.customer.creation"} -{* We use $INDEX_PAGE as form action to avoid mixing post and get data *} +{* We use {navigate to="index"} as form action to avoid mixing post and get data *} {* The two fields below are not par of the form, they are here to defines @@ -16,7 +16,7 @@ *} {form_field form=$form field='success_url'} - {* the url the user is redirected to on login success *} + {* the url the user is redirected to on login success *} {/form_field} {form_field form=$form field='auto_login'} diff --git a/templates/default/login.html b/templates/default/login.html index 0041fd80c..a5a7585b7 100755 --- a/templates/default/login.html +++ b/templates/default/login.html @@ -3,8 +3,8 @@

{intl l='Please login'}

{form name="thelia.customer.login" } -{* We use $INDEX_PAGE as form action to avoid mixing post and get data *} - +{* We use {navigate to="index"} as form action to avoid mixing post and get data *} + {* The two fields below are not par of the Login form, they are here to defines @@ -20,7 +20,7 @@ *} {form_field form=$form field='success_url'} - {* the url the user is redirected to on login success *} + {* the url the user is redirected to on login success *} {/form_field} {* diff --git a/web/index_dev.php b/web/index_dev.php index b5a98978a..8991dc4a8 100755 --- a/web/index_dev.php +++ b/web/index_dev.php @@ -21,8 +21,6 @@ if ( false === in_array($request->getClientIp(), $trustIp)) { $thelia = new Thelia("dev", true); -\Thelia\Tools\URL::retrieveCurrent($request); - $response = $thelia->handle($request)->prepare($request)->send(); $thelia->terminate($request, $response); From e63ff065c7ed884156b43c4fdd47bd473945f6b7 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 30 Aug 2013 15:04:08 +0200 Subject: [PATCH 5/7] product page --- templates/default/product.html | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 templates/default/product.html diff --git a/templates/default/product.html b/templates/default/product.html new file mode 100755 index 000000000..4f82b5fb8 --- /dev/null +++ b/templates/default/product.html @@ -0,0 +1,88 @@ +Here you are : {navigate to="current"}
+From : {navigate to="return_to"}
+Index : {navigate to="index"}
+ +

Product page

+ +{ifloop rel="product"} + +{loop type="product" name="product" current="true"} + +
+

PRODUCT (#ID) : #REF

+

#TITLE

+

#DESCRIPTION

+ + {ifloop rel="acc"} +

Accessories

+
    + {loop name="acc" type="accessory" product="#ID" order="accessory"} +
  • #REF
  • + {/loop} +
+ {/ifloop} + {elseloop rel="acc"} +

No accessory

+ {/elseloop} + + {ifloop rel="prod_ass_cont"} +

Associated Content

+
    + {loop name="prod_ass_cont" type="associated_content" product="#ID" order="associated_content"} +
  • #TITLE
  • + {/loop} +
+ {/ifloop} + {elseloop rel="prod_ass_cont"} +

No associated content

+ {/elseloop} + + {ifloop rel="ft"} +

Features

+
    + {assign var=current_product value=#ID} + {loop name="ft" type="feature" order="manual" product="#ID"} +
  • + #TITLE : + {loop name="ft_v" type="feature_value" product="{$current_product}" feature="#ID"} + #TITLE / #PERSONAL_VALUE + {/loop} +
  • + {/loop} +
+ {/ifloop} + {elseloop rel="ft"} +

No feature

+ {/elseloop} + +

Product sale elements

+ + {assign var=current_product value=#ID} + {loop name="pse" type="product_sale_elements" product="#ID"} +
+ {loop name="combi" type="attribute_combination" product_sale_elements="#ID"} + #ATTRIBUTE_TITLE = #ATTRIBUTE_AVAILABILITY_TITLE
+ {/loop} +
#WEIGHT g +
{if #IS_PROMO == 1} #PROMO_PRICE € (instead of #PRICE) {else} #PRICE € {/if} +

+ Add + + to my cart + +
+ {/loop} + +
+ +{/loop} + +{/ifloop} + +{elseloop rel="product"} +

Produit introuvable !

+{/elseloop} \ No newline at end of file From d8df46737dceab03eb6cbc71e817467d78d9ebd7 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 30 Aug 2013 16:02:37 +0200 Subject: [PATCH 6/7] specific rewrittend url retrievement --- .../Thelia/Rewriting/RewritingRetriever.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 73b09dd2c..34be346f1 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -59,8 +59,9 @@ class RewritingRetriever { $urlQuery = RewritingUrlQuery::create() ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - ->withColumn('`ra`.PARAMETER', 'ra_parameter') - ->withColumn('`ra`.VALUE', 'ra_value') + //->withColumn('`ra`.PARAMETER', 'ra_parameter') + //->withColumn('`ra`.VALUE', 'ra_value') + ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') ->filterByView($view) ->filterByViewLocale($viewLocale) ->filterByViewId($viewId) @@ -70,23 +71,23 @@ class RewritingRetriever $otherParametersCount = count($viewOtherParameters); if($otherParametersCount > 0) { $parameterConditions = array(); + foreach($viewOtherParameters as $parameter => $value) { $conditionName = 'other_parameter_condition_' . count($parameterConditions); - $urlQuery->condition('parameter_condition', '`ra_parameter`= ?', $parameter, \PDO::PARAM_STR) - ->condition('value_condition', '`ra_value` = ?', $value, \PDO::PARAM_STR) + $urlQuery->condition('parameter_condition', '`ra`.PARAMETER= ?', $parameter, \PDO::PARAM_STR) + ->condition('value_condition', '`ra`.VALUE = ?', $value, \PDO::PARAM_STR) ->combine(array('parameter_condition', 'value_condition'), Criteria::LOGICAL_AND, $conditionName); $parameterConditions[] = $conditionName; } - $urlQuery->combine($parameterConditions, Criteria::LOGICAL_OR, 'parameter_full_condition'); + $urlQuery->where($parameterConditions, Criteria::LOGICAL_OR); $urlQuery->groupBy(RewritingUrlTableMap::ID); - $urlQuery->condition('count_condition', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) - ->combine(array('count_condition', 'parameter_full_condition'), Criteria::LOGICAL_AND, 'full_having_condition'); + $urlQuery->condition('count_condition_1', 'COUNT(' . RewritingUrlTableMap::ID . ') = ?', $otherParametersCount, \PDO::PARAM_INT) // ensure we got all the asked parameters (provided by the query) + ->condition('count_condition_2', 'COUNT(' . RewritingUrlTableMap::ID . ') = (SELECT COUNT(*) FROM rewriting_argument WHERE rewriting_argument.REWRITING_URL_ID = ra_REWRITING_URL_ID)'); // ensure we don't miss any parameters (needed to match the rewritten url) - - $urlQuery->having(array('full_having_condition')); + $urlQuery->having(array('count_condition_1', 'count_condition_2'), Criteria::LOGICAL_AND); } else { $urlQuery->where('ISNULL(`ra`.REWRITING_URL_ID)'); } From 6fa4d3a9238917c5eb01d199b4c008b085e26c2e Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Fri, 30 Aug 2013 16:47:13 +0200 Subject: [PATCH 7/7] rewriting --- .../Thelia/Rewriting/RewritingRetriever.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Rewriting/RewritingRetriever.php b/core/lib/Thelia/Rewriting/RewritingRetriever.php index 34be346f1..0deb7de45 100755 --- a/core/lib/Thelia/Rewriting/RewritingRetriever.php +++ b/core/lib/Thelia/Rewriting/RewritingRetriever.php @@ -35,6 +35,13 @@ use Thelia\Model\Map\RewritingUrlTableMap; */ class RewritingRetriever { + /** + * @param $view + * @param $viewLocale + * @param $viewId + * + * @return null|$url + */ public function getViewUrl($view, $viewLocale, $viewId) { $url = $this->getViewUrlQuery($view, $viewId, $viewLocale); @@ -42,6 +49,13 @@ class RewritingRetriever return $url === null ? null : $url->getUrl(); } + /** + * @param $view + * @param $viewId + * @param $viewLocale + * + * @return null|RewritingUrl + */ protected function getViewUrlQuery($view, $viewId, $viewLocale) { return RewritingUrlQuery::create() @@ -55,12 +69,18 @@ class RewritingRetriever ->findOne(); } + /** + * @param $view + * @param $viewLocale + * @param null $viewId + * @param array $viewOtherParameters + * + * @return null|$url + */ public function getSpecificUrl($view, $viewLocale, $viewId = null, $viewOtherParameters = array()) { $urlQuery = RewritingUrlQuery::create() ->joinRewritingArgument('ra', Criteria::LEFT_JOIN) - //->withColumn('`ra`.PARAMETER', 'ra_parameter') - //->withColumn('`ra`.VALUE', 'ra_value') ->withColumn('`ra`.REWRITING_URL_ID', 'ra_REWRITING_URL_ID') ->filterByView($view) ->filterByViewLocale($viewLocale)