From: Walter M. <eth...@us...> - 2004-03-01 16:03:41
|
Update of /cvsroot/twiki/twiki/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31205 Modified Files: TWiki.pm Log Message: Codev.FormattedTWikiFormDataInTopicText patch, revised Index: TWiki.pm =================================================================== RCS file: /cvsroot/twiki/twiki/lib/TWiki.pm,v retrieving revision 1.294 retrieving revision 1.295 diff -C2 -r1.294 -r1.295 *** TWiki.pm 29 Feb 2004 12:49:01 -0000 1.294 --- TWiki.pm 1 Mar 2004 15:52:35 -0000 1.295 *************** *** 2947,2950 **** --- 2947,2951 ---- handleInternalTags( $text, $theTopic, $theWeb ); + $text =~ s/%FORMFIELD{(.*?)}%/&getFormField($theWeb,$theTopic,$1)/ge; $text =~ s/%TOC{([^}]*)}%/&handleToc($text,$theTopic,$theWeb,$1)/ge; $text =~ s/%TOC%/&handleToc($text,$theTopic,$theWeb,"")/ge; *************** *** 3712,3715 **** --- 3713,3784 ---- } + =pod + + ---++ sub getFormField ( $web, $topic, $args ) + + Handles %FORMFIELD{}% tags in topics, used in handleInternalTags + + TODO: use Prefs subsystem to read form info, instead of rereadeing + topic every time a form field value is requested. + + =cut + + sub getFormField + { + my( $web, $topic, $args ) = @_; + + my ( $altText, $found, $format ); + my ( $formField, $formTopic, $default ); + + $formField = extractNameValuePair( $args ); + $formTopic = extractNameValuePair( $args, "topic" ); + $altText = extractNameValuePair( $args, "alttext" ); + $default = extractNameValuePair( $args, "default" ) || undef; + $format = extractNameValuePair( $args, "format" ) || '$value'; + + my $meta; + if ($formTopic) { + my $formTopicWeb; + if ($topic =~ /^([^.]+)\.([^.]+)/o) { + ( $formTopicWeb, $topic ) = ( $1, $2 ); + } else { + $formTopicWeb = extractNameValuePair( $args, "web" ); + } + $formTopicWeb = $web unless defined $formTopicWeb; + ( $meta, my $dummyText ) = &TWiki::Store::readTopic( $formTopicWeb, $formTopic ); + } else { + ( $meta, my $dummyText ) = &TWiki::Store::readTopic( $web, $topic ); + } + + my $text = ""; + my @fields = $meta->find( "FIELD" ); + foreach my $field ( @fields ) { + my $title = $field->{"title"}; + my $name = $field->{"name"}; + if( $title eq $formField || $name eq $formField ) { + my $value = $field->{"value"}; + if (length $value) { + $found = 1; + $text = $format; + $text =~ s/\$value/$value/g; + } elsif (defined $altText) { + $found = 1; + $text = $altText; + } + last; #one hit suffices + } + } + if (!$found) { + if (defined $default) { + $text = $format; + $text =~ s/\$value/$default/g; + } else { + $text = $altText; + } + } + $text = getRenderedVersion( $text, $web ); + return $text; + } + # ========================= |