// Fix adminMeta (dispatcher notices) + generateHtaccess

This commit is contained in:
rMalie
2011-09-14 08:53:37 +00:00
parent 483bcc121b
commit 0dd3f002e3
2 changed files with 54 additions and 54 deletions
+5 -5
View File
@@ -75,7 +75,7 @@ class AdminMeta extends AdminTab
public function addFieldRoute($routeID, $title)
{
$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);
$this->optionsList['routes']['fields']['PS_ROUTE_'.$routeID] = array(
@@ -84,7 +84,7 @@ class AdminMeta extends AdminTab
'validation' => 'isString',
'type' => 'text',
'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)
{
$defaultRoutes = Dispatcher::getInstance()->defaultRoutes;
if (!isset($defaultRoutes[$routeID]))
$default_routes = Dispatcher::getInstance()->default_routes;
if (!isset($default_routes[$routeID]))
return ;
$rule = Tools::getValue('PS_ROUTE_'.$routeID);
if (!$rule || $rule == $defaultRoutes[$routeID]['rule'])
if (!$rule || $rule == $default_routes[$routeID]['rule'])
{
Configuration::updateValue('PS_ROUTE_'.$routeID, '');
return ;
+49 -49
View File
@@ -1559,113 +1559,113 @@ class ToolsCore
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
$specificBefore = $specificAfter = '';
$specific_before = $specific_after = '';
if (file_exists($path))
{
$content = file_get_contents($path);
if (preg_match('#^(.*)\# ~~start~~.*\# ~~end~~[^\n]*(.*)$#s', $content, $m))
{
$specificBefore = $m[1];
$specificAfter = $m[2];
$specific_before = $m[1];
$specific_after = $m[2];
}
else
{
// For retrocompatibility
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
$specificBefore = $content;
$specific_before = $content;
}
}
// Write .htaccess data
if (!$writeFd = @fopen($path, 'w'))
if (!$write_fd = @fopen($path, 'w'))
return false;
fwrite($writeFd, trim($specificBefore)."\n\n");
fwrite($write_fd, trim($specific_before)."\n\n");
$domains = array();
foreach (ShopUrl::getShopUrls() as $shopUrl)
foreach (ShopUrl::getShopUrls() as $shop_url)
{
if (!isset($domains[$shopUrl['domain']]))
$domains[$shopUrl['domain']] = array();
if (!isset($domains[$shop_url['domain']]))
$domains[$shop_url['domain']] = array();
$domains[$shopUrl['domain']] = array(
'physical' => $shopUrl['physical_uri'],
'virtual' => $shopUrl['virtual_uri'],
$domains[$shop_url['domain']][] = array(
'physical' => $shop_url['physical_uri'],
'virtual' => $shop_url['virtual_uri'],
);
}
// 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, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\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($write_fd, "# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution\n");
fwrite($write_fd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n");
// RewriteEngine
fwrite($writeFd, "<IfModule mod_rewrite.c>\n");
fwrite($write_fd, "<IfModule mod_rewrite.c>\n");
// Disable multiviews ?
if ($disableMuliviews)
fwrite($writeFd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");
if ($disable_multiviews)
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 ($list_uri as $uri)
// Rewrite virtual multishop uri
if ($uri['virtual'])
{
fwrite($writeFd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
fwrite($writeFd, "RewriteRule ^".ltrim($uri['virtual'], '/')."(.*) ".$uri['physical']."$1 [L]\n\n");
fwrite($write_fd, 'RewriteCond %{HTTP_HOST} ^'.$domain.'$'."\n");
fwrite($write_fd, 'RewriteRule ^'.ltrim($uri['virtual'], '/').'(.*) '.$uri['physical']."$1 [L]\n\n");
}
// 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)
{
// Compatibility with the old image filesystem
fwrite($writeFd, "# Images\n");
fwrite($write_fd, "# 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");
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($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
for ($i = 1; $i <= 8; $i++)
{
$imgPath = $imgName = '';
$img_path = $img_name = '';
for ($j = 1; $j <= $i; $j++)
{
$imgPath .= '$'.$j.'/';
$imgName .= '$'.$j;
$img_path .= '$'.$j.'/';
$img_name .= '$'.$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");
$img_name .= '$'.$j;
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($writeFd, 'RewriteRule ^c/([a-zA-Z-]+)/[a-zA-Z0-9-]+\.jpg$ img/c/$1.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($write_fd, '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($write_fd, "\n# Dispatcher\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -l [OR]\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -d\n");
fwrite($write_fd, "RewriteRule ^.*$ - [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
if ($cache_control)
{
$cacheControl = "<IfModule mod_expires.c>
$cache_control = "<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif \"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/x-javascript
</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($writeFd, "\n\n".trim($specificAfter));
fclose($writeFd);
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($write_fd, "\n\n".trim($specific_after));
fclose($write_fd);
Module::hookExec('afterCreateHtaccess');