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);