<?php
/**
 * Search script for use with Blosxom
 *
 * Uses Ape Search by Eduardo Baldan dos Santos
 *   http://phpclasses.org/browse.html/package/655.html
 *
 * This code is based on the Ape Search code. Modified by Paul Bissex
 * 
 * USAGE
 *
 * 1. upload this script and the Ape Search "_classSearch.php" file
 *
 * 2. include the following code in your page template somewhere: 
 * 
 *   <form action="blosxearch.php" method="GET">
 *   <input type="text" size="10" name="keyword" />
 *   </form>
 *
 * 3. create "head.search" and "foot.search" templates in "flavours".  Note that  
 *    these are not real Blosxom templates, just HTML files included by blosxearch. 
 * 
 * 4. see script comments below for configuration and customization.
 *
 *
 * @url http://e-scribe.com/software/blosxearch/
 *
 * @version 0.2.1
 * @license GPL
 */

require_once "./_classSearch.php";

/// Where are your Blosxom text files? ///
$pagebase "/usr/home/foo/";
/// What's the URL of your Blosxom script? ///
$sitebase "http://example.com/blosxom.cgi";


/**
 * Convert "foo.txt" to "foo"
 */
function filestub ($filename)
    {
    
$bits explode ("."$filename);
    return 
$bits [0];
    }
    

/** 
 * Convert "http://example.com//usr/www/mysite/blog/category/foo.txt" to "category/foo.txt"
 * 
 * Hardcoded "10" is specific to neobike.net -- change accordingly
 */
function filepath ($boguspath)
    {
    
$bits explode ("/"$boguspath);
    
$relevant_bits array_slice ($bits10, -1);
    
$path implode ("/"$relevant_bits);
    return 
$path;
    }
    

/// Process search submission ///
$keyword $_REQUEST ['keyword'];
if (
$keyword
    {
    
$search = new search();
    
    
# Set a message when the user does not fill the field, (the class already has a default msg)
    
$search->emptySearch "No search term given";
    
    
# Set a message when the keyword is not found, (the class already has a default msg)
    
$search->notFound "No matches found";
    
    
# Set the path ( if not set the class assumes the actual dir )
    
$search->path $pagebase;
    
    
# set the file-extensions that you want to search
    
$search->ext = array ("txt");
    
    
# set the directories you DON'T want to search 
    
$search->excDir = array("_STATIC","_PENDING""_OLD");
    
    
# perform the search ( returns an array with PageName, WebPath, ModifyDate, FileSize(bytes) )
    
$result $search->Find($keyword);
    
    
# gets the count of the items
    
$total $search->totalRes;

    
# gets the searchtime in seconds
    
$stime $search->searchTime;    
    
    
/// Begin page display: include header ///
    
include $pagebase "flavours/head.search";

    
/// Display results ///
    
if (is_array($result)) 
        {
        
# print "<b>The search took $stime seconds</b><br />";
        
print "Found $total items<br /><ul>";
        foreach (
$result as $item
            { 
            
/// Build URL and printable bits ///
            
$stub filestub ($item ['Name']);
            
/// Prettify Blosxom filename ///
            
$stubdisplay ucwords ((strtr ($stub"_"" ")));
            
$path filepath ($item ['WebPath']);
            print 
"<li>In <b>$path</b>: <a href='$sitebase$path/$stub.html'>$stubdisplay</a></li>";
            } 
        print 
"</ul>";
        } 
    else 
        {
        print 
$search->notFound;
         } 
    print 
"<br /><br />";
    include 
$pagebase "flavours/foot.search";
    } 
?>