4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Flo2005 on October 30, 2006, 06:20:20 PM

Title: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Flo2005 on October 30, 2006, 06:20:20 PM
This tutorial explains, how to get existing keywords in searchform:

example:

(http://www.snuup.de/4img_gfx/search_form.jpg)

1. create a new php-file called ajax-list-keywords.php in root/4images with this code in it (edit host-username-password-dbName):

Code: [Select]
<?php

$conn 
mysql_connect("host","username","password");
mysql_select_db("dbName",$conn);

if(isset(
$_GET['getKeywordsByLetters']) && isset($_GET['letters'])){
$letters $_GET['letters'];
$letters preg_replace("/[^a-z0-9 ]/si","",$letters);
$res mysql_query("select word_id,word_text from 4images_wordlist where word_text like '".$letters."%'") or die(mysql_error());
#echo "1###select word_id,word_text from 4images_wordlist where word_text like '".$letters."%'|";
while($inf mysql_fetch_array($res)){
echo $inf["word_id"]."###".$inf["word_text"]."|";
}
}

?>


2. add the following files to your gallery in root/4images/js folder
http://www.snuup.de/4img_mods/ajax-js.zip (http://www.snuup.de/4img_mods/ajax-js.zip)
[EDIT] zip file attached to the bottom of this post

3. edit: templates/default/header.html

find:
Code: [Select]
<link rel="stylesheet" href="{template_url}/style.css" />
add after:

Code: [Select]
<style type="text/css">

/* Big box with list of options */
#ajax_listOfOptions{
position:absolute; /* Never change this one */
width:175px; /* Width of box */
height:250px; /* Height of box */
overflow:auto; /* Scrolling features */
border:1px solid #317082; /* Dark green border */
background-color:#FFF; /* White background color */
text-align:left;
font-size:0.9em;
z-index:100;
}
#ajax_listOfOptions div{ /* General rule for both .optionDiv and .optionDivSelected */
margin:1px;
padding:1px;
cursor:pointer;
font-size:0.9em;
}
#ajax_listOfOptions .optionDiv{ /* Div for each item in list */

}
#ajax_listOfOptions .optionDivSelected{ /* Selected item in the list */
background-color:#317082;
color:#FFF;
}
#ajax_listOfOptions_iframe{
background-color:#F00;
position:absolute;
z-index:5;
}

form{
display:inline;
}

</style>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="js/ajax-dynamic-list.js"></script>

4. edit: templates/default/search_form.html

find:

Code: [Select]
<input type="text" name="search_keywords" size="40" value="{search_keywords}" class="input" />
replace with:

Code: [Select]
<input type="text" name="search_keywords" size="40" value="{search_keywords}" class="input" onkeyup="ajax_showOptions(this,'getKeywordsByLetters',event)" />
you can use this searchform also in your header of 4images:

(http://www.snuup.de/4img_gfx/search_header.jpg)

edit every toplevel html-file like details.html, home.html, register.html, lightbox.html, member.html and some more... and find:

Code: [Select]
<input type="text" name="search_keywords" size="15" class="searchinput" />
replace with:

Code: [Select]
<input type="text" name="search_keywords" size="15" class="searchinput" onkeyup="ajax_showOptions(this,'getKeywordsByLetters',event)" />
Hope it works 4you!

Cu by Flo :wink:
Title: Re: 4images searchform with keywords - like google suggest by using ajax
Post by: pda on October 31, 2006, 11:25:15 AM
Wow. It works like a charm. Thanks!!

I just adapted it a little bit to get it work with the memberlist MOD.
There is actually just one problem which occurs.
How can I show  special characters in this Ajax drop down Box?

For example: German umlauts like
ö  ü   ä

Those are now shown by a question mark sign


Title: Re: 4images searchform with keywords - like google suggest by using ajax
Post by: cristina on May 17, 2007, 07:41:25 PM
Hi, nice MOD!

Well, I just installed it BUT... why the need to use DB names and passwords on the php file? Ok, not sure if this will be of interest, but I just modified the file and now it looks like this:

Code: [Select]
<?php

define
('ROOT_PATH''./');
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');

if(isset(
$_GET['getKeywordsByLetters']) && isset($_GET['letters'])) {

$letters $_GET['letters'];

$letters preg_replace("/[^a-z0-9 ]/si","",$letters);

$sql ="SELECT i.word_id, i.word_text
FROM "
.WORDLIST_TABLE." i
WHERE i.word_text like '"
.$letters."%'";
$result $site_db->query($sql);

while($inf mysql_fetch_array($result)) {

echo $inf["word_id"]."###".$inf["word_text"]."|";

}

}

?>

BTW, it is nice to turn auto-complete off in the input field so it won't interfere with the AJAX auto-complete div (I used uppercase to you can view it better):

Code: [Select]
<input type="text" name="search_keywords" size="40" value="{search_keywords}" AUTOCOMPLETE="OFF" class="input" />
Excuse me for my poor english, and sorry if something is wrong!

Regards.
Title: Re: 4images searchform with keywords - like google suggest by using ajax
Post by: BlueScorpion on June 29, 2007, 09:51:49 AM
Hello,

I installed this great MOD too and now i need your advice/help.

Is it for this MOD possible too, to filter words depending on authentication of the user/guest like here for the searchform-keywords-list http://www.4homepages.de/forum/index.php?topic=3850.45 (http://www.4homepages.de/forum/index.php?topic=3850.45) ?
But in the other, linked, MOD this sql-statement is used...

$sql = "SELECT `image_keywords` FROM ".IMAGES_TABLE." WHERE 1 AND cat_id IN (".get_auth_cat_sql("auth_viewcat").") order by `image_keywords` DESC";

... and for the ajax-mod is used...

$sql ="SELECT i.word_id, i.word_text FROM ".WORDLIST_TABLE." i WHERE i.word_text like '".$letters."%'";

Any ideas to solve the problem for the ajax-mod too?

Thx
BluE
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Vincent on July 09, 2007, 11:08:17 PM
Hello i Installed the mod
but ...
on the start page www.foto-kocher.com it is not showing up

if i click "Suchen ..." and i start to fill in it show just writen in white of white feld - so it is difficult to read - if you move over with the cursor it highliht and you could search

to the following toplevel html file - they don't have the requested input to change

edit every toplevel html-file like details.html, home.html, register.html, lightbox.html, member.html and some more... and find:


Code:
<input type="text" name="search_keywords" size="15" class="searchinput" />
replace with:


Code:
<input type="text" name="search_keywords" size="15" class="searchinput" onkeyup="ajax_showOptions(this,'getKeywordsByLetters',event)" />
Hope it works 4you!
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Vincent on July 09, 2007, 11:40:35 PM
hello
i think i found my problem -  i can't remember in which file i but the search-Box on the leftside!
sincerly
vincent
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Vincent on July 17, 2007, 12:00:30 AM
Hello
it is working only it is showing withe letters on withe ground so you can't really read it!
how to make some blak letters?
vincent
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Buggy Driver on July 17, 2007, 08:27:03 PM
In de code you added in step 3 look for

Code: [Select]
background-color:#FFF; /* White background color */

add after
Code: [Select]
color:#000000;  /* text color   (000000 for Black   FFFFFF for White)  */

Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Vincent on July 17, 2007, 11:06:01 PM
thanks a lot
i found it and i change it - the only problem i have is - in europe you have some caracter like  ö ä ü
they are not showing right

sincerly
vincent
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: sowtrig on August 18, 2007, 06:03:27 AM
thx 4 this gr8 MOD,

but how could i use it for anthor lang like Arabic?
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: m.a on November 10, 2007, 01:59:25 AM
thanks a lot
i found it and i change it - the only problem i have is - in europe you have some caracter like  ö ä ü
they are not showing right

sincerly
vincent


thanks Flo2005,
nice MOD! :D

but it is not only Problem with ö ä ü!, and other language like Persian and Arab letters are not showing right!

can you solve the problem?

best Reg.
m.a
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: dave on November 21, 2007, 05:11:45 AM
Cool, this is a really helpfull MOD for our users!  :D
And the umlauts are shown correctly if you overwrite
Code: [Select]
echo $inf["word_id"]."###".$inf["word_text"]."|"; with
Code: [Select]
echo $inf["word_id"]."###".utf8_encode($inf["word_text"])."|";.


Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Vincent on November 21, 2007, 12:27:14 PM
@dave
hello - thanks for the code part - but still you can't search for it.
try on my page to find türkei (turkey)

sincerly
vincent
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: dave on November 21, 2007, 05:46:13 PM
...  but still you can't search for it.

Ah, right! It only fixes the suggestion list entries.  :roll:
The umlauts get lost due to the string replacement in ajax-list-keywords.php. But the DB plays a role in it, too!
Hopefully someone has more time to take a deeper look at it ...
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: ch€ri{Bi}² on December 21, 2007, 06:48:15 PM
:thumbdown:  the link (zip file) is dead :?

[EDIT]
here is the missing file !
Good pretty MOD  :wink:

 :idea: How about authentification ? i mean : users can see only keywords they are allowed to access...
 :arrow: like it was done here (http://www.4homepages.de/forum/index.php?topic=3850.msg95229#msg95229)
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: bernd on August 01, 2008, 11:04:33 AM
This is not too bad but how about making it display how many search results the user can expect when submitting the searchform? I mean I start to type "tre" and it shows me that there is a keyword used named "tree" - nice but I have to submit the search first before I know how many hits I achieve. If I were to see that searching for "tree" would provide me with 1000 images but if I searched for "tree winter" it would only be 10, that would be helpful. So more like Google suggest (still not quite but better :) )
http://www.google.com/webhp?complete=1&hl=en

Any ideas?

cheers,
Bernd
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Sunny C. on August 01, 2008, 02:29:05 PM
Was genau bewirkt das teil?
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: V@no on August 01, 2008, 03:07:34 PM
This is not too bad but how about making it display how many search results the user can expect when submitting the searchform? I mean I start to type "tre" and it shows me that there is a keyword used named "tree" - nice but I have to submit the search first before I know how many hits I achieve. If I were to see that searching for "tree" would provide me with 1000 images but if I searched for "tree winter" it would only be 10, that would be helpful. So more like Google suggest (still not quite but better :) )
http://www.google.com/webhp?complete=1&hl=en

Any ideas?

cheers,
Bernd
Its a good idea, but this will hit so much on performance of this mod...just calculate how much time your site takes to search and then add that to each letter you type.
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Sin Nombre on August 13, 2008, 06:07:41 PM
thank you so much for an easy and useful mod that works right away without having to add more things except for the file which is minor and simple compared to other threads i've seen that have many posts of things they forgot.
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: FunnyUser on November 28, 2008, 09:02:28 AM
I want to shoup the IMAGE_NAME and not the KEYWORDS.

Example: I haven an image in my database named: "Holiday with my family".
And now someone searches for: "holiday" or "family" or "day" than the ajax-script should showup the complete image suggestion like in the example.

OR BETTER: It should search the "keywords" and the "image_name" fields from my database.


Is this possible? Thank you
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: V@no on November 28, 2008, 09:20:07 AM
image name and description is already stored as keywords.
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: ATROXX on July 04, 2009, 05:57:29 PM
I am missing the .zip file in the first post.
the link is dead.

That`s why I am posting it here again. (found in my archives)
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: daymos on July 15, 2009, 12:19:50 AM
how to correct for cyrillic letters?
I try add
Code: [Select]
$letters = preg_replace("/[^а-яa-z0-9 ]/si","",$letters); but still don't work
Title: Re: [MOD] 4images searchform with keywords - like google suggest by using ajax
Post by: Kaliha on November 22, 2009, 06:16:40 PM
а как насчет использования кирилцы? пробовал и
Quote
echo $inf["word_id"]."###".cp1251_encode($inf["word_text"])."|";
И
Quote
$letters = preg_replace("/[^а-яa-z0-9 ]/si","",$letters);
Отображает криво или вообще неработает

i found utf8 to win encode function, but it is not work ((

Code: [Select]
function utf_to_win($str,$to = "w") {
$outstr=;
$recode=array();
$recode[k]=array(
0x2500,0x2502,0x250c,0x2510,0x2514,0x2518,0x251c,0x2524,
0x252c,0x2534,0x253c,0x2580,0x2584,0x2588,0x258c,0x2590,
0x2591,0x2592,0x2593,0x2320,0x25a0,0x2219,0x221a,0x2248,
0x2264,0x2265,0x00a0,0x2321,0x00b0,0x00b2,0x00b7,0x00f7,
0x2550,0x2551,0x2552,0x0451,0x2553,0x2554,0x2555,0x2556,
0x2557,0x2558,0x2559,0x255a,0x255b,0x255c,0x255d,0x255e,
0x255f,0x2560,0x2561,0x0401,0x2562,0x2563,0x2564,0x2565,
0x2566,0x2567,0x2568,0x2569,0x256a,0x256b,0x256c,0x00a9,
0x044e,0x0430,0x0431,0x0446,0x0434,0x0435,0x0444,0x0433,
0x0445,0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,
0x043f,0x044f,0x0440,0x0441,0x0442,0x0443,0x0436,0x0432,
0x044c,0x044b,0x0437,0x0448,0x044d,0x0449,0x0447,0x044a,
0x042e,0x0410,0x0411,0x0426,0x0414,0x0415,0x0424,0x0413,
0x0425,0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,
0x041f,0x042f,0x0420,0x0421,0x0422,0x0423,0x0416,0x0412,
0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x042a
);
$recode[w]=array(
0x0402,0x0403,0x201A,0x0453,0x201E,0x2026,0x2020,0x2021,
0x20AC,0x2030,0x0409,0x2039,0x040A,0x040C,0x040B,0x040F,
0x0452,0x2018,0x2019,0x201C,0x201D,0x2022,0x2013,0x2014,
0x0000,0x2122,0x0459,0x203A,0x045A,0x045C,0x045B,0x045F,
0x00A0,0x040E,0x045E,0x0408,0x00A4,0x0490,0x00A6,0x00A7,
0x0401,0x00A9,0x0404,0x00AB,0x00AC,0x00AD,0x00AE,0x0407,
0x00B0,0x00B1,0x0406,0x0456,0x0491,0x00B5,0x00B6,0x00B7,
0x0451,0x2116,0x0454,0x00BB,0x0458,0x0405,0x0455,0x0457,
0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,
0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F,
0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,
0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F,
0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,
0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F,
0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,
0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x044F
);
$recode[i]=array(
0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,
0x0098,0x0099,0x009A,0x009B,0x009C,0x009D,0x009E,0x009F,
0x00A0,0x0401,0x0402,0x0403,0x0404,0x0405,0x0406,0x0407,
0x0408,0x0409,0x040A,0x040B,0x040C,0x00AD,0x040E,0x040F,
0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,
0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F,
0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,
0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F,
0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,
0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F,
0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,
0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x044F,
0x2116,0x0451,0x0452,0x0453,0x0454,0x0455,0x0456,0x0457,
0x0458,0x0459,0x045A,0x045B,0x045C,0x00A7,0x045E,0x045F
);
$recode[a]=array(
0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,
0x0418,0x0419,0x041a,0x041b,0x041c,0x041d,0x041e,0x041f,
0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,
0x0428,0x0429,0x042a,0x042b,0x042c,0x042d,0x042e,0x042f,
0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,
0x0438,0x0439,0x043a,0x043b,0x043c,0x043d,0x043e,0x043f,
0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,
0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510,
0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,
0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567,
0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,
0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580,
0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,
0x0448,0x0449,0x044a,0x044b,0x044c,0x044d,0x044e,0x044f,
0x0401,0x0451,0x0404,0x0454,0x0407,0x0457,0x040e,0x045e,
0x00b0,0x2219,0x00b7,0x221a,0x2116,0x00a4,0x25a0,0x00a0
);
$recode[d]=$recode[a];
$recode[m]=array(
0x0410,0x0411,0x0412,0x0413,0x0414,0x0415,0x0416,0x0417,
0x0418,0x0419,0x041A,0x041B,0x041C,0x041D,0x041E,0x041F,
0x0420,0x0421,0x0422,0x0423,0x0424,0x0425,0x0426,0x0427,
0x0428,0x0429,0x042A,0x042B,0x042C,0x042D,0x042E,0x042F,
0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x0406,
0x00AE,0x00A9,0x2122,0x0402,0x0452,0x2260,0x0403,0x0453,
0x221E,0x00B1,0x2264,0x2265,0x0456,0x00B5,0x2202,0x0408,
0x0404,0x0454,0x0407,0x0457,0x0409,0x0459,0x040A,0x045A,
0x0458,0x0405,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
0x00BB,0x2026,0x00A0,0x040B,0x045B,0x040C,0x045C,0x0455,
0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x201E,
0x040E,0x045E,0x040F,0x045F,0x2116,0x0401,0x0451,0x044F,
0x0430,0x0431,0x0432,0x0433,0x0434,0x0435,0x0436,0x0437,
0x0438,0x0439,0x043A,0x043B,0x043C,0x043D,0x043E,0x043F,
0x0440,0x0441,0x0442,0x0443,0x0444,0x0445,0x0446,0x0447,
0x0448,0x0449,0x044A,0x044B,0x044C,0x044D,0x044E,0x00A4
);
$and=0x3F;
for ($i=0;$i<strlen($str);$i++) {
$letter=0x0;
$octet=array();
$octet[0]=ord($str[$i]);
$octets=1;
$andfirst=0x7F;
if (($octet[0]>>1)==0x7E) {
$octets=6;
$andfirst=0x1;
} elseif (($octet[0]>>2)==0x3E) {
$octets=5;
$andfirst=0x3;
} elseif (($octet[0]>>3)==0x1E) {
$octets=4;
$andfirst=0x7;
} elseif (($octet[0]>>4)==0xE) {
$octets=3;
$andfirst=0xF;
} elseif (($octet[0]>>5)==0x6) {
$octets=2;
$andfirst=0x1F;
}
$octet[0]=$octet[0] & $andfirst;
$octet[0]=$octet[0] << ($octets-1)*6;
$letter+=$octet[0];
for ($j=1;$j<$octets;$j++) {
$i++;
$octet[$j]=ord($str[$i]) & $and;
$octet[$j]=$octet[$j] << ($octets-1-$j)*6;
$letter+=$octet[$j];
}
if ($letter<0x80) {
$outstr.=chr($letter);
} else {
if (in_array($letter,$recode[$to])) {
$outstr.=chr(array_search($letter,$recode[$to])+128);
}
}
}
return($letters);
}