You are here:  » Global Filter

Support Forum



Global Filter

Submitted by Confuscius on Tue, 2009-12-15 10:51 in

With the various changes between the old and new versions there is one bit of functionality that I wish was in both! For example, there used to be an import function to strip tags that is now a filter that can be applied to EACH feed, say on the description field.

What I would really like to see is a standalone set of GLOBAL filters that can be defined via the interface (eg add the filters to a DUMMY hard coded merchant so that the existing filters table can be used and actually run the global filters AFTER the feed specific filters have been run) - I am sure that you get the idea - it may have been suggested already but I cannot find any reference through search.

What is the best way of approaching this issue? A feeds filter global php file hooked into the admin top menu? Any suggestions or pointers to old topics?

Thanks.

Submitted by support on Tue, 2009-12-15 13:03

Hi,

Thanks for the comments.

What I would suggest in the mean time is adding any code that you require to modify values in all feeds within the import record handler function in includes/admin.php.

In that file, look for the following comment around line 186:

/* apply user filters */

...and immediately BEFORE that point you can add PHP code to modify any value in the $importRecord array; for example $importRecord["description"]. So, to strip HTML from all description fields, add this code:

  $importRecord["description"] = strip_tags($importRecord["description"]);

I'll look into the options for adding Global Filters also.

Cheers,
David.

Submitted by Confuscius on Wed, 2009-12-16 17:31

Hi David

I already have the t-shirt for adding global amendments to the php files!

Anyways, I am getting someway towards a solution. The story so far ...

I have copied the 'filters' table structure to a new table called 'filters_global'. I have then dropped the 'filename' field because I just want to store global filters that are not feed specific!

Next stage is that I have 3 new php files:

/admin/feeds_filters_global.php
/admin/feeds_filters_global_configure.php
/admin/feeds_filters_global_delete.php

whcih I have adjusted to maintain the new table. So I now have a table full of global filters and just one thing to work out - how to append these global rules to the normal rules per feed so that as they are appended back to the array then they need to pick up the related field used from the induvidual feed - or is there another simpler way?

My maintenance screen ends up looking like this ( a simple example) with the fieldd names being stored a the 'generic' references.

============================================================

Site Home | Admin Home | Filters Global | ....

Manage GLOBAL Feed
GLOBAL Filters

Name Case Configure Delete field_name
Text After Configure Delete field_description
Trim Configure Delete field_image_url
Trim Configure Delete field_buy_url
Name Case Configure Delete field_category
Name Case Configure Delete field_brand
Trim Configure Delete field_price

New GLOBAL Filter
Filter Type:

Field:

Add

============================================================

My new table like this:

============================================================

Full Texts id field name created data
Edit Delete 11 field_image_url trim 1260982224 [BLOB - 4 B]
Edit Delete 9 field_description textAfter 1260982012 [BLOB - 29 B]
Edit Delete 8 field_name nameCase 1260982010 [BLOB - 4 B]
Edit Delete 12 field_buy_url trim 1260982412 [BLOB - 4 B]
Edit Delete 13 field_category nameCase 1260982460 [BLOB - 4 B]
Edit Delete 14 field_brand nameCase 1260982570 [BLOB - 4 B]
Edit Delete 15 field_price trim 1260982612 [BLOB - 4 B]

============================================================

I Am sure that you can see my approach - just looking to the best way to 'hook in' the new filters.

Hoping for help / advice.

Paul

Submitted by support on Thu, 2009-12-17 08:54

Hi Paul,

The easiest way is probably to simply load your global filters just as if they were regular "per feed" filters at the same point within the admin_import() function. Look for the following around line 375 of includes/admin.php:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' ORDER BY created";
    if (database_querySelect($sql,$rows))
    {
      $admin_importFiltersExist = true;
      $admin_importFilters = array();
      foreach($rows as $filter)
      {
        $filter["data"] = unserialize($filter["data"]);
        $admin_importFilters[] = $filter;
      }
    }
    else
    {
      $admin_importFiltersExist = false;
    }

...and REPLACE with:

    $admin_importFiltersExist = false;
    $admin_importFilters = array();
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters` WHERE filename='".database_safe($admin_importFeed["filename"])."' ORDER BY created";
    if (database_querySelect($sql,$rows))
    {
      $admin_importFiltersExist = true;
      foreach($rows as $filter)
      {
        $filter["data"] = unserialize($filter["data"]);
        $admin_importFilters[] = $filter;
      }
    }
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."filters_global` ORDER BY created";
    if (database_querySelect($sql,$rows))
    {
      $admin_importFiltersExist = true;
      foreach($rows as $filter)
      {
        $filter["data"] = unserialize($filter["data"]);
        $admin_importFilters[] = $filter;
      }
    }

Hope this helps!

Cheers,
David.

Submitted by Confuscius on Thu, 2009-12-17 11:13

Thanks for the advice - I had been messing with a similar idea BUT it fails because with the global filter then it is not tied to any one feed and for any one feed then the ACTUAL field titles used will vary feed to feed. Anyways, the upshot is that because my original population of my new global filters table inserts the field names of the feeds table as the reference to which field to update (Because I hard coded the original array because I had to!) then it is possible to in effect turn the global filters back into in effect feed specific ones with a couple of nifty lookups. I tried your code, then debugged it by print_r the arrays and then I saw what was missing and 5 minutes later it looks like I have GLOBAL filters!!! Brilliant!!!

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters_global` ORDER BY created";
    if (database_querySelect($sql,$rows))
    {
      $admin_importFiltersExist = true;
      foreach($rows as $filter)
      {
        $filter["data"] = unserialize($filter["data"]);
        $admin_importFilters[] = $filter;
      }
    }

is changed to:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."filters_global` ORDER BY created";
    if (database_querySelect($sql,$rows))
    {
      $admin_importFiltersExist = true;
      foreach($rows as $filter)
      {
$filter["filename"] = $admin_importFeed[filename];
$filter["field" = $admin_importFeed[$filter[field]];
        $filter["data"] = unserialize($filter["data"]);
        $admin_importFilters[] = $filter;
      }
    }

Basically, I need to add back which feed I am working with to the filter array and then substitute the real field name for my dummy one used at the outset. Simplez! Still some more testing but this is a brilliant time saver. :)

Just need to get rid of the filter dependencies on when they were added and turn them into a user selectable ordering system and we can start cooking!

Submitted by Keeop on Mon, 2010-03-29 15:17

Hi David,

Thanks for emailing me the multi-merchant mods - they all seem to be working fine. What I've come across though, as I'm now dealing with these AWin CSV files, is a lot of the data in multiple fields is enclosed by quotes, i.e. "This is product1". I've attempted to remove these in admin.php but with no success. Any help would be most appreciated!

Here's what I've got in admin.php:

foreach($record as $k => $v)
    {
      $tempRec = trim($v);
      $tempRec = str_replace("
","",$tempRec);
      if ($tempRec[0] == "\"")
      {
        $tempRec = substr($tempRec, 1);
        $tempRec = substr($tempRec, 0, -1);
      }
      $record[$k] = $tempRec;
    }

Cheers.
Keeop

Submitted by support on Mon, 2010-03-29 16:34

Hi,

That sounds like quoted text has not been auto-detected; which happens if the data itself is quoted text but the header row is not. In these situations, it's best to select the correct format from the drop-down box instead of choosing the auto-detected Format String on Feed Registration (Step 1), for example "Quoted Text - Header Row - Comma Separated".

That should be all it is...

Cheers,
David.

Submitted by Keeop on Mon, 2010-03-29 16:52

Thanks David! It's been so long since I've used CSV rather than XML that I completely forgot to check that!

Cheers.
Keeop