Removing case sensitive from the glossary extension

Author Message

Børge Warvik

Monday 14 August 2006 7:33:49 am

Hi

I'm using the glossary extension and it workes fine. Only problem is that it is case sensitive and therefor doesn't see the words "word", "wOrd" and "Word" as the same. I've turned on the feature so it only shows words once.

How can I fix this?

Børge

Claudia Kosny

Tuesday 15 August 2006 11:26:44 am

Hello,

I haven't used the glossary extension yet, so here just a wild guess based on a quick look at the code in file sckglossarytemplateoperator.php.
Here is an extract (lines 113 to 134)

        // Loop through each element
        foreach( $glossaryTree as $item )
        {
            $tmp = array(); 
            // All variations of the Name, NAME and name
            $tmp[] = strtoupper( $item["Name"] );
            $tmp[] = strtolower( $item["Name"] );
            $tmp[] = ucfirst( $item["Name"] );

            /*
			* Prevent an upfirst version if it equals the uppercase version
			* This prevents problems when using uppercase glossary words
			* */
            $tmp = array_unique( $tmp ); 
            // Take each variation and make a $replace entry for it
            // the $replace entry contains a link to the full object
            foreach( $tmp as $name )
            {
                $search[] = "/\b" . preg_quote( $name, "/" ) . "(?![$exempt]\w)" . "\b/";
                $replace[] = "<a href=\"" . $sys->indexDir() . "/" . $item["URL"] . "\" title=\"" . strip_tags( $item["Desc"] ) . "\">" . $name . "</a>";
			      }
        } 

In the last foreach you can see the regular expression that is used to find the words in the text. If you want to have this case insensitive you need to change this expression. I think that an 'i' for insensitive behind the delimiter (the last slash) in the value for search[] should be sufficient, but I have not tried it out.
You also need to remove the lines

$tmp[] = strtoupper( $item["Name"] );
$tmp[] = strtolower( $item["Name"] );
$tmp[] = ucfirst( $item["Name"] );

and replace them by a single

$tmp[] =  $item["Name"] ;

as otherwise each found word will be replaced three times.

Please keep in mind that I have not tried it all and the above idea might go totally haywire.

Good luck

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.