16 Feb 2008

I found a solution for aLinks and international characters

Arquivado em: Uncategorized

If you are a WordPress addicted like me, of course you know the aLinks plugin, that automatically convers keywords into links.

And, if like me, you write in some non English language, you certainly passed through the frustration on not getting your local words (like Spanish “niño”) correctly linked by it.

But your troubles are over. I found a way to put aLinks on the rails again, and if it worked for me, I am pretty sure it can work for you too!

Before beginning with the real fun, I must apologize for using images where you are supposed to read code. Unfortunately I was unable to make WordPress render the correct HTML for my code samples, thus I decided to use the images.

Warning: there are no warranties that the process described below will work with any blog but mine! By reading the following paragraphs you agree that you are the only one responsible for data losses, financial losses or nuclear wars this process can derive! It’s totally up to you, I have nothing to do! Back up your site before trying to mess with your database!

First, you have to ensure your wp-config.php states you are using UTF-8 in your blog. If you find two lines like the code below, then that’s OK.

Now, ensure your database is in UTF-8, too. If you can see the correct special chars when you read your posts, it’s quite sure the database is correctly set up. If you need help converting your database, use the UTF-8 Database Converter plugin. Again, it is totally up to you, using it or not. It worked for me, but this means nothing at all.

Now you are almost on your way for working special characters in aLinks.

Now you have to hack three files from the aLinks original package.

First, you have to edit the file includes.php, located inside the subdirectory views.

Then, using your text editor, change every instance of “escape” (but not “unescape”, take care) by “encodeURIComponent”. The snippet below shows the commented code (the original form) and the actual code (the hacked form) from my own include.php.

Second, open the classes/aLinksBackend.php file, and locate the lines where the variables $phrase and $description are encoded to UTF-8 before being sent back to the grid. This is not necessary, because they come correctly encoded from the database already. In my case, those lines are 199 and 200. Just comment those lines (like the snippet below).

Almost there!

Now you have to open classes/aLinksController.php and find the line where the function utf8_encode() is called, and again you have to comment it. You don’t need this function anymore for the same reason you didn’t before: your database is already correctly encoded. In my case, it was line 305.

And you’re done! Now your aLinks is totally able to work with your beloved special chars.

Technorati : , ,

Adv: Online Dating Made Easy!

Confira ofertas de: DVD, filmes, celulares, notebooks, livros, jogos, Wii, PS3

Digg!




6 Respostas para “I found a solution for aLinks and international characters”

  1. [...] De saco cheio de ficar à mercê de gente que não está nem aí para os pobres rapazes latino-americanos, sem dinheiro no banco, sem parentes importantes, e vindos do interior, assim como eu, resolvi gastar um tempo estudando o funcionamento do plugin, e finalmente cheguei a uma solução, que pode ser lida em Inglês macarrônico aqui: I found a solution for aLinks and international characters. [...]

  2. sgon on 16 Feb 2008 at 6:43 am

    Great one, thanks

    [Reply]

  3. [...] Quando fiz a conversão da base de dados de Latin1 para UTF8 (explicado aqui: I found a solution for aLinks and international characters) ocorreu um problema bem chato, que só identifiquei agora: os comentários todos [...]

  4. Lu Monte on 04 Mar 2008 at 2:29 pm

    Wow, I almost didn’t see that! Great, Janio, thanks! :D

    [Reply]

  5. Marie-Aude on 30 Jun 2008 at 11:35 am

    Thanks a lot for this tip.
    I translated it in the french WordPress forum, with reference to your blog (and using your images) here :
    http://www.wordpress-fr.net/support/viewtopic.php?pid=83113#p83113

    I hope it’s not a problem ?

    [Reply]

  6. [...] Outra excelente notícia é que os caracteres acentuados funcionam lindamente nessa nova versão, não carecendo de nenhum hack (I found a solution for aLinks and international characters). [...]

Trackback URI | Comments RSS

Deixe uma resposta