Correcting Alias of Joomla articles

Rate this topic: Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.Evaluations: 1, 1.00 on the average.1.00 out of 6 based on 1 vote(s)
GK User
Mon Jan 23, 2017 7:59 am
Reply with quote
Report this post
Hi Teitbite,

I posted a ticket in VIP support but my VIP account is out of date so can you please help me here? I copied my problem here:


I am using CB in my site. CB component helps to manage users and users can add articles from the front end.

When user post an article from front-end, CB will create an alias for that article. And they use following codes:

--------------------

private static function getTitleAlias( $title )
{
$alias = str_replace( '-', ' ', $title );
$alias = trim( cbIsoUtf_strtolower( $alias ) );
$alias = preg_replace( '/(\s|[^A-Za-z0-9\-])+/', '-', $alias );
$alias = trim( $alias, '-' );
return $alias;
}

------------------

In this file:
components/com_comprofiler/plugin/user/plug_cbblogs/models/joomla25.php

The codes work well with English title.

But with Vietnamese which have some special characters as: ù ú ụ ủ ũ ì í ị ỉ ĩ ò ó ọ ỏ õ è é ẹ ẻ ẽ d á à ạ ả ã đ â ỡ ở ừ ứ ự ử ữ ơ ờ ớ ợ ư ỗ ổ ộ ố ồ ô ễ ể ệ ế ề ê ẵ ẳ ặ ắ ằ ă ẫ ẩ ậ ấ ầ.

When the title of an article have one of those special charaters, it will become a dash “-“.

For example:

If the title is “Anh yêu em rất nhiều”

The alias is: “anh-y-u-em-r-t-nhi-u”

And it is not readable by human.

What I want is that the special characters become normal Latin characters. For example, with the above title, the alias will be: “anh-yeu-em-rat-nhieu”

But I do not know how to do.

At the moment, I am using following codes instead:

-------------

private static function getTitleAlias( $title )
{
$alias = str_replace( '-', ' ', $title );
$alias = trim( cbIsoUtf_strtolower( $alias ) );
$alias = preg_replace( '/(\s|[^A-Za-z0-9ùúụủũìíịỉĩòóọỏõèéẹẻẽđáàạảãđâỡởừứựửữơờớợưỗổộốồôễểệếềêẵẳặắằăẫẩậấầ\-])+/', '-', $alias );
$alias = trim( $alias, '-' );

return $alias;
}


-------------

And the alias becomes: “anh-yêu-em-rất-nhiều”

With this alias, sometimes it is readable, but sometimes it becomes as follows:

“anh-yêu-em-rất-nhiều”

And it does not look nice and also cannot be read.

Please help me to change the codes so that the alias will become:

“anh-yeu-em-rat-nhieu”

In order to do that

ừ,ứ,ự,ử,ữ,ư, ù, ú, ụ, ủ, ũ will become u
ì, í, ị, ỉ, ĩ will become i
ễ,ể,ệ,ế,ề,ê,è,é,ẹ,ẻ,ẽ will become e
á,à,ạ,ả,ã,â,ẵ,ẳ,ặ,ắ,ằ,ă,ẫ,ẩ,ậ,ấ,ầ will become a
đ will become d
ò,ó,ọ,ỏ,õ,ơ,ờ,ớ,ợ,ỗ,ổ,ộ,ố,ồ,ô,ỡ,ở will become o

Thank you very much for your help so far,

Hai
User avatar
Gold Boarder

teitbite
Wed Jan 25, 2017 12:17 pm
Reply with quote
Report this post
Hi

This is way more problematic than that. Luckily I have came across a similar issue some time ago and build a translation table for that. Not sure if it consists of Thai characters since I've made it for Scandinavian website, but You will get an idea how to extend it.

Code: Select all
function transliterateString($txt) {
    $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'e', 'ё' => 'e', 'Ё' => 'e', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja', ' ' => '-', "'" => '', '&' => '');
;     $txt = str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
     return $txt;
}


add it before the code You have copied to post. Than just process the title before it will be used to create an alias:

Code: Select all
private static function getTitleAlias( transliterateString( $title ) )
{
$alias = str_replace( '-', ' ', $title );
$alias = trim( cbIsoUtf_strtolower( $alias ) );
$alias = preg_replace( '/(\s|[^A-Za-z0-9\-])+/', '-', $alias );
$alias = trim( $alias, '-' );
return $alias;
}


I cannot help more since it's strictly ocnnected with CB component, but I hope it will solve Your problem.
User avatar
Moderator

GK User
Thu Jan 26, 2017 10:56 am
Reply with quote
Report this post
Thank you very much Teitbite,

I tried to do as you told but there is something wrong with the code and the site is down.

Here is the whole code in the file after I corrected it:

--------------------------------

/**
* Autogenerates an URL-compatible title-alias for a title
*
* @param string $title Title
* @return string URL-compatible Alias corresponding to title
*/

function transliterateString($txt) {
$transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ả' => 'a', 'Ả' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ạ' => 'a', 'Ạ' => 'A', 'ắ' => 'a', 'Ắ' => 'A', 'ằ' => 'a', 'Ằ' => 'A', 'ẳ' => 'a', 'Ẳ' => 'A', 'ẵ' => 'a', 'Ẵ' => 'A', 'ặ' => 'a', 'Ặ' => 'A', 'ấ' => 'a', 'Ấ' => 'A', 'ầ' => 'a', 'Ầ' => 'A', 'ẩ' => 'a', 'Ẩ' => 'A', 'ẫ' => 'a', 'Ẫ' => 'A', 'ậ' => 'a', 'Ậ' => 'A', 'đ' => 'd', 'Đ' => 'D', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ỏ' => 'o', 'Ỏ' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ọ' => 'o', 'Ọ' => 'O', 'ố' => 'o', 'Ố' => 'O', 'ồ' => 'o', 'Ồ' => 'O', 'ổ' => 'o', 'Ổ' => 'O', 'ỗ' => 'o', 'Ỗ' => 'O', 'ộ' => 'o', 'Ộ' => 'O', 'ớ' => 'o', 'Ớ' => 'O', 'ờ' => 'o', 'Ờ' => 'O', 'ở' => 'o', 'Ở' => 'O', 'ỡ' => 'o', 'Ỡ' => 'O', 'ợ' => 'o', 'Ợ' => 'O', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ẻ' => 'e', 'Ẻ' => 'E', 'ẽ' => 'e', 'Ẽ' => 'E', 'ẹ' => 'e', 'Ẹ' => 'E', 'ế' => 'e', 'Ế' => 'E', 'ề' => 'e', 'Ề' => 'E', 'ể' => 'e', 'Ể' => 'E', 'ễ' => 'e', 'Ễ' => 'E', 'ệ' => 'e', 'Ệ' => 'E', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'ỉ' => 'i', 'Ỉ' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'ị' => 'i', 'Ị' => 'I', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ủ' => 'u', 'Ủ' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ụ' => 'u', 'Ụ' => 'U', 'ứ' => 'u', 'Ứ' => 'U', 'ừ' => 'u', 'Ừ' => 'U', 'ử' => 'u', 'Ử' => 'U', 'ữ' => 'u', 'Ữ' => 'U', 'ự' => 'u', 'Ự' => 'U', ' ' => '-', "'" => '', '&' => '');
; $txt = str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
return $txt;
}


private static function getTitleAlias( transliterateString( $title ) )
{
$alias = str_replace( '-', ' ', $title );
$alias = trim( cbIsoUtf_strtolower( $alias ) );
$alias = preg_replace( '/(\s|[^A-Za-z0-9\-])+/', '-', $alias );
$alias = trim( $alias, '-' );
return $alias;
}




--------------------------------


Can you help me to find out what is wrong with the code?

Thank you,

Hai
User avatar
Gold Boarder

teitbite
Wed Feb 01, 2017 8:06 pm
Reply with quote
Report this post
Hi

Is there no message telling in which line the issue is? I see nothing wrong in code above.

Most probably the issue is with calling a function inside a private function. Lets simplify it:

Code: Select all
/**
* Autogenerates an URL-compatible title-alias for a title
*
* @param string $title Title
* @return string URL-compatible Alias corresponding to title
*/

private static function getTitleAlias( transliterateString( $title ) )
{
$transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ả' => 'a', 'Ả' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ạ' => 'a', 'Ạ' => 'A', 'ắ' => 'a', 'Ắ' => 'A', 'ằ' => 'a', 'Ằ' => 'A', 'ẳ' => 'a', 'Ẳ' => 'A', 'ẵ' => 'a', 'Ẵ' => 'A', 'ặ' => 'a', 'Ặ' => 'A', 'ấ' => 'a', 'Ấ' => 'A', 'ầ' => 'a', 'Ầ' => 'A', 'ẩ' => 'a', 'Ẩ' => 'A', 'ẫ' => 'a', 'Ẫ' => 'A', 'ậ' => 'a', 'Ậ' => 'A', 'đ' => 'd', 'Đ' => 'D', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ỏ' => 'o', 'Ỏ' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ọ' => 'o', 'Ọ' => 'O', 'ố' => 'o', 'Ố' => 'O', 'ồ' => 'o', 'Ồ' => 'O', 'ổ' => 'o', 'Ổ' => 'O', 'ỗ' => 'o', 'Ỗ' => 'O', 'ộ' => 'o', 'Ộ' => 'O', 'ớ' => 'o', 'Ớ' => 'O', 'ờ' => 'o', 'Ờ' => 'O', 'ở' => 'o', 'Ở' => 'O', 'ỡ' => 'o', 'Ỡ' => 'O', 'ợ' => 'o', 'Ợ' => 'O', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ẻ' => 'e', 'Ẻ' => 'E', 'ẽ' => 'e', 'Ẽ' => 'E', 'ẹ' => 'e', 'Ẹ' => 'E', 'ế' => 'e', 'Ế' => 'E', 'ề' => 'e', 'Ề' => 'E', 'ể' => 'e', 'Ể' => 'E', 'ễ' => 'e', 'Ễ' => 'E', 'ệ' => 'e', 'Ệ' => 'E', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'ỉ' => 'i', 'Ỉ' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'ị' => 'i', 'Ị' => 'I', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ủ' => 'u', 'Ủ' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ụ' => 'u', 'Ụ' => 'U', 'ứ' => 'u', 'Ứ' => 'U', 'ừ' => 'u', 'Ừ' => 'U', 'ử' => 'u', 'Ử' => 'U', 'ữ' => 'u', 'Ữ' => 'U', 'ự' => 'u', 'Ự' => 'U', ' ' => '-', "'" => '', '&' => '');
$title = str_replace(array_keys($transliterationTable), array_values($transliterationTable), $title);

$alias = str_replace( '-', ' ', $title );
$alias = trim( cbIsoUtf_strtolower( $alias ) );
$alias = preg_replace( '/(\s|[^A-Za-z0-9\-])+/', '-', $alias );
$alias = trim( $alias, '-' );
return $alias;
}


I got rid of the extra function and moved chars transition inside the old one.
User avatar
Moderator

GK User
Thu Feb 02, 2017 4:35 am
Reply with quote
Report this post
Hi Teitbite,

I tried the code but it still not work prefectly. The homepage can be read but other pages inside are not displayed.

The error 500 appears.

Can you help me to correct the code a little more?

Thank you a lot,

Hai
User avatar
Gold Boarder

GK User
Fri Feb 03, 2017 2:46 am
Reply with quote
Report this post
Hi Teitbite,

I updated CB and in the new version, they are now using Joomla alias instead of their own for the articles. That means when posting an article via CB in front page, the alias is created like when creating an article in the administrator page.

However, with Joomla alias, the same problem happens.

When the title of an article have a special charater, it will become a a wrong character and dash “-”.

For example:

If the title is “Anh yêu em rất nhiều”

The alias is: “anh-ya-u-em-ra-t-nhia-u”

And it is not readable by human.

When I change alias mode to unicode, the alias becomes:

“anh-yêu-em-rất-nhiều”.

And other problem happens like in CB.

Please help me to correct alias of Joomla core instead of CB. So that the special characters becomes relevant Latin charaters like what you are helping me with CB.

Then the alias will be:

“anh-yeu-em-rat-nhieu”

I assume that we will use the same array but don’t know which file will be changed.

Thank you very much,

Hai
User avatar
Gold Boarder

teitbite
Tue Feb 07, 2017 5:58 pm
Reply with quote
Report this post
Hi

I'm afraid that was the only idea I had :( Try talking to joomla developers or CB developers. This problem is strictly connected with this extensions. Our template does not interfere with aliases, so I believe they are better fit to answer Your question. Sorry.
User avatar
Moderator

GK User
Wed Feb 08, 2017 1:54 am
Reply with quote
Report this post
Thank you Teitbite,

Can the issue be solved if I order the VIP support?

Hai
User avatar
Gold Boarder

teitbite
Mon Feb 13, 2017 6:06 pm
Reply with quote
Report this post
Hi

I'm afraid not, I've already stepped up trying to help with my script I've been using to rewrite aliases, but the issues is somewhere inside CB and we do not provide a support for that component.
User avatar
Moderator


cron