Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Mods & Themes (http://www.bvlist.com/forumdisplay.php?f=117)
-   -   Ajax Search (http://www.bvlist.com/showthread.php?t=5742)

lateam 20th November 2010 21:54

Ajax Search
 
1 Attachment(s)
attention

Attention

coding in course






1. create the plugin

Plugin Name:TESTLATEAM.php

Plugin Title:Rechercher un Torrent

Plugin Content:
PHP Code:

<script src="ajaxsearch.js"></script>
<form name="form1">
<input name="keyword" onKeyUp="SendQuery(this.value)" style="WIDTH:100px" autocomplete="off">
<div align="left" class="box" id="autocomplete" style="WIDTH:200px;BACKGROUND-COLOR:#EDF3DE"></div>
</form>
<script language="JavaScript"> HideDiv("autocomplete"); </script> 

2. create root/ajaxsearch.js

PHP Code:

// AjaxSearch 0.1
// Adding Ajax-like search into your ts 5.6
// By lateam

 
var req;
 
function 
Initialize()
{
    try
    {
        
req=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(
e)
    {
        try
        {
            
req=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(
oc)
        {
            
req=null;
        }
    }
 
    if(!
req&&typeof XMLHttpRequest!="undefined")
    {
        
req = new XMLHttpRequest();
    }
 
}
function 
SendQuery(key)
{
    
Initialize();
    
    var 
url="ajaxsearch.php?s="+key;
 
    if(
req!=null)
    {
        
req.onreadystatechange Process;
        
req.open("GET"urltrue);
        
req.send(null);
 
    }
}
 
function 
Process()
{
    if (
req.readyState == 4)
    {
    
// only if "OK"
        
if (req.status == 200)
        {
            if(
req.responseText=="")
                
HideDiv("autocomplete");
            else
            {
                
ShowDiv("autocomplete");
                
document.getElementById("autocomplete").innerHTML =req.responseText;
            }
        }
        else
        {
            
document.getElementById("autocomplete").innerHTML=
                
"There was a problem retrieving data:"+req.statusText;
        }
    }
}
 
function 
ShowDiv(divid)
{
   if (
document.layersdocument.layers[divid].visibility="show";
   else 
document.getElementById(divid).style.display="inline";
}
 
function 
HideDiv(divid)
{
   if (
document.layersdocument.layers[divid].visibility="hide";
   else 
document.getElementById(divid).style.display="block";
}
 
function 
BodyLoad()
{
    
HideDiv("autocomplete");
    
document.form1.keyword.focus();


2. create root/ajaxsearch.php

PHP Code:

<?
    
// AjaxSearch 0.1
    // by lateam
  
    
    
    
$config['dbhost'] = "localhost";        // Database host
    
$config['dbname'] = "xxxxxxxxx";        // Database name
    
$config['dbusername'] = "xxxxxxxx";            // Database username
    
$config['dbpass'] = "xxxxxxxxxxx";                    // Database password
    
$config['tableprefix'] = "";            // Table prefix
    
    
$config['systemtype'] = "drupal";    // valid choices are: drupal, wordpress
    
$config['maxresult'] = 10;                // Number of results to return
    
$config['maxbodylength'] = 60;            // Trimming body length to x number of characters
    
    
    
    
    
if (isset($_REQUEST['s']) && trim($_REQUEST['s'] != ""))
    {
        if (
$link mysql_connect($config['dbhost'], $config['dbusername'], $config['dbpass']))
        {
            if (
mysql_select_db($config['dbname'], $link))
            {
                switch (
strtolower($config['systemtype']))
                {
                    case 
"drupal":
                        
$storytable "torrents";
                        
$titlefield "name";
                        
$bodyfield "genre";
                        
$storyid "id";
                        
$desturl "details.php?id=--storyid--";
                        break;
                    
                    case 
"wordpress":
                        
$storytable "posts";
                        
$titlefield "post_title";
                        
$bodyfield "post_content";
                        
$storyid "ID";
                        
$desturl "?p=--storyid--";
                        break;
                    
                    default:
                        echo 
"Sorry, search is not available.";        // Oopss ..
                
}
                    
                    
                    
                
$stmt "SELECT * FROM " $config['tableprefix'] . "$storytable WHERE $titlefield LIKE '%" addslashes($_REQUEST['s']) . "%' OR $bodyfield LIKE '%" addslashes($_REQUEST['s']) . "%' LIMIT " $config['maxresult'];
                
                if (
$result mysql_query($stmt$link))
                {
                    if (
mysql_num_rows($result) > 0)
                    {
                        while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
                        {
                            
// stripping images and links...
                            
$contents preg_replace("/<img(.)*>|<a (.)*>|<\/a>/i"""$row[$bodyfield]);
                            if (
strlen($contents) > $config['maxbodylength'])
                                
$contents substr($contents0$config['maxbodylength']) . " ...";
                            
$linkurl = (str_replace("--storyid--"$row[$storyid], $desturl));
                            echo 
"<p style=\"cursor: pointer;\" onclick=\"document.location='$linkurl'\"<strong>" $row[$titlefield] . "</strong> - $contents</p>";
                        }  
                    }
                    else
                        echo 
"Sorry, no record matching your search criteria...";
                }
                else
                    echo 
"Sorry, search is not available.";
            }
            else
                echo 
"Sorry, search is not available.";
        }
        else
            echo 
"Sorry, search is not available.";
    }
    else
        echo 
"<script language=\"JavaScript\">HideDiv(\"autocomplete\");</script>";
?>


lafouine022 21st November 2010 23:54

fix charset caracter

1. in ajaxsearch.php

find:
PHP Code:

 $config['dbhost'] = "localhost";        // Database host 

replace with:
PHP Code:

header("Content-Type: text/html; charset=iso-8859-1");  
    
$config['dbhost'] = "localhost";        // Database host 

2. in browse.php

find:
PHP Code:

<form method="post" action="'.$_SERVER['SCRIPT_NAME'].'?">
            <
input type="hidden" name="do" value="search" />
            
'.$lang->browse['bykeyword'].' <input type="text" id="auto_keywords" autocomplete="off" name="keywords" size="40" value="'.(isset($keywords) ? htmlspecialchars_uni($keywords) : '').'" />
            <
script type="text/javascript">
                new 
AutoComplete(\'auto_keywords\', \'ts_ajax.php?action=autocomplete&type=torrent&field=name&keyword=\', { delay: 0.25, resultFormat: AutoComplete.Options.RESULT_FORMAT_TEXT });
            </script>
            <select name="search_type">
                <option value="t_name"'
.($search_type == 't_name' ' selected="selected"' '').'>'.$lang->browse['t_name'].'</option>
                <option value="t_description"'
.($search_type == 't_description' ' selected="selected"' '').'>'.$lang->browse['t_description'].'</option>
                <option value="t_both"'
.($search_type == 't_both' ' selected="selected"' '').'>'.$lang->browse['t_both'].'</option>
                <option value="t_uploader"'
.($search_type == 't_uploader' ' selected="selected"' '').'>'.$lang->browse['t_uploader'].'</option>
                <option value="t_genre"'
.($search_type == 't_genre' ' selected="selected"' '').'>'.$lang->browse['t_genre'].'</option>
            </select>
            '
.$lang->browse['in'].'
                '
.$catdropdown.'
            <input type="image" class="none" style="vertical-align: middle;" src="'
.$BASEURL.'/'.$pic_base_url.'torrent_search.gif" alt="'.$lang->browse['tsearch'].'" />
            </form> 

replace with:
PHP Code:

<script src="ajaxsearch.js"></script>
            <form name="form1" method="post" action="'.$_SERVER['SCRIPT_NAME'].'?">

            <input type="hidden" name="do" value="search" />

            '.$lang->browse['bykeyword'].' <input type="text" id="auto_keywords" onKeyUp="SendQuery(this.value)" autocomplete="off" name="keywords" size="40" value="'.(isset($keywords) ? htmlspecialchars_uni($keywords) : '').'" />


            <script type="text/javascript">

                new AutoComplete(\'auto_keywords\', \'ts_ajax.php?action=autocomplete&type=torrent&field=name&keyword=\', { delay: 0.25, resultFormat: AutoComplete.Options.RESULT_FORMAT_TEXT });

            </script>

            <select name="search_type">

                <option value="t_name"'.($search_type == 't_name' ? ' selected="selected"' : '').'>'.$lang->browse['t_name'].'</option>

                <option value="t_description"'.($search_type == 't_description' ? ' selected="selected"' : '').'>'.$lang->browse['t_description'].'</option>

                <option value="t_both"'.($search_type == 't_both' ? ' selected="selected"' : '').'>'.$lang->browse['t_both'].'</option>

                <option value="t_uploader"'.($search_type == 't_uploader' ? ' selected="selected"' : '').'>'.$lang->browse['t_uploader'].'</option>

                <option value="t_genre"'.($search_type == 't_genre' ? ' selected="selected"' : '').'>'.$lang->browse['t_genre'].'</option>

            </select>

            '.$lang->browse['in'].'

                '.$catdropdown.'

            <input type="image" class="none" style="vertical-align: middle;" src="'.$BASEURL.'/'.$pic_base_url.'torrent_search.gif" alt="'.$lang->browse['tsearch'].'" />
<div align="left" class="none" id="autocomplete" style="WIDTH:200px;BACKGROUND-COLOR:#ADCBE7"></div>
            </form><script language="JavaScript"> HideDiv("autocomplete"); </script> 

:friend::drink:

mmisu120000 22nd November 2010 09:19

Yes, guys, works like a charm!

Good job, really nice one...!

Marco 23rd November 2010 13:54

thx guys

for all searches i have sorry , search is not available ...:)
i see this is a reply error line...so please help me .

lafouine022 23rd November 2010 14:36

1. in ajaxsearch.php

PHP Code:

$config['dbname'] = "xxxxxxxxx";        // Database name
    
$config['dbusername'] = "xxxxxxxx";            // Database username
    
$config['dbpass'] = "xxxxxxxxxxx";                    // Database password 



did you enter the field correctly allocate??

Marco 23rd November 2010 22:55

off course if i didn't wright well then i can't connect to DB but i haven't connection error just this .... :)


thank you :)

lafouine022 24th November 2010 06:11

remplace Genre for seeders
 
oki yes sorry ^^

you have not installed GENRE MOD :smack:
so replace genre by seeders


in ajaxsearch.php

replace:
PHP Code:

switch (strtolower($config['systemtype']))
                {
                    case 
"drupal":
                        
$storytable "torrents";
                        
$titlefield "name";
                        
$bodyfield "genre";
                        
$storyid "id";
                        
$desturl "details.php?id=--storyid--";
                        break; 

with this:
PHP Code:

switch (strtolower($config['systemtype'])) 
                { 
                    case 
"drupal"
                        
$storytable "torrents"
                        
$titlefield "name"
                        
$bodyfield "seeders"
                        
$storyid "id"
                        
$desturl "details.php?id=--storyid--";
                        break; 

and replace this:
PHP Code:

 echo "<p style=\"cursor: pointer;\" onclick=\"document.location='$linkurl'\"<strong>" $row[$titlefield] . "</strong> - $contents</p>"

by this:
PHP Code:

echo "<p style=\"cursor: pointer;\" onclick=\"document.location='$linkurl'\"<font color=navy><b>" $row[$titlefield] . "</b> - $contents Seeders</font></p>"

is work :bubble:

PAX 5th March 2012 15:32

very good mod, thanks :drink:

z3ro 12th December 2013 22:07

Help!
 
What is?

install ajax search and not works!

write torrent name and goto logo.

Help! what problem?

firefly007 14th December 2013 10:21

Quote:

Originally Posted by Raven (Post 43452)
What is?

install ajax search and not works!

write torrent name and goto logo.

Help! what problem?

A little lacking in info :) Could you explain what error you getting.


All times are GMT +2. The time now is 00:57.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.