Lỗi mất ký tự tiếng Việt trong tiêu đề Joomla 1.5 + 2.5
Lỗi mất ký tự tiếng Việt trong tiêu đề Joomla 1.5

Cách khắc phục
Bước 1: Tìm file [Joomla1.5]/libraries/joomla/filter/filteroutput.php
Bước 2: Mở file này bằng trình soạn thảo Notepad++ (miễn phí, nhanh, gọn...).
Bước 3: Save file bằng định dạng UTF-8 Without BOM: cho phép lưu các ký tự UTF-8 và quan trọng là không có ký tự đánh dấu UTF8 ở đầu file. Xem hình để rõ hơn

Bước 4: Tìm đến ~ dòng 87 và chèn thêm 10 dòng mã sau (dòng 88-97):

10 dòng mã cần chèn:
$utf8characters = 'à|a, ả|a, ã|a, á|a, ạ|a, ă|a, ằ|a, ẳ|a, ẵ|a, ắ|a, ặ|a, â|a, ầ|a, ẩ|a, ẫ|a, ấ|a, ậ|a, đ|d, è|e, ẻ|e, ẽ|e, é|e, ẹ|e, ê|e, ề|e, ể|e, ễ|e, ế|e, ệ|e, ì|i, ỉ|i, ĩ|i, í|i, ị|i, ò|o, ỏ|o, õ|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, ự|u, ỳ|y, ỷ|y, ỹ|y, ý|y, ỵ|y, À|A, Ả|A, Ã|A, Á|A, Ạ|A, Ă|A, Ằ|A, Ẳ|A, Ẵ|A, Ắ|A, Ặ|A, Â|A, Ầ|A, Ẩ|A, Ẫ|A, Ấ|A, Ậ|A, Đ|D, È|E, Ẻ|E, Ẽ|E, É|E, Ẹ|E, Ê|E, Ề|E, Ể|E, Ễ|E, Ế|E, Ệ|E, Ì|I, Ỉ|I, Ĩ|I, Í|I, Ị|I, Ò|O, Ỏ|O, Õ|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, Ự|U, Ỳ|Y, Ỷ|Y, Ỹ|Y, Ý|Y, Ỵ|Y, "|, &|';
$replacements = array();
$items = explode(',', $utf8characters);
foreach ($items as $item) {
@list($src, $dst) = explode('|', trim($item));
$replacements[trim($src)] = trim($dst);
}
$str = strtr($str, $replacements);
Bước 5: Save file lần cuối và kiểm tra
Cách sửa lỗi tiếng Việt trong Title Alias của Joomla! 2.5
Phiên bản Joomla! 2.5 mặc dù đã có chức năng Unicode Aliases, cho phép hiển thị tiếng Việt có dấu trong Title Alias nhưng vẫn chưa hỗ trợ tiếng Việt không dấu. Sau đây là cách sửa lỗi tiếng Việt trong Title Alias của Joomla! 2.5
Mở tập tin /libraries/joomla/filter/output.php
public static function stringURLSafe($string)Thay thế bằng:
{
// remove any '-' from the string since they will be used as concatenaters
$str = str_replace('-', ' ', $string);
$lang = JFactory::getLanguage();
$str = $lang->transliterate($str);
// Trim white spaces at beginning and end of alias and make lowercase
$str = trim(JString::strtolower($str));
// Remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);
// Trim dashes at beginning and end of alias
$str = trim($str, '-');
return $str;
}
public static function stringURLSafe($string)
{
$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",);
//remove any '-' from the string they will be used as concatonater
$str = str_replace('-', ' ', $string);
$str = strtr($str, $trans);
$lang =& JFactory::getLanguage();
$str = $lang->transliterate($str);
// remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'), array('-',''), $str);
// lowercase and trim
$str = trim(strtolower($str));
return $str;
}
Sau khi sửa xong thì save file này lại. Việc sửa đổi này chỉ có hiệu lực đối với các bài viết từ nay về sau mà thôi, còn các bài viết trước vẫn còn bị lỗi. Bạn phải mở (Edit) bài viết ra và xóa hết toàn bộ ký tự trong ô Alias (nằm ngay phía dưới Title) và nhấn Save (hoặc Apply) các lỗi sẽ được tự động sửa.
Lưu ý: Phải chọn Unicode Aliases là No trong phần thiết lập cấu hình SEO/SEF của joomla! 2.5
file "output.php"
<?php
/**
* @package Joomla.Platform
* @subpackage Filter
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* JFilterOutput
*
* @package Joomla.Platform
* @subpackage Filter
* @since 11.1
*/
class JFilterOutput
{
/**
* Makes an object safe to display in forms
*
* Object parameters that are non-string, array, object or start with underscore
* will be converted
*
* @param object &$mixed An object to be parsed
* @param integer $quote_style The optional quote style for the htmlspecialchars function
* @param mixed $exclude_keys An optional string single field name or array of field names not
* to be parsed (eg, for a textarea)
*
* @return void
*
* @since 11.1
*/
public static function objectHTMLSafe(&$mixed, $quote_style = ENT_QUOTES, $exclude_keys = '')
{
if (is_object($mixed))
{
foreach (get_object_vars($mixed) as $k => $v)
{
if (is_array($v) || is_object($v) || $v == null || substr($k, 1, 1) == '_')
{
continue;
}
if (is_string($exclude_keys) && $k == $exclude_keys)
{
continue;
}
elseif (is_array($exclude_keys) && in_array($k, $exclude_keys))
{
continue;
}
$mixed->$k = htmlspecialchars($v, $quote_style, 'UTF-8');
}
}
}
/**
* This method processes a string and replaces all instances of & with & in links only.
*
* @param string $input String to process
*
* @return string Processed string
*
* @since 11.1
*/
public static function linkXHTMLSafe($input)
{
$regex = 'href="([^"]*(&(amp;){0})[^"]*)*?"';
return preg_replace_callback("#$regex#i", array('JFilterOutput', '_ampReplaceCallback'), $input);
}
/**
* This method processes a string and replaces all accented UTF-8 characters by unaccented
* ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercase.
*
* @param string $string String to process
*
* @return string Processed string
*
* @since 11.1
*/
public static function stringURLSafe($string)
{
$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","ờ"=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"=>"U","Ự"=>"U",);
//remove any '-' from the string they will be used as concatonater
$str = str_replace('-', ' ', $string);
$str = strtr($str, $trans);
$lang =& JFactory::getLanguage();
$str = $lang->transliterate($str);
// remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace(array('/\s+/','/[^A-Za-z0-9\-]/'), array('-',''), $str);
// lowercase and trim
$str = trim(strtolower($str));
return $str;
}
/**
* This method implements unicode slugs instead of transliteration.
*
* @param string $string String to process
*
* @return string Processed string
*
* @since 11.1
*/
public static function stringURLUnicodeSlug($string)
{
// Replace double byte whitespaces by single byte (East Asian languages)
$str = preg_replace('/\xE3\x80\x80/', ' ', $string);
// Remove any '-' from the string as they will be used as concatenator.
// Would be great to let the spaces in but only Firefox is friendly with this
$str = str_replace('-', ' ', $str);
// Replace forbidden characters by whitespaces
$str = preg_replace('#[:\#\*"@+=;!><&\.%()\]\/\'\\\\|\[]#', "\x20", $str);
// Delete all '?'
$str = str_replace('?', '', $str);
// Trim white spaces at beginning and end of alias and make lowercase
$str = trim(JString::strtolower($str));
// Remove any duplicate whitespace and replace whitespaces by hyphens
$str = preg_replace('#\x20+#', '-', $str);
return $str;
}
/**
* Replaces & with & for XHTML compliance
*
* @param string $text Text to process
*
* @return string Processed string.
*
* @since 11.1
*
* @todo There must be a better way???
*/
public static function ampReplace($text)
{
$text = str_replace('&&', '*--*', $text);
$text = str_replace('&#', '*-*', $text);
$text = str_replace('&', '&', $text);
$text = preg_replace('|&(?![\w]+;)|', '&', $text);
$text = str_replace('*-*', '&#', $text);
$text = str_replace('*--*', '&&', $text);
return $text;
}
/**
* Callback method for replacing & with & in a string
*
* @param string $m String to process
*
* @return string Replaced string
*
* @since 11.1
*/
public static function _ampReplaceCallback($m)
{
$rx = '&(?!amp;)';
return preg_replace('#' . $rx . '#', '&', $m[0]);
}
/**
* Cleans text of all formatting and scripting code
*
* @param string &$text Text to clean
*
* @return string Cleaned text.
*
* @since 11.1
*/
public static function cleanText(&$text)
{
$text = preg_replace("'<script[^>]*>.*?</script>'si", '', $text);
$text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
$text = preg_replace('/<!--.+?-->/', '', $text);
$text = preg_replace('/{.+?}/', '', $text);
$text = preg_replace('/ /', ' ', $text);
$text = preg_replace('/&/', ' ', $text);
$text = preg_replace('/"/', ' ', $text);
$text = strip_tags($text);
$text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
return $text;
}
/**
* Strip img-tags from string
*
* @param string $string Sting to be cleaned.
*
* @return string Cleaned string
*
* @since 11.1
*/
public static function stripImages($string)
{
return preg_replace('#(<[/]?img.*>)#U', '', $string);
}
}
Nếu muốn sử dụng plugin có sẳn thì xem tiếp bài này
Chủ đề: w. Web w.Joomla basic