Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-07-2011, 12:48 PM
Scandal's Avatar
Scandal Scandal is offline
 
Join Date: Dec 2005
Location: Athens / Greece
Posts: 409
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Word Suggestion (help with AJAX & PHP - simple question) Mindestic GlosPro

Well, on memberlist search, there is the function for word (username) suggest:


The HTML Code of this search field is:
HTML Code:
<div class="fieldset">
            Όνομα χρήστη (ψευδώνυμο)
            <div id="userfield"><input type="text" class="bginput" id="userfield_txt" size="50" name="ausername" value="" /></div>
            
               <div id="userfield_menu" class="vbmenu_popup" style="display:none"></div>
               <script type="text/javascript" src="clientscript/vbulletin_ajax_namesugg.js?v=$vboptions[simpleversion]"></script>
               <script type="text/javascript">
               <!--
               vbmenu_register('userfield', true);
               snc = new vB_AJAX_NameSuggest('snc', 'userfield_txt', 'userfield');
               //-->
               </script>
            
         </div>
The content of vbulletin_ajax_namesugg.js is the following (look the "ajax.php?do=usersearch") :
----------------------------
function vB_AJAX_NameSuggest(C,A,D){var B=userAgent.match(/applewebkit\/([0-9]+)/);if(AJAX_Compatible&&!(is_saf&&!(B[1]>=412))){this.menuobj=fetch_object(D+"_menu");this .textobj=fetch_object(A);this.textobj.setAttribute ("autocomplete","off");this.textobj.onfocus=functi on(E){this.obj.active=true};this.textobj.onblur=fu nction(E){this.obj.active=false};this.textobj.obj= this;this.varname=C;this.menukey=D;this.fragment=" ";this.donenames="";this.selected=0;this.menuopen= false;this.timeout=null;this.names=new Array();this.active=false;this.ajax_req=null;this. allow_multiple=false;this.min_chars=3;this.get_tex t=function(){if(this.allow_multiple){var E=this.textobj.value.lastIndexOf(";");if(E==-1){this.donenames=new String("");this.fragment=new String(this.textobj.value)}else{this.donenames=new String(this.textobj.value.substring(0,E+1));this.f ragment=new String(this.textobj.value.substring(E+1))}}else{th is.fragment=new String(this.textobj.value)}this.fragment=PHP.trim( this.fragment)};this.set_text=function(E){if(this. allow_multiple){this.textobj.value=PHP.ltrim(this. donenames+" "+PHP.unhtmlspecialchars(this.names[E])+" ; ")}else{this.textobj.value=PHP.unhtmlspecialchars( this.names[E])}this.textobj.focus();this.menu_hide();return false};this.move_row_selection=function(E){var F=parseInt(this.selected,10)+parseInt(E,10);if(F<0 ){F=this.names.length-1}else{if(F>=this.names.length){F=0}}this.set_row_ selection(F);return false};this.set_row_selection=function(E){var F=fetch_tags(this.menuobj,"td");F[this.selected].className="vbmenu_option";this.selected=E;F[this.selected].className="vbmenu_hilite"};this.key_event_handler =function(E){E=E?E:window.event;if(this.menuopen){ switch(E.keyCode){case 38:this.move_row_selection(-1);return false;case 40:this.move_row_selection(1);return false;case 27:this.menu_hide();return false;case 13:this.set_text(this.selected);return false}}this.get_text();if(this.fragment.length>=th is.min_chars){clearTimeout(this.timeout);this.time out=setTimeout(this.varname+".name_search();",500) }else{this.menu_hide()}};this.name_search=function (){if(this.active){this.names=new Array();if(YAHOO.util.Connect.isCallInProgress(thi s.ajax_req)){YAHOO.util.Connect.abort(this.ajax_re q)}this.ajax_req=YAHOO.util.Connect.asyncRequest(" POST","ajax.php?do=usersearch",{success:this.handle_ajax_request,failure:vBulle tin_AJAX_Error_Handler,timeout:vB_Default_Timeout, scope:this},SESSIONURL+"securitytoken="+SECURITYTO KEN+"&do=usersearch&fragment="+PHP.urlencode(this. fragment))}};this.handle_ajax_request=function(F){ if(F.responseXML){var G=F.responseXML.getElementsByTagName("user");for(v ar E=0;E<G.length;E++){this.names[E]=G[E].firstChild.nodeValue}if(this.names.length>0){this .menu_build();this.menu_show()}else{this.menu_hide ()}}};this.menu_build=function(){this.menu_empty() ;var F=new RegExp("^("+PHP.preg_quote(this.fragment)+")","i") ;var G=document.createElement("table");G.cellPadding=4; G.cellSpacing=1;G.border=0;for(var E in this.names){if(YAHOO.lang.hasOwnProperty(this.name s,E)){var H=G.insertRow(-1).insertCell(-1);H.className=(E==this.selected?"vbmenu_hilite":" vbmenu_option");H.title="nohilite";H.innerHTML='<a onclick="return '+this.varname+".set_text("+E+')">'+this.names[E].replace(F,"<strong>$1</strong>")+"</a>"}}this.menuobj.appendChild(G);if(this.vbmenu==n ull){if(typeof (vBmenu.menus[this.menukey])!="undefined"){this.vbmenu=vBmenu.menus[this.menukey]}else{this.vbmenu=vBmenu.register(this.menukey,tru e)}}else{this.vbmenu.init_menu_contents()}};this.m enu_empty=function(){this.selected=0;while(this.me nuobj.firstChild){this.menuobj.removeChild(this.me nuobj.firstChild)}};this.menu_show=function(){if(t his.active){this.vbmenu.show(fetch_object(this.men ukey),this.menuopen);this.menuopen=true}};this.men u_hide=function(){try{this.vbmenu.hide()}catch(E){ }this.menuopen=false};this.textobj.onkeyup=functio n(E){return this.obj.key_event_handler(E)};this.textobj.onkeyp ress=function(E){E=E?E:window.event;if(E.keyCode== 13){return(this.obj.menuopen?false:true)}}}};
-------------------------------

For ajax.php?do=usersearch, in ajax.php there are these lines:
PHP Code:
// #############################################################################
// user name search

if ($_POST['do'] == 'usersearch')
{
    
$vbulletin->input->clean_array_gpc('p', array('fragment' => TYPE_STR));

    
$vbulletin->GPC['fragment'] = convert_urlencoded_unicode($vbulletin->GPC['fragment']);

    if (
$vbulletin->GPC['fragment'] != '' AND strlen($vbulletin->GPC['fragment']) >= 3)
    {
        
$fragment htmlspecialchars_uni($vbulletin->GPC['fragment']);
    }
    else
    {
        
$fragment '';
    }

    
$xml = new vB_AJAX_XML_Builder($vbulletin'text/xml');
    
$xml->add_group('users');

    if (
$fragment != '')
    {
        
$users $db->query_read_slave("
            SELECT userid, username FROM " 
TABLE_PREFIX "user
            WHERE username LIKE('" 
$db->escape_string_like($fragment) . "%')
            ORDER BY username
            LIMIT 15
        "
);
        while (
$user $db->fetch_array($users))
        {
            
$xml->add_tag('user'$user['username'], array('userid' => $user['userid']));
        }
    }

    
$xml->close_group();
    
$xml->print_xml();




I want to use a similar word suggestion function on the search page of Mindestic GlosPro:

HTML Code:
<td>
$vbphrase[glossary_search_word]:<br />
<input type="text" class="bginput" name="search" value="$searchtermword" size="25">
</td>
The terms of the glossary, there are on the table "glossary" in the field "glossaryname".

I think that I should create a copy of vbulletin_ajax_namesugg.js for example with the name vbulletin_ajax_termsugg.js with some changes, then to add an if ($_POST['do'] == 'glossarysearch') on ajax.php and finally to make some changes on the html code of the search field...

Any help with these changes?
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:49 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03909 seconds
  • Memory Usage 2,320KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete