Interchange Reference Pages: Filters


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
alpha — eliminate non-alpha characters
alphanumeric — eliminate non-alphanumeric characters
backslash — eliminate backslashes
bold — enclose input in HTML <b> (bold) tag
cgi — expand to value of the CGI variable specified in body
checkbox — return user-supplied value if its length is 1 or more, an empty string otherwise
colons_to_null — replace double colons "::" with \0 (null) character
commify — add thousands separator to a number, and trim to specified number of decimal places
compress_space — eliminate leading and trailing whitespace and compress all "in-string" whitespace occurrences to exactly 1 space each
convert_date — convert date to a specified format
crypt — run Unix crypt() function on input data
currency — format number as currency, honoring default or specified locale
date2time — convert date (possibly with specified time) to number of seconds since Epoch
date_change — convert MMDDYYYY date (possibly with specified time) to YYYYMMDDhhmm
datetime2epoch — convert date (possibly with specified time) to number of seconds since Epoch
dbi_quote — safely quote strings for use in SQL statements using DBI's quote method
decode_entities — decode encoded HTML characters back to their unencoded representation
digits — eliminate non-digit characters
digits_dash — eliminate non-digit characters, with the exception of dashes
digits_dot — eliminate non-digit characters, with the exception of dots
dos — convert UNIX or Max ASCII text to DOS format
duration — calculate end date from given start date and duration
encode_entities — encode non-standard HTML characters
encrypt — PGP-encrypt input
filesafe — make sure the input is ready for use as a filename
filter_select — automatically select filter based on HTML widget type
gate — return input verbatim if the specified Scratch variable exists, empty string otherwise
hash2acl — convert Interchange ACL hash to string representation
html2text — transform basic HTML input to plain-text
integer — simply return integer value of the input
italics — enclose input in HTML <i> (italic) tag
large — enclose input in HTML <large> tag
last_non_null — return last non-null entry from an input consisting of null-separated fields
lc — transform all input to lowercase
lcfirst — transform first character in input to lowercase
line — output just the first line of input
line2options — replace newlines in input with commas
linkdecode — decode hex-encoded entities found within URLs
liven_urls — make all kinds of URLs clickable
loc — localize provided input
lookup — perform lookup in another database
lspace_to_nbsp — replace leading spaces (" ") with nonbreakable space ("&nbsp;") characters
mac — convert UNIX or DOS ASCII text to Apple Macintosh format
mailto — enclose input in HTML <a href='mailto: ...'> link
md5 — calculate MD5 sum of input
mime_type — print file MIME type, based on file extension
name — transform "Last, First" name format to "First Last"
namecase — transform any "NAME" to "Name"
next_sequential — perform lookup in another database
no_white — eliminate all whitespace in input
null_to_colons — replace \0 (null) characters with double colon "::"
null_to_comma — replace \0 (null) characters with comma ","
null_to_space — replace \0 (null) characters with space " "
nullselect — split input on \0 (null) characters and return first non-empty string
oneline — delete everything after first null or newline character, effectively "onelining" the input
option_format
options2line — replace commas in input with newlines
pagefile — make sure the input is ready for use as an Interchange page
pgbool — return "f" (false) or "t" (true), depending on input data
pgbooln — return undef (NULL), "f" (false) or "t" (true), depending on input data
pre — enclose input in HTML <pre> (preformatted) tag
qb_safe — make input safe for QuickBooks by removing unfriendly characters
restrict_html — filter out all but the restricted set of allowed HTML tags in input
roman — transform input integer to Roman numerals
round — round value in floating-point-safe way
sha1 — calculate SHA1 sum of input
show_null — replace null-characters (\0) with literal "\0"
small — enclose input in HTML <small> tag
space_to_nbsp — replace all spaces (" ") with nonbreakable space ("&nbsp;") characters
space_to_null — replace space " " with \0 (null) character
sql — quote strings for use in SQL statements, without referencing a specific database
strftime — transform UNIX time (number of seconds) to a date/time string, according to specified format
strikeout — enclose input in HTML <strike> tag
strip — trim leading and trailing whitespace
tabbed — replace newlines in input with TAB characters
text2html — transform input plain-text to most basic HTML
textarea_get — replace &amp; (ampersand) entities in input with literal &
textarea_put — replace &, < and [ characters with their encoded representation
tt — simply enclose input in HTML <tt> (typewriter) tag
uc — transform all input to uppercase
ucfirst — transform first character in input to uppercase
unix — convert DOS or Mac ASCII text to Unix format
upload
urldecode — replace encoded (hex) characters with their unencoded representation
urlencode — replace non-word characters or a colon with encoded (hex) representation
value — expand to value of the UserDB variable specified in body
vars_and_comments — interpolate variables and remove comments
word — eliminate any non-word characters
yesno — return Yes for non-empty input, No otherwise
zerofix — eliminate possible zeros at beginning of input

Name

acl2hash — convert Interchange ACL string to a Perl hash representation

DESCRIPTION

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.

EXAMPLES

Example: Filter example


NOTES

AVAILABILITY

acl2hash is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

alpha — eliminate non-alpha characters

DESCRIPTION

The filter eliminates any non-alpha characters (that is, anything that's not in a-zA-Z range).

EXAMPLES

Example: Filter example

[filter alpha]** Test 1: Hello, World! **[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

alpha is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

alphanumeric — eliminate non-alphanumeric characters

DESCRIPTION

The filter eliminates any non-alphanumeric characters (that is, anything that's not in a-zA-Z0-9 range).

EXAMPLES

Example: Filter example

[filter alphanumeric]** Test 2: Hello, World! **[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

alphanumeric is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO

alpha(7ic)


Name

backslash — eliminate backslashes

DESCRIPTION

The filter eliminates backslashes.

EXAMPLES

Example: Filter example

[filter backslash]The filter will remove all of those: \\\\ \\\\[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

backslash is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

bold — enclose input in HTML <b> (bold) tag

DESCRIPTION

The filter encloses input data in HTML <b> (bold) tag.

EXAMPLES

Example: Filter example

"[filter bold]To Boldly Go Where No One Has Gone Before![/filter]"
  -- Star Trek

NOTES

AVAILABILITY

bold is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO

italics(7ic)


Name

cgi — expand to value of the CGI variable specified in body

DESCRIPTION

The filter expands to the value of a CGI variable. Name of the variable is specified in filter body.

EXAMPLES

Example: Filter example

[cgi name=online_cgi_test set="TEST VALUE" hide=1]

My test value is [filter cgi]online_cgi_test[/filter]

NOTES

AVAILABILITY

cgi is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO

value(7ic)


Name

checkbox — return user-supplied value if its length is 1 or more, an empty string otherwise

DESCRIPTION

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.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

checkbox is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

colons_to_null — replace double colons "::" with \0 (null) character

DESCRIPTION

The filter replaces double colons (::) with a \0 (null) character.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

colons_to_null is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

commify — add thousands separator to a number, and trim to specified number of decimal places

DESCRIPTION

The filter adds thousands separator (a comma ",", usually) to a number, and trims decimal places to a specified maximum length.

EXAMPLES

Example: Filter example

[set online_commify_test]1234567890.123456[/set]
[filter op=commify.2 interpolate=1][scratchd online_commify_test][/filter]

NOTES

AVAILABILITY

commify is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

compress_space — eliminate leading and trailing whitespace and compress all "in-string" whitespace occurrences to exactly 1 space each

DESCRIPTION

The filter eliminates leading and trailing whitespace, and compresses all occurrences of whitespace in a string to exactly 1 space on each occurrence.

EXAMPLES

Example: Filter example

[filter compress_space]   LEADING   Hello,  World!   TRAILING  [/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

compress_space is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

convert_date — convert date to a specified format

DESCRIPTION

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.

EXAMPLES

Example: Filter example

Year is [filter convert_date.%Y][time][/filter].

Example: Filter example

To get a pretty formatted date, such as "May 16, 2007", use
[filter convert_date."%B %e, %Y"][time][/filter].

NOTES

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.

AVAILABILITY

convert_date is available in Interchange versions:

5.0.1-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

crypt — run Unix crypt() function on input data

DESCRIPTION

The filter calls Perl crypt function to encrypt input data.

EXAMPLES

Example: Filter example with random salt

The encrypted string should be different each time you run the code because the salt is random.
Encrypted string TEST with random salt is: 
[filter crypt]TEST[/filter].

Example: Filter example with hand-specified salt

The encrypted string should be the same each time you run the code because the salt does not change.
Encrypted string TEST with salt of AB is: 
[filter crypt.AB]TEST[/filter].

NOTES

AVAILABILITY

crypt is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

currency — format number as currency, honoring default or specified locale

DESCRIPTION

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.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

AVAILABILITY

currency is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

date2time — convert date (possibly with specified time) to number of seconds since Epoch

DESCRIPTION

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.

EXAMPLES

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]

NOTES

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.

AVAILABILITY

date2time is available in Interchange versions:

5.0.1-5.7.0 (cvs-head)

SOURCE

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


Name

date_change — convert MMDDYYYY date (possibly with specified time) to YYYYMMDDhhmm

DESCRIPTION

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

EXAMPLES

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]

NOTES

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.

AVAILABILITY

date_change is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

datetime2epoch — convert date (possibly with specified time) to number of seconds since Epoch

DESCRIPTION

The filter replaces date specification with optional time, in format of

MM[/-]DD[/-]YY(YY)?(:hh(:?mm(:ss)?)?)?, or
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.

EXAMPLES

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]

NOTES

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.

AVAILABILITY

datetime2epoch is available in Interchange versions:

5.6.0, 5.7.0 (cvs-head)

SOURCE

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

AUTHORS

Kevin Walsh


Name

dbi_quote — safely quote strings for use in SQL statements using DBI's quote method

DESCRIPTION

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.

EXAMPLES

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

NOTES

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.

AVAILABILITY

dbi_quote is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

decode_entities — decode encoded HTML characters back to their unencoded representation

DESCRIPTION

The filter decodes encoded HTML characters back to their unencoded representation.

EXAMPLES

Example: Filter example

[filter decode_entities]One & Two & Three[filter]

NOTES

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, &amp; is replaced with &, &lt; with < etc.

AVAILABILITY

decode_entities is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

digits — eliminate non-digit characters

DESCRIPTION

The filter eliminates any non-digit characters (that is, anything that's not in 0-9 range).

EXAMPLES

Example: Filter example

[filter digits]Only 2 digits should come out of this 1 line ;-)[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

digits is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

digits_dash — eliminate non-digit characters, with the exception of dashes

DESCRIPTION

The filter eliminates any non-digit characters, except dashes. (That is, anything that's not a dash ("-") or in a 0-9 range).

EXAMPLES

Example: Filter example

[filter digits_dash]Digits-dash code is: 90901212-3124[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

digits_dash is available in Interchange versions:

5.6.0, 5.7.0 (cvs-head)

SOURCE

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


Name

digits_dot — eliminate non-digit characters, with the exception of dots

DESCRIPTION

The filter eliminates any non-digit characters, except dots. (That is, anything that's not a dot (".") or in a 0-9 range).

EXAMPLES

Example: Filter example

[filter digits_dot]Only the date should come out, and it is 01.01.2000[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

digits_dot is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

dos — convert UNIX or Max ASCII text to DOS format

DESCRIPTION

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.

EXAMPLES

Example: Filter example

[filter dos]
  Input text with Unix newlines
  Input text with DOS newlines
  Input text with Max newlines
[/filter]

NOTES

AVAILABILITY

dos is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

duration — calculate end date from given start date and duration

DESCRIPTION

The filter takes a start date and a duration as inputs, and outputs the end date.

EXAMPLES

Example: Obtaining an end date string

The following example sets start date to Feb 12, 2005 (at 8:00 am), and the duration to 12 hours. Filter output should return again, Feb 12, 2005, but with the time set to 8:00 pm. So exactly, it should return 200502122000.
[cgi name=start_date set=200502120800 hide=1]
[cgi name=length     set="12 hours"   hide=1]
[filter op=duration.start_date.length /]

NOTES

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.

AVAILABILITY

duration is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

encode_entities — encode non-standard HTML characters

DESCRIPTION

The filter encodes non-standard HTML characters to their encoded representation.

EXAMPLES

Example: Filter example

[filter encode_entities]One & Two & Three[filter]

NOTES

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 &amp;, < with &lt; etc.

AVAILABILITY

encode_entities is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO

evalue(7ic)


Name

encrypt — PGP-encrypt input

DESCRIPTION

The filter PGP-encrypts the provided input.

EXAMPLES

Example: Filter example

[filter encrypt.KEY]Secret phrase or a credit card number[filter]

NOTES

AVAILABILITY

encrypt is available in Interchange versions:

5.0.1-5.7.0 (cvs-head)

SOURCE

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


Name

filesafe — make sure the input is ready for use as a filename

DESCRIPTION

The filter makes sure (possibly by intervening) that the input string is ready and safe to be used as a filename.

EXAMPLES

Example: Filter example

Here's a hypothetical download filename from the Prelinger Collection at archive.org.
[filter filesafe]/tmp/uploads/new_world_through_chemistry/new_world_through_chemistry_edit.mp4[/filter]

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

filesafe is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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


Name

filter_select — automatically select filter based on HTML widget type

DESCRIPTION

The filter identifies the widget type and returns the name of the corresponding suitable filter for it.

EXAMPLES

No examples are available at this time. We do consider this a problem and will try to supply some.

NOTES

Keep in mind that you can specify <filter>filter_select</filter> along with your custom filters in the same call.

AVAILABILITY

filter_select is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

gate — return input verbatim if the specified Scratch variable exists, empty string otherwise

DESCRIPTION

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.

EXAMPLES

Example: Filter example

[set tide]1[/set]

[filter gate.tide]The Gate is open.[/filter]

NOTES

AVAILABILITY

gate is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

hash2acl — convert Interchange ACL hash to string representation

DESCRIPTION

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.

EXAMPLES

Example: Filter example


NOTES

AVAILABILITY

hash2acl is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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/,/&#44;/g;
  $val =~ s/=/&#61;/g;
  push @opts, "$val=$hash->{$_}";
}
$value = join ",", @opts;
return $value;
}
EOR


Name

html2text — transform basic HTML input to plain-text

DESCRIPTION

The filter performs simple replacement of input HTML — it strips the <b>, <i> and <u> tags, and replaces line breaks (<br>) and paragraphs (<p>) with newlines.

EXAMPLES

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]

NOTES

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).

AVAILABILITY

html2text is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

integer — simply return integer value of the input

DESCRIPTION

The filter simply returns integer value of the input

EXAMPLES

Example: Filter example

[filter integer]12.4[filter] 

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] 

NOTES

For more information on Perl Regular Expressions, pattern matching and character classes, see perlre(1).

AVAILABILITY

integer is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)

SOURCE

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

SEE ALSO


Name

italics — enclose input in HTML <i> (italic) tag

DESCRIPTION

The filter encloses input data in HTML <i> (italics) tag.

EXAMPLES

Example: Filter example

"[filter italics]To Italicly Go Where No One Has Gone Before![/filter]"
  -- Modified Star Trek ;-)

NOTES

AVAILABILITY

italics is available in Interchange versions:

5.4.0-5.7.0 (cvs-head)