Changeset 811 for trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm
- Timestamp:
- 11/19/08 15:00:00 (4 years ago)
- Location:
- trunk/MailerContrib/lib/Foswiki
- Files:
-
- 1 edited
- 1 moved
-
. (moved) (moved from trunk/MailerContrib/lib/TWiki)
-
Contrib/MailerContrib.pm (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm
r781 r811 2 2 # 3 3 # Copyright (C) 2004 Wind River Systems Inc. 4 # Copyright (C) 1999-2006 TWiki Contributors.5 # All Rights Reserved. TWiki Contributors4 # Copyright (C) 1999-2006 Foswiki Contributors. 5 # All Rights Reserved. Foswiki Contributors 6 6 # are listed in the AUTHORS file in the root of this distribution. 7 7 # NOTE: Please extend that file, not this notice. … … 21 21 =pod 22 22 23 ---+ package TWiki::Contrib::MailerContrib23 ---+ package Foswiki::Contrib::MailerContrib 24 24 25 25 Package of support for extended Web<nop>Notify notification, supporting per-topic notification and notification of changes to children. … … 29 29 =cut 30 30 31 package TWiki::Contrib::MailerContrib;31 package Foswiki::Contrib::MailerContrib; 32 32 33 33 use strict; … … 36 36 use CGI qw(-any); 37 37 38 require TWiki;39 require TWiki::Plugins;40 require TWiki::Time;41 require TWiki::Func;42 require TWiki::Contrib::MailerContrib::WebNotify;43 require TWiki::Contrib::MailerContrib::Change;44 require TWiki::Contrib::MailerContrib::UpData;38 require Foswiki; 39 require Foswiki::Plugins; 40 require Foswiki::Time; 41 require Foswiki::Func; 42 require Foswiki::Contrib::MailerContrib::WebNotify; 43 require Foswiki::Contrib::MailerContrib::Change; 44 require Foswiki::Contrib::MailerContrib::UpData; 45 45 46 46 use vars qw ( $VERSION $RELEASE $verbose ); … … 51 51 # PROTECTED STATIC ensure the contrib is initernally initialised 52 52 sub initContrib { 53 $ TWiki::cfg{MailerContrib}{EmailFilterIn} ||=54 $ TWiki::regex{emailAddrRegex};53 $Foswiki::cfg{MailerContrib}{EmailFilterIn} ||= 54 $Foswiki::regex{emailAddrRegex}; 55 55 } 56 56 … … 90 90 91 91 if (!defined $twiki) { 92 $twiki = new TWiki();93 } 94 95 $ TWiki::Plugins::SESSION = $twiki;96 97 my $context = TWiki::Func::getContext();92 $twiki = new Foswiki(); 93 } 94 95 $Foswiki::Plugins::SESSION = $twiki; 96 97 my $context = Foswiki::Func::getContext(); 98 98 99 99 $context->{command_line} = 1; … … 105 105 106 106 my $report = ''; 107 foreach my $web ( TWiki::Func::getListOfWebs( 'user ') ) {107 foreach my $web ( Foswiki::Func::getListOfWebs( 'user ') ) { 108 108 if ( $web =~ /^($webstr)$/ && $web !~ /^($exwebstr)$/ ) { 109 109 $report .= _processWeb( $twiki, $web ); … … 124 124 125 125 #we can get away with a normalise on a list of topics, so long as the list starts with a topic 126 my ($web, $t) = TWiki::Func::normalizeWebTopicName($defaultWeb, $topicList);126 my ($web, $t) = Foswiki::Func::normalizeWebTopicName($defaultWeb, $topicList); 127 127 #TODO: this limits us to subscribing to one web. 128 my $wn = new TWiki::Contrib::MailerContrib::WebNotify(129 $ TWiki::Plugins::SESSION, $web, $TWiki::cfg{NotifyTopicName}, 1 );128 my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( 129 $Foswiki::Plugins::SESSION, $web, $Foswiki::cfg{NotifyTopicName}, 1 ); 130 130 $wn->parsePageSubscriptions( $who, $topicList, $unsubscribe ); 131 131 $wn->writeWebNotify(); … … 151 151 }; 152 152 153 my $ret = TWiki::Contrib::MailerContrib::parsePageList($subscribed, $who, $topicList);153 my $ret = Foswiki::Contrib::MailerContrib::parsePageList($subscribed, $who, $topicList); 154 154 155 155 return (!defined($subscribed->{not_subscribed}) || … … 159 159 my ( $subscribed, $who, $unsubscribe, $topic, $options, $childDepth ) = @_; 160 160 161 require TWiki::Contrib::MailerContrib::WebNotify;162 my ($sweb, $stopic) = TWiki::Func::normalizeWebTopicName($subscribed->{currentWeb}, $topic);161 require Foswiki::Contrib::MailerContrib::WebNotify; 162 my ($sweb, $stopic) = Foswiki::Func::normalizeWebTopicName($subscribed->{currentWeb}, $topic); 163 163 164 164 #TODO: extract this code so we only create $wn objects for each web once.. 165 my $wn = new TWiki::Contrib::MailerContrib::WebNotify( $TWiki::Plugins::SESSION, $sweb, $TWiki::cfg{NotifyTopicName} );165 my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( $Foswiki::Plugins::SESSION, $sweb, $Foswiki::cfg{NotifyTopicName} ); 166 166 my $subscriber = $wn->getSubscriber($who); 167 167 168 my $db = new TWiki::Contrib::MailerContrib::UpData( $TWiki::Plugins::SESSION, $sweb );168 my $db = new Foswiki::Contrib::MailerContrib::UpData( $Foswiki::Plugins::SESSION, $sweb ); 169 169 #TODO: need to check $childDepth topics too (somehow) 170 170 if ( $subscriber->isSubscribedTo($stopic, $db) && … … 207 207 my( $twiki, $web) = @_; 208 208 209 if( ! TWiki::Func::webExists( $web ) ) {209 if( ! Foswiki::Func::webExists( $web ) ) { 210 210 # print STDERR "**** ERROR mailnotifier cannot find web $web\n"; 211 211 return ''; … … 217 217 218 218 # Read the webnotify and load subscriptions 219 my $wn = new TWiki::Contrib::MailerContrib::WebNotify(220 $twiki, $web, $ TWiki::cfg{NotifyTopicName} );219 my $wn = new Foswiki::Contrib::MailerContrib::WebNotify( 220 $twiki, $web, $Foswiki::cfg{NotifyTopicName} ); 221 221 if ( $wn->isEmpty() ) { 222 222 print "\t$web has no subscribers\n" if $verbose; … … 224 224 # create a DB object for parent pointers 225 225 print $wn->stringify(1) if $verbose; 226 my $db = new TWiki::Contrib::MailerContrib::UpData( $twiki, $web );226 my $db = new Foswiki::Contrib::MailerContrib::UpData( $twiki, $web ); 227 227 $report .= _processSubscriptions( $twiki, $web, $wn, $db ); 228 228 } … … 235 235 my ( $twiki, $web, $notify, $db ) = @_; 236 236 237 my $metadir = TWiki::Func::getWorkArea('MailerContrib');237 my $metadir = Foswiki::Func::getWorkArea('MailerContrib'); 238 238 my $notmeta = $web; 239 239 $notmeta =~ s#/#.#g; … … 249 249 if ( $verbose ) { 250 250 print "\tLast notification was at " . 251 TWiki::Time::formatTime( $timeOfLastNotify, 'iso' ). "\n";251 Foswiki::Time::formatTime( $timeOfLastNotify, 'iso' ). "\n"; 252 252 } 253 253 … … 270 270 my %allSet; 271 271 272 if( !defined( & TWiki::Func::eachChangeSince )) {273 require TWiki::Contrib::MailerContrib::CompatibilityHacks;272 if( !defined( &Foswiki::Func::eachChangeSince )) { 273 require Foswiki::Contrib::MailerContrib::CompatibilityHacks; 274 274 } 275 275 276 276 # + 1 because the 'since' check is >= 277 my $it = TWiki::Func::eachChangeSince( $web, $timeOfLastNotify + 1 );277 my $it = Foswiki::Func::eachChangeSince( $web, $timeOfLastNotify + 1 ); 278 278 while( $it->hasNext() ) { 279 279 my $change = $it->next(); 280 280 next if $change->{more} && $change->{more} =~ /minor$/; 281 281 282 next unless TWiki::Func::topicExists( $web, $change->{topic} );282 next unless Foswiki::Func::topicExists( $web, $change->{topic} ); 283 283 284 284 $timeOfLastChange = $change->{time} unless( $timeOfLastChange ); 285 285 286 286 print "\tChange to $change->{topic} at ". 287 TWiki::Time::formatTime( $change->{time}, 'iso' ).287 Foswiki::Time::formatTime( $change->{time}, 'iso' ). 288 288 ". New revision is $change->{revision}\n" if ( $verbose ); 289 289 290 290 # Formulate a change record, irrespective of 291 291 # whether any subscriber is interested 292 $change = new TWiki::Contrib::MailerContrib::Change(292 $change = new Foswiki::Contrib::MailerContrib::Change( 293 293 $twiki, $web, $change->{topic}, $change->{user}, 294 294 $change->{time}, $change->{revision} ); … … 300 300 # For each topic, see if there's a compulsory subscription independent 301 301 # of the time since last notify 302 foreach my $topic ( TWiki::Func::getTopicList($web)) {302 foreach my $topic (Foswiki::Func::getTopicList($web)) { 303 303 $notify->processCompulsory( $topic, $db, \%allSet ); 304 304 } … … 307 307 my $report = _sendChangesMails( 308 308 $twiki, $web, \%changeset, 309 TWiki::Time::formatTime($timeOfLastNotify) );309 Foswiki::Time::formatTime($timeOfLastNotify) ); 310 310 311 311 $report .= _sendNewsletterMails( $twiki, $web, \%allSet); … … 326 326 my $report = ''; 327 327 328 my $skin = TWiki::Func::getSkin();329 my $template = TWiki::Func::readTemplate( 'mailnotify', $skin );330 331 my $homeTopic = $ TWiki::cfg{HomeTopicName};332 333 my $before_html = TWiki::Func::expandTemplate( 'HTML:before' );334 my $middle_html = TWiki::Func::expandTemplate( 'HTML:middle' );335 my $after_html = TWiki::Func::expandTemplate( 'HTML:after' );336 337 my $before_plain = TWiki::Func::expandTemplate( 'PLAIN:before' );338 my $middle_plain = TWiki::Func::expandTemplate( 'PLAIN:middle' );339 my $after_plain = TWiki::Func::expandTemplate( 'PLAIN:after' );340 341 my $mailtmpl = TWiki::Func::expandTemplate( 'MailNotifyBody' );342 $mailtmpl = TWiki::Func::expandCommonVariables(328 my $skin = Foswiki::Func::getSkin(); 329 my $template = Foswiki::Func::readTemplate( 'mailnotify', $skin ); 330 331 my $homeTopic = $Foswiki::cfg{HomeTopicName}; 332 333 my $before_html = Foswiki::Func::expandTemplate( 'HTML:before' ); 334 my $middle_html = Foswiki::Func::expandTemplate( 'HTML:middle' ); 335 my $after_html = Foswiki::Func::expandTemplate( 'HTML:after' ); 336 337 my $before_plain = Foswiki::Func::expandTemplate( 'PLAIN:before' ); 338 my $middle_plain = Foswiki::Func::expandTemplate( 'PLAIN:middle' ); 339 my $after_plain = Foswiki::Func::expandTemplate( 'PLAIN:after' ); 340 341 my $mailtmpl = Foswiki::Func::expandTemplate( 'MailNotifyBody' ); 342 $mailtmpl = Foswiki::Func::expandCommonVariables( 343 343 $mailtmpl, $homeTopic, $web ); 344 if( $ TWiki::cfg{RemoveImgInMailnotify} ) {344 if( $Foswiki::cfg{RemoveImgInMailnotify} ) { 345 345 # change images to [alt] text if there, else remove image 346 346 $mailtmpl =~ s/<img\s[^>]*\balt=\"([^\"]+)[^>]*>/[$1]/goi; … … 360 360 } 361 361 362 $plain =~ s/\($ TWiki::cfg{UsersWebName}\./\(/go;362 $plain =~ s/\($Foswiki::cfg{UsersWebName}\./\(/go; 363 363 364 364 my $mail = $mailtmpl; … … 368 368 $mail =~ s/%PLAIN_TEXT%/$before_plain$plain$after_plain/go; 369 369 $mail =~ s/%LASTDATE%/$lastTime/geo; 370 $mail = TWiki::Func::expandCommonVariables( $mail, $homeTopic, $web );371 372 my $base = $ TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath};370 $mail = Foswiki::Func::expandCommonVariables( $mail, $homeTopic, $web ); 371 372 my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 373 373 $mail =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 374 374 $mail =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; … … 377 377 $mail =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; 378 378 379 my $error = TWiki::Func::sendEmail( $mail, 5 );379 my $error = Foswiki::Func::sendEmail( $mail, 5 ); 380 380 381 381 if ($error) { … … 410 410 sub _sendNewsletterMail { 411 411 my ($twiki, $web, $topic, $emails) = @_; 412 my $wikiName = TWiki::Func::getWikiName();412 my $wikiName = Foswiki::Func::getWikiName(); 413 413 414 414 # SMELL: this code is almost identical to PublishContrib 415 415 416 416 # Read topic data. 417 my ($meta, $text) = TWiki::Func::readTopic( $web, $topic );418 419 if (!defined( & TWiki::Func::pushTopicContext )) {420 require TWiki::Contrib::MailerContrib::TopicContext;421 } 422 TWiki::Func::pushTopicContext( $web, $topic );417 my ($meta, $text) = Foswiki::Func::readTopic( $web, $topic ); 418 419 if (!defined( &Foswiki::Func::pushTopicContext )) { 420 require Foswiki::Contrib::MailerContrib::TopicContext; 421 } 422 Foswiki::Func::pushTopicContext( $web, $topic ); 423 423 424 424 $twiki->enterContext( 'can_render_meta', $meta ); 425 425 426 426 # Get the skin for this topic 427 my $skin = TWiki::Func::getSkin();428 TWiki::Func::readTemplate( 'newsletter', $skin );429 my $header = TWiki::Func::expandTemplate( 'NEWS:header' );430 my $body = TWiki::Func::expandTemplate( 'NEWS:body' );431 my $footer = TWiki::Func::expandTemplate( 'NEWS:footer' );427 my $skin = Foswiki::Func::getSkin(); 428 Foswiki::Func::readTemplate( 'newsletter', $skin ); 429 my $header = Foswiki::Func::expandTemplate( 'NEWS:header' ); 430 my $body = Foswiki::Func::expandTemplate( 'NEWS:body' ); 431 my $footer = Foswiki::Func::expandTemplate( 'NEWS:footer' ); 432 432 433 433 my ($revdate, $revuser, $maxrev); … … 437 437 $body =~ s/%TEXT%/$text/g; 438 438 # Don't render the header, it is preformatted 439 $header = TWiki::Func::expandCommonVariables($header, $topic, $web);439 $header = Foswiki::Func::expandCommonVariables($header, $topic, $web); 440 440 my $tmpl = "$body\n$footer"; 441 $tmpl = TWiki::Func::expandCommonVariables($tmpl, $topic, $web);442 $tmpl = TWiki::Func::renderText($tmpl, "", $meta);441 $tmpl = Foswiki::Func::expandCommonVariables($tmpl, $topic, $web); 442 $tmpl = Foswiki::Func::renderText($tmpl, "", $meta); 443 443 $tmpl = "$header$tmpl"; 444 444 … … 475 475 476 476 # Rewrite absolute URLs 477 my $base = $ TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath};477 my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 478 478 $tmpl =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 479 479 $tmpl =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; … … 489 489 $mail =~ s/%EMAILTO%/$email/go; 490 490 491 my $base = $ TWiki::cfg{DefaultUrlHost} . $TWiki::cfg{ScriptUrlPath};491 my $base = $Foswiki::cfg{DefaultUrlHost} . $Foswiki::cfg{ScriptUrlPath}; 492 492 $mail =~ s/(href=\")([^"]+)/$1.relativeURL($base,$2)/goei; 493 493 $mail =~ s/(action=\")([^"]+)/$1.relativeURL($base,$2)/goei; … … 496 496 $mail =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois; 497 497 498 my $error = TWiki::Func::sendEmail( $mail, 5 );498 my $error = Foswiki::Func::sendEmail( $mail, 5 ); 499 499 500 500 if ($error) { … … 508 508 $report .= "\t$sentMails newsletters from $web\n"; 509 509 510 TWiki::Func::popTopicContext();510 Foswiki::Func::popTopicContext(); 511 511 512 512 return $report;
Note: See TracChangeset
for help on using the changeset viewer.
