Question
I wanted to change ATTACHEDFILELINKFORMAT as specified in
ConfigurableAttachLinkFormat. Now I wanted to use other place holders like $fileextension, $date (date the attachment was added) or $year-$mo-$day to be more precise.
Now I see that this is not possible. Is there a extension planed or do I need to request that for further development?
Is it possible to set this variable in the topic I want to attach to (or any topic that is included)?
Environment
--
MichaelDeckert - 26 Mar 2008
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
I think I found an answer myself. I changed some details in Time.pm:
$value = $formatString;
$value =~ s/\$seco?n?d?s?/sprintf('%02d',$sec)/gei;
$value =~ s/\$minu?t?e?s?/sprintf('%02d',$min)/gei;
$value =~ s/\$hour?s?/sprintf('%02d',$hour)/gei;
$value =~ s/\$day/sprintf('%02d',$day)/gei;
$value =~ s/\$wday/$WEEKDAY[$wday]/gi;
$value =~ s/\$dow/$wday/gi;
$value =~ s/\$week/_weekNumber($day,$mon,$year,$wday)/egi;
$value =~ s/\$mont?h?/$ISOMONTH[$mon]/gi;
$value =~ s/\$mo/sprintf('%02d',$mon+1)/gei;
$value =~ s/\$year?/sprintf('%04d',$year+1900)/gei;
$value =~ s/\$ye/sprintf('%02d',$year%100)/gei;
$value =~ s/\$epoch/$epochSeconds/gi;
so have leading zeros. Then i added to Attach.pm:
...
$fileComment = $attName unless ( $fileComment );
my $date = $att->{date} if defined $att->{date};
...
and
...
$fileLink =~ s/\$name/$attName/;
my $fileext = $attName;
$fileext =~ s/(.*\.)*([^.]*)/\2/;
$fileLink =~ s/\$fileext/$fileext/;
use Time::localtime;
my ($seconds,$minutes,$hours,$day,$mo,$ye,$wday,$ydat,$isdst) = gmtime($date);
require TWiki::time;
$fileLink =~ s/\$date/TWiki::Time::formatTime( $date || 0)/gei;
$fileLink =~ s/\$seconds/TWiki::Time::formatTime( $date || 0, "\$seconds")/gei;
$fileLink =~ s/\$minutes/TWiki::Time::formatTime( $date || 0, "\$minutes")/gei;
$fileLink =~ s/\$hours/TWiki::Time::formatTime( $date || 0, "\$hours")/gei;
$fileLink =~ s/\$wday/TWiki::Time::formatTime( $date || 0, "\$wday")/gei;
$fileLink =~ s/\$day/TWiki::Time::formatTime( $date || 0, "\$day")/gei;
$fileLink =~ s/\$month/TWiki::Time::formatTime( $date || 0, "\$month")/gei;
$fileLink =~ s/\$mo/TWiki::Time::formatTime( $date || 0, "\$mo")/gei;
$fileLink =~ s/\$year/TWiki::Time::formatTime( $date || 0, "\$year")/gei;
$fileLink =~ s/\$ye/TWiki::Time::formatTime( $date || 0, "\$ye")/gei;
...
--
MichaelDeckert - 27 Mar 2008