<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# ----------------------------------------------------------------------------
# This software is Copyright (C) 2007, All Rights Reserved
# ----------------------------------------------------------------------------
# This program is protected by local and international copyright laws. Any
# use of this program is subject to the the terms of the license agreement
# included as part of this distribution archive. Any other uses are strictly
# prohibited without the written permission of the Vendor and all
# other rights are reserved.
# -----------------------------------------------------------------------------
# Warning : Modifying this program violates your license agreement!
# -----------------------------------------------------------------------------

package IT::Template::PlaceholderModifiers;

use strict;

use IT::Globals;

# module globals
use vars qw($DEFAULT_LIST_SEPARATOR);

$DEFAULT_LIST_SEPARATOR = ", ";

# ------------------------------------------------------------------------------
# Function    : checkedIf
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::checkedIf($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub checkedIf {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # apply modifier
  if ($modifiedValue eq $modifierArguments) { $modifiedValue = 'checked="checked"'; }
  else                                      { $modifiedValue = ''; }

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : date_format
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::dateFormat($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub dateFormat {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  my $originalType   = &amp;IT::Template::getPlaceholderType($originalValue);
  if ($originalType ne 'date') { return "[format() modifier isn't available for \$$placeholderName]"; }

  # apply modifier
  my $dateFormat    = $modifierArguments || 'date_and_time';
  my $dateString    = &amp;IT::Date::formatDate($dateFormat, $originalValue-&gt;{'time'});

  #
  return $dateString;
}

# ------------------------------------------------------------------------------
# Function    : getFieldValueByNum
# Description : Placeholder modifier to return a field value references by it's
#               table, fieldname, and record number
# Usage       : my $value = &amp;_getFieldValueByNum($tableNameWithoutPrefix, $fieldname, $recordNum, [$optionalNotFoundMessage]);
# ------------------------------------------------------------------------------

sub getFieldValueByNum {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  unless ($modifierArguments =~ m/[^,]+,[^,]+(,.+)?/) {
    return "[Invalid arguments in getFieldValueByNum($modifierArguments),  Examples: getFieldValueByNum(tablename, fieldname, Not found message)]";
  }
  my($tableNameWithoutPrefix, $fieldName, $notFoundMessage) = split(/,\s*/, $modifierArguments, 3);
  $notFoundMessage      ||= "[no value found]";
  my $recordNum           = $modifiedValue;
  my $tableNameWithPrefix = $TABLE_PREFIX . $tableNameWithoutPrefix;

  # error checking
  if ($recordNum eq '')                                                { return ""; }
  if (int $recordNum ne $recordNum)                                    { return "[Invalid arguments in getFieldValueByNum($modifierArguments), Invalid record number '$recordNum']"; }
  unless ($tableNameWithoutPrefix)                                     { return "[Invalid arguments in getFieldValueByNum($modifierArguments), no tableName specified!]"; }
  if (!&amp;IT::DB::Schema::existsTable($tableNameWithPrefix))             { return "[Invalid arguments in getFieldValueByNum($modifierArguments), There is no '$tableNameWithPrefix' table!]"; }
  unless ($fieldName)                                                  { return "[Invalid arguments in getFieldValueByNum($modifierArguments), no fieldName specified!]"; }
  if (!&amp;IT::DB::Schema::existsField($tableNameWithPrefix, $fieldName)) { return "[Invalid arguments in getFieldValueByNum($modifierArguments), There is no '$fieldName' field in table '$tableNameWithPrefix'!]"; }

  # lookup value
  my $fieldValue;
  eval {
    &amp;IT::FileLock::getLock('shared');
    my $records = &amp;IT::DB::select({
      'tableName'  =&gt; $tableNameWithPrefix,
      'whereQuery' =&gt; "num = '$recordNum'",
      'limit'      =&gt; [0,1],
    });
    my $record = $records-&gt;[0];
    &amp;IT::FileLock::releaseLock();

    if (exists $record-&gt;{$fieldName}) { $fieldValue = $record-&gt;{$fieldName}; }
    else                              { $fieldValue = $notFoundMessage; }
  };
  if ($@) { $fieldValue = "[getFieldValueByNum error: $@]"; }

  return $fieldValue;
}

# ------------------------------------------------------------------------------
# Function    : htmlEncoded
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::htmlEncoded($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub htmlEncoded {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[htmlEncoded modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  $modifiedValue = &amp;IT::Common::htmlEncode( $modifiedValue );

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : defaultValue
# Description : display default is value is undefined, "", 0 or whitespace
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::defaultValue($placeholderName, $originalValue, $modifiedValue, $modifierArguments, $isDefined);
# ------------------------------------------------------------------------------

sub defaultValue {
  if (@_ != 5) { die "functin takes 5 arguments!"; }
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;
  my $isDefined         = shift;

  # apply modifier
  if (!$isDefined || !$modifiedValue) { $modifiedValue = $modifierArguments; }

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : javascriptSafe
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::javascriptSafe($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub javascriptSafe {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  my $quoteChar;
  if    ($modifierArguments eq '')            { $quoteChar = q|'|; }
  elsif ($modifierArguments eq 'singleQuote') { $quoteChar = q|'|; }
  elsif ($modifierArguments eq 'doubleQuote') { $quoteChar = q|"|; }
  else {
    return "[Invalid arguments in javascriptSafe($modifierArguments), must be blank, 'singleQuote' or 'doubleQuote']";
  }

  # apply modifier
  $modifiedValue = &amp;IT::Common::javascriptEncode( $quoteChar, $modifiedValue );

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : limitParagraphs
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::limitParagraphs($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub limitParagraphs {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  my($start, $end);
  if    ($modifierArguments =~ /\A([0-9]+)-([0-9]+)\z/) { ($start, $end) = ($1, $2); }
  elsif ($modifierArguments =~ /\A([0-9]+)(\+)\z/)      { ($start, $end) = ($1, $2); }
  elsif ($modifierArguments =~ /\A([0-9]+)\z/)          { ($start, $end) = ($1, $1); }
  else {
    return "[Invalid arguments in limitParagraphs($modifierArguments), must be (PARAGRAPH_NUM), (START-END) or (START+)]";
  }

  # error checking
  if ($start &lt; 1)                   { return "[Invalid arguments in limitParagraphs($modifierArguments), START value must be greater than zero]"; }
  if ($end ne '+' &amp;&amp; $end &lt; $start) { return "[Invalid arguments in limitParagraphs($modifierArguments), END value cannot be less than START value]"; }

  # apply modifier
  my $tokens     = &amp;IT::HTMLParser::tokenize($modifiedValue);
  $tokens        = &amp;IT::HTMLParser::returnTokensFromSelectedParagraphs($tokens, $start, $end);
  $modifiedValue = &amp;IT::HTMLParser::convertTokensToHtmlString($tokens);

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : lowercase
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::lowercase($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub lowercase {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[lowercase modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  my $tokens = &amp;IT::HTMLParser::tokenize($modifiedValue);
  foreach my $token (@$tokens) {
    if ($token-&gt;{'type'} eq 'text') {
      $token-&gt;{'content'} = lc $token-&gt;{'content'};
    }
  }
  $modifiedValue = &amp;IT::HTMLParser::convertTokensToHtmlString($tokens);

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : listSeparator
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::listSeparator($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub listSeparator {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  my $originalType   = &amp;IT::Template::getPlaceholderType($originalValue);
  if ($originalType ne 'list') { return "[separator() modifier isn't available for \$$placeholderName]"; }

  # apply modifier
  my $separator     = defined $modifierArguments ? $modifierArguments  : $DEFAULT_LIST_SEPARATOR;
  my $delimitedList = join $separator, @{$originalValue-&gt;{'listValues'}};

  #
  return $delimitedList;
}

# ------------------------------------------------------------------------------
# Function    : maxChars
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::maxChars($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
#
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by templatePlaceholderList
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by templatePlaceholderList
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by templatePlaceholderList
# ------------------------------------------------------------------------------

sub maxChars {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  my $match1stArg = q[('|")(.*?)\1\s*];
  my $match2ndArg = q[\s*('|")(.*?)\3];
  my($maxChars, $truncatedSuffix);
  if ($modifierArguments =~ /^$match1stArg,$match2ndArg/) {
    ($maxChars, $truncatedSuffix) = ($2, $4);
  }
  else {
    return "[Invalid arguments in maxChars($modifierArguments),  Example: maxChars('25', '...')]";
  }

  # apply modifier
  if (length $modifiedValue &gt; $maxChars) {
    $modifiedValue  = substr($modifiedValue, 0, $maxChars);
    $modifiedValue .= $truncatedSuffix;
  }

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : maxWords
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::maxWords($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub maxWords {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  my $maxWords = $modifierArguments;
  if ($maxWords ne int($maxWords)) {
    return "[Invalid arguments in maxWords($modifierArguments), must be a number!]";
  }

  # apply modifier
  my $tokens         = &amp;IT::HTMLParser::tokenize($modifiedValue);
  my $maxWordsString = &amp;IT::HTMLParser::convertTokensToMaxWordsString($tokens, $maxWords);

  #
  return $maxWordsString;
}

# ------------------------------------------------------------------------------
# Function    : repeat
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::repeat($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
#
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by admin templates to display padded category depth
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by admin templates to display padded category depth
# NOTE        : UNDOCUMENTED MODIFIER - MAY CHANGE OR BE REMOVED IN FUTURE - used by admin templates to display padded category depth
# ------------------------------------------------------------------------------

sub repeat {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  my($repeatText, $suffix);
  my $match1stArg = q[('|")(.*?)\1\s*];
  my $match2ndArg = q[\s*('|")(.*?)\3];
  if ($modifierArguments =~ /^$match1stArg,$match2ndArg/) {
    ($repeatText, $suffix) = ($2, $4);
  }
  else {
    return "[Invalid arguments in repeat($modifierArguments), Examples: repeat('text', 'suffix')]";
  }

  # apply modifier
  my $quantity    = $modifiedValue;
  my $newValue    = $repeatText x $quantity;
  $newValue      .= $suffix if ($quantity &gt; 0);

  #
  return $newValue;
}

# ------------------------------------------------------------------------------
# Function    : replace
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::replace($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub replace {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # parse arguments
  my($matchText, $match_replaceValue, $nomatch_replaceValue);
  my $match1stArg = q[('|")(.*?)\1\s*];
  my $matchANYVAL = q[()(ANY_VALUE)\s*];
  my $match2ndArg                    = q[\s*('|")(.*?)\3];
  my $matchOptional3rdArg = '(?:\s*,'. q[\s*('|")(.*?)\5] .')?';

  if ($modifierArguments =~ /^$match1stArg,$match2ndArg$matchOptional3rdArg$/ ||
      $modifierArguments =~ /^$matchANYVAL,$match2ndArg$matchOptional3rdArg$/) {
   $matchText            = $2;
   $match_replaceValue   = $4;
   $nomatch_replaceValue = $6;
  }
  else {
   return "[Invalid arguments in replace($modifierArguments),  Examples: replace(ANY_VALUE, 'widgets:') or replace('red', 'blue')]";
  }

  # apply modifier
  my $matchesAnyValue = $matchText eq 'ANY_VALUE' &amp;&amp; $modifiedValue;
  my $matchesString   = $matchText eq $modifiedValue;

  if    ($matchesAnyValue || $matchesString) { $modifiedValue = $match_replaceValue; }
  elsif (defined $nomatch_replaceValue)      { $modifiedValue = $nomatch_replaceValue; }

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : selectedIf
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::selectedIf($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub selectedIf {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # apply modifier
  if ($modifiedValue eq $modifierArguments) { $modifiedValue = 'selected="selected"'; }
  else                                      { $modifiedValue = ''; }

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : spacesToNbsp
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::spacesToNbsp($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub spacesToNbsp {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[spacesToNbsp modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  my $tokens = &amp;IT::HTMLParser::tokenize($modifiedValue);
  foreach my $token (@$tokens) {
    if ($token-&gt;{'type'} eq 'text') {
      $token-&gt;{'content'} =~ s/ /&amp;nbsp;/gs;
    }
  }
  $modifiedValue = &amp;IT::HTMLParser::convertTokensToHtmlString($tokens);

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : textOnly
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::textOnly($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub textOnly {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[textOnly modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  my $tokens     = &amp;IT::HTMLParser::tokenize($modifiedValue);
  $modifiedValue = &amp;IT::HTMLParser::convertTokensToTextOnlyString($tokens);

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : uploadFileAttribute
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::uploadFileAttribute($placeholderName, $originalValue, $modifiedValue, $modifierArguments, $placeholders);
# ------------------------------------------------------------------------------

sub uploadFileAttribute {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;
  my $placeholders      = shift || die "no placeholders specified!";

  # error checking
  my $originalType   = &amp;IT::Template::getPlaceholderType($originalValue);
  if ($originalType ne 'upload') { return "[fileAttribute() modifier isn't available for \$$placeholderName]"; }

  # parse arguments
  my($fileNumber, $attributeName);
  if ($modifierArguments =~ /^\s*(\d+)\s*,\s*(\w+)\s*/s) {
    ($fileNumber, $attributeName) = ($1, $2);
  }
  else {
    return "[Invalid arguments in fileAttribute($modifierArguments) modifier.  Examples: fileAttribute(1, webUrl)]";
  }

  # get fileAttributes hash
  my $fileAttributes;
  foreach my $thisRow (@{$originalValue-&gt;{'rows'}}) {
    if ($thisRow-&gt;{'_num'} &amp;&amp; $thisRow-&gt;{'_num'} == $fileNumber) { $fileAttributes = $thisRow;  }
  }
  unless ($fileAttributes) { return ""; }  # return blank if no file uploaded in numbered slot

  # get specified attribute value
  my $filePlaceholders = &amp;IT::App::createUploadFilePlaceholders({}, $fileAttributes);
  unless (exists $filePlaceholders-&gt;{"file.$attributeName"}) {
    my $placeholderListAsCSV  = join ", ",  map { s/^file.//; $_ } sort keys %$filePlaceholders;
    return "[Unknown file attribute '$attributeName' in fileAttributes() modifier.  Valid attributes: $placeholderListAsCSV]";
  }
  my $attributeValue = $filePlaceholders-&gt;{"file.$attributeName"};

  #
  return $attributeValue;
}

# ------------------------------------------------------------------------------
# Function    : uppercase
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::uppercase($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub uppercase {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[uppercase modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  my $tokens = &amp;IT::HTMLParser::tokenize($modifiedValue);
  foreach my $token (@$tokens) {
    if ($token-&gt;{'type'} eq 'text') {
      $token-&gt;{'content'} = uc $token-&gt;{'content'};
    }
  }
  $modifiedValue = &amp;IT::HTMLParser::convertTokensToHtmlString($tokens);

  #
  return $modifiedValue;
}

# ------------------------------------------------------------------------------
# Function    : urlEncoded
# Description :
# Usage       : $modifiedValue = IT::Template::PlaceholderModifiers::urlEncoded($placeholderName, $originalValue, $modifiedValue, $modifierArguments);
# ------------------------------------------------------------------------------

sub urlEncoded {
  my $placeholderName   = shift || die "no placeholder name specified!";
  my $originalValue     = shift;
  my $modifiedValue     = shift;
  my $modifierArguments = shift;

  # error checking
  if ($modifierArguments) { return "[urlEncoded modifier doesn't take any arguments ($modifierArguments)]"; }

  # apply modifier
  $modifiedValue = &amp;IT::Common::urlEncode( $modifiedValue );

  #
  return $modifiedValue;
}

# ----------------------------------------------------------------------------
# end of file
1;

</pre></body></html>