New Searchbox if there a no results New Searchbox if there a no results
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

New Searchbox if there a no results

Started by flasyn, January 26, 2006, 09:36:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

flasyn

Hi,

I am trying to make the searchfunction easier for users. If there are no matches I would like to send out the standard message "No image to display" and put a new searchbox beneath.

I guess I have to edit functions.inc.php in  line 1704 or 1869 (right?) and put in the code for a new search box. Is there anyone who can assist me?


        } else {
                theme_no_img_to_display($album_name);
        }


Tkank you!


Paver

You could actually do this with a plugin, I'm pretty sure, so you don't have to modify the core code.  My plugin "Search Album Title & Description" on the plugins board adds on a Search Albums table to the search results page, so you could use the same hook to add in the search box.  (The plugin also replaces the search page with a custom one, but that's not related to what you need.)

Take a look at the plugin.  If you prefer to simply modify the core script, I can lend a hand, when I have a little more time.

flasyn

Thanks Paver for helping out.  ;)  I didn't know about the plugin. I will take a look at it.

Paver

I take back my previous statement.  Well, what I mean to say is that sure, you could do it with a plugin, but you could also do it in your theme.php, which is not modifying the core code, so that's a very reasonable way to do it.

What you'll be doing is creating a custom theme_no_img_to_display() function.  Copy the code below into your theme.php:
function theme_no_img_to_display($album_name)
{
    global $lang_errors, $template_no_img_to_display;

    static $template = '';
    static $spacer;

    if ((!$template)) {
        $template = $template_no_img_to_display;
        $spacer = template_extract_block($template, 'spacer');
    }

  // put mod here for quick search box before "no image to display" table

    $params = array('{TEXT}' => $lang_errors['no_img_to_display']);
    starttable('100%', $album_name);
    echo template_eval($template, $params);
    endtable();

  // put mod here for quick search box afer "no image to display" table
}


This is the sample code from sample/theme.php that is used to customize the "no image to display" table, except I added in 2 comment lines that tell you where to put the code for adding a quick search box.  This function is used whenever an album has no image to display, either for an empty album, or an empty search results meta-album.  Since it's used for both, you need to check whether this function is being called for an empty search results reason and not for an empty regular album.

To add a quick search box, choose whether you want this above or below the "no image to display" table, and put the code below at the appropriate line:

  // mod begin - add quick search box
   if ($_POST['search'] || $_GET['search']) {

echo <<<EOT
<form method="get" action="thumbnails.php" name="searchcpg">
            <input type="hidden" name="album" value="search" />
            <input type="hidden" name="type" value="full" />
            <input type="input" name="search" maxlength="255" value="" class="textinput" />
            <input type="submit" value="Quick Search" />
&gt; <a href="search.php">Advanced Search</a>
          </form>
          <script language="javascript" type="text/javascript">
          <!--
          document.searchcpg.search.focus();
          -->
          </script>
EOT;
    }
  // mod end - add quick search box


Warning:  If you want to use my Search Album plugin, you need to modify the "Advanced Search" link above to point to "index.php?file=search_album/search" instead of "search.php".  I just realized my plugin breaks the regular search form and so if you link to it, an error will occur.  I will fix that for my plugin, but for now, please pick the correct link for the "Advanced Search" link, or just delete that line if you don't want it.  So I don't need to add a post to this thread in the future, version 1.02 of the Search Album plugin has this problem.  I'll make sure to put the fix into the next release, so look in the plugin thread for the version number to determine if you need to change this code or not.  Ideally, you don't want to manually change anything when activating or deactivating a plugin.  Otherwise, what's the point of having a plugin as opposed to a hack?   :P

flasyn

Wow, thanks a lot!  ;)

I'll implement that.

[whisper-mode: on] I know I shouldn't be saying that and I hope no one accuses me of highjacking the 1.4 forum, but I'm still using 1.3 (extremly modified and not open to public, thus no risk concerning the security leaks in 1.3).  I just saw that the code for the  searchfunction is still the same in 1.4 and thought that other users want to offer their users the advanteges of an easier search. But your plugin is certainly the easiest and most convenient solution. [whisper-mode: off]

Joachim Müller

Quote from: flasyn on January 27, 2006, 05:16:08 PM
but I'm still using 1.3
Why did you post your thread on this board then?

Quote from: flasyn on January 27, 2006, 05:16:08 PMI just saw that the code for the  searchfunction is still the same in 1.4
no, it isn't - it has changed completely. How do you come to this conclusion?

Paver

@flasyn: You don't have to whisper about using 1.3.  It's perfectly acceptable to stick with 1.3 and it will be supported.  But please use the appropriate boards for asking questions about issues in 1.3.

My answer was for 1.4.  If you want to ask the same question for 1.3, please start a thread on the analogous section of the 1.3 board.