Custom replacement for title injection

Discussions and support about the different URL Rewriting techniques for phpBB.

Moderator: Moderators

Custom replacement for title injection

Postby dcz » Fri Jun 12, 2009 7:59 am

Custom replacement for title injection
The phpbb_seo class handles de-accentuation for most of the occidental characters, but you could need to handle more cases for your project.
Starting from v0.6.0, we introduced a simple way to set up custom replacements.
This is useful for special characters not properly handled by default, such as Russian ones (Г => G), or to implement custom replacements such as $ => dollar.
It works with any string, but you MUST perform the edits with an UTF-8 (without BOM) capable text editor.
This is still done in phpbb_seo/includes/setup_phpbb_seo.php, and still before :

Code: Select all
      // Let's make sure that settings are consistent
      $this->check_config();


The principle is simple, you can set up your custom replacement by filling the phpbb_seo::url_replace array ($this->url_replace).
The pattern to use is :

Code: Select all
      $this->url_replace = array(
         'character(s) to find' => 'replacement to apply',
      );


EXAMPLE :
Code: Select all
      $this->url_replace = array(
         // Purely cosmetic replace
         '$' => 'dollar', '€' => 'euro',
         '\'s' => 's', // it's => its / mary's => marys ...
         // Language specific replace (German example)
         'ß' => 'ss',
         'Ä' => 'Ae', 'ä' => 'ae',
         'Ö' => 'Oe', 'ö' => 'oe',
         'Ü' => 'Ue', 'ü' => 'ue',
      );


Just make sure that the characters you may add are not already handled properly but the default replacements before you add some more.
Please note that English characters are already properly handled.

You can use this thread to discuss about your case and to share the code for specific languages.
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Advertisement

Custom replacement for Cyrillic char-set

Postby dcz » Fri Jun 12, 2009 8:03 am

I recently helped akon for Cyrillic char-set, so here is the replacement we put together, translated to the new way of doing it :
Open :
Code: Select all
phpbb_seo/includes/setup_phpbb_seo.php

Find :
Code: Select all
      // Let's make sure that settings are consistent
      $this->check_config();

Before add :
Code: Select all
      // Custom characters replacement for Cyrillic char-set
      $this->url_replace = array(
         'А' => 'A', 'а' => 'a',
         'Б' => 'B', 'б' => 'b',
         'В' => 'V', 'в' => 'v',
         'Г' => 'G', 'г' => 'g',
         'Д' => 'D', 'д' => 'd',
         'Е' => 'E', 'е' => 'e',
         'Ж' => 'J', 'ж' => 'j',
         'З' => 'Z', 'з' => 'z',
         'И' => 'I', 'и' => 'i',
         'Й' => 'Y', 'й' => 'y',
         'К' => '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',
         'Щ' => 'SHT', 'щ' => 'sht',
         'Ъ' => 'A', 'ъ' => 'a',
         'Ь' => 'X', 'ь' => 'x',
         'Ю' => 'YU', 'ю' => 'yu',
         'Я' => 'YA','я' => 'ya',   
      );
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby NTH08 » Sat Jun 13, 2009 1:59 pm

can you help me with the Vietnamese charset. I use this but it doesn't work well.
Code: Select all
      // Custom characters replacement for Vietnamese char-set
         $this->url_replace = 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',
            'Ẵ' => 'A', 'ẵ' => 'a',
            'Ặ' => 'A', 'ặ' => 'a',
            
            'Đ' => 'D', 'đ' => 'd',
            
            'É' => 'E', 'é' => 'e',
            'È' => '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',
            
            'Ó' => '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',
            'Ỡ' => 'O', 'ỡ' => 'o',
            'Ợ' => 'O', 'ợ' => 'o',
            
            'Ú' => 'U', 'ú' => 'u',
            'Ù' => 'U', 'ù' => 'u',
            'Ủ' => 'U', 'ủ' => 'u',
            'Ũ' => 'U', 'ũ' => 'u',
            'Ụ' => 'U', 'ụ' => 'u',
            'Ư' => 'U', 'ư' => 'u',
            'Ứ' => 'U', 'ứ' => 'u',
            'Ừ' => 'U', 'ừ' => 'u',
            'Ử' => 'U', 'ử' => 'u',
            'Ữ' => 'U', 'ữ' => 'u',
            'Ự' => 'U', 'ự' => 'u',
            
            'Ý' => 'Y', 'ý' => 'y',
            'Ỳ' => 'Y', 'ỳ' => 'y',
            'Ỷ' => 'Y', 'ỷ' => 'y',
            'Ỹ' => 'Ỹ', 'ỹ' => 'y',
            'Ỵ' => 'Y', 'ỵ' => 'y',
         );


E.g: it shows
thcsthanhda.info/forum/thong-bao/earth-hour-gi-trai-t-t-t-en-b-t-t-ng-lai-28-3-09-t239.html
for topic title Earth Hour -Giờ Trái đất: Tắt đèn để bật tương lai (28/3/09)
Last edited by NTH08 on Tue Aug 04, 2009 3:00 am, edited 1 time in total.
NTH08
 
Posts: 8
Joined: Sun Jan 25, 2009 4:56 am

Re: Custom replacement for title injection

Postby iwanttobelieve » Sun Jun 14, 2009 1:53 pm

Sorry let me talk to him using native language :lol:

Có thể anh đang bật chế độ SQL rewriting. Cái method này chỉ có tác dụng khi tạo topic mới thôi, còn những topic cũ sẽ vẫn có link như thế vì nó lấy link từ cái URL chứ không phải từ title của topic. Nếu muốn sửa lại thì anh edit lại cái URL.

Hy vọng giúp được anh^^
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: Custom replacement for title injection

Postby dcz » Mon Jun 15, 2009 7:36 am

Hopefully you helped him.

Just in case, if you implement these custom replacement after you've filled your db (with SQL rewriting and sync_url.php), then you need to a) clear the topic_url field and b) re sync your urls in both case with the sync_url.php script.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby NTH08 » Wed Jun 17, 2009 3:23 am

I got it. Thanks guys :lol:
NTH08
 
Posts: 8
Joined: Sun Jan 25, 2009 4:56 am

Re: Custom replacement for title injection

Postby dcz » Wed Jun 17, 2009 9:21 am

So, these code change are the good ones for Vietnamese : Custom replacement for Vietnamese

Can you confirm, since I have no authority for that ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby iwanttobelieve » Wed Jun 17, 2009 1:48 pm

I can confirm it works perfectly. However, we might want to change 'Ị' => 'i' into 'Ị' => 'I' to keep the unity.
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: Custom replacement for title injection

Postby dcz » Wed Jun 17, 2009 6:25 pm

Done ;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby mafiaWolf » Tue Jun 30, 2009 1:06 am

I don't use 3.0.5premod, iam now using 3.0.4 premod. How to edit with Vietnamese charset
mafiaWolf
 
Posts: 34
Joined: Thu Jun 04, 2009 2:28 am

Re: Custom replacement for title injection

Postby dcz » Fri Jul 03, 2009 8:22 am

You could follow the advices provided here about Cyrillic char-set and previous phpBB version : Setup and cyrillic char-set

Of course using the Vietnamese replacements.

But updating phpBB would still be the best thing to do ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby Lucky65 » Sun Aug 30, 2009 7:42 am

Hello, I am translating into Italian the gym sitemap, I wanted to ask if they are even special characters such as accented vowels à è ì ò ù, for the following post on this topic I have a problem on my index map indicates it is the only one that does not work . Moreover, the language file is language \ en \ common.php? Thank
Lucky65
 
Posts: 13
Joined: Sun Aug 30, 2009 7:20 am
Location: Italy

Re: Custom replacement for title injection

Postby dcz » Tue Sep 01, 2009 9:40 am

à è ì ò ù characters are handled by the default replacements, there is no need to do anything for it. About your sitemap issue, it's off topic on this thread, and by the way looks like working great on your site.

About translating, have a look at the files added by GYM, as well as to the bit of code added to the phpBB language files.

language/en/gym_sitemaps/gym_common.php contain the publicly viewable language entries, others are used in acp.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21325
Joined: Fri Apr 28, 2006 9:03 pm

Re: Custom replacement for title injection

Postby Lucky65 » Tue Sep 01, 2009 10:47 am

Thank i have solved the problem was the special carachter &.
Lucky65
 
Posts: 13
Joined: Sun Aug 30, 2009 7:20 am
Location: Italy

Re: Custom replacement for title injection

Postby Bembis » Sat Sep 05, 2009 7:37 am

Code: Select all
      }
      // <== Special for lazy French, others may delete this part
      // Custom characters replacement for Cyrillic char-set
      $this->url_replace = array(
         'Ą' => 'A', 'ą' => 'a',
         'Č' => 'c', 'č' => 'c',
         'Ę' => 'e', 'ę' => 'e',
         'Ė' => 'e', 'ė' => 'e',
         'Į' => 'i', 'į' => 'i',
         'Š' => 's', 'š' => 's',
         'Ų' => 'u', 'ų' => 'u',
         'Ū' => 'u', 'ū' => 'u',
         'Ž' => 'z', 'ž' => 'z',
      
      // Let's make sure that settings are consistent
      $this->check_config();
   }
   // Here start the add-on methods
} // End of the phpbb_seo_modules class
?>

setup_phpbb_seo.php like this and error
Code: Select all
Parse error: syntax error, unexpected ';', expecting ')' in /home/algiz/domains/plepuciai.lt/public_html/phpbb_seo/includes/setup_phpbb_seo.php on line 102
Bembis
 
Posts: 13
Joined: Sun May 25, 2008 9:37 am

Next

Return to phpBB mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 9 guests