Tag localization for your NON-ENGLISH language (searching)

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-04-2007, 05:39 PM
AnAlienHolakres3's Avatar
Pligg Donor/Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 116
Send a message via ICQ to AnAlienHolakres3
Many of you know this problem. You´ve got Pligg, you spend so much time customizing it, but the situation with Tag searching in Your own language for accentic words (words with special characters), thats problem (no search result). This thing makes you probably crazy, so did me. I did research of this problem, I installed my own MySQL+PHP server, used PHP debugger and this resulted in one thing - I was frustrated even more then before, beceause that sql query was right, but search term was not. i finally realized that we need something general and something appliable to all languages and after many hours I made it. So there is a short tutorial how you can made it also. It´s dirty (just like all my tuts),but it´s working).

Features:
1) You can use any normal language (normal = not chinese and other symbol languages).
2) Tags will be displayed with any characters correctly and searching with tags will give you results

Requirements:
-As usually, Notepad++,PHP Designer or PHPed...whatever good for editing php files

Steps to do:
3a) We need add a new column in your tags table. Column with name "tags_safe". So open your MyAdmin and run following sql:
Code:
alter table your_domain_tags add column tag_safe varchar(30)
3b) Open your tags.php in libs foldder, watch and edit following code:

Code:
function tags_insert_string($link, $lang, $string, $date = 0) {
	global $db;

	$string = tags_normalize_string($string);
	if ($date == 0) $date=time();
	$words = preg_split('/[,;]+/', $string);
	if ($words) {
		$db->query("delete from " . table_tags . " where tag_link_id = $link");
		foreach ($words as $word) {
			$word=trim($word);
            //************************************************************
            //SAFE words
              $replace_what = array("á","ě","š","č","ř","ž","ý","á","í","é","ň","ť","ď","ó");
              $replace_with = array("a","e","s","c","r","z","y","a","i","e","n","t","d","o");
              $word_safe= str_ireplace($replace_what,$replace_with,$word);
              
              
            //*******************************************************
			if (!$inserted[$word] && !empty($word)) {
    
				$db->query("insert into " . table_tags . " (tag_link_id, tag_lang, tag_words, tag_safe,tag_date) values ($link, '$lang', '$word','$word_safe', from_unixtime($date))");
				$inserted[$word] = true;
			}
		}
		return true;
	}
	return false;

}
As you can see the first real thing you have to do is replace original function tags_insert_string with this code and replace red characters to your special characters. Please note that Count of items in $replace_what must be the same like in $replace_with . After it you can save this file and close.

3c) Open search.php in your libs folder. Watch this code and carefully edit first part of get_search_clause function like this:

Code:
	function get_search_clause($option='') {
		if(!empty($this->searchTerm)) {
			// make sure there is a search term
            //change to search
			$words = $this->searchTerm;
			$SearchMethod = SearchMethod; // create a temp variable so we can change the value without possibly affecting anything else

			if($this->isTag == true){
				// search the tags table
				$this->searchTable = table_tags . " INNER JOIN " . table_links . " ON " . table_tags . ".tag_link_id = " . table_links . ".link_id";
				
				// thanks to jalso for this code
					$x = explode(",",$words);
					$sq .= "(";
					foreach($x as $k=>$v){
                    //**************************************************************** 
                        
                                                       
                        $replace_what = array("ú","ó","é","ý","š","á","í","á","ě","š","č","ř","ž","ý","á","í","é","ň","ť","ď","ó");
                        $replace_with = array("u","o","e","y","s","a","i","a","e","s","c","r","z","y","a","i","e","n","t","d","o");
                        $word_safe= str_ireplace($replace_what,$replace_with,trim($x[$k]));
                        
                        
                    
					 $sq .= "tag_safe = '".$word_safe."'";
					//*************************************************************************************   
                       
					 if($k != (count($x) - 1))$sq .= " OR ";
					}
					$sq .= ")";
                
					$where .= " AND ".$sq." GROUP BY " . table_links . ".link_id, `link_votes` ORDER BY `link_votes` DESC"; 
				
				// ---
Save the file and close.

3d). This could be end, but this works for your NEW tags. And if you have (i assume you have many tags, you could spend a little time to editing link in your pligg site or in database. There are 2 choices what is your situation:

- you have language incorrect tags but with non-accent characters - you have to edit all of them manually, there is no way how to automatize it

- you have language correct tags with no results, there is a way how to do it faster, i made this script (but i neednt it myself), so customize it to your own needs:
PHP Code:
<?php
  
global $db$main_smarty;
  
  
$tagCount $db->get_var("SELECT count(tag_link_id) FROM ".$table_tags);
  for (
$i=1$i <= $tagCount$i++) {
    
$tag_name $db->get_var("SELECT tag_words FROM ".$table_tags ." WHERE tag_link_id=".$i);
    
    
$replace_what = array("á","ě","š","č","ř","ž","ý","á","í","é","ň","ť","ď","ó");
    
$replace_with = array("a","e","s","c","r","z","y","a","i","e","n","t","d","o");
    
     
$word_safestr_ireplace($replace_what,$replace_with,$tag_name);
     
$db->query("UPDATE your_domain_tags SET tag_safe=" .$word_safe ." WHERE tag_link_id=".$i);
     
  }
      
?>
Ok that´s all. I hope this will be for someone useuful

Last edited by AnAlienHolakres3; 09-04-2007 at 05:52 PM.
Reply With Quote
  #2 (permalink)  
Old 12-26-2007, 10:12 AM
Casual Pligger
Pligg Version: 9.8.2
Pligg Template: Vera
 
Join Date: Dec 2007
Posts: 59
It will be really useful for spanish pligg users
I'll try it as soon as I arrive at home. Thanks
Reply With Quote
  #3 (permalink)  
Old 12-26-2007, 02:57 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 43
Great work! It will be really useful if the developers will support this mod in all the future releases, all my headaches on pligg are coming from special characters compatibility!
Reply With Quote
  #4 (permalink)  
Old 12-28-2007, 04:17 AM
Pligg Donor
Pligg Version: 9.9.0
Pligg Template: Custom
 
Join Date: Dec 2007
Posts: 40
When i did all the steps in your post, i did't get it to work -- also my ordinary search stopped working and was only displaying empty search results.

Here i paste in some relevant code from tags.php and search.php, but i also attach both files to this post.

From my tags.php:
$replace_what = array("æ","ø","å","é");
$replace_with = array("e","o","a","e");

From my search.php:
$replace_what = array("&uacute;","&oacute;","&eacute;","&yacute;", "&scaron;","&aacute;","&iacute;","æ","ø","å"," é");
$replace_with = array("u","o","e","y","s","a","i","e","o","a","e") ;

I am using URL method 2, and the "makeFriendly" module.

I am especially uncertain about the change in search.php, should i change the characters in the $replace_with-line there according to the characters i used in replace_what in both tags.php and search.php? It seemed like you did that in your code, and that is what i did (as you can see).

Just to have mentioned it, i of course i did add the column tags_safe to the database as you described, and also changed the line to contain my domain-name.

What could i be doing wrong? Thanks!
Attached Files
File Type: txt search.php.txt (18.4 KB, 87 views)
File Type: txt tags.php.txt (5.7 KB, 97 views)
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 04:30 AM
AnAlienHolakres3's Avatar
Pligg Donor/Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 116
Send a message via ICQ to AnAlienHolakres3
Quote:
Originally Posted by ditto View Post
What could i be doing wrong? Thanks!
It seems to be ok and i cannot see any errors, could you provide some SQL query output when search is performed?
Reply With Quote
  #6 (permalink)  
Old 01-05-2008, 07:40 AM
Pligg Donor
Pligg Version: 9.9.0
Pligg Template: Custom
 
Join Date: Dec 2007
Posts: 40
Thanks for your reply. I have just started all over again with a fresh 9.9.0 installation of Pligg -- and i will give it another try in a few hours. I will let you know how it went, hopefully it will work this time (if not i will give you more information).
Reply With Quote
  #7 (permalink)  
Old 01-05-2008, 10:57 AM
Pligg Donor
Pligg Version: 9.9.0
Pligg Template: Custom
 
Join Date: Dec 2007
Posts: 40
Quote:
Originally Posted by AnAlienHolakres3 View Post
It seems to be ok and i cannot see any errors, could you provide some SQL query output when search is performed?
I am only beginning to learn about databases, and don't know how to get a "SQL query output".

Now i have tried again, spending hours and hours, but it still don't work. I just don't get it to work. But with your fix applied, normal search still work, and tags also work when they don't have special characters in them.

I don't think i ever will be able to fix this.

If you would help me fix this, i can pay you 100 dollar. If so, please email me at (edit: email removed). If so, i will give you access to my FTP, and to phpMyadmin.

Last edited by ditto; 01-06-2008 at 09:47 AM. Reason: Problem is solved, email removed. Thank you AnAlienHolakres3!
Reply With Quote
  #8 (permalink)  
Old 01-06-2008, 08:06 AM
Pligg Donor
Pligg Version: 9.9.0
Pligg Template: Custom
 
Join Date: Dec 2007
Posts: 40
Thank you so very much for fixing it for me, AnAlienHolakres3. You are THE BEST!
Reply With Quote
  #9 (permalink)  
Old 01-09-2008, 12:33 AM
Casual Pligger
Pligg Version: 9.9
Pligg Template: default
 
Join Date: Jan 2008
Posts: 46
Need help I have done your method

Mine does not work I have done it exactly as you told

i would really appreciate help

my files are attached if you have time please can you look at it...
Attached Files
File Type: php search.php (18.1 KB, 90 views)
File Type: php tags.php (5.5 KB, 94 views)

Last edited by werushka; 01-09-2008 at 01:12 AM.
Reply With Quote
  #10 (permalink)  
Old 01-10-2008, 05:23 AM
AnAlienHolakres3's Avatar
Pligg Donor/Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 116
Send a message via ICQ to AnAlienHolakres3
Quote:
Originally Posted by werushka View Post
Need help I have done your method

Mine does not work I have done it exactly as you told

i would really appreciate help

my files are attached if you have time please can you look at it...
Yes I think I have discovered your problem although i do not fully understand why the behavior is so strange. You can thank to user Ditto who provided some donation for solving this problem (on his own site).

The problem is that in search.php file cannot be special characters directly,but as html entity. For example
PHP Code:
$replace_what = array("&aelig;","&oslash;","&eacute;","&aring;"); 
You can find more html entities on:
HTML 4.0 Latin-1 Entities
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced search in another language (not English) not working with URL2 onliner Questions and Comments 3 06-29-2009 12:26 PM
[SOLVED] does pligg support any username language other than english? crowng Questions and Comments 6 03-08-2009 12:52 PM
Right to left language localization? hugzzz Questions and Comments 0 09-20-2007 05:55 PM
Pligg,searching and tags in NOT english language AnAlienHolakres3 Questions and Comments 0 08-19-2007 08:58 AM
New Mod :Instant Language Translation chuckroast Questions and Comments 6 04-14-2007 09:29 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development