url global substitution
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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'))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)');
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user