For a complete introduction to Interchange filters, please see the filter glossary entry.
Table of Contents
acl2hash — convert Interchange ACL string to a Perl hash representation
The filter is specific to the ACL widget and probably should not be used otherwise.
The filter doesn't need to be selected for the widget to
operate in the table-editor.
Interchange 5.7.0:
Source: code/Filter/acl2hash.filter
Lines: 34
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: acl2hash.filter,v 1.3 2007/03/30 23:40:44 pajamian Exp $
CodeDef acl2hash Filter
CodeDef acl2hash Description acl2hash
CodeDef acl2hash Visibility private
CodeDef acl2hash Routine <<EOR
sub {
my ($value) = @_;
my $orig = $value;
$value =~ s/^[\s,\0]+//;
$value =~ s/[\s,\0]+$//;
return $value if $value =~ /^\{.*\}$/s;
$value =~ s/\0//g;
my $hash = Vend::Util::get_option_hash($value)
or return '{}';
my @del;
while(my ($k, $v) = each %$hash) {
push @del, $k if $v =~ /d/;
push @del, $k if ! length($k);
}
delete @{$hash}{@del} if @del;
my $out = ::uneval_it($hash);
return $out;
}
EOR
alpha — eliminate non-alpha characters
The filter eliminates any non-alpha characters (that is, anything that's not
in a-zA-Z range).
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/alpha.filter
Lines: 20
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: alpha.filter,v 1.7 2007/08/20 21:11:09 jon Exp $
CodeDef alpha Filter
CodeDef alpha Description A-Za-z only
CodeDef alpha Help Returns only ASCII alphabetic characters (A-Z and a-z)
CodeDef alpha Routine <<EOR
sub {
my $val = shift;
$val =~ s/[^A-Za-z]+//g;
return $val;
}
EOR
alphanumeric — eliminate non-alphanumeric characters
The filter eliminates any non-alphanumeric characters
(that is, anything that's not in a-zA-Z0-9 range).
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/alphanumeric.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: alphanumeric.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef alphanumeric Filter
CodeDef alphanumeric Description A-Za-z0-9 only
CodeDef alphanumeric Routine <<EOR
sub {
my $val = shift;
$val =~ s/[^A-Za-z0-9]+//g;
return $val;
}
EOR
backslash — eliminate backslashes
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/backslash.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: backslash.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef backslash Filter
CodeDef backslash Description Strip backslash
CodeDef backslash Routine <<EOR
sub {
my $val = shift;
$val =~ s/\\+//g;
return $val;
}
EOR
bold — enclose input in HTML <b> (bold) tag
Example: Filter example
"[filter bold]To Boldly Go Where No One Has Gone Before![/filter]" -- Star Trek
Interchange 5.7.0:
Source: code/Filter/bold.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: bold.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef bold Filter
CodeDef bold Description HTML bold
CodeDef bold Routine <<EOR
sub {
return '<b>' . shift(@_) . '</b>';
}
EOR
cgi — expand to value of the CGI variable specified in body
The filter expands to the value of a CGI variable. Name of the variable is specified in filter body.
Example: Filter example
[cgi name=online_cgi_test set="TEST VALUE" hide=1] My test value is [filter cgi]online_cgi_test[/filter]
Interchange 5.7.0:
Source: code/Filter/cgi.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: cgi.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef cgi Filter
CodeDef cgi Description Get CGI value of variable
CodeDef cgi Routine <<EOR
sub {
return $CGI::values{$_[0]};
}
EOR
checkbox — return user-supplied value if its length is 1 or more, an empty string otherwise
The filter checks for the length of input. In case the input contains one or more characters (a true number, in fact), it returns the input itself. If the length is zero, an empty string is returned.
The filter is suitable for retrieving values out of HTML checkboxes.
Interchange 5.7.0:
Source: code/Filter/checkbox.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: checkbox.filter,v 1.3 2007/03/30 23:40:44 pajamian Exp $
CodeDef checkbox Filter
CodeDef checkbox Routine <<EOR
sub {
my $val = shift;
return length($val) ? $val : '';
}
EOR
colons_to_null — replace double colons "::" with \0 (null) character
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/colons_to_null.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: colons_to_null.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef colons_to_null Filter
CodeDef colons_to_null Description :: to NULL
CodeDef colons_to_null Routine <<EOR
sub {
my $val = shift;
$val =~ s/::/\0/g;
return $val;
}
EOR
commify — add thousands separator to a number, and trim to specified number of decimal places
The filter adds thousands separator (a comma ",", usually)
to a number, and trims decimal places to a specified maximum length.
Example: Filter example
[set online_commify_test]1234567890.123456[/set] [filter op=commify.2 interpolate=1][scratchd online_commify_test][/filter]
Interchange 5.7.0:
Source: code/Filter/commify.filter
Lines: 20
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: commify.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef commify Filter
CodeDef commify Description Commify
CodeDef commify Routine <<EOR
sub {
my ($val, $tag, $places) = @_;
$places = 2 unless defined $places;
$val = sprintf("%.${places}f", $val) if $places;
return Vend::Util::commify($val);
}
EOR
compress_space — eliminate leading and trailing whitespace and compress all "in-string" whitespace occurrences to exactly 1 space each
The filter eliminates leading and trailing whitespace, and compresses all occurrences of whitespace in a string to exactly 1 space on each occurrence.
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/compress_space.filter
Lines: 21
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: compress_space.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef compress_space Filter
CodeDef compress_space Description Collapse whitespace
CodeDef compress_space Routine <<EOR
sub {
my $val = shift;
$val =~ s/\s+$//g;
$val =~ s/^\s+//g;
$val =~ s/\s+/ /g;
return $val;
}
EOR
convert_date — convert date to a specified format
The filter calls convert-date to output date according to the
specified format string.
For the accepted formats in which the input date needs to be specified,
see convert-date.
See time glossary entry for a list and description of format specifiers.
Example: Filter example
[filter convert_date."%B %e, %Y"][time][/filter].
Although this filter looks almost exactly like the convert-date tag,
there's one simple difference in the implementation which is interesting
to mention. If you call the convert-date tag with empty
(or invalid) time string, it will default to the current
time; if you call this <filter>convert_date</filter> filter with an empty time string,
then the current time will not be assumed
(because <filter>convert_date</filter> won't call convert-date with no data)
and empty string will stay an empty string.
Interchange 5.7.0:
Source: code/Filter/convert_date.filter
Lines: 26
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: convert_date.filter,v 1.7 2007/03/30 23:40:44 pajamian Exp $
CodeDef convert_date Filter
CodeDef convert_date Description Convert date
CodeDef convert_date Visibility private
CodeDef convert_date Routine <<EOR
sub {
my $time = shift(@_);
# Don't convert nothing to something
return '' unless $time;
shift(@_);
my $fmt = shift(@_);
while(my $add = shift(@_)) {
$fmt .= " $add";
}
return $Tag->convert_date({ fmt => $fmt, body => $time});
}
EOR
crypt — run Unix crypt() function on input data
Example: Filter example with random salt
Encrypted string TEST with random salt is:
[filter crypt]TEST[/filter].
Example: Filter example with hand-specified salt
Encrypted stringTESTwith salt ofABis: [filter crypt.AB]TEST[/filter].
Interchange 5.7.0:
Source: code/Filter/crypt.filter
Lines: 18
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: crypt.filter,v 1.5 2007/03/30 23:40:44 pajamian Exp $
CodeDef crypt Filter
CodeDef crypt Description Crypt
CodeDef crypt Routine <<EOR
sub {
my ($val, $tag, $salt) = @_;
return crypt($val, $salt ? $salt : random_string(2));
}
EOR
currency — format number as currency, honoring default or specified locale
The filter formats input number as a currency. The default locale is honored, but a specific locale can also be specified. Interchange currency-related options are honored too, of course.
Interchange 5.7.0:
Source: code/Filter/currency.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: currency.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef currency Filter
CodeDef currency Description Currency
CodeDef currency Routine <<EOR
sub {
my ($val, $tag, $locale) = @_;
my $convert = $locale ? 1 : 0;
return Vend::Util::currency($val, 0, $convert, { locale => $locale });
}
EOR
date2time — convert date (possibly with specified time) to number of seconds since Epoch
The filter replaces date specification in form of
MM[/-]DD[/-]YY(YY)?(:hh(mm)?)?
to a number of seconds since epoch.
If the year specification contains 2 digits only and is less than
50, as is say, 02,
then it is treated as an offset from year 2000, and not
1900. In other words, 05 is understood
as year 2005, 80 is understood as
1980.
Unspecified month or day default to 1, unspecified
hours or minutes default to 0.
Example: Converting dates and times to seconds since Epoch
[filter date2time]01/01/2005[/filter] [filter date2time]01/01/05[/filter] [filter date2time]01-01-2005[/filter] [filter date2time]01-01-05[/filter] [filter date2time]01-01-2005:10[/filter] [filter date2time]01-01-05:1045[/filter]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The timelocal() function used in the filter comes from the
Time::Local Perl module.
Interchange 5.7.0:
Source: code/Filter/date2time.filter
Lines: 50
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: date2time.filter,v 1.6 2007/03/30 23:40:44 pajamian Exp $
CodeDef date2time Filter
CodeDef date2time Description Date to UNIX time (deprecated - use datetime2epoch instead)
CodeDef date2time Visibility private
CodeDef date2time Routine <<EOR
sub {
my $val = shift;
use Time::Local;
$val =~ s/\0+//g;
if($val =~ m:(\d+)[-/]+(\d+)[-/]+(\d+):) {
my ($yr, $mon, $day) = ($3, $1, $2);
my $time;
$val =~ /:(\d+)$/
and $time = $1;
if(length($yr) < 4) {
$yr =~ s/^0//;
$yr = $yr < 50 ? $yr + 2000 : $yr + 1900;
}
$mon =~ s/^0//;
$day =~ s/^0//;
$val = sprintf("%d%02d%02d", $yr, $mon, $day);
return $val unless $time;
$val .= sprintf('%04d', $time);
}
my $time;
$val =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?/;
my ($yr, $mon, $day, $hr, $min) = ($1 || 0, $2 || 1, $3 || 1, $4 || 0, $5 || 0);
$mon--;
eval {
$time = timelocal(0, $min, $hr, $day, $mon, $yr);
};
if($@) {
logError("bad time value passed to date2time: %s", $@);
return 0;
}
return $time;
}
EOR
date_change — convert MMDDYYYY date (possibly with specified time) to YYYYMMDDhhmm
The filter replaces date specification in form of
MM[/-]DD[/-]YY(YY)?(:hh(mm)?)?
or
YYYY[/-]MM[/-]DD(:hh(mm)?)?
to
.
YYYYMMDD((hh)?(mm)?)?
If the year specification contains 2 digits only and is less than
50, as is say, 02,
then it is treated as an offset from year 2000, and not
1900. In other words, 05 is understood
as year 2005, 80 is understood as year
1980.
Time specification unspecified in input get omitted from output as well.
The filter optionally accepts three arguments:
iso - output date in ISO format
undef - don't default to current date if no date is specified
no_time - output only date, without time portion
Example: Using date_change
[filter date_change]2005-01-01[/filter] [filter date_change]2005/01/01[/filter] [filter date_change]2005-01-01:10[/filter] [filter date_change]2005/05/29:1536[/filter] [filter date_change]05-29-2005:1536[/filter] [filter date_change]05-29-05:1536[/filter] [filter date_change]0000-00-00[/filter] [filter date_change][/filter]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The filter is most commonly used with date selection fields.
If only two out of four time digits are specified, then due to the operation
of the sprintf() function, they tend to indicate minutes
and not hours!
When the input data starts with year specification, the year must have
4-digit format (i.e. 2005 and
not just 05)!
If the date is empty, the filter defaults to current date. To
force an absence of a date (as required by some SQL databases),
use the undef filter option.
Interchange 5.7.0:
Source: code/Filter/date_change.filter
Lines: 82
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: date_change.filter,v 1.8 2007/03/30 23:40:44 pajamian Exp $
CodeDef date_change Filter
CodeDef date_change Description Date widget
CodeDef date_change Routine <<EOR
sub {
my $val = shift;
shift; # discard tag
my $opt = { map { $_ => 1 } @_ };
HTML::Entities::decode_entities($val) if $val =~ /&/;
$val =~ s/\0+//g;
my $re = $opt->{undef}
? qr:^(\d*)[-/]+(\d*)[-/]+(\d*)(.*)$:
: qr:^(\d+)[-/]+(\d+)[-/]+(\d+)(.*)$:
;
return $val unless $val =~ /$re/;
my ($year, $month, $day, $timeval);
if (length($1) == 4) {
# ISO date style 2003-03-20
($year, $month, $day) = ($1, $2, $3);
}
else {
# U.S. date style 3/20/2003 or 3/20/03
($year, $month, $day) = ($3, $1, $2);
}
$timeval = $4;
if ($opt->{undef}) {
# return nothing (undef, which DBI treats as SQL NULL) for an
# empty date (all zeroes or nothing at all)
return unless grep /[1-9]/, ($year, $month, $day);
}
# Y2K fun: Try to guess intent of year "03" as "2003"
if (length($year) < 4) {
$year = $year < 50 ? $year + 2000 : $year + 1900;
}
my ($date_format, $time_format);
if ($opt->{iso}) {
$date_format = '%04d-%02d-%02d';
$time_format = 'T%02d:%02d:%02d';
}
else {
$date_format = '%04d%02d%02d';
$time_format = '%02d%02d';
}
my $time;
if ($timeval =~ /^:(\d{1,4})\s*$/) {
# accept traditional Interchange date_time widget times
# of format '0130', e.g. '20080201:0130'
$time = sprintf('%04d', $1);
$time = sprintf($time_format, substr($time, 0, 2), substr($time, 2, 2));
}
elsif (
# accept times of format '1:30', '1:30:05',
# to support PostgreSQL's timestamp with time zone format
# e.g. '2008-02-01 01:30:05-07'
my ($hours, $minutes, $seconds)
= ($timeval =~ /\s(\d\d?):(\d\d?)(?::(\d\d+))/)
) {
$time = sprintf($time_format, $hours, $minutes, $seconds);
}
my $out = sprintf($date_format, $year, $month, $day);
$out .= $time if $time and not $opt->{no_time};
return $out;
}
EOR
datetime2epoch — convert date (possibly with specified time) to number of seconds since Epoch
The filter replaces date specification with optional time, in format of
, orMM[/-]DD[/-]YY(YY)?(:hh(:?mm(:ss)?)?)?
YYYY-MM-DD([T ]hh(:mm(:ss)?)?)?
to a number of seconds since Unix epoch.
If the year specification contains 2 digits only and is less than
50, then it is treated as an offset from year
2000, and not 1900.
In other words, 05 is understood
as year 2005,
80 is understood as
1980.
Unspecified month or day default to 01, unspecified
hours or minutes default to 00.
Example: Converting dates and times to seconds since Epoch
[filter datetime2epoch]01/01/2008[/filter] [filter datetime2epoch]01/01/08[/filter] [filter datetime2epoch]01-01-2008[/filter] [filter datetime2epoch]01-01-08[/filter] [filter datetime2epoch]01-01-2008:10[/filter] [filter datetime2epoch]01-01-08:10:45[/filter] [filter datetime2epoch]01-01-08:10:45:00[/filter]
Example: Converting ISO/MySQL dates and times to seconds since Epoch
[filter datetime2epoch]2008-01-01 10[/filter] [filter datetime2epoch]2008-01-01 10:45[/filter] [filter datetime2epoch]2008-01-01 10:45:00[/filter]
This filter is designed to replace <filter>date2time</filter>, which can be considered deprecated.
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The timelocal() function used in the filter comes from the
Time::Local Perl module.
Interchange 5.7.0:
Source: code/Filter/datetime2epoch.filter
Lines: 46
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: datetime2epoch.filter,v 1.2 2007/03/30 23:40:44 pajamian Exp $
CodeDef datetime2epoch Filter
CodeDef datetime2epoch Description Date and optional time to seconds since the UNIX Epoch
CodeDef datetime2epoch Routine <<EOR
sub {
use Time::Local;
my ($year, $mon, $day, $hr, $min, $sec, $time);
my $val = shift;
$val =~ s/\0+//g;
$val =~ m%^\s*(\d\d)[-/]+(\d+)[-/]+(\d+)% and do {
($year, $mon, $day) = ($3, $1, $2);
$val =~ /:(\d\d):?(\d\d)?:?(\d\d)?\s*$/
and $time = sprintf('T%02d:%02d:%02d', $1, $2 || 0, $3 || 0);
if (length($year) < 4) {
$year =~ s/^0//;
$year = $year < 50 ? $year + 2000 : $year + 1900;
}
$val = sprintf('%d-%02d-%02d%s', $year, $mon || 1, $day || 1, $time);
};
$val =~ /^\s*(\d\d\d\d)-(\d\d)-(\d\d)(?:[T\s](\d\d)?(?::(\d\d)?(?::(\d\d)?)?)?)?/;
($year, $mon, $day, $hr, $min, $sec) = ($1, $2, $3, $4 || 0, $5 || 0,$6 || 0);
eval {
$time = timelocal($sec, $min, $hr, $day, --$mon, $year);
};
if ($@) {
logError("bad time value passed to datetime2epoch: %s", $@);
return 0;
}
return $time;
}
EOR
dbi_quote — safely quote strings for use in SQL statements using DBI's quote method
This filter uses the Perl DBI quoting method (or actually the DBD, if it redefines it) to make strings safe for use in SQL commands.
All database-specific needs are honored, including (but not limited
to) \ escapes for PostgreSQL or MySQL,
truncating at the first ASCII NUL for PostgreSQL, and turning a newline into a
literal two-character \n for MySQL.
The default database handle is used (the first ProductFiles database),
unless a different one is specified.
Example: Quoting a literal string, specifying DBI quote method
[filter dbi_quote.DATABASE_NAME]some string \ or other[/filter]
The above would produce 'some string \\ or other'
for MySQL or PostgreSQL, and
'some string \ or other' for Oracle.
Example: Quoting for the $Db query method
ActionMap set <<EOR
sub {
my ($action, $name) = split('/', shift, 2);
my ($val, $set);
# lookup code first
$Tag->perl({tables => 'sets'});
$val = $Tag->filter({op => 'dbi_quote.sets', body => $name});
$set = $Db{sets}->query({sql => "select code,description from sets where name = $val"});
...
}
EOR
DBI quoting is different from Interchange's native <filter>sql</filter> filter. See the DBI man page details about the DBI quoting method.
Since the filter uses database handles, safe must be considered if
it is being used via the $Tag object in a Perl block.
For more information see DBI(3) and the DBD documentation for your database.
Interchange 5.7.0:
Source: code/Filter/dbi_quote.filter
Lines: 26
# Copyright 2005-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: dbi_quote.filter,v 1.3 2007/03/30 23:40:44 pajamian Exp $
CodeDef dbi_quote Filter
CodeDef dbi_quote Description SQL quoting using DBI
CodeDef dbi_quote Routine <<EOR
sub {
my ($val, $tag, $table) = @_;
$table ||= $Vend::Cfg->{ProductFiles}[0];
my $db;
unless ($db = dbref($table)) {
::logError("filter dbi_quote cannot find database handle for table '%s'", $table);
return;
}
return $db->quote($val);
}
EOR
decode_entities — decode encoded HTML characters back to their unencoded representation
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The filter is most commonly used as pre_filter in
mv_metadata entries, for fields that contain
characters from a character set other than iso8859-1.
For example, & is replaced with &, < with < etc.
Interchange 5.7.0:
Source: code/Filter/decode_entities.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: decode_entities.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef decode_entities Filter
CodeDef decode_entities Description Decode HTML entities
CodeDef decode_entities Routine <<EOR
sub {
return HTML::Entities::decode(shift);
}
EOR
digits — eliminate non-digit characters
The filter eliminates any non-digit characters (that is, anything that's not
in 0-9 range).
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/digits.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: digits.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef digits Filter
CodeDef digits Description Digits only
CodeDef digits Routine <<EOR
sub {
my $val = shift;
$val =~ s/\D+//g;
return $val;
}
EOR
digits_dash — eliminate non-digit characters, with the exception of dashes
The filter eliminates any non-digit characters, except dashes. (That is,
anything that's not a dash ("-") or
in a 0-9 range).
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/digits_dash.filter
Lines: 19
# Copyright 2008 Interchange Development Group
# Copyright 2008 Davor Ocelic
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: digits_dash.filter,v 1.1 2008-04-27 17:37:10 docelic Exp $
CodeDef digits_dash Filter
CodeDef digits_dash Description Digits-dashes
CodeDef digits_dash Routine <<EOR
sub {
my $val = shift;
$val =~ s/[^\d-]+//g;
return $val;
}
EOR
digits_dot — eliminate non-digit characters, with the exception of dots
The filter eliminates any non-digit characters, except dots. (That is,
anything that's not a dot (".") or
in a 0-9 range).
Example: Filter example
[filter digits_dot]Only the date should come out, and it is 01.01.2000[/filter]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/digits_dot.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: digits_dot.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef digits_dot Filter
CodeDef digits_dot Description Digits-dots
CodeDef digits_dot Routine <<EOR
sub {
my $val = shift;
$val =~ s/[^\d.]+//g;
return $val;
}
EOR
dos — convert UNIX or Max ASCII text to DOS format
convert UNIX or Mac ASCII newlines to DOS format.
Unix uses LF (Line feed: \n) sequence to identify a newline.
DOS uses CRLF (Carriage return/Line feed: \r\n) sequence to identify a newline.
Mac uses CR (Carriage return: \r) sequence to identify a newline.
Example: Filter example
[filter dos] Input text with Unix newlines Input text with DOS newlines Input text with Max newlines [/filter]
Interchange 5.7.0:
Source: code/Filter/dos.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: dos.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef dos Filter
CodeDef dos Description UNIX to DOS newlines
CodeDef dos Routine <<EOR
sub {
my $val = shift;
$val =~ s/\r?\n/\r\n/g;
return $val;
}
EOR
duration — calculate end date from given start date and duration
Example: Obtaining an end date string
200502122000.
[cgi name=start_date set=200502120800 hide=1] [cgi name=length set="12 hours" hide=1] [filter op=duration.start_date.length /]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The timelocal() function used in the filter comes from the
Time::Local Perl module.
Interchange 5.7.0:
Source: code/Filter/duration.filter
Lines: 79
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: duration.filter,v 1.6 2007/03/30 23:40:44 pajamian Exp $
CodeDef duration Filter
CodeDef duration Description Duration
CodeDef duration Routine <<EOR
sub {
my ($val, undef, $startvar, $durvar, @extra) = @_;
## Accepts two parameters, the name of the CGI variables which
## hold the start date/time and the duration value. With this:
#
# [cgi name=start_date set=200502120800]
# [cgi name=length set="12 hours"]
# [filter op=duration.start_date.length /]
#
# The filter call will return 20050212200000
#
## Can also be used like this, with the same output:
#
# [filter duration.-dummy.12.hours]200502120800[/filter]
#
use vars qw/$CGI/;
my $start = $CGI->{$startvar} || $val;
my $durstring = $CGI->{$durvar};
my $duration = 0;
use Time::Local;
if (!length($durstring) && $durvar =~ /^\d+$/) {
$durstring = join(' ', $durvar, @extra);
}
while($durstring =~ s/(\d+\s*[hmwd]\w*)\s*//) {
$duration += Vend::Config::time_to_seconds($1);
}
## Want to allow setting the value directly
return $val unless $duration;
$start =~ s/\0+//g;
if($start =~ m:(\d+)[-/]+(\d+)[-/]+(\d+):) {
my ($yr, $mon, $day) = ($3, $1, $2);
my $time;
$start =~ /:(\d+)$/
and $time = $1;
if(length($yr) < 4) {
$yr =~ s/^0//;
$yr = $yr < 50 ? $yr + 2000 : $yr + 1900;
}
$mon =~ s/^0//;
$day =~ s/^0//;
$start = sprintf("%d%02d%02d", $yr, $mon, $day);
return $val unless $time;
$start .= sprintf('%04d', $time);
}
my $time;
$start =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?/;
my ($yr, $mon, $day, $hr, $min) = ($1 || 0, $2 || 1, $3 || 1, $4 || 0, $5 || 0);
$mon--;
eval {
$time = timelocal(0, $min, $hr, $day, $mon, $yr);
};
if($@) {
logError("bad time value passed to duration filter: %s", $@);
return 0;
}
$time += $duration;
return POSIX::strftime("%Y%m%d%H%M%S", localtime($time));
}
EOR
encode_entities — encode non-standard HTML characters
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
The filter is most commonly used to make untrusted CGI input variables harmless to the Interchange environment.
For example, & is replaced with &, < with < etc.
Interchange 5.7.0:
Source: code/Filter/encode_entities.filter
Lines: 23
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: encode_entities.filter,v 1.5 2007/03/30 23:40:44 pajamian Exp $
CodeDef e Filter
CodeDef e Alias encode_entities
CodeDef entities Filter
CodeDef entities Alias encode_entities
CodeDef encode_entities Filter
CodeDef encode_entities Description Encode HTML entities
CodeDef encode_entities Routine <<EOR
sub {
return HTML::Entities::encode(shift, $ESCAPE_CHARS::std);
}
EOR
encrypt — PGP-encrypt input
Interchange 5.7.0:
Source: code/Filter/encrypt.filter
Lines: 18
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: encrypt.filter,v 1.5 2007/03/30 23:40:44 pajamian Exp $
CodeDef encrypt Filter
CodeDef encrypt Description PGP encrypt
CodeDef encrypt Routine <<EOR
sub {
my ($val, $tag, $key) = @_;
return Vend::Order::pgp_encrypt($val, $key);
}
EOR
filesafe — make sure the input is ready for use as a filename
The filter makes sure (possibly by intervening) that the input string is ready and safe to be used as a filename.
Example: Filter example
[filter filesafe]/tmp/uploads/new_world_through_chemistry/new_world_through_chemistry_edit.mp4[/filter]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/filesafe.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: filesafe.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef filesafe Filter
CodeDef filesafe Description Safe for filename
CodeDef filesafe Routine <<EOR
sub {
return Vend::Util::escape_chars(shift);
}
EOR
filter_select — automatically select filter based on HTML widget type
The filter identifies the widget type and returns the name of the corresponding suitable filter for it.
Keep in mind that you can specify <filter>filter_select</filter> along with your custom filters in the same call.
Interchange 5.7.0:
Source: code/Filter/filter_select.filter
Lines: 32
# Copyright 2005-2007 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: filter_select.filter,v 1.3 2007/03/30 23:40:44 pajamian Exp $
CodeDef calculated Filter
CodeDef calculated Alias filter_select
CodeDef filter_select Filter
CodeDef filter_select Description Auto-select filter
CodeDef filter_select Visibility private
CodeDef filter_select Version $Revision: 1.3 $
CodeDef filter_select Routine <<EOR
sub {
## This replaces the calculated filter for the survey
## Selects an appropriate filter based on the widget type
my $wid = $CGI->{type};
if($wid =~ /fillin/) {
return 'nullselect';
}
elsif($wid =~ /select.*multip/) {
return 'null_to_comma';
}
elsif ($wid =~ /checkbox/) {
return 'checkbox null_to_comma';
}
return '';
}
EOR
gate — return input verbatim if the specified Scratch variable exists, empty string otherwise
The filter allows "conditional output" of the input string, based on the value of a scratch variable.
In other words, received input is passed through verbatim, if the specified scratch variable holds a true value. Empty string is returned otherwise.
Interchange 5.7.0:
Source: code/Filter/gate.filter
Lines: 19
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: gate.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef gate Filter
CodeDef gate Description Gate with scratch
CodeDef gate Routine <<EOR
sub {
my ($val, $var) = @_;
return '' unless $::Scratch->{$var};
return $val;
}
EOR
hash2acl — convert Interchange ACL hash to string representation
The filter is specific to the ACL widget and probably should not be used otherwise.
The filter doesn't need to be selected for the widget to
operate in the table-editor.
Interchange 5.7.0:
Source: code/Filter/hash2acl.filter
Lines: 34
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: hash2acl.filter,v 1.3 2007/03/30 23:40:44 pajamian Exp $
CodeDef hash2acl Filter
CodeDef hash2acl Description hash2acl
CodeDef hash2acl Visibility private
CodeDef hash2acl Routine <<EOR
sub {
my ($value) = @_;
my $orig = $value;
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$value =~ s/\0+//g;
my $hash = Vend::Util::get_option_hash($value)
or return $orig;
my @opts;
for(sort keys %$hash) {
! defined $hash and $hash->{$_} = '';
my $val = $_;
$val =~ s/,/,/g;
$val =~ s/=/=/g;
push @opts, "$val=$hash->{$_}";
}
$value = join ",", @opts;
return $value;
}
EOR
html2text — transform basic HTML input to plain-text
The filter performs simple replacement of input HTML —
it strips the
<b>,
<i> and
<u> tags, and replaces
line breaks (<br>) and
paragraphs (<pgt;)
with newlines.
Example: Filter example
[filter html2text] <p> Perl is <b>a lot</b> of <u>fun</u>! </p> <p> Interesting tricks with <i>the language</i> can be seen at: <br> MJD's <a href="http://perl.plover.com/">plover.com</a>. </p> <p> Programming is an art. </p> [/filter]
Support for stripping
<b>,
<i> and
<u> tags was added
in Interchange 5.5.2.
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/html2text.filter
Lines: 20
# Copyright 2002-2008 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: html2text.filter,v 1.9 2008-06-30 23:53:44 jon Exp $
CodeDef html2text Filter
CodeDef html2text Description Simple html2text
CodeDef html2text Routine <<EOR
sub {
my $val = shift;
$val =~ s%</?(b|i|u)>%%gi;
$val =~ s%\s*<(?:br\s*/?|/?p[^>]*)>\s*%\n%gi;
return $val;
}
EOR
integer — simply return integer value of the input
Example: Erase whitespace, filter out non-digits, and return integer part of the number
The whole is: [filter no_white digits_dot integer]Stock 904.82[filter]
For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).
Interchange 5.7.0:
Source: code/Filter/integer.filter
Lines: 17
# Copyright 2002-2007 Interchange Development Group and others
# Copyright 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
#
# $Id: integer.filter,v 1.4 2007/03/30 23:40:44 pajamian Exp $
CodeDef integer Filter
CodeDef integer Description Integer
CodeDef integer Routine <<EOR
sub {
return int(shift);
}
EOR