// Routes for dispatcher (part 4) + some fix
This commit is contained in:
@@ -75,7 +75,6 @@ function includeDatepicker($id, $time = false)
|
||||
function rewriteSettingsFile($baseUrls = NULL, $theme = NULL, $arrayDB = NULL)
|
||||
{
|
||||
$defines = array();
|
||||
$defines['_PS_DIRECTORY_'] = ($baseUrls AND $baseUrls['_PS_DIRECTORY_']) ? $baseUrls['_PS_DIRECTORY_'] : _PS_DIRECTORY_;
|
||||
$defines['_MEDIA_SERVER_1_'] = ($baseUrls AND isset($baseUrls['_MEDIA_SERVER_1_'])) ? $baseUrls['_MEDIA_SERVER_1_'] : _MEDIA_SERVER_1_;
|
||||
$defines['_MEDIA_SERVER_2_'] = ($baseUrls AND isset($baseUrls['_MEDIA_SERVER_2_'])) ? $baseUrls['_MEDIA_SERVER_2_'] : _MEDIA_SERVER_2_;
|
||||
$defines['_MEDIA_SERVER_3_'] = ($baseUrls AND isset($baseUrls['_MEDIA_SERVER_3_'])) ? $baseUrls['_MEDIA_SERVER_3_'] : _MEDIA_SERVER_3_;
|
||||
|
||||
+1
-2
@@ -34,8 +34,7 @@ if (isset($_GET['logout']))
|
||||
|
||||
if (!$cookie->isLoggedBack())
|
||||
{
|
||||
$destination = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])) + 1);
|
||||
Tools::redirectAdmin('login.php'.(empty($destination) || ($destination == 'index.php?logout') ? '' : '?redirect='.$destination));
|
||||
Tools::redirectAdmin('login.php?redirect='.$_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
||||
// Set current index
|
||||
|
||||
+2
-4
@@ -51,10 +51,8 @@ if ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) == 'off')
|
||||
.'<br/><br/><a href="https://'.Tools::getServerName().$_SERVER['REQUEST_URI'].'">https://'.Tools::getServerName().$_SERVER['REQUEST_URI'].'</a>';
|
||||
}
|
||||
|
||||
$cookie = new Cookie('psAdmin', substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__), -10));
|
||||
if (!isset($cookie->id_lang))
|
||||
$cookie->id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
$iso = strtolower(Language::getIsoById((int)($cookie->id_lang)));
|
||||
$cookie = Context::getContext()->cookie;
|
||||
$iso = strtolower(Language::getIsoById(Context::getContext()->language->id));
|
||||
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
|
||||
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
|
||||
|
||||
|
||||
@@ -38,17 +38,19 @@ class AdminLanguages extends AdminTab
|
||||
$this->fieldImageSettings = array(array('name' => 'flag', 'dir' => 'l'), array('name' => 'no-picture', 'dir' => 'p'));
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_lang' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'flag' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'l', 'orderby' => false, 'search' => false),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 120),
|
||||
'iso_code' => array('title' => $this->l('ISO code'), 'width' => 70, 'align' => 'center'),
|
||||
'language_code' => array('title' => $this->l('Language code'), 'width' => 70, 'align' => 'center'),
|
||||
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'));
|
||||
'id_lang' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'flag' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'l', 'orderby' => false, 'search' => false),
|
||||
'name' => array('title' => $this->l('Name'), 'width' => 120),
|
||||
'iso_code' => array('title' => $this->l('ISO code'), 'width' => 70, 'align' => 'center'),
|
||||
'language_code' => array('title' => $this->l('Language code'), 'width' => 70, 'align' => 'center'),
|
||||
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'),
|
||||
);
|
||||
|
||||
$this->optionTitle = $this->l('Languages options');
|
||||
$this->_fieldsOptions = array(
|
||||
'PS_LANG_DEFAULT' => array('title' => $this->l('Default language:'), 'desc' => $this->l('The default language used in shop'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_lang', 'list' => Language::getlanguages(false)),
|
||||
'PS_LANG_DEFAULT' => array('title' => $this->l('Default language:'), 'desc' => $this->l('The default language used in shop'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'id_lang', 'list' => Language::getlanguages(false)),
|
||||
);
|
||||
$this->_group = 'GROUP BY a.id_lang';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class AdminPreferences extends AdminTab
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
Tools::clearCache($smarty);
|
||||
Tools::clearCache($this->context->smarty);
|
||||
|
||||
/* Check required fields */
|
||||
foreach ($fields AS $field => $values)
|
||||
@@ -289,7 +289,6 @@ class AdminPreferences extends AdminTab
|
||||
else
|
||||
$tab[$key] = Tools::getValue($key, Configuration::get($key));
|
||||
}
|
||||
$tab['_PS_DIRECTORY_'] = _PS_DIRECTORY_;
|
||||
$tab['_MEDIA_SERVER_1_'] = _MEDIA_SERVER_1_;
|
||||
$tab['_MEDIA_SERVER_2_'] = _MEDIA_SERVER_2_;
|
||||
$tab['_MEDIA_SERVER_3_'] = _MEDIA_SERVER_3_;
|
||||
|
||||
@@ -34,19 +34,19 @@ class AdminShopUrl extends AdminTab
|
||||
$this->className = 'ShopUrl';
|
||||
$this->edit = true;
|
||||
$this->delete = true;
|
||||
$this->_select = 's.name shop_name';
|
||||
$this->_select = 's.name AS shop_name, CONCAT(a.physical_uri, a.virtual_uri) AS uri';
|
||||
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'shop` s ON (s.id_shop = a.id_shop)';
|
||||
$this->_listSkipDelete = array(1);
|
||||
|
||||
$this->fieldsDisplay = array(
|
||||
'id_shop_url' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'domain' => array('title' => $this->l('Domain'), 'width' => 130, 'filter_key' => 'domain'),
|
||||
'domain_ssl' => array('title' => $this->l('Domain SSL'), 'width' => 130, 'filter_key' => 'domain'),
|
||||
'uri' => array('title' => $this->l('Uri'), 'width' => 130, 'filter_key' => 'uri'),
|
||||
'shop_name' => array('title' => $this->l('Shop name'), 'width' => 70),
|
||||
'main' => array('title' => $this->l('Main URL'), 'align' => 'center', 'activeVisu' => 'main', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'main'),
|
||||
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'));
|
||||
$this->_fieldsOptions = array('_PS_DIRECTORY_' => array('title' => $this->l('PS directory'), 'desc' => $this->l('Name of the PrestaShop directory on your Web server, bracketed by forward slashes (e.g., /shop/)'), 'validation' => 'isUrl', 'type' => 'text', 'size' => 20, 'default' => _PS_DIRECTORY_, 'visibility' => Shop::CONTEXT_ALL));
|
||||
'id_shop_url' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'domain' => array('title' => $this->l('Domain'), 'width' => 130, 'filter_key' => 'domain'),
|
||||
'domain_ssl' => array('title' => $this->l('Domain SSL'), 'width' => 130, 'filter_key' => 'domain'),
|
||||
'uri' => array('title' => $this->l('Uri'), 'width' => 130, 'filter_key' => 'uri'),
|
||||
'shop_name' => array('title' => $this->l('Shop name'), 'width' => 70),
|
||||
'main' => array('title' => $this->l('Main URL'), 'align' => 'center', 'activeVisu' => 'main', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'main'),
|
||||
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'),
|
||||
);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -66,15 +66,6 @@ class AdminShopUrl extends AdminTab
|
||||
|
||||
Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), Configuration::get('PS_HTACCESS_SPECIFIC'));
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitOptions'.$this->table))
|
||||
{
|
||||
$baseUrls = array();
|
||||
if ($_PS_DIRECTORY_ = Tools::getValue('_PS_DIRECTORY_'))
|
||||
$baseUrls['_PS_DIRECTORY_'] = $_PS_DIRECTORY_;
|
||||
rewriteSettingsFile($baseUrls, NULL, NULL);
|
||||
unset($this->_fieldsGeneral['_PS_DIRECTORY_']);
|
||||
}
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
@@ -90,6 +81,30 @@ class AdminShopUrl extends AdminTab
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
|
||||
echo <<<EOF
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$().ready(function()
|
||||
{
|
||||
$('#domain, #physical_uri, #virtual_uri').keyup(function()
|
||||
{
|
||||
var domain = $('#domain').val();
|
||||
var physical = $('#physical_uri').val();
|
||||
var virtual = $('#virtual_uri').val();
|
||||
var url = 'http://';
|
||||
url += ((domain) ? domain : '???');
|
||||
if (physical)
|
||||
url += '/'+physical;
|
||||
if (virtual)
|
||||
url += '/'+virtual;
|
||||
url = url.replace(/\/+/g, "/");
|
||||
$('#final_url').val(url);
|
||||
});
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
EOF;
|
||||
|
||||
echo '
|
||||
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'" method="post">
|
||||
@@ -103,11 +118,20 @@ class AdminShopUrl extends AdminTab
|
||||
<div class="margin-form">
|
||||
<input type="text" name="domain_ssl" id="domain_ssl" value="'.$this->getFieldValue($obj, 'domain_ssl').'" />
|
||||
</div>
|
||||
<label for="uri">'.$this->l('URI').'</label>
|
||||
<label for="physical_uri">'.$this->l('Physical URI').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="uri" id="uri" value="'.$this->getFieldValue($obj, 'uri').'" />
|
||||
<input type="text" name="physical_uri" id="physical_uri" value="'.$this->getFieldValue($obj, 'physical_uri').'" />
|
||||
<p>'.$this->l('Folder of your store ex: ipods for http://yourshopname.com/ipods/, leave empty if no folder.').'<br /><b>'.$this->l('URL Rewrite must be activated to use this feature.').'</b></p>
|
||||
</div>
|
||||
<label for="virtual_uri">'.$this->l('Virtual URI').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="virtual_uri" id="virtual_uri" value="'.$this->getFieldValue($obj, 'virtual_uri').'" />
|
||||
<p>'.$this->l('Folder of your store ex: ipods for http://yourshopname.com/ipods/, leave empty if no folder.').'<br /><b>'.$this->l('URL Rewrite must be activated to use this feature.').'</b></p>
|
||||
</div>
|
||||
<label>'.$this->l('Your final URL will be').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" readonly="readonly" id="final_url" style="width: 400px" value="'.$obj->getURL().'" />
|
||||
</div>
|
||||
<label for="id_shop">'.$this->l('Shop').'</label>
|
||||
<div class="margin-form">
|
||||
<select name="id_shop" id="id_shop">';
|
||||
|
||||
+1
-1
@@ -1167,7 +1167,7 @@ class CartCore extends ObjectModel
|
||||
$id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
|
||||
|
||||
if (!isset(self::$_carriers[$id_carrier]))
|
||||
self::$_carriers[$id_carrier] = new Carrier((int)($id_carrier), Configuration::get('PS_LANG_DEFAULT'));
|
||||
self::$_carriers[$id_carrier] = new Carrier($id_carrier, Configuration::get('PS_LANG_DEFAULT'));
|
||||
$carrier = self::$_carriers[$id_carrier];
|
||||
if (!Validate::isLoadedObject($carrier))
|
||||
die(Tools::displayError('Fatal error: "no default carrier"'));
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ class CookieCore
|
||||
$this->_content = array();
|
||||
$this->_expire = isset($expire) ? (int)($expire) : (time() + 1728000);
|
||||
$this->_name = md5($name);
|
||||
$this->_path = trim(__PS_BASE_URI__.$path, '/\\').'/';
|
||||
$this->_path = trim(Context::getContext()->shop->getPhysicalURI().$path, '/\\').'/';
|
||||
if ($this->_path{0} != '/') $this->_path = '/'.$this->_path;
|
||||
$this->_path = rawurlencode($this->_path);
|
||||
$this->_path = str_replace('%2F', '/', $this->_path);
|
||||
|
||||
+62
-27
@@ -36,6 +36,8 @@ class DispatcherCore
|
||||
public static $instance = null;
|
||||
|
||||
/**
|
||||
* List of default routes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultRoutes = array(
|
||||
@@ -70,16 +72,22 @@ class DispatcherCore
|
||||
);
|
||||
|
||||
/**
|
||||
* If true, use routes to build URL (mod rewrite must be activated)
|
||||
*
|
||||
* @var $useRoutes bool
|
||||
*/
|
||||
protected $useRoutes = false;
|
||||
|
||||
/**
|
||||
* List of loaded routes
|
||||
*
|
||||
* @var $routes array
|
||||
*/
|
||||
protected $routes = array();
|
||||
|
||||
/**
|
||||
* List of allowed keywords in routes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keywords = array(
|
||||
@@ -88,11 +96,25 @@ class DispatcherCore
|
||||
);
|
||||
|
||||
/**
|
||||
* Current controller name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
public static $controllers = array();
|
||||
|
||||
/**
|
||||
* Current request uri
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $requestURI;
|
||||
|
||||
/**
|
||||
* Store empty route (a route with an empty rule)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $emptyRoute;
|
||||
|
||||
/**
|
||||
* Get current instance of dispatcher (singleton)
|
||||
@@ -113,18 +135,34 @@ class DispatcherCore
|
||||
{
|
||||
$this->useRoutes = (bool)Configuration::get('PS_REWRITING_SETTINGS');
|
||||
$this->loadRoutes();
|
||||
|
||||
// Get request uri (HTTP_X_REWRITE_URL is used by IIS)
|
||||
if (isset($_SERVER['REQUEST_URI']))
|
||||
$this->requestURI = $_SERVER['REQUEST_URI'];
|
||||
else if (isset($_SERVER['HTTP_X_REWRITE_URL']))
|
||||
$this->requestURI = $_SERVER['HTTP_X_REWRITE_URL'];
|
||||
}
|
||||
|
||||
/**
|
||||
* "main" method of dispatcher, call the controller
|
||||
* Find the controller and instantiate it
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
$this->getController();
|
||||
$this->requestURI = preg_replace('#^'.preg_quote(Context::getContext()->shop->getBaseURI(), '#').'#i', '/', $this->requestURI);
|
||||
|
||||
// If there are several languages, get language from uri
|
||||
if ($this->useRoutes && Language::isMultiLanguageActivated())
|
||||
if (preg_match('#^/([a-z]{2})/#', $this->requestURI, $m))
|
||||
{
|
||||
$_GET['isolang'] = $m[1];
|
||||
$this->requestURI = substr($this->requestURI, 3);
|
||||
}
|
||||
|
||||
// Get and instantiate controller
|
||||
$this->getController();
|
||||
$controllers = Dispatcher::getControllers();
|
||||
if (!isset($controllers[$this->controller]))
|
||||
$this->controller = 'index';
|
||||
$this->controller = 'pagenotfound';
|
||||
ControllerFactory::getController($controllers[$this->controller])->run();
|
||||
}
|
||||
|
||||
@@ -146,7 +184,16 @@ class DispatcherCore
|
||||
WHERE id_lang = '.(int)$context->language->id;
|
||||
if ($results = Db::getInstance()->ExecuteS($sql))
|
||||
foreach ($results as $row)
|
||||
$this->addRoute($row['page'], $row['url_rewrite'], $row['page']);
|
||||
{
|
||||
if ($row['url_rewrite'])
|
||||
$this->addRoute($row['page'], $row['url_rewrite'], $row['page']);
|
||||
else
|
||||
$this->emptyRoute = array(
|
||||
'routeID' => $row['page'],
|
||||
'rule' => $row['url_rewrite'],
|
||||
'controller' => $row['page'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,17 +225,6 @@ class DispatcherCore
|
||||
'required' => $required,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a route is defined
|
||||
*
|
||||
* @param string $routeID
|
||||
* @return bool
|
||||
*/
|
||||
public function routeExists($routeID)
|
||||
{
|
||||
return isset($this->routes[$routeID]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an url from
|
||||
@@ -259,17 +295,16 @@ class DispatcherCore
|
||||
// Use routes ? (for url rewriting)
|
||||
if ($this->useRoutes && !$controller)
|
||||
{
|
||||
// Get request uri (HTTP_X_REWRITE_URL is used by IIS)
|
||||
if (isset($_SERVER['REQUEST_URI']))
|
||||
$request = $_SERVER['REQUEST_URI'];
|
||||
else if (isset($_SERVER['HTTP_X_REWRITE_URL']))
|
||||
$request = $_SERVER['HTTP_X_REWRITE_URL'];
|
||||
else
|
||||
return 'index';
|
||||
|
||||
if (!$this->requestURI)
|
||||
return 'pagenotfound';
|
||||
$controller = 'index';
|
||||
|
||||
// Add empty route as last route to prevent this greedy regexp to match request uri before right time
|
||||
if ($this->emptyRoute)
|
||||
$this->addRoute($this->emptyRoute['routeID'], $this->emptyRoute['rule'], $this->emptyRoute['controller']);
|
||||
|
||||
foreach ($this->routes as $route)
|
||||
if (preg_match($route['regexp'], $request, $m))
|
||||
if (preg_match($route['regexp'], $this->requestURI, $m))
|
||||
{
|
||||
// Route found ! Now fill $_GET with parameters of uri
|
||||
$controller = $route['controller'];
|
||||
@@ -278,7 +313,7 @@ class DispatcherCore
|
||||
$_GET[$k] = $v;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->controller = $controller;
|
||||
}
|
||||
// Default mode, take controller from url
|
||||
|
||||
@@ -136,7 +136,7 @@ class FrontControllerCore
|
||||
$protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
|
||||
$link = new Link($protocol_link, $protocol_content);
|
||||
$this->context->link = $link;
|
||||
|
||||
|
||||
if ($this->auth AND !$cookie->isLogged($this->guestAllowed))
|
||||
Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : ''));
|
||||
|
||||
@@ -398,7 +398,7 @@ class FrontControllerCore
|
||||
{
|
||||
header('HTTP/1.0 301 Moved');
|
||||
$params = '';
|
||||
$excludedKey = array('isolang', 'id_lang');
|
||||
$excludedKey = array('isolang', 'id_lang', 'controller');
|
||||
foreach ($_GET as $key => $value)
|
||||
if (!in_array($key, $excludedKey))
|
||||
$params .= ($params == '' ? '?' : '&').$key.'='.$value;
|
||||
|
||||
@@ -662,4 +662,15 @@ class LanguageCore extends ObjectModel
|
||||
self::$countActiveLanguages = Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'lang` WHERE `active` = 1');
|
||||
return self::$countActiveLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if more on than one language is activated
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return bool
|
||||
*/
|
||||
public static function isMultiLanguageActivated()
|
||||
{
|
||||
return (Language::countActiveLanguages() > 1);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-22
@@ -73,11 +73,12 @@ class LinkCore
|
||||
public function getProductLink($id_product, $alias = null, $category = null, $ean13 = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
$url = _PS_BASE_URL_.__PS_BASE_URI__;
|
||||
|
||||
|
||||
// @todo use specific method ?
|
||||
if ($id_shop && ($shop = Shop::getShop($id_shop)))
|
||||
$url = 'http://'.$shop['domain'].'/'.$shop['uri'].$this->getLangLink($id_lang);
|
||||
|
||||
$url = 'http://'.$shop['domain'].'/'.$shop['uri'];
|
||||
$url .= $this->getLangLink($id_lang);
|
||||
|
||||
if (is_object($id_product))
|
||||
{
|
||||
$product = clone($id_product);
|
||||
@@ -86,7 +87,7 @@ class LinkCore
|
||||
$alias = $product->link_rewrite;
|
||||
$ean13 = $product->ean13;
|
||||
}
|
||||
|
||||
|
||||
if ($category AND $category != 'home')
|
||||
return $url.Dispatcher::getInstance()->createUrl('product_rule2', array(
|
||||
'id_product' => $id_product,
|
||||
@@ -269,7 +270,7 @@ class LinkCore
|
||||
* @param string $controller
|
||||
* @param bool $ssl
|
||||
* @param int $id_lang
|
||||
* @param string $request
|
||||
* @param string|array $request
|
||||
* @param Context $context
|
||||
*/
|
||||
public function getPageLink($controller, $ssl = false, $id_lang = null, $request = null)
|
||||
@@ -278,6 +279,11 @@ class LinkCore
|
||||
|
||||
if (!$id_lang)
|
||||
$id_lang = (int)Context::getContext()->language->id;
|
||||
if (is_array($request))
|
||||
{
|
||||
unset($request['controller']);
|
||||
$request = http_build_query($request);
|
||||
}
|
||||
|
||||
$uri_path = Dispatcher::getInstance()->createUrl($controller);
|
||||
$url = ($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true);
|
||||
@@ -313,24 +319,13 @@ class LinkCore
|
||||
$request = str_replace($rewrite, $url_rewrite, $request);
|
||||
}
|
||||
|
||||
$queryTab = array();
|
||||
parse_str($_SERVER['QUERY_STRING'], $queryTab);
|
||||
unset($queryTab['isolang']);
|
||||
$query = http_build_query($queryTab);
|
||||
|
||||
if (!empty($query) OR !$this->allow)
|
||||
$query = '?'.$query;
|
||||
|
||||
$switchLangLink = $this->getPageLink(substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)), false, $id_lang).$query;
|
||||
unset($queryTab['isolang'], $queryTab['controller']);
|
||||
|
||||
if (!$this->allow)
|
||||
if ($id_lang != $context->language->id)
|
||||
{
|
||||
if (strpos($switchLangLink,'id_lang'))
|
||||
$switchLangLink = preg_replace('`id_lang=[0-9]*`','id_lang='.$id_lang,$switchLangLink);
|
||||
else
|
||||
$switchLangLink = $switchLangLink.'&id_lang='.$id_lang;
|
||||
}
|
||||
return $switchLangLink;
|
||||
$queryTab['id_lang'] = $id_lang;
|
||||
|
||||
return $this->getPageLink(Dispatcher::getInstance()->getController(), false, $id_lang, $queryTab);
|
||||
}
|
||||
|
||||
public function goPage($url, $p)
|
||||
@@ -382,7 +377,7 @@ class LinkCore
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if (!$this->allow OR Language::countActiveLanguages() <= 1)
|
||||
if (!$this->allow OR !Language::isMultiLanguageActivated())
|
||||
return '';
|
||||
|
||||
if (!$id_lang)
|
||||
|
||||
+1
-1
@@ -1509,7 +1509,7 @@ class ProductCore extends ObjectModel
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.$context->shop->sqlAsso('product', 'p').'
|
||||
'.Product::sqlStock('p', 0, false, $context).'
|
||||
'.Product::sqlStock('p', 0, false, $context->shop).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->sqlLang('pl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
|
||||
+19
-24
@@ -37,8 +37,9 @@ class ShopCore extends ObjectModel
|
||||
public $id_category;
|
||||
public $deleted;
|
||||
|
||||
protected $base_uri;
|
||||
protected $theme_name;
|
||||
protected $physical_uri;
|
||||
protected $virtual_uri;
|
||||
|
||||
/**
|
||||
* @var GroupShop
|
||||
@@ -179,37 +180,26 @@ class ShopCore extends ObjectModel
|
||||
$excluded_uris[] = $directory;
|
||||
|
||||
// Parse request_uri
|
||||
preg_match('/^'.Tools::pRegexp(_PS_DIRECTORY_, '/').'([a-z0-9]+)\/.*$/Ui', $_SERVER['REQUEST_URI'], $res);
|
||||
$uri = (isset($res[1]) AND !in_array($res[1], $excluded_uris)) ? $res[1] : '';
|
||||
|
||||
if (!$id_shop = Tools::getValue('id_shop'))
|
||||
{
|
||||
// Find current shop from URL
|
||||
$db = Db::getInstance();
|
||||
$sql = 'SELECT s.id_shop, su.uri
|
||||
$sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri
|
||||
FROM '._DB_PREFIX_.'shop_url su
|
||||
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
|
||||
WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\'
|
||||
AND s.active = 1
|
||||
AND s.deleted = 0';
|
||||
$default = false;
|
||||
AND s.deleted = 0
|
||||
ORDER BY LENGTH(uri) DESC';
|
||||
if ($results = Db::getInstance()->executeS($sql))
|
||||
foreach ($results as $row)
|
||||
{
|
||||
if (!$default)
|
||||
$default = $row;
|
||||
else if (!$row['uri'])
|
||||
$default = $row;
|
||||
|
||||
if ($uri == $row['uri'])
|
||||
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
|
||||
{
|
||||
$id_shop = $row['id_shop'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$id_shop)
|
||||
$id_shop = ($default) ? $default['id_shop'] : (int)Db::getInstance()->getValue('SELECT value FROM '._DB_PREFIX_.'configuration WHERE name = \'PS_SHOP_DEFAULT\'');
|
||||
die('Shop not found ... redirect me please !');
|
||||
}
|
||||
|
||||
// Get instance of found shop
|
||||
@@ -226,7 +216,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
protected function loadShopInfos()
|
||||
{
|
||||
$sql = 'SELECT su.uri, t.name
|
||||
$sql = 'SELECT su.physical_uri, su.virtual_uri, t.name
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
|
||||
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
|
||||
@@ -238,7 +228,8 @@ class ShopCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
$this->theme_name = $row['name'];
|
||||
$this->base_uri = ($row['uri']) ? $row['uri'].'/' : '';
|
||||
$this->physical_uri = $row['physical_uri'];
|
||||
$this->virtual_uri = $row['virtual_uri'];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -258,14 +249,18 @@ class ShopCore extends ObjectModel
|
||||
*
|
||||
* Get shop URI
|
||||
*
|
||||
* @param bool $with_base
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseURI($with_base = true)
|
||||
public function getBaseURI()
|
||||
{
|
||||
if (!$this->theme_name)
|
||||
$this->loadShopInfos();
|
||||
return ($with_base ? _PS_DIRECTORY_ : '').$this->base_uri;
|
||||
return $this->physical_uri.$this->virtual_uri.'/';
|
||||
}
|
||||
|
||||
public function getPhysicalURI()
|
||||
{
|
||||
return $this->physical_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,7 +351,7 @@ class ShopCore extends ObjectModel
|
||||
if (self::$shops && !$refresh)
|
||||
return;
|
||||
|
||||
$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.uri
|
||||
$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri
|
||||
FROM '._DB_PREFIX_.'group_shop gs
|
||||
LEFT JOIN '._DB_PREFIX_.'shop s
|
||||
ON s.id_group_shop = gs.id_group_shop
|
||||
@@ -387,7 +382,7 @@ class ShopCore extends ObjectModel
|
||||
'id_category' => $row['id_category'],
|
||||
'domain' => $row['domain'],
|
||||
'domain_ssl' => $row['domain_ssl'],
|
||||
'uri' => $row['uri'],
|
||||
'uri' => $row['physical_uri'].$row['virtual_uri'],
|
||||
'active' => $row['active'],
|
||||
);
|
||||
}
|
||||
|
||||
+24
-3
@@ -30,7 +30,8 @@ class ShopUrlCore extends ObjectModel
|
||||
public $id_shop;
|
||||
public $domain;
|
||||
public $domain_ssl;
|
||||
public $uri;
|
||||
public $physical_uri;
|
||||
public $virtual_uri;
|
||||
public $main;
|
||||
public $active;
|
||||
|
||||
@@ -39,7 +40,7 @@ class ShopUrlCore extends ObjectModel
|
||||
|
||||
|
||||
protected $fieldsRequired = array('domain', 'id_shop');
|
||||
protected $fieldsSize = array('domain' => 255, 'uri' => 64);
|
||||
protected $fieldsSize = array('domain' => 255, 'physical_uri' => 64, 'virtual_uri' => 64);
|
||||
protected $fieldsValidate = array('active' => 'isBool');
|
||||
|
||||
protected $table = 'shop_url';
|
||||
@@ -48,15 +49,35 @@ class ShopUrlCore extends ObjectModel
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$this->physical_uri = trim($this->physical_uri, '/');
|
||||
$this->physical_uri .= '/'.$this->physical_uri;
|
||||
if ($this->physical_uri)
|
||||
$this->physical_uri = preg_replace('#/+#', '/', $this->physical_uri);
|
||||
|
||||
$this->virtual_uri = trim($this->virtual_uri, '/');
|
||||
if ($this->virtual_uri)
|
||||
$this->virtual_uri = '/'.preg_replace('#/+#', '/', trim($this->virtual_uri, '/'));
|
||||
|
||||
$fields['domain'] = pSQL($this->domain);
|
||||
$fields['domain_ssl'] = pSQL($this->domain_ssl);
|
||||
$fields['uri'] = pSQL($this->uri);
|
||||
$fields['physical_uri'] = pSQL($this->physical_uri);
|
||||
$fields['virtual_uri'] = pSQL($this->virtual_uri);
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$fields['main'] = (int)$this->main;
|
||||
$fields['active'] = (int)$this->active;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getURL($ssl = false)
|
||||
{
|
||||
if (!$this->id)
|
||||
return ;
|
||||
|
||||
$url = ($ssl) ? 'https://'.$this->domain_ssl : 'http://'.$this->domain;
|
||||
return $url.$this->physical_uri.$this->virtual_uri;
|
||||
}
|
||||
|
||||
public static function getShopUrls($id_shop = false)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
|
||||
+83
-122
@@ -1538,144 +1538,103 @@ class ToolsCore
|
||||
|
||||
public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disableMuliviews = false)
|
||||
{
|
||||
// Check current content of .htaccess and save all code outside of prestashop comments
|
||||
$specificBefore = $specificAfter = '';
|
||||
if (file_exists($path))
|
||||
{
|
||||
$content = file_get_contents($path);
|
||||
if (preg_match('#^(.*)\# ~~start~~.*\# ~~end~~[^\n]*(.*)$#s', $content, $m))
|
||||
{
|
||||
$specificBefore = $m[1];
|
||||
$specificAfter = $m[2];
|
||||
}
|
||||
else
|
||||
$specificBefore = $content;
|
||||
}
|
||||
|
||||
// Write .htaccess data
|
||||
if (!$writeFd = @fopen($path, 'w'))
|
||||
return false;
|
||||
|
||||
$tab = array('ErrorDocument' => array(), 'RewriteEngine' => array(), 'RewriteRule' => array());
|
||||
$multilang = (Language::countActiveLanguages() > 1);
|
||||
$shop_urls = ShopUrl::getShopUrls();
|
||||
|
||||
foreach ($shop_urls AS &$url)
|
||||
fwrite($writeFd, trim($specificBefore)."\n\n");
|
||||
|
||||
$domains = array();
|
||||
foreach (ShopUrl::getShopUrls() as $shopUrl)
|
||||
{
|
||||
$url['uri'] .= (!empty($url['uri']) ? '/' : '');
|
||||
$domains[$url['domain']][] = $url;
|
||||
$domains[$shopUrl['domain']] = array(
|
||||
'physical' => $shopUrl['physical_uri'],
|
||||
'virtual' => $shopUrl['virtual_uri'],
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($domains AS $domain => $row)
|
||||
{
|
||||
foreach ($row AS $uri)
|
||||
{
|
||||
// ErrorDocument
|
||||
$tab['ErrorDocument'][$domain]['comment'] = '# Catch 404 errors';
|
||||
$tab['ErrorDocument'][$domain]['content'] = '404 '.$uri['uri'].'404.php';
|
||||
|
||||
// Compatibility with the old image filesystem
|
||||
if (Configuration::get('PS_LEGACY_IMAGES'))
|
||||
{
|
||||
$tab['RewriteRule'][$domain]['content']['^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1-$2$3.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1-$2.jpg [L]';
|
||||
}
|
||||
|
||||
// Rewriting for product image id < 100 millions
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$1$2.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$1$2$3.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$1$2$3$4.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$1$2$3$4$5.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = 'img/c/$1$2.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$'] = 'img/c/$1.jpg [L]';
|
||||
|
||||
if ($multilang)
|
||||
{
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$2&isolang=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'index.php?controller=product&id_product=$2&isolang=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*'] = 'index.php?controller=category&id_category=$2&isolang=$1&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/content/([0-9]+)\-[a-zA-Z0-9-]*'] = 'index.php?controller=cms&isolang=$1&id_cms=$2&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/content/category/([0-9]+)\-[a-zA-Z0-9-]*'] = 'index.php?controller=cms&isolang=$1&id_cms_category=$2&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/([0-9]+)__[a-zA-Z0-9-]*'] = 'index.php?controller=supplier&isolang=$1&id_supplier=$2&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
//$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z]{2})/([0-9]+)_[a-zA-Z0-9-]*'] = 'index.php?controller=manufacturer&isolang=$1&id_manufacturer=$2&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
}
|
||||
|
||||
// PS BASE URI automaticaly prepend the string, do not use PS defines for the image directories
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1-$2$3.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$'] = _PS_PROD_IMG_.'$1-$2.jpg [L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').'([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$'] = 'img/c/$1$2.jpg [L]';
|
||||
|
||||
Language::loadLanguages();
|
||||
$default_meta = Meta::getMetasByIdLang((int)Configuration::get('PS_LANG_DEFAULT'), new Shop($uri['id_shop']));
|
||||
|
||||
if ($multilang)
|
||||
foreach (Language::getLanguages() as $language)
|
||||
{
|
||||
foreach (Meta::getMetasByIdLang((int)$language['id_lang'], new Shop($uri['id_shop'])) as $key => $meta)
|
||||
if (!empty($meta['url_rewrite']) AND Validate::isLinkRewrite($meta['url_rewrite']))
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$language['iso_code'].'/'.$meta['url_rewrite'].'$'] = 'index.php?controller='.$meta['page'].'&isolang='.$language['iso_code'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '')
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$language['iso_code'].'/'.$default_meta[$key]['url_rewrite'].'$'] = 'index.php?controller='.$default_meta[$key]['page'].'&isolang='.$language['iso_code'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$language['iso_code'].'$'] = $language['iso_code'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$language['iso_code'].'/([^?&]*)$'] = '$2?isolang='.$language['iso_code'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
}
|
||||
else
|
||||
foreach ($default_meta as $key => $meta)
|
||||
if (!empty($meta['url_rewrite']))
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$meta['url_rewrite'].'$'] = 'index.php?controller='.$meta['page'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
else if (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '')
|
||||
$tab['RewriteRule'][$domain]['content']['^'.ltrim($uri['uri'], '/').''.$default_meta[$key]['url_rewrite'].'$'] = 'index.php?controller='.$default_meta[$key]['page'].'&id_shop='.$uri['id_shop'].' [QSA,L]';
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (!Configuration::get('PS_INSTALL_VERSION') OR version_compare(Configuration::get('PS_INSTALL_VERSION'), '1.4.0.7') == -1)
|
||||
{
|
||||
// This is a nasty copy/paste of the previous links, but with "lang-en" instead of "en"
|
||||
// Do not update it when you add something in the one at the top, it's only for the old links
|
||||
$tab['RewriteRule'][$domain]['content']['^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html'] = 'product.php?id_product=$4&isolang=$2 [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)\.html'] = 'product.php?id_product=$3&isolang=$2 [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^lang-([a-z]{2})/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'category.php?id_category=$3&isolang=$2 [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^content/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms=$2 [QSA,L]';
|
||||
$tab['RewriteRule'][$domain]['content']['^content/category/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms_category=$2 [QSA,L]';
|
||||
}
|
||||
*/
|
||||
// PS Comments
|
||||
// Write data in .htaccess file
|
||||
fwrite($writeFd, "# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again\n");
|
||||
fwrite($writeFd, "# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution\n");
|
||||
fwrite($writeFd, "# WARNING: PLEASE DO NOT MODIFY THIS FILE MANUALLY. IF NECESSARY, ADD YOUR SPECIFIC CONFIGURATION WITH THE HTACCESS GENERATOR IN BACK OFFICE\n");
|
||||
fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n");
|
||||
if (!empty($specific))
|
||||
fwrite($writeFd, $specific);
|
||||
// RewriteEngine
|
||||
fwrite($writeFd, "\n<IfModule mod_rewrite.c>\n");
|
||||
|
||||
// RewriteEngine
|
||||
fwrite($writeFd, "<IfModule mod_rewrite.c>\n");
|
||||
|
||||
// Disable multiviews ?
|
||||
if ($disableMuliviews)
|
||||
fwrite($writeFd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
|
||||
|
||||
fwrite($writeFd, $tab['RewriteEngine']['comment']."\nRewriteEngine on\n\n");
|
||||
fwrite($writeFd, $tab['RewriteRule']['comment']."\n");
|
||||
// Webservice
|
||||
fwrite($writeFd, 'RewriteRule ^api/?(.*)$ '.__PS_BASE_URI__."webservice/dispatcher.php?url=$1 [QSA,L]\n");
|
||||
|
||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\nRewriteCond %{REQUEST_FILENAME} -l [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^.*$ - [NC,L]\nRewriteRule ^.*\$ index.php [NC,L]\n");
|
||||
foreach ($domains AS $domain => $row)
|
||||
|
||||
fwrite($writeFd, "RewriteEngine on\n\n");
|
||||
foreach ($domains as $domain => $uri)
|
||||
{
|
||||
foreach ($row AS $uri)
|
||||
// Rewrite virtual multishop uri
|
||||
if ($uri['virtual'])
|
||||
{
|
||||
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
||||
fwrite($writeFd, $tab['ErrorDocument'][$domain]['comment']."\nErrorDocument ".$tab['ErrorDocument'][$domain]['content']."\n");
|
||||
// Classic URL rewriting
|
||||
if ($rewrite_settings)
|
||||
foreach ($tab['RewriteRule'][$domain]['content'] as $rule => $url)
|
||||
{
|
||||
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
||||
fwrite($writeFd, 'RewriteRule '.$rule.' '.$url."\n");
|
||||
}
|
||||
if (Tools::strlen(ltrim($uri['uri'], '/')) > 0)
|
||||
{
|
||||
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
||||
fwrite($writeFd, 'RewriteRule ^'.ltrim($uri['uri'], '/').'(.*) $1?id_shop='.$uri['id_shop'].' [QSA,L]'."\n");
|
||||
}
|
||||
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
||||
fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."/(.*) ".$uri['physical']."/$1 [L]\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Webservice
|
||||
fwrite($writeFd, 'RewriteRule ^api/?(.*)$ '.$uri['physical']."webservice/dispatcher.php?url=$1 [QSA,L]\n\n");
|
||||
|
||||
if ($rewrite_settings)
|
||||
{
|
||||
// Compatibility with the old image filesystem
|
||||
fwrite($writeFd, "# Images\n");
|
||||
if (Configuration::get('PS_LEGACY_IMAGES'))
|
||||
{
|
||||
fwrite($writeFd, 'RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ '._PS_PROD_IMG_.'$1-$2$3.jpg [L]'."\n");
|
||||
fwrite($writeFd, 'RewriteRule ^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$ '._PS_PROD_IMG_.'$1-$2.jpg [L]'."\n");
|
||||
}
|
||||
|
||||
// Rewrite product images < 100 millions
|
||||
for ($i = 1; $i <= 8; $i++)
|
||||
{
|
||||
$imgPath = $imgName = '';
|
||||
for ($j = 1; $j <= $i; $j++)
|
||||
{
|
||||
$imgPath .= '$'.$j.'/';
|
||||
$imgName .= '$'.$j;
|
||||
}
|
||||
$imgName .= '$'.$j;
|
||||
fwrite($writeFd, 'RewriteRule ^'.str_repeat('([0-9])', $i).'(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ '._PS_PROD_IMG_.$imgPath.$imgName.".jpg [L]\n");
|
||||
}
|
||||
fwrite($writeFd, 'RewriteRule ^c/([0-9]+)(\-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*\.jpg$ img/c/$1$2.jpg [L]'."\n");
|
||||
fwrite($writeFd, 'RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ img/c/$1.jpg [L]'."\n");
|
||||
}
|
||||
|
||||
// Redirections to dispatcher
|
||||
if ($rewrite_settings)
|
||||
{
|
||||
fwrite($writeFd, "\n# Dispatcher\n");
|
||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\n");
|
||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -l [OR]\n");
|
||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -d\n");
|
||||
fwrite($writeFd, "RewriteRule ^.*$ - [NC,L]\n");
|
||||
fwrite($writeFd, "RewriteRule ^.*\$ index.php [NC,L]\n");
|
||||
}
|
||||
|
||||
fwrite($writeFd, "</IfModule>\n\n");
|
||||
|
||||
// ErrorDocument
|
||||
|
||||
|
||||
// Cache control
|
||||
if ($cache_control)
|
||||
{
|
||||
$cacheControl = "
|
||||
<IfModule mod_expires.c>
|
||||
$cacheControl = "<IfModule mod_expires.c>
|
||||
ExpiresActive On
|
||||
ExpiresByType image/gif \"access plus 1 month\"
|
||||
ExpiresByType image/jpeg \"access plus 1 month\"
|
||||
@@ -1694,10 +1653,12 @@ FileETag INode MTime Size
|
||||
AddOutputFilterByType DEFLATE text/javascript
|
||||
AddOutputFilterByType DEFLATE application/javascript
|
||||
AddOutputFilterByType DEFLATE application/x-javascript
|
||||
</IfModule>
|
||||
";
|
||||
</IfModule>\n\n";
|
||||
fwrite($writeFd, $cacheControl);
|
||||
}
|
||||
|
||||
fwrite($writeFd, "# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again\n");
|
||||
fwrite($writeFd, "\n\n".trim($specificAfter));
|
||||
fclose($writeFd);
|
||||
|
||||
Module::hookExec('afterCreateHtaccess');
|
||||
|
||||
@@ -100,18 +100,11 @@ Language::loadLanguages();
|
||||
$defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
/* Instantiate cookie */
|
||||
$cookieLifetime = (time() + (((int)Configuration::get('PS_COOKIE_LIFETIME_BO') > 0 ? (int)Configuration::get('PS_COOKIE_LIFETIME_BO') : 1)* 3600));
|
||||
if (defined('PS_ADMIN_DIR'))
|
||||
{
|
||||
$currentFileName = array_reverse(explode("/", $_SERVER['SCRIPT_NAME']));
|
||||
$cookieLifetime = (time() + (((int)Configuration::get('PS_COOKIE_LIFETIME_BO') > 0 ? (int)Configuration::get('PS_COOKIE_LIFETIME_BO') : 1)* 3600));
|
||||
$cookie = new Cookie('psAdmin', substr($_SERVER['SCRIPT_NAME'], strlen(__PS_BASE_URI__), -strlen($currentFileName['0'])), $cookieLifetime);
|
||||
}
|
||||
$cookie = new Cookie('psAdmin', '', $cookieLifetime);
|
||||
else
|
||||
{
|
||||
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
|
||||
$cookieLifetime = (time() + (((int)Configuration::get('PS_COOKIE_LIFETIME_FO') > 0 ? (int)Configuration::get('PS_COOKIE_LIFETIME_FO') : 1)* 3600));
|
||||
$cookie = new Cookie('ps', '', $cookieLifetime);
|
||||
}
|
||||
Context::getContext()->cookie = $cookie;
|
||||
|
||||
/* Instantiate language */
|
||||
|
||||
+13
-12
@@ -1735,18 +1735,19 @@ CREATE TABLE IF NOT EXISTS `PREFIX_shop` (
|
||||
KEY `id_theme` (`id_theme`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_shop_url` (
|
||||
`id_shop_url` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_shop` int(11) unsigned NOT NULL,
|
||||
`domain` varchar(255) NOT NULL,
|
||||
`domain_ssl` varchar(255) NOT NULL,
|
||||
`uri` varchar(64) NOT NULL,
|
||||
`main` TINYINT(1) NOT NULL,
|
||||
`active` TINYINT(1) NOT NULL,
|
||||
PRIMARY KEY (`id_shop_url`),
|
||||
KEY `id_shop` (`id_shop`),
|
||||
UNIQUE KEY `shop_url` (`domain`, `uri`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_shop_url` (
|
||||
`id_shop_url` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id_shop` int(11) unsigned NOT NULL,
|
||||
`domain` varchar(255) NOT NULL,
|
||||
`domain_ssl` varchar(255) NOT NULL,
|
||||
`physical_uri` varchar(64) NOT NULL,
|
||||
`virtual_uri` varchar(64) NOT NULL,
|
||||
`main` TINYINT(1) NOT NULL,
|
||||
`active` TINYINT(1) NOT NULL,
|
||||
PRIMARY KEY (`id_shop_url`),
|
||||
KEY `id_shop` (`id_shop`),
|
||||
UNIQUE KEY `shop_url` (`domain`, `virtual_uri`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_theme` (
|
||||
`id_theme` int(11) NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -37,12 +37,13 @@ CREATE TABLE IF NOT EXISTS `PREFIX_shop_url` (
|
||||
`id_shop` int(11) unsigned NOT NULL,
|
||||
`domain` varchar(255) NOT NULL,
|
||||
`domain_ssl` varchar(255) NOT NULL,
|
||||
`uri` varchar(64) NOT NULL,
|
||||
`physical_uri` varchar(64) NOT NULL,
|
||||
`virtual_uri` varchar(64) NOT NULL,
|
||||
`main` TINYINT(1) NOT NULL,
|
||||
`active` TINYINT(1) NOT NULL,
|
||||
PRIMARY KEY (`id_shop_url`),
|
||||
KEY `id_shop` (`id_shop`),
|
||||
UNIQUE KEY `shop_url` (`domain`, `uri`)
|
||||
UNIQUE KEY `shop_url` (`domain`, `virtual_uri`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `PREFIX_theme` (
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
{if isset($lang_rewrite_urls.$indice_lang)}
|
||||
<a href="{$lang_rewrite_urls.$indice_lang}" title="{$language.name}">
|
||||
{else}
|
||||
<a href="{$link->getLanguageLink($language.id_lang, $language.name)}" title="{$language.name}">
|
||||
<a href="{$link->getLanguageLink($language.id_lang)}" title="{$language.name}">
|
||||
{/if}
|
||||
|
||||
{/if}
|
||||
|
||||
@@ -131,7 +131,7 @@ class GAnalytics extends Module
|
||||
|
||||
// Otherwise, create Google Analytics stats
|
||||
$ganalytics_id = Configuration::get('GANALYTICS_ID');
|
||||
$multilang = (Language::countActiveLanguages() > 1);
|
||||
$multilang = Language::isMultiLanguageActivated();
|
||||
$defaultMetaOrder = Meta::getMetaByPage('order',$this->context->language->id);
|
||||
$order = ($multilang?((string)Tools::getValue('isolang').'/'):'').$defaultMetaOrder['url_rewrite'];
|
||||
$pageTrack = ((strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__.'order.php') === 0 || strpos($_SERVER['REQUEST_URI'], __PS_BASE_URI__.($multilang?((string)Tools::getValue('isolang').'/'):'').$defaultMetaOrder['url_rewrite']) === 0) ? '/order/step'.(int)(Tools::getValue('step')).'.html' : '');
|
||||
|
||||
Reference in New Issue
Block a user