You are here:  » Filtering Forward Slashes In Category Field


Filtering Forward Slashes In Category Field

Submitted by jmrwv on Sat, 2006-09-16 15:53 in

I'm trying to work around a few issues with categories in CJ feeds. I think I can make use of the Split Before and Split After filters found elsewhere in the forum, but some of my category fields use "/" to show heirarchical categories like:

Department/Category/Subcategory

I could split out what I want with the Split filters above, except that I think PT is removing the "/" before I can filter it myself. My goal here is to remove the "Department/" part using Split After and then change "Category/Subcategory" to "Category - Subcategory".

I could take the approach of removing the tapestry_normalise function from the category field only as described here:

http://www.pricetapestry.com/node/320

and then do the filtering on the "/" manually, but I don't want to miss something and create unpredictable side effects by allowing other weird characters to get through. Instead of removing the normalisation of the category field, would it make sense to create a new function in tapestry.php and call it tapestry_normalise_category, then simply alter the code to change "/" characters to a safer character that would allow for further filtering? If so, how could you change the tapestry_normalise code to do this (I don't understand regular expressions at all)?

If I'm making this more complicated than necessary, by all means point me in the right direction.

Thanks,
Jim

Submitted by support on Sun, 2006-09-17 02:29

Hi Jim,

In fact, you can provide an optional second parameter in the call to the tapesty_normalise() function containing a list of characters to allow in the string. Therefore, you only need to make a change to includes/admin.php in order to do this. Find the following code (starting at line 168 in the distribution):

    if ($admin_importFeed["field_category"])
    {
      $record[$admin_importFeed["field_category"]] = tapestry_normalise($record[$admin_importFeed["field_category"]]);
    }

And change it as follows:

    if ($admin_importFeed["field_category"])
    {
      $record[$admin_importFeed["field_category"]] = tapestry_normalise($record[$admin_importFeed["field_category"]],"\/");
    }

"/" is a special character within a regular expression, which is why it needs to be escaped with a backslash. Ordinary characters would not need to be prefixed in this way.

Hope this helps!
Cheers,
David.