// Fix adminMeta (dispatcher notices) + generateHtaccess
This commit is contained in:
@@ -75,7 +75,7 @@ class AdminMeta extends AdminTab
|
|||||||
public function addFieldRoute($routeID, $title)
|
public function addFieldRoute($routeID, $title)
|
||||||
{
|
{
|
||||||
$keywords = array();
|
$keywords = array();
|
||||||
foreach (Dispatcher::getInstance()->defaultRoutes[$routeID]['keywords'] as $keyword => $data)
|
foreach (Dispatcher::getInstance()->default_routes[$routeID]['keywords'] as $keyword => $data)
|
||||||
$keywords[] = ((isset($data['param'])) ? '<span class="red">'.$keyword.'*</span>' : $keyword);
|
$keywords[] = ((isset($data['param'])) ? '<span class="red">'.$keyword.'*</span>' : $keyword);
|
||||||
|
|
||||||
$this->optionsList['routes']['fields']['PS_ROUTE_'.$routeID] = array(
|
$this->optionsList['routes']['fields']['PS_ROUTE_'.$routeID] = array(
|
||||||
@@ -84,7 +84,7 @@ class AdminMeta extends AdminTab
|
|||||||
'validation' => 'isString',
|
'validation' => 'isString',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'size' => 70,
|
'size' => 70,
|
||||||
'defaultValue' => Dispatcher::getInstance()->defaultRoutes[$routeID]['rule'],
|
'defaultValue' => Dispatcher::getInstance()->default_routes[$routeID]['rule'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,12 +226,12 @@ class AdminMeta extends AdminTab
|
|||||||
*/
|
*/
|
||||||
public function checkAndUpdateRoute($routeID)
|
public function checkAndUpdateRoute($routeID)
|
||||||
{
|
{
|
||||||
$defaultRoutes = Dispatcher::getInstance()->defaultRoutes;
|
$default_routes = Dispatcher::getInstance()->default_routes;
|
||||||
if (!isset($defaultRoutes[$routeID]))
|
if (!isset($default_routes[$routeID]))
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
$rule = Tools::getValue('PS_ROUTE_'.$routeID);
|
$rule = Tools::getValue('PS_ROUTE_'.$routeID);
|
||||||
if (!$rule || $rule == $defaultRoutes[$routeID]['rule'])
|
if (!$rule || $rule == $default_routes[$routeID]['rule'])
|
||||||
{
|
{
|
||||||
Configuration::updateValue('PS_ROUTE_'.$routeID, '');
|
Configuration::updateValue('PS_ROUTE_'.$routeID, '');
|
||||||
return ;
|
return ;
|
||||||
|
|||||||
+46
-46
@@ -1559,113 +1559,113 @@ class ToolsCore
|
|||||||
return self::getHttpHost();
|
return self::getHttpHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disableMuliviews = false)
|
public static function generateHtaccess($path, $rewrite_settings, $cache_control, $specific = '', $disable_multiviews = false)
|
||||||
{
|
{
|
||||||
// Check current content of .htaccess and save all code outside of prestashop comments
|
// Check current content of .htaccess and save all code outside of prestashop comments
|
||||||
$specificBefore = $specificAfter = '';
|
$specific_before = $specific_after = '';
|
||||||
if (file_exists($path))
|
if (file_exists($path))
|
||||||
{
|
{
|
||||||
$content = file_get_contents($path);
|
$content = file_get_contents($path);
|
||||||
if (preg_match('#^(.*)\# ~~start~~.*\# ~~end~~[^\n]*(.*)$#s', $content, $m))
|
if (preg_match('#^(.*)\# ~~start~~.*\# ~~end~~[^\n]*(.*)$#s', $content, $m))
|
||||||
{
|
{
|
||||||
$specificBefore = $m[1];
|
$specific_before = $m[1];
|
||||||
$specificAfter = $m[2];
|
$specific_after = $m[2];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// For retrocompatibility
|
// For retrocompatibility
|
||||||
if (preg_match('#\# http://www\.prestashop\.com - http://www\.prestashop\.com/forums\s*(.*)<IfModule mod_rewrite\.c>#si', $content, $m))
|
if (preg_match('#\# http://www\.prestashop\.com - http://www\.prestashop\.com/forums\s*(.*)<IfModule mod_rewrite\.c>#si', $content, $m))
|
||||||
$specificBefore = $m[1];
|
$specific_before = $m[1];
|
||||||
else
|
else
|
||||||
$specificBefore = $content;
|
$specific_before = $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write .htaccess data
|
// Write .htaccess data
|
||||||
if (!$writeFd = @fopen($path, 'w'))
|
if (!$write_fd = @fopen($path, 'w'))
|
||||||
return false;
|
return false;
|
||||||
fwrite($writeFd, trim($specificBefore)."\n\n");
|
fwrite($write_fd, trim($specific_before)."\n\n");
|
||||||
|
|
||||||
$domains = array();
|
$domains = array();
|
||||||
foreach (ShopUrl::getShopUrls() as $shopUrl)
|
foreach (ShopUrl::getShopUrls() as $shop_url)
|
||||||
{
|
{
|
||||||
if (!isset($domains[$shopUrl['domain']]))
|
if (!isset($domains[$shop_url['domain']]))
|
||||||
$domains[$shopUrl['domain']] = array();
|
$domains[$shop_url['domain']] = array();
|
||||||
|
|
||||||
$domains[$shopUrl['domain']] = array(
|
$domains[$shop_url['domain']][] = array(
|
||||||
'physical' => $shopUrl['physical_uri'],
|
'physical' => $shop_url['physical_uri'],
|
||||||
'virtual' => $shopUrl['virtual_uri'],
|
'virtual' => $shop_url['virtual_uri'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write data in .htaccess file
|
// 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($write_fd, "# ~~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($write_fd, "# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution\n");
|
||||||
fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n");
|
fwrite($write_fd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n");
|
||||||
|
|
||||||
// RewriteEngine
|
// RewriteEngine
|
||||||
fwrite($writeFd, "<IfModule mod_rewrite.c>\n");
|
fwrite($write_fd, "<IfModule mod_rewrite.c>\n");
|
||||||
|
|
||||||
// Disable multiviews ?
|
// Disable multiviews ?
|
||||||
if ($disableMuliviews)
|
if ($disable_multiviews)
|
||||||
fwrite($writeFd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
|
fwrite($write_fd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
|
||||||
|
|
||||||
fwrite($writeFd, "RewriteEngine on\n\n");
|
fwrite($write_fd, "RewriteEngine on\n\n");
|
||||||
foreach ($domains as $domain => $list_uri)
|
foreach ($domains as $domain => $list_uri)
|
||||||
foreach ($list_uri as $uri)
|
foreach ($list_uri as $uri)
|
||||||
// Rewrite virtual multishop uri
|
// Rewrite virtual multishop uri
|
||||||
if ($uri['virtual'])
|
if ($uri['virtual'])
|
||||||
{
|
{
|
||||||
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
fwrite($write_fd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
|
||||||
fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."$1 [L]\n\n");
|
fwrite($write_fd, 'RewriteRule ^'.ltrim($uri['virtual'], '/').'(.*) '.$uri['physical']."$1 [L]\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webservice
|
// Webservice
|
||||||
fwrite($writeFd, 'RewriteRule ^api/?(.*)$ '."webservice/dispatcher.php?url=$1 [QSA,L]\n\n");
|
fwrite($write_fd, 'RewriteRule ^api/?(.*)$ '."webservice/dispatcher.php?url=$1 [QSA,L]\n\n");
|
||||||
|
|
||||||
if ($rewrite_settings)
|
if ($rewrite_settings)
|
||||||
{
|
{
|
||||||
// Compatibility with the old image filesystem
|
// Compatibility with the old image filesystem
|
||||||
fwrite($writeFd, "# Images\n");
|
fwrite($write_fd, "# Images\n");
|
||||||
if (Configuration::get('PS_LEGACY_IMAGES'))
|
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($write_fd, '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");
|
fwrite($write_fd, 'RewriteRule ^([0-9]+)\-([0-9]+)/[_a-zA-Z0-9-]*\.jpg$ '._PS_PROD_IMG_.'$1-$2.jpg [L]'."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite product images < 100 millions
|
// Rewrite product images < 100 millions
|
||||||
for ($i = 1; $i <= 8; $i++)
|
for ($i = 1; $i <= 8; $i++)
|
||||||
{
|
{
|
||||||
$imgPath = $imgName = '';
|
$img_path = $img_name = '';
|
||||||
for ($j = 1; $j <= $i; $j++)
|
for ($j = 1; $j <= $i; $j++)
|
||||||
{
|
{
|
||||||
$imgPath .= '$'.$j.'/';
|
$img_path .= '$'.$j.'/';
|
||||||
$imgName .= '$'.$j;
|
$img_name .= '$'.$j;
|
||||||
}
|
}
|
||||||
$imgName .= '$'.$j;
|
$img_name .= '$'.$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($write_fd, 'RewriteRule ^'.str_repeat('([0-9])', $i).'(\-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*\.jpg$ '._PS_PROD_IMG_.$img_path.$img_name.".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($write_fd, '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");
|
fwrite($write_fd, 'RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ img/c/$1.jpg [L]'."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirections to dispatcher
|
// Redirections to dispatcher
|
||||||
if ($rewrite_settings)
|
if ($rewrite_settings)
|
||||||
{
|
{
|
||||||
fwrite($writeFd, "\n# Dispatcher\n");
|
fwrite($write_fd, "\n# Dispatcher\n");
|
||||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\n");
|
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\n");
|
||||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -l [OR]\n");
|
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -l [OR]\n");
|
||||||
fwrite($writeFd, "RewriteCond %{REQUEST_FILENAME} -d\n");
|
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -d\n");
|
||||||
fwrite($writeFd, "RewriteRule ^.*$ - [NC,L]\n");
|
fwrite($write_fd, "RewriteRule ^.*$ - [NC,L]\n");
|
||||||
fwrite($writeFd, "RewriteRule ^.*\$ index.php [NC,L]\n");
|
fwrite($write_fd, "RewriteRule ^.*\$ index.php [NC,L]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite($writeFd, "</IfModule>\n\n");
|
fwrite($write_fd, "</IfModule>\n\n");
|
||||||
|
|
||||||
// Cache control
|
// Cache control
|
||||||
if ($cache_control)
|
if ($cache_control)
|
||||||
{
|
{
|
||||||
$cacheControl = "<IfModule mod_expires.c>
|
$cache_control = "<IfModule mod_expires.c>
|
||||||
ExpiresActive On
|
ExpiresActive On
|
||||||
ExpiresByType image/gif \"access plus 1 month\"
|
ExpiresByType image/gif \"access plus 1 month\"
|
||||||
ExpiresByType image/jpeg \"access plus 1 month\"
|
ExpiresByType image/jpeg \"access plus 1 month\"
|
||||||
@@ -1685,12 +1685,12 @@ FileETag INode MTime Size
|
|||||||
AddOutputFilterByType DEFLATE application/javascript
|
AddOutputFilterByType DEFLATE application/javascript
|
||||||
AddOutputFilterByType DEFLATE application/x-javascript
|
AddOutputFilterByType DEFLATE application/x-javascript
|
||||||
</IfModule>\n\n";
|
</IfModule>\n\n";
|
||||||
fwrite($writeFd, $cacheControl);
|
fwrite($write_fd, $cache_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
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($write_fd, "# ~~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));
|
fwrite($write_fd, "\n\n".trim($specific_after));
|
||||||
fclose($writeFd);
|
fclose($write_fd);
|
||||||
|
|
||||||
Module::hookExec('afterCreateHtaccess');
|
Module::hookExec('afterCreateHtaccess');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user