Ignore:
Timestamp:
01/29/09 13:35:57 (3 years ago)
Author:
CrawfordCurrie
Message:

Item455: port to foswiki Item5974: correct CSS for search results table Item5938: load CSS for ACTIONSEARCH Item5606: Item5915: respect global settings for time format

Location:
trunk/ActionTrackerPlugin/lib/Foswiki
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/ActionTrackerPlugin/lib/Foswiki/Plugins/ActionTrackerPlugin/ActionNotify.pm

    r1340 r2226  
    1717 
    1818# This module contains the functionality of the bin/actionnotify script 
    19 package TWiki::Plugins::ActionTrackerPlugin::ActionNotify; 
     19package Foswiki::Plugins::ActionTrackerPlugin::ActionNotify; 
    2020 
    2121use strict; 
     
    2727require Time::ParseDate; 
    2828 
    29 require TWiki::Net; 
    30  
    31 require TWiki::Attrs; 
    32  
    33 require TWiki::Plugins::ActionTrackerPlugin::Action; 
    34 require TWiki::Plugins::ActionTrackerPlugin::ActionSet; 
    35 require TWiki::Plugins::ActionTrackerPlugin::Format; 
     29require Foswiki::Net; 
     30 
     31require Foswiki::Attrs; 
     32 
     33require Foswiki::Plugins::ActionTrackerPlugin::Action; 
     34require Foswiki::Plugins::ActionTrackerPlugin::ActionSet; 
     35require Foswiki::Plugins::ActionTrackerPlugin::Format; 
    3636 
    3737my $wikiWordRE; 
    3838my $options; 
    3939 
    40 require TWiki::Plugins::ActionTrackerPlugin::Options; 
     40require Foswiki::Plugins::ActionTrackerPlugin::Options; 
    4141 
    4242# PUBLIC actionnotify script entry point. Reinitialises TWiki. 
     
    4848    my $expr = shift; 
    4949 
    50     my $twiki = new TWiki(); 
     50    my $twiki = new Foswiki(); 
    5151    # Assign SESSION so that Func methods work 
    52     $TWiki::Plugins::SESSION = $twiki; 
     52    $Foswiki::Plugins::SESSION = $twiki; 
    5353 
    5454    if ( $expr =~ s/DEBUG//o ) { 
     
    6464    my ( $webName, $expr, $debugMailer ) = @_; 
    6565 
    66     $options = TWiki::Plugins::ActionTrackerPlugin::Options::load(); 
     66    $options = Foswiki::Plugins::ActionTrackerPlugin::Options::load(); 
    6767    # Disable the state shortcut in mails 
    6868    $options->{ENABLESTATESHORTCUT} = 0; 
    6969 
    70     my $attrs = new TWiki::Attrs( $expr, 1 ); 
     70    my $attrs = new Foswiki::Attrs( $expr, 1 ); 
    7171    my $hdr = $attrs->remove('header') || $options->{TABLEHEADER}; 
    7272    my $bdy = $attrs->remove('format') || $options->{TABLEFORMAT}; 
     
    7676    my $changes = $options->{NOTIFYCHANGES}; 
    7777 
    78     my $format = new TWiki::Plugins::ActionTrackerPlugin::Format( 
     78    my $format = new Foswiki::Plugins::ActionTrackerPlugin::Format( 
    7979        $hdr, $bdy, $orient, $textform, $changes ); 
    8080 
     
    102102    if ( !$attrs->isEmpty() ) { 
    103103        # Get all the actions that match the search 
    104         $actions = TWiki::Plugins::ActionTrackerPlugin::ActionSet::allActionsInWebs( $webs, $attrs, 1 ); 
     104        $actions = Foswiki::Plugins::ActionTrackerPlugin::ActionSet::allActionsInWebs( $webs, $attrs, 1 ); 
    105105        $actions->getActionees( \%people ); 
    106106    } 
     
    130130 
    131131        if ( !defined( $mailaddr ) ) { 
    132             TWiki::Func::writeWarning( "No mail address found for $wikiname" ); 
     132            Foswiki::Func::writeWarning( "No mail address found for $wikiname" ); 
    133133            $result .= "No mail address found for $wikiname<br />" if ( $debugMailer ); 
    134134            next; 
     
    138138        my $myActions; 
    139139        if ( $actions ) { 
    140             my $ats = new TWiki::Attrs( "who=\"$wikiname\"", 1 ); 
     140            my $ats = new Foswiki::Attrs( "who=\"$wikiname\"", 1 ); 
    141141            $myActions = $actions->search( $ats ); 
    142142        } 
     
    147147                if ( !defined( $actionsPerEmail{$email} )) { 
    148148                    $actionsPerEmail{$email} = 
    149                       new TWiki::Plugins::ActionTrackerPlugin::ActionSet(); 
     149                      new Foswiki::Plugins::ActionTrackerPlugin::ActionSet(); 
    150150                } 
    151151                $actionsPerEmail{$email}->concat( $myActions ); 
     
    195195                $result .= $message; 
    196196            } else { 
    197                 my $error = TWiki::Func::sendEmail( $message ); 
     197                my $error = Foswiki::Func::sendEmail( $message ); 
    198198                if ( $error ) { 
    199199                    $error = "ActionTrackerPlugin:ActionNotify: $error"; 
    200                     TWiki::Func::writeWarning( $error ); 
     200                    Foswiki::Func::writeWarning( $error ); 
    201201                } 
    202202            } 
     
    212212    my ( $mailAddress ) = @_; 
    213213 
    214     foreach my $web ( TWiki::Func::getListOfWebs( 'user' )) { 
     214    foreach my $web ( Foswiki::Func::getListOfWebs( 'user' )) { 
    215215        _loadWebNotify( $web, $mailAddress ); 
    216216    } 
     
    223223 
    224224    # COVERAGE OFF safety net 
    225     if( ! TWiki::Func::webExists( $web ) ) { 
     225    if( ! Foswiki::Func::webExists( $web ) ) { 
    226226        my $error = 'ActionTrackerPlugin:ActionNotify: did not find web $web'; 
    227         TWiki::Func::writeWarning( $error ); 
     227        Foswiki::Func::writeWarning( $error ); 
    228228        return; 
    229229    } 
    230230    # COVERAGE ON 
    231231 
    232     my $topicname = $TWiki::cfg{NotifyTopicName}; 
    233     return undef unless TWiki::Func::topicExists( $web, $topicname ); 
     232    my $topicname = $Foswiki::cfg{NotifyTopicName}; 
     233    return undef unless Foswiki::Func::topicExists( $web, $topicname ); 
    234234 
    235235    my $list = {}; 
    236     my $mainweb = TWiki::Func::getMainWebname(); 
    237     my $text = TWiki::Func::readTopicText( $web, $topicname, undef, 1 ); 
     236    my $mainweb = Foswiki::Func::getMainWebname(); 
     237    my $text = Foswiki::Func::readTopicText( $web, $topicname, undef, 1 ); 
    238238    foreach my $line ( split( /\r?\n/, $text)) { 
    239239        if ( $line =~ /^\s+\*\s([\w\.]+)\s+-\s+([\w\-\.\+]+\@[\w\-\.\+]+)/o ) { 
    240240            my $who = $1; 
    241241            my $addr = $2; 
    242             $who = TWiki::Plugins::ActionTrackerPlugin::Action::_canonicalName( $who ); 
     242            $who = Foswiki::Plugins::ActionTrackerPlugin::Action::_canonicalName( $who ); 
    243243            if ( !defined( $mailAddress->{$who} )) { 
    244                 TWiki::Func::writeWarning( 'ActionTrackerPlugin:ActionNotify: mail address for $who found in WebNotify' ); 
     244                Foswiki::Func::writeWarning( 'ActionTrackerPlugin:ActionNotify: mail address for $who found in WebNotify' ); 
    245245                $mailAddress->{$who} = $addr; 
    246246            } 
     
    259259    } 
    260260    my $addresses; 
    261         my $wikiWordRE = TWiki::Func::getRegularExpression('wikiWordRegex'); 
    262         my $webNameRE = TWiki::Func::getRegularExpression('webNameRegex'); 
     261        my $wikiWordRE = Foswiki::Func::getRegularExpression('wikiWordRegex'); 
     262        my $webNameRE = Foswiki::Func::getRegularExpression('webNameRegex'); 
    263263 
    264264    if ( $who =~ m/^([\w\-\.\+]+\@[\w\-\.\+]+)$/o ) { 
     
    282282        # A legal topic wikiname 
    283283        $who = 
    284           TWiki::Plugins::ActionTrackerPlugin::Action::_canonicalName( $who ); 
     284          Foswiki::Plugins::ActionTrackerPlugin::Action::_canonicalName( $who ); 
    285285        $addresses = _getMailAddress( $who, $mailAddress ); 
    286286        # Replaced by NKO 
     
    289289        elsif ( $who =~ m/^($webNameRE)\.($wikiWordRE)$/o ) { 
    290290        my( $inweb, $intopic ) = ( $1, $2 ); 
    291         $addresses = TWiki::Func::wikiToEmail($intopic); 
    292  
     291        $addresses = join(',', Foswiki::Func::wikinameToEmails($intopic)); 
    293292        # LEGACY - Try and expand groups the old way 
    294         if( !$addresses && TWiki::Func::topicExists( $inweb, $intopic ) ) { 
     293        if( !$addresses && Foswiki::Func::topicExists( $inweb, $intopic ) ) { 
    295294            my $text = 
    296               TWiki::Func::readTopicText( $inweb, $intopic, undef, 1 ); 
     295              Foswiki::Func::readTopicText( $inweb, $intopic, undef, 1 ); 
    297296            if ( $intopic =~ m/Group$/o ) { 
    298297                # If it's a Group topic, match * Set GROUP =  
     
    324323         $since, $mailaddr, $format ) = @_; 
    325324 
    326     my $from = $TWiki::cfg{WebMasterEmail} || 
    327       TWiki::Func::getPreferencesValue( 'WIKIWEBMASTER' ) || ''; 
    328  
    329     my $text = TWiki::Func::readTemplate( 'actionnotify' ) || <<'HERE'; 
     325    my $from = $Foswiki::cfg{WebMasterEmail} || 
     326      Foswiki::Func::getPreferencesValue( 'WIKIWEBMASTER' ) || ''; 
     327 
     328    my $text = Foswiki::Func::readTemplate( 'actionnotify' ) || <<'HERE'; 
    330329From: %EMAILFROM% 
    331330To: %EMAILTO% 
     
    352351    if ( $actionsString ne '' ) { 
    353352        $text =~ s/%ACTIONS_AS_STRING%/$actionsString/go; 
    354         my $asHTML = TWiki::Func::renderText( $actionsHTML ); 
     353        my $asHTML = Foswiki::Func::renderText( $actionsHTML ); 
    355354        $text =~ s/%ACTIONS_AS_HTML%/$asHTML/go; 
    356355        $text =~ s/%ACTIONS%(.*?)%END%/$1/gso; 
     
    360359 
    361360    if( $since ) { 
    362         $since = TWiki::Func::formatTime( $since ); 
     361        $since = Foswiki::Func::formatTime( $since ); 
    363362    } else { 
    364363        $since = ''; 
     
    368367    if ( $changesString ne '' ) { 
    369368        $text =~ s/%CHANGES_AS_STRING%/$changesString/go; 
    370         my $asHTML = TWiki::Func::renderText( $changesHTML ); 
     369        my $asHTML = Foswiki::Func::renderText( $changesHTML ); 
    371370        $text =~ s/%CHANGES_AS_HTML%/$asHTML/go; 
    372371        $text =~ s/%CHANGES%(.*?)%END%/$1/gso; 
     
    375374    } 
    376375 
    377     $text = TWiki::Func::expandCommonVariables( $text, 
    378                                                 $TWiki::cfg{HomeTopicName} ); 
     376    $text = Foswiki::Func::expandCommonVariables( $text, 
     377                                                $Foswiki::cfg{HomeTopicName} ); 
    379378 
    380379    $text =~ s/<img src=.*?[^>]>/[IMG]/goi;  # remove all images 
     
    382381    # add the url host to any in-twiki urls that lack it 
    383382    # SMELL: doesn't handle (undocumented) {ScriptUrlPaths} 
    384     my $sup = $TWiki::cfg{ScriptUrlPath}; 
     383    my $sup = $Foswiki::cfg{ScriptUrlPath}; 
    385384    $sup =~ s#/$##; 
    386     my $sun = TWiki::Func::getUrlHost() . $sup; 
     385    my $sun = Foswiki::Func::getUrlHost() . $sup; 
    387386    $text =~ s#href=\"$sup/#href=\"$sun/#ogi; 
    388387    $text =~ s/<\/?nop( \/)?>//goi; 
     
    406405    # Recover the rev at the previous date 
    407406    my $oldrev = 
    408       TWiki::Func::getRevisionAtTime( $theWeb, $theTopic, $theDate ); 
     407      Foswiki::Func::getRevisionAtTime( $theWeb, $theTopic, $theDate ); 
    409408    return unless defined( $oldrev ); 
    410409 
    411410    $oldrev =~ s/\d+\.(\d+)/$1/o; 
    412411    # Recover the action set at that date 
    413     my $text = TWiki::Func::readTopicText( $theWeb, $theTopic, $oldrev, 1 ); 
     412    my $text = Foswiki::Func::readTopicText( $theWeb, $theTopic, $oldrev, 1 ); 
    414413 
    415414    my $oldActions = 
    416       TWiki::Plugins::ActionTrackerPlugin::ActionSet::load( $theWeb, 
     415      Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $theWeb, 
    417416                                                            $theTopic, $text ); 
    418417    # Recover the current action set. 
    419     $text = TWiki::Func::readTopicText( $theWeb, $theTopic, undef, 1 ); 
     418    $text = Foswiki::Func::readTopicText( $theWeb, $theTopic, undef, 1 ); 
    420419    my $currentActions = 
    421       TWiki::Plugins::ActionTrackerPlugin::ActionSet::load( $theWeb, 
     420      Foswiki::Plugins::ActionTrackerPlugin::ActionSet::load( $theWeb, 
    422421                                                            $theTopic, $text ); 
    423422 
     
    434433sub _findChangesInWeb { 
    435434    my ( $web, $topics, $theDate, $format, $notifications ) = @_; 
    436     my $actions = new TWiki::Plugins::ActionTrackerPlugin::ActionSet(); 
    437  
    438         my @tops = TWiki::Func::getTopicList( $web ); 
     435    my $actions = new Foswiki::Plugins::ActionTrackerPlugin::ActionSet(); 
     436 
     437        my @tops = Foswiki::Func::getTopicList( $web ); 
    439438    my $grep = 
    440       TWiki::Func::searchInWebContent( '%ACTION{.*}%', $web, \@tops, 
     439      Foswiki::Func::searchInWebContent( '%ACTION{.*}%', $web, \@tops, 
    441440                                       { type => 'regex', 
    442441                                         casesensitive => 1, 
     
    458457sub _findChangesInWebs { 
    459458    my ( $webs, $topics, $date, $format, $notifications ) = @_; 
    460     my @weblist = grep { /^$webs$/ } TWiki::Func::getListOfWebs( 'user' ); 
     459    my @weblist = grep { /^$webs$/ } Foswiki::Func::getListOfWebs( 'user' ); 
    461460    foreach my $web ( @weblist ) { 
    462461        _findChangesInWeb( $web, $topics, $date, 
Note: See TracChangeset for help on using the changeset viewer.