Name

value-extended — Expand value

ATTRIBUTES

Attribute Pos. Req. Default Description
name Yes Yes Name of variable.
values_space
yes 1 Return value on success.
no Return value on failure.
test
put_contents
enable_html
enable_itl
file_contents Returns file contents from a upload field.
put_ref
outfile File name for output file.
encoding Encoding for output file (UTF-8, raw).
auto_create_dir     0 Auto-create directories in the file path?
umask       File creation umask.
ascii
maxsize Maximum size of uploaded file.
joiner
'index'
elements
filter
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

[value-extended] can be used for a number of tasks related to user input:

  • Manipulate files uploaded by the user.

  • Output variables from value space.

  • Perform a test.

BEHAVIOR

This tag does not appear to be affected by, or affect, the rest of Interchange.

EXAMPLES

Example: Test for uploaded file

[value-extended name="picture" 
	test="isfile" 
	yes="Your picture has been uploaded."
	no="Please upload your picture!"
]

NOTES

AVAILABILITY

value-extended is available in Interchange versions:

4.6.0-5.7.0 (git-head)

SOURCE

Interchange 5.7.0:

Source: code/SystemTag/value_extended.coretag
Lines: 14


# Copyright 2002-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: value_extended.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $

UserTag value-extended      Order        name
UserTag value-extended      addAttr
UserTag value-extended      PosNumber    1
UserTag value-extended      Version      $Revision: 1.5 $
UserTag value-extended      MapRoutine   Vend::Interpolate::tag_value_extended

Source: lib/Vend/Interpolate.pm
Lines: 2380

sub tag_value_extended {
  my($var, $opt) = @_;

my $vspace = $opt->{values_space};
my $vref;
if (defined $vspace) {
  if ($vspace eq '') {
    $vref = $Vend::Session->{values};
  }
  else {
    $vref = $Vend::Session->{values_repository}{$vspace} ||= {};
  }
}
else {
  $vref = $::Values;
}

my $yes = $opt->{yes} || 1;
my $no = $opt->{'no'} || '';

if($opt->{test}) {
  $opt->{test} =~ /(?:is)?put/i
    and
    return defined $CGI::put_ref ? $yes : $no;
  $opt->{test} =~ /(?:is)?file/i
    and
    return defined $CGI::file{$var} ? $yes : $no;
  $opt->{test} =~ /defined/i
    and
    return defined $CGI::values{$var} ? $yes : $no;
  return length $CGI::values{$var}
    if $opt->{test} =~ /length|size/i;
  return '';
}

if($opt->{put_contents}) {
  return undef if ! defined $CGI::put_ref;
  return $$CGI::put_ref;
}

my $val = $CGI::values{$var} || $vref->{$var} || return undef;
$val =~ s/</&lt;/g unless $opt->{enable_html};
$val =~ s/\[/&#91;/g unless $opt->{enable_itl};

if($opt->{file_contents}) {
  return '' if ! defined $CGI::file{$var};
  return $CGI::file{$var};
}

if($opt->{put_ref}) {
  return $CGI::put_ref;
}

if($opt->{outfile}) {
  my $file = $opt->{outfile};
  $file =~ s/^\s+//;
  $file =~ s/\s+$//;

  unless (Vend::File::allowed_file($file)) {
    Vend::File::log_file_violation($file, 'value-extended');
    return '';
  }

  if($opt->{ascii}) {
    my $replace = $^O =~ /win32/i ? "\r\n" : "\n";
    if($CGI::file{$var} !~ /\n/) {
      # Must be a mac file.
      $CGI::file{$var} =~ s/\r/$replace/g;
    }
    elsif ( $CGI::file{$var} =~ /\r\n/) {
      # Probably a PC file
      $CGI::file{$var} =~ s/\r\n/$replace/g;
    }
    else {
      $CGI::file{$var} =~ s/\n/$replace/g;
    }
  }
  if($opt->{maxsize} and length($CGI::file{$var}) > $opt->{maxsize}) {
    logError(
      "Uploaded file write of %s bytes greater than maxsize %s. Aborted.",
      length($CGI::file{$var}),
      $opt->{maxsize},
    );
    return $no;
  }
#::logDebug(">$file \$CGI::file{$var}" . uneval($opt));
  $opt->{encoding} ||= $CGI::file_encoding{$var};
  Vend::Util::writefile(">$file", \$CGI::file{$var}, $opt)
    and return $yes;
  return $no;
}

my $joiner;
if (defined $opt->{joiner}) {
  $joiner = $opt->{joiner};
  if($joiner eq '\n') {
    $joiner = "\n";
  }
  elsif($joiner =~ m{\\}) {
    $joiner = $ready_safe->reval("qq{$joiner}");
  }
}
else {
  $joiner = ' ';
}

my $index = defined $opt->{'index'} ? $opt->{'index'} : '*';

$index = '*' if $index =~ /^\s*\*?\s*$/;

my @ary;
if (!ref $val) {
  @ary = split /\0/, $val;
}
elsif($val =~ /ARRAY/) {
  @ary = @$val;
}
else {
  logError( "value-extended %s: passed non-scalar, non-array object", $var);
}

return join " ", 0 .. $#ary if $opt->{elements};

eval {
  @ary = @ary[$ready_safe->reval( $index eq '*' ? "0 .. $#ary" : $index )];
};
logError("value-extended $var: bad index") if $@;

if($opt->{filter}) {
  for(@ary) {
    $_ = filter_value($opt->{filter}, $_, $var);
  }
}
return join $joiner, @ary;
}

AUTHORS

Interchange Development Group

SEE ALSO

values-space(7ic)

DocBook! Interchange!