vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How can I add a search widget to my vb 4 cms? (https://vborg.vbsupport.ru/showthread.php?t=271889)

metalguy639 10-12-2011 12:42 PM

How can I add a search widget to my vb 4 cms?
 
I need to create a search widget for my vb4 cms. I tried just copying and pasting the search box code into a html widget and it does not process the special vb raw codes. So I need to know how to add the search box that members can use to search the site with. Thanks

kh99 10-12-2011 01:01 PM

Maybe you could create a new template and put the search box code in it, then write a php widget to render the template. Here's an article about rendering templates: https://vborg.vbsupport.ru/showthread.php?t=228078 , you should be able to copy code from that and modify it. (For a php widget you'd want to set $output to the result of the call to render() ).

metalguy639 10-12-2011 09:16 PM

YUCK! Sorry that is way more involved than I wanted. I'm not a php programmer so some of that stuff makes no sense to me. There is not a widget already done for this somewhere? I find it hard to believe that no one has done one yet. I searched for hours but could not find anything.

kh99 10-12-2011 09:35 PM

I really don't know if one exists or not, but if you post the search form code you found I'll see if I can do the php for it.

metalguy639 10-12-2011 10:05 PM

I took the navbar search code because I wanted it to basically be like the navbar but just in a widget.

Code:

<vb:if condition="$vboptions['enablesearches']">
        <div id="globalsearch" class="globalsearch">
                <form action="search.php?{vb:raw session.sessionurl}do=process" method="post" id="navbar_search" class="navbar_search">
                        <vb:comment><input type="hidden" name="s" value="{vb:raw session.sessionurl}" /></vb:comment>
                        <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
                        <input type="hidden" name="do" value="process" />
                        <span class="textboxcontainer"><span><input type="text" value="" name="query" class="textbox" tabindex="99"/></span></span>
                        <span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search<vb:if condition="$stylevar['textdirection'] == 'rtl'">_rtl</vb:if>.<vb:if condition="(is_browser('ie') AND !is_browser('ie', 7) AND !is_browser('ie', 8))">gif<vb:else />png</vb:if>" name="submit" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span>
                </form>
                <ul class="navbar_advanced_search">
                        <li><a href="search.php{vb:raw session.sessionurl_q}" accesskey="4">{vb:rawphrase advanced_search}</a></li>
                </ul>
        </div>
        </vb:if>

Thanks

kh99 10-12-2011 11:11 PM

OK, well, it basically works but there's problems with the formatting and I'm not really big on CSS. I had to take out some of the classes to get it to look right, and I had to change the submit button to a standard button because for some reason the image wouldn't show up (even though it showed exactly the same path as the one in the navbar :confused:). Anyway, I created a new template named search_widget with this code:

Code:

        <div id="globalsearch_widget">
                <form action="search.php?{vb:raw session.sessionurl}do=process" method="post" id="search_widget">
                        <input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
                        <input type="hidden" name="do" value="process" />
                        <span class="textboxcontainer"><span><input type="text" value="" name="query" class="textbox" tabindex="99"/></span></span>
<span class="buttoncontainer"><span><input type="submit" name="submit" value="Search" tabindex="100"/></span></span>
                </form>
                <a href="search.php{vb:raw session.sessionurl_q}" accesskey="4">{vb:rawphrase advanced_search}</a>
        </div>


and then created a new "php direct execution" widget, and in the configuration I inserted this (replace the code that's already there)

Code:

$templater = vB_Template::create('search_widget');
$output = $templater->render();


and I set the cache refresh time to 0 (you could probably set it to something high so it doesn't refresh since it never changes, but then when you want to work on it it's annoying). Also, naming the template search_widget makes it go inside the "Search Templates" group in the style manager template list, so if you don't want that you could name it something else (and change it in the php code as well).

Anyway, it's not just like the navbar so I realize it's not exactly what you wanted, but maybe you can figure out the formatting.

metalguy639 10-13-2011 12:23 AM

Awesome! That has worked perfectly! Thanks so much :)


All times are GMT. The time now is 11:21 PM.

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.01551 seconds
  • Memory Usage 1,732KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete