cross
New Foswiki release 2.1.6 is available with important security fixes.
Sourceforge foswiki email lists being discontinued. Subscribe to the new Foswiki announce and discuss lists at MailingLists
You are here: Foswiki>Tasks Web>Item5935 (05 Jul 2015, GeorgeClark)Edit Attach

Item5935: attach.pm enhancement: add time processing to code

pencil
Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: TopicAttachment
Branches: trunk
Reported By: TWiki:Main.SaschaVetter
Waiting For:
Last Change By: GeorgeClark
Following changes to lib/TWiki/attach.pm allows time/date processing:

Add after
use strict; 
use Assert; 
use TWiki::Time; 

and add before
    # I18N: Site specified %ATTACHEDIMAGEFORMAT% or %ATTACHEDFILELINKFORMAT%,
    # ensure that filename is URL encoded - first $name must be URL.
    $fileLink =~ s/\$name/$fileURL/;
    $fileLink =~ s/\$name/$attName/;
    my $fileext = $attName;
    $fileext =~ s/(.*\.)*([^.]*)/$2/;
    $fileLink =~ s/\$fileext/$fileext/;

    if (defined $att->{date})
    {
      my $date = $att->{date};
      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;
    }


After this change, following attachment example is possible:
On TWIki Site:
   * Local ATTACHEDFILELINKFORMAT = |$year-$mo-$day|Effort        |[[%ATTACHURL%/$name][%ICON{$fileext}% $name]]| received from company xy |


Simple enhancement with nice effects, good enough to add to the next twiki version?

-- TWiki:Main/SaschaVetter - 18 Aug 2008

Sascha, I just discovered this because it was waiting for feedback, but had no-one in the "Waiting For" field. That's a sort of limbo; nothing will happen to reports in that state. I changed it to "New". The code is fine, but this should really have been raised as a feature proposal and we are now in feature-freeze for Foswiki 1.0.0.

I have created AddTimeFeaturesToAttachmentLinks for you.

Going ahead with this, with some changes:
  • Uses Foswiki::Time::formatTime() to expand any of the defined date/time tokens
  • Uses Foswiki::expandStandardEscapes() to handle $n, $comma, $lt, etc.

Added unit tests.

-- GeorgeClark - 26 May 2012

ItemTemplate edit

Summary attach.pm enhancement: add time processing to code
ReportedBy TWiki:Main.SaschaVetter
Codebase trunk
SVN Range
AppliesTo Engine
Component TopicAttachment
Priority Enhancement
CurrentState Closed
WaitingFor
Checkins distro:35eaacd8d9e2
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches trunk
trunkCheckins distro:35eaacd8d9e2
Release01x01Checkins
Topic revision: r7 - 05 Jul 2015, GeorgeClark - This page was cached on 15 Jul 2018 - 12:03.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy