You are here:  » Text After - Conditional Filter


Text After - Conditional Filter

Submitted by ChrisNBC on Thu, 2015-04-02 12:09 in

Hi David,

Hope all is going well.

As you know, for one of my sites I'm breaking down a number of product feeds so that I can re build the product names using 'text after' and 'text before' filters. I wondered if you could tell me if there are any existing filters which would allow me to add 'text after' but conditionally. For example if the product name did not contain the word 'green', the filter would add the word 'green'?

Thanks in advance.

Regards
Chris

Submitted by support on Thu, 2015-04-02 13:23

Hi Chris,

You can make a Text After Conditional filter to do just that - have a go with the following, add to the end of includes/filter.php, just before the closing PHP tag:

  /*************************************************/
  /* textAfterConditional */
  /*************************************************/
  $filter_names["textAfterConditional"] = "Text After Conditional";
  function filter_textAfterConditionalConfigure($filter_data)
  {
    widget_textBox("Text","text",TRUE,$filter_data["text"],"",3);
  }
  function filter_textAfterConditionalValidate($filter_data)
  {
    if (!$filter_data["text"])
    {
      widget_errorSet("text","required field");
    }
  }
  function filter_textAfterConditionalExec($filter_data,$text)
  {
    if (strpos($text,trim($filter_data["text"]))===FALSE)
    {
      return $text.filter_recordPlaceholders($filter_data["text"]);
    }
    else
    {
      return $text;
    }
  }

You can still include the leading space etc. in the text to add, the strpos() check will ignore this (by way of the trim() function) and then the text will be only be applied if it does not already exist in the field value being processed.

Cheers,
David.
--
PriceTapestry.com