Guest User

Prestashop hidding accents in Url Rewriting patch

a guest
Nov 12th, 2012
328
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff -Naur prestashop_old/classes/Link.php prestashop/classes/Link.php
  2. --- prestashop_old/classes/Link.php 2012-11-12 22:29:18.761238985 +0100
  3. +++ prestashop/classes/Link.php 2012-11-12 22:28:48.463863350 +0100
  4. @@ -43,6 +43,9 @@
  5.     public function __construct($protocol_link = null, $protocol_content = null)
  6.     {
  7.         $this->allow = (int)Configuration::get('PS_REWRITING_SETTINGS');
  8. +       //This check because if patched without loading and setting the value in admin/SEO pannel (which sets the PS_REWRITING_ACCEPT_ACCENTS in the database),
  9. +       //we should continue with the old behavior (ie: with accents)
  10. +       $this->allow_accents = !is_bool(Configuration::get('PS_REWRITING_ACCEPT_ACCENTS')) ? (int)Configuration::get('PS_REWRITING_ACCEPT_ACCENTS') : 1;
  11.         $this->url = $_SERVER['SCRIPT_NAME'];
  12.         $this->protocol_link = $protocol_link;
  13.         $this->protocol_content = $protocol_content;
  14. @@ -107,7 +110,11 @@
  15.         // Set available keywords
  16.         $params = array();
  17.         $params['id'] = $product->id;
  18. -       $params['rewrite'] = (!$alias) ? $product->getFieldByLang('link_rewrite') : $alias;
  19. +
  20. +       if(!$this->allow_accents)
  21. +           $params['rewrite'] = (!$alias) ? Tools::replaceAccentedChars($product->getFieldByLang('link_rewrite')) : Tools::replaceAccentedChars($alias);
  22. +       else
  23. +           $params['rewrite'] = (!$alias) ? $product->getFieldByLang('link_rewrite') : $alias;
  24.         $params['ean13'] = (!$ean13) ? $product->ean13 : $ean13;
  25.         $params['meta_keywords'] =  Tools::str2url($product->getFieldByLang('meta_keywords'));
  26.         $params['meta_title'] = Tools::str2url($product->getFieldByLang('meta_title'));
  27. @@ -131,8 +138,12 @@
  28.         {
  29.             $params['category'] = (!$category) ? $product->category : $category;
  30.             $cats = array();
  31. -           foreach ($product->getParentCategories() as $cat)
  32. -               $cats[] = $cat['link_rewrite'];
  33. +           foreach ($product->getParentCategories() as $cat){
  34. +               $link_rewrite = $cat['link_rewrite'];
  35. +               if(!$this->allow_accents)
  36. +                   $link_rewrite = Tools::replaceAccentedChars($link_rewrite);
  37. +               $cats[] = $link_rewrite;
  38. +           }
  39.             $params['categories'] = implode('/', $cats);
  40.         }
  41.         $anchor = $ipa ? $product->getAnchor($ipa) : '';
  42. @@ -161,7 +172,11 @@
  43.         // Set available keywords
  44.         $params = array();
  45.         $params['id'] = $category->id;
  46. -       $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
  47. +       if(!$this->allow_accents)
  48. +           $params['rewrite'] = (!$alias) ? Tools::replaceAccentedChars($category->link_rewrite) : Tools::replaceAccentedChars($alias);
  49. +       else
  50. +           $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
  51. +      
  52.         $params['meta_keywords'] =  Tools::str2url($category->meta_keywords);
  53.         $params['meta_title'] = Tools::str2url($category->meta_title);
  54.  
  55. @@ -199,7 +214,10 @@
  56.         // Set available keywords
  57.         $params = array();
  58.         $params['id'] = $category->id;
  59. -       $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
  60. +       if(!$this->allow_accents)
  61. +           $params['rewrite'] = (!$alias) ? Tools::replaceAccentedChars($category->link_rewrite) : Tools::replaceAccentedChars($alias);
  62. +       else
  63. +           $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias;
  64.         $params['meta_keywords'] =  Tools::str2url($category->meta_keywords);
  65.         $params['meta_title'] = Tools::str2url($category->meta_title);
  66.  
  67. @@ -229,7 +247,10 @@
  68.         // Set available keywords
  69.         $params = array();
  70.         $params['id'] = $cms->id;
  71. -       $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias;
  72. +       if(!$this->allow_accents)
  73. +           $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? Tools::replaceAccentedChars($cms->link_rewrite[(int)$id_lang]) : Tools::replaceAccentedChars($cms->link_rewrite)) : Tools::replaceAccentedChars($alias);
  74. +       else
  75. +           $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias;
  76.  
  77.         if (isset($cms->meta_keywords) && !empty($cms->meta_keywords))
  78.             $params['meta_keywords'] = is_array($cms->meta_keywords) ?  Tools::str2url($cms->meta_keywords[(int)$id_lang]) :  Tools::str2url($cms->meta_keywords);
  79. @@ -264,7 +285,10 @@
  80.         // Set available keywords
  81.         $params = array();
  82.         $params['id'] = $supplier->id;
  83. -       $params['rewrite'] = (!$alias) ? $supplier->link_rewrite : $alias;
  84. +       if(!$this->allow_accents)
  85. +           $params['rewrite'] = (!$alias) ? Tools::replaceAccentedChars($supplier->link_rewrite) : Tools::replaceAccentedChars($alias);
  86. +       else
  87. +           $params['rewrite'] = (!$alias) ? $supplier->link_rewrite : $alias;
  88.         $params['meta_keywords'] =  Tools::str2url($supplier->meta_keywords);
  89.         $params['meta_title'] = Tools::str2url($supplier->meta_title);
  90.  
  91. @@ -291,7 +315,10 @@
  92.         // Set available keywords
  93.         $params = array();
  94.         $params['id'] = $manufacturer->id;
  95. -       $params['rewrite'] = (!$alias) ? $manufacturer->link_rewrite : $alias;
  96. +       if(!$this->allow_accents)
  97. +           $params['rewrite'] = (!$alias) ? Tools::replaceAccentedChars($manufacturer->link_rewrite) : Tools::replaceAccentedChars($alias);
  98. +       else
  99. +           $params['rewrite'] = (!$alias) ? $manufacturer->link_rewrite : $alias;
  100.         $params['meta_keywords'] =  Tools::str2url($manufacturer->meta_keywords);
  101.         $params['meta_title'] = Tools::str2url($manufacturer->meta_title);
  102.  
  103. @@ -354,6 +381,8 @@
  104.      */
  105.     public function getImageLink($name, $ids, $type = null)
  106.     {
  107. +       if(!$this->allow_accents)
  108. +           $name = Tools::replaceAccentedChars($name);
  109.         $not_default = false;
  110.         // legacy mode or default image
  111.         $theme = ((Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_.$ids.($type ? '-'.$type : '').'-'.(int)Context::getContext()->shop->id_theme.'.jpg')) ? '-'.Context::getContext()->shop->id_theme : '');
  112. @@ -377,7 +406,6 @@
  113.             else
  114.                 $uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').$theme.'.jpg';
  115.         }
  116. -
  117.         return $this->protocol_content.Tools::getMediaServer($uri_path).$uri_path;
  118.     }
  119.  
  120. diff -Naur prestashop_old/controllers/admin/AdminMetaController.php prestashop/controllers/admin/AdminMetaController.php
  121. --- prestashop_old/controllers/admin/AdminMetaController.php    2012-11-12 22:29:06.787625892 +0100
  122. +++ prestashop/controllers/admin/AdminMetaController.php    2012-11-12 20:06:31.132509986 +0100
  123. @@ -72,6 +72,13 @@
  124.                 'cast' => 'intval',
  125.                 'type' => 'bool'
  126.             ),
  127. +           'PS_REWRITING_ACCEPT_ACCENTS' => array(
  128. +               'title' => $this->l('Accept accents in url rewriting'),
  129. +               'desc' => $this->l('Recommended, but your webserver must be compliant'),
  130. +               'validation' => 'isBool',
  131. +               'cast' => 'intval',
  132. +               'type' => 'bool'
  133. +           ),
  134.         );
  135.  
  136.         $url_description = '';
RAW Paste Data