haylam.vn Posted September 7, 2011 Share Posted September 7, 2011 Viết lại đường dẫn thân thiện với tiếng Việt trong PrestaShop. Tạo đường dẫn thân thiện trong PrestaShop thay thế các ký tự tiếng Việt bằng các ký tự không dấu. Hỗ trợ SEO Prestashop Xem thêm Tạo đường dẫn URL thân thiện trong Prestashop Lưu ý: Lưu file với format UTF-8 without BOM. Áp dụng cho phiên bản PrestaShop 1.4.4 Với Prestashop 1.5 làm tương tự. Sửa File js/admin.js dòng 29 function strUnicodeToAscii(str){ str = str.replace(/[\'\~\@\#\%\^\&]/g,''); str = str.replace(/[\u0105\u0104\u00E4\u00E5\u00E0\u00C0\u1EA3\u1EA2\u00E3\u00C3\u00E1\u00C1\u1EA1\u1EA0\u0103\u0102\u1EB1\u1EB0\u1EB3\u1EB2\u1EB5\u1EB4\u1EAF\u1EAE\u1EB7\u1EB6\u00E2\u00C2\u1EA7\u1EA6\u1EA9\u1EA8\u1EAB\u1EAA\u1EA5\u1EA4\u1EAD\u1EAC]/g,'a'); str = str.replace(/[\u00E7\u010D\u0107\u0106]/g,'c'); str = str.replace(/[\u0111\u0110\u010F]/g,'d'); str = str.replace(/[\u00EB\u0119\u011B\u0118\u00E8\u00C8\u1EBB\u1EBA\u1EBD\u1EBC\u00E9\u00C9\u1EB9\u1EB8\u00EA\u00CA\u1EC1\u1EC0\u1EC3\u1EC2\u1EC5\u1EC4\u1EBF\u1EBE\u1EC7\u1EC6]/g,'e'); str = str.replace(/[\u00EC\u00CC\u1EC9\u1EC8\u0129\u0128\u00ED\u00CD\u1ECB\u1ECA\u00EE\u00EF]/g,'i'); str = str.replace(/[\u0142\u0141\u013E\u013A]/g,'l'); str = str.replace(/[\u00F1\u0148]/g,'n'); str = str.replace(/[\u00F2\u00D2\u1ECF\u1ECE\u00F5\u00F6\u00F8\u00D5\u00F3\u00D3\u1ECD\u1ECC\u00F4\u00D4\u1ED3\u1ED2\u1ED5\u1ED4\u1ED7\u1ED6\u1ED1\u1ED0\u1ED9\u1ED8\u01A1\u01A0\u1EDD\u1EDC\u1EDF\u1EDE\u1EE1\u1EE0\u1EDB\u1EDA\u1EE3\u1EE2]/g,'o'); str = str.replace(/[\u0159\u0155]/g,'r'); str = str.replace(/[\u015B\u015A\u0161]/g,'s'); str = str.replace(/[\u0165]/g,'t'); str = str.replace(/[\u00F9\u00D9\u1EE7\u1EE6\u0169\u0168\u00FA\u00DA\u1EE5\u1EE4\u01B0\u01AF\u1EEB\u1EEA\u1EED\u1EEC\u1EEF\u1EEE\u1EE9\u1EE8\u1EF1\u1EF0\u00FB\u00FC\u016F]/g,'u'); str = str.replace(/[\u1EF3\u1EF2\u1EF7\u1EF6\u1EF9\u1EF8\u00FD\u00DD\u1EF5\u1EF4\u00FF]/g,'y'); str = str.replace(/[\u017C\u017A\u017B\u0179\u017E]/g,'z'); str = str.replace(/[\u0153]/g,'oe'); str = str.replace(/[\u00E6]/g,'ae'); str = str.replace(/[\u00DF]/g,'ss'); str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]/g,''); str = str.replace(/[\s\'\:\/\[\]-]+/g,' '); str = str.replace(/[ ]/g,'-'); str = str.replace(/[\/]/g,'-'); return str; } function str2url(str,encoding,ucfirst) { str = str.toUpperCase(); str = str.toLowerCase(); str = strUnicodeToAscii(str); if (ucfirst == 1) { c = str.charAt(0); str = c.toUpperCase()+str.slice(1); } return str; } function strToAltImgAttr(str,encoding,ucfirst) { str = strUnicodeToAscii(str); if (ucfirst == 1) { c = str.charAt(0); str = c.toUpperCase()+str.slice(1); } return str; } Bước 2: Sửa File classes/Tools.php dòng 953 /** * Return a friendly url made from the provided string * If the mbstring library is available, the output is the same as the js function of the same name * * @param string $str * @return string */ public static function str2url($str) { if (function_exists('mb_strtolower')) $str = mb_strtolower($str, 'utf-8'); /*friendly url for vietnamese *coded by thetoan.cao */ $trans = array( "đ"=>"d","ă"=>"a","â"=>"a","á"=>"a","à"=>"a","ả"=>"a","ã"=>"a","ạ"=>"a", "ấ"=>"a","ầ"=>"a","ẩ"=>"a","ẫ"=>"a","ậ"=>"a", "ắ"=>"a","ằ"=>"a","ẳ"=>"a","ẵ"=>"a","ặ"=>"a", "é"=>"e","è"=>"e","ẻ"=>"e","ẽ"=>"e","ẹ"=>"e", "ế"=>"e","ề"=>"e","ể"=>"e","ễ"=>"e","ệ"=>"e", "í"=>"i","ì"=>"i","ỉ"=>"i","ĩ"=>"i","ị"=>"i", "ư"=>"u","ô"=>"o","ơ"=>"o","ê"=>"e", "Ư"=>"u","Ô"=>"o","Ơ"=>"o","Ê"=>"e", "ú"=>"u","ù"=>"u","ủ"=>"u","ũ"=>"u","ụ"=>"u", "ứ"=>"u","ừ"=>"u","ử"=>"u","ữ"=>"u","ự"=>"u", "ó"=>"o","ò"=>"o","ỏ"=>"o","õ"=>"o","ọ"=>"o", "ớ"=>"o","ờ"=>"o","ở"=>"o","ỡ"=>"o","ợ"=>"o", "ố"=>"o","ồ"=>"o","ổ"=>"o","ỗ"=>"o","ộ"=>"o", "ú"=>"u","ù"=>"u","ủ"=>"u","ũ"=>"u","ụ"=>"u", "ứ"=>"u","ừ"=>"u","ử"=>"u","ữ"=>"u","ự"=>"u",'ý'=>'y','ỳ'=>'y','ỷ'=>'y','ỹ'=>'y','ỵ'=>'y', 'Ý'=>'Y','Ỳ'=>'Y','Ỷ'=>'Y','Ỹ'=>'Y','Ỵ'=>'Y', "Đ"=>"D","Ă"=>"A","Â"=>"A","Á"=>"A","À"=>"A","Ả"=>"A","Ã"=>"A","Ạ"=>"A", "Ấ"=>"A","Ầ"=>"A","Ẩ"=>"A","Ẫ"=>"A","Ậ"=>"A", "Ắ"=>"A","Ằ"=>"A","Ẳ"=>"A","Ẵ"=>"A","Ặ"=>"A", "É"=>"E","È"=>"E","Ẻ"=>"E","Ẽ"=>"E","Ẹ"=>"E", "Ế"=>"E","Ề"=>"E","Ể"=>"E","Ễ"=>"E","Ệ"=>"E", "Í"=>"I","Ì"=>"I","Ỉ"=>"I","Ĩ"=>"I","Ị"=>"I", "Ư"=>"U","Ô"=>"O","Ơ"=>"O","Ê"=>"E", "Ư"=>"U","Ô"=>"O","Ơ"=>"O","Ê"=>"E", "Ú"=>"U","Ù"=>"U","Ủ"=>"U","Ũ"=>"U","Ụ"=>"U", "Ứ"=>"U","Ừ"=>"U","Ử"=>"U","Ữ"=>"U","Ự"=>"U", "Ó"=>"O","Ò"=>"O","Ỏ"=>"O","Õ"=>"O","Ọ"=>"O", "Ớ"=>"O","Ờ"=>"O","Ở"=>"O","Ỡ"=>"O","Ợ"=>"O", "Ố"=>"O","Ồ"=>"O","Ổ"=>"O","Ỗ"=>"O","Ộ"=>"O", "Ú"=>"U","Ù"=>"U","Ủ"=>"U","Ũ"=>"U","Ụ"=>"U", "Ứ"=>"U","Ừ"=>"U","Ử"=>"U","Ữ"=>"U","Ự"=>"U",); $str = trim($str); $str = strtr($str, $trans); /*friendly url for vietnamese *coded by thetoan.cao */ $str = preg_replace('/[\x{0105}\x{0104}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u','a', $str); $str = preg_replace('/[\x{00E7}\x{010D}\x{0107}\x{0106}]/u','c', $str); $str = preg_replace('/[\x{010F}]/u','d', $str); $str = preg_replace('/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{011B}\x{0119}\x{0118}]/u','e', $str); $str = preg_replace('/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}]/u','i', $str); $str = preg_replace('/[\x{0142}\x{0141}\x{013E}\x{013A}]/u','l', $str); $str = preg_replace('/[\x{00F1}\x{0148}]/u','n', $str); $str = preg_replace('/[\x{00F2}\x{00F3}\x{00F4}\x{00F5}\x{00F6}\x{00F8}\x{00D3}]/u','o', $str); $str = preg_replace('/[\x{0159}\x{0155}]/u','r', $str); $str = preg_replace('/[\x{015B}\x{015A}\x{0161}]/u','s', $str); $str = preg_replace('/[\x{00DF}]/u','ss', $str); $str = preg_replace('/[\x{0165}]/u','t', $str); $str = preg_replace('/[\x{00F9}\x{00FA}\x{00FB}\x{00FC}\x{016F}]/u','u', $str); $str = preg_replace('/[\x{00FD}\x{00FF}]/u','y', $str); $str = preg_replace('/[\x{017C}\x{017A}\x{017B}\x{0179}\x{017E}]/u','z', $str); $str = preg_replace('/[\x{00E6}]/u','ae', $str); $str = preg_replace('/[\x{0153}]/u','oe', $str); // Remove all non-whitelist chars. $str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]-]/','', $str); $str = preg_replace('/[\s\'\:\/\[\]-]+/',' ', $str); $str = preg_replace('/[ ]/','-', $str); $str = preg_replace('/[\/]/','-', $str); // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations. // This way we lose fewer special chars. $str = strtolower($str); return $str; } Lưu ý: Lưu file với format UTF-8 without BOM. Download mã nguồn Nguồn Kênh 360 Công nghệ 7 Link to comment Share on other sites More sharing options...
quochuy689 Posted December 16, 2012 Share Posted December 16, 2012 bài hay thế này mà k ai like 1 Link to comment Share on other sites More sharing options...
hoanghuonghn Posted April 11, 2013 Share Posted April 11, 2013 Bài viết mình đang cần..like ủng hộ bạn nhé.. ------------- truyen ngan | Van hoc the gioi | Tour ghep mien bac 1 Link to comment Share on other sites More sharing options...
haylam.vn Posted April 19, 2013 Author Share Posted April 19, 2013 Mới edit lại bài cho ae dễ nhìn Có vấn đề gì mọi người báo lại nhé. Link to comment Share on other sites More sharing options...
Recommended Posts