Joomla! com_search glitch

Tags: ,

Let’s come on a site joomla.org and click on the Search menu item. Now we enter text “test   test” for search (with three spaces between words!). As a result of the search the huge document with a lot of “<span class=”highlight”></span>” is received.

To get rid of this glitch, it is necessary in a file /components/com_search/search.php after a line

$searchword = strval( mosGetParam( $_REQUEST, 'searchword', '' ) );

(or, in older versions

$searchword = $database->getEscaped( trim( $searchword ) );

) add

$searchword = preg_replace( '/\s{2,}/s', ' ', $searchword );

It will allow to remove a series of spaces from the search query.

PS. Firstly I have found the description of this glitch and a method of solution at russian forum joomlaforum.ru.

Related Posts

6 Responses to “Joomla! com_search glitch”

  1. 1
    Anthony Says:

    Now THAT works great - thanks!!

  2. 2
    Tien Do Xuan Says:

    Here is another good (not sure if better) solution but clear for PHP new bies like me.
    Open file components/com_search/search.php find this line of code:

    $searchword = strval( mosGetParam( $_REQUEST, ’searchword’, ” ) );

    Add these lines:

    //Remove many redundant spaces - hacker :))
    $searchword_array = explode(” “, $searchword);
    $searchword = “”;
    for($i=0;$i

  3. 3
    Physicist Says:

    I conjecture what you mean, but I think preg_replace works faster then explode and following concatenation.

  4. 4
    Bahri Bare Says:

    Hi there and thanks for the tutorials they actually worked  now I had a  question for you :

    I would like to give my users the ability to search the database and instead displaying the link as a text is it possible to have displayed picture instead as a link .

    The other question I had was I like to display three drop down select lists on the front page so for example one of them would have Car Names listed   the otherone  would have Car Model  listings and the third one would have  Car Color  now my question is how can I make it work so that if one of my users  selects :BMW car—>320–>RED  it would show only that type of Car and not all types of cars that I have stored in my database  and again no text as a link but Picture of that car .

    Thank you for your help in this matter!

    Bahri Bare

  5. 5
    Physicist Says:

    Bahri Bare:

    I would like to give my users the ability to search the database and instead displaying the link as a text is it possible to have displayed picture instead as a link.

    The most convenient way to solve this problem is creation of own search component which will display images in results. However, if you will not use the built in search for other purposes, it is possible to unpublish all search mambots and to write the mambot, which will display images.

    The other question I had was I like to display three drop down select lists on the front page so for example one of them would have Car Names listed the otherone would have Car Model listings and the third one would have Car Color now my question is how can I make it work so that if one of my users selects :BMW car–>320->RED it would show only that type of Car and not all types of cars that I have stored in my database and again no text as a link but Picture of that car.

    In this case, it is really easier to write the component. Thus, it is possible to use any way of creation of "dependent" lists (including AJAX).

  6. 6
    Easyman Says:

    Hi!

    Just wanted to give thanks for this fix.

You can follow any responses to this entry through the RSS 2.0 feed.

Leave a Reply