Skip to content

Commit

Permalink
Item1223: HeadlinesPlugin needs to be imported and made available to …
Browse files Browse the repository at this point in the history
…compete with (tm)wiki

Clean twiki2foswiki macro run


git-svn-id: http://svn.foswiki.org/trunk/HeadlinesPlugin@2927 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Mar 8, 2009
1 parent 0c59c00 commit 7baf364
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="TWikiContributor" date="1234497345" format="1.1" version="$Rev$"}%
%META:TOPICINFO{author="ProjectContributor" date="1234497345" format="1.1" version="$Rev$"}%
<!--
Contributions to this plugin are appreciated. Please update the plugin page
at http://twiki.org/cgi-bin/view/Plugins/HeadlinesPlugin or provide feedback
Expand Down Expand Up @@ -174,10 +174,10 @@ defining the default CSS properties (indentation illustrates enclosure).
* [[%ATTACHURL%/%TOPIC%.zip][Download]] the ZIP file
* Unzip it in your twiki installation directory. Content:
| *File:* | *Description:* |
| ==data/TWiki/%TOPIC%.txt== | plugin topic |
| ==pub/TWiki/%TOPIC%/style.css== | default css |
| ==lib/TWiki/%TOPIC%.pm== | plugin perl module |
| ==lib/TWiki/%TOPIC%/Core.pm== | plugin core |
| ==data/System/%TOPIC%.txt== | plugin topic |
| ==pub/System/%TOPIC%/style.css== | default css |
| ==lib/Foswiki/%TOPIC%.pm== | plugin perl module |
| ==lib/Foswiki/%TOPIC%/Core.pm== | plugin core |
Check if above examples show a news feed instead of variable.
* Optionally, run ==%TOPIC%_installer.pl== to automatically check and
install other TWiki modules that this module depends on. You can also do
Expand Down
Expand Up @@ -23,7 +23,7 @@
#

# =========================
package TWiki::Plugins::HeadlinesPlugin;
package Foswiki::Plugins::HeadlinesPlugin;
use strict;

# =========================
Expand Down Expand Up @@ -61,12 +61,12 @@ sub commonTagsHandler {
sub handleHeadlinesTag {

unless ($isInitialized) {
eval 'use TWiki::Plugins::HeadlinesPlugin::Core;';
eval 'use Foswiki::Plugins::HeadlinesPlugin::Core;';
die $@ if $@;
$isInitialized = 1;
}

return TWiki::Plugins::HeadlinesPlugin::Core::handleHeadlinesTag(@_);
return Foswiki::Plugins::HeadlinesPlugin::Core::handleHeadlinesTag(@_);
}

1;
Expand Up @@ -23,7 +23,7 @@
#

# =========================
package TWiki::Plugins::HeadlinesPlugin::Core;
package Foswiki::Plugins::HeadlinesPlugin::Core;

use strict;
use Digest::MD5 qw(md5_hex);
Expand Down Expand Up @@ -293,7 +293,7 @@ $debug = 0; # toggle me

# =========================
sub writeDebug {
TWiki::Func::writeDebug('HeadlinesPlugin - ' . $_[0]) if $debug;
Foswiki::Func::writeDebug('HeadlinesPlugin - ' . $_[0]) if $debug;
print STDERR 'HeadlinesPlugin - ' . $_[0] . "\n" if $debug;
}

Expand All @@ -304,18 +304,18 @@ sub doInit {
$isInitialized = 1;

# Get plugin preferences
$defaultRefresh = TWiki::Func::getPreferencesValue('HEADLINESPLUGIN_REFRESH') || 60;
$defaultLimit = TWiki::Func::getPreferencesValue('HEADLINESPLUGIN_LIMIT') || 100;
$defaultHeader = TWiki::Func::getPreferencesValue('HEADLINESPLUGIN_HEADER') ||
$defaultRefresh = Foswiki::Func::getPreferencesValue('HEADLINESPLUGIN_REFRESH') || 60;
$defaultLimit = Foswiki::Func::getPreferencesValue('HEADLINESPLUGIN_LIMIT') || 100;
$defaultHeader = Foswiki::Func::getPreferencesValue('HEADLINESPLUGIN_HEADER') ||
'| *[[$link][$title ]]* |';
$defaultFormat = TWiki::Func::getPreferencesValue('HEADLINESPLUGIN_FORMAT') ||
$defaultFormat = Foswiki::Func::getPreferencesValue('HEADLINESPLUGIN_FORMAT') ||
'| [[$link][$title]] |';
$useLWPUserAgent = TWiki::Func::getPreferencesValue('HEADLINESPLUGIN_USELWPUSERAGENT')
$useLWPUserAgent = Foswiki::Func::getPreferencesValue('HEADLINESPLUGIN_USELWPUSERAGENT')
|| 'on';
$userAgentTimeout = TWiki::Func::getPreferencesValue("HEADLINESPLUGIN_USERAGENTTIMEOUT")
$userAgentTimeout = Foswiki::Func::getPreferencesValue("HEADLINESPLUGIN_USERAGENTTIMEOUT")
|| 20;
$userAgentName = TWiki::Func::getPreferencesValue("HEADLINESPLUGIN_USERAGENTNAME") ||
'TWikiHeadlinesPlugin/' . $TWiki::Plugins::HeadlinesPlugin::RELEASE;
$userAgentName = Foswiki::Func::getPreferencesValue("HEADLINESPLUGIN_USERAGENTNAME") ||
'TWikiHeadlinesPlugin/' . $Foswiki::Plugins::HeadlinesPlugin::RELEASE;

$useLWPUserAgent =~ s/^\s*(.*?)\s*$/$1/go;
$useLWPUserAgent = ($useLWPUserAgent =~ /on|yes|1/)?1:0;
Expand All @@ -326,7 +326,7 @@ sub doInit {
sub errorMsg {
return
$_[0] .
'<span class="twikiAlert">' .
'<span class="foswikiAlert">' .
'<noautolink>'."\n".
'HeadlinesPlugin '.
$_[1] ."\n".
Expand All @@ -344,27 +344,27 @@ sub readRssFeed
my $cacheDir = '';
my $cacheFile = '';
if ($theRefresh) {
if (defined &TWiki::Func::getWorkArea) {
$cacheDir = TWiki::Func::getWorkArea('HeadlinesPlugin');
if (defined &Foswiki::Func::getWorkArea) {
$cacheDir = Foswiki::Func::getWorkArea('HeadlinesPlugin');
} else {
my $twikiWeb = &TWiki::Func::getTwikiWebname();
$cacheDir = TWiki::Func::getPubDir() . '/' . $twikiWeb . '/HeadlinesPlugin';
my $foswikiWeb = ::cfg{SystemWebName};
$cacheDir = Foswiki::Func::getPubDir() . '/' . $foswikiWeb . '/HeadlinesPlugin';
$cacheDir =~ /(.*)/;
$cacheDir = $1; # untaint (save because only internal variables)
}
$cacheFile = $cacheDir . '/_rss-' . md5_hex($theUrl);
$cacheFile =~ /(.*)/; $cacheFile = $1; # untaint
if ((-e $cacheFile) && ((time() - (stat(_))[9]) <= ($theRefresh * 60))) {
# return cached version if it exists and isn't too old. 1440 = 24h * 60min
return TWiki::Func::readFile($cacheFile);
return Foswiki::Func::readFile($cacheFile);
}
}

unless ($theUrl =~ /^https?:\/\//) { # internal
my ($thisWeb, $thisTopic) = TWiki::Func::normalizeWebTopicName($web, $theUrl);
$theUrl = TWiki::Func::getViewUrl($thisWeb, $thisTopic);
my ($thisWeb, $thisTopic) = Foswiki::Func::normalizeWebTopicName($web, $theUrl);
$theUrl = Foswiki::Func::getViewUrl($thisWeb, $thisTopic);
if ($theUrl =~ /^\//) {
$theUrl = TWiki::Func::getUrlHost().$theUrl;
$theUrl = Foswiki::Func::getUrlHost().$theUrl;
}
}
#writeDebug("url=$theUrl");
Expand All @@ -379,7 +379,7 @@ sub readRssFeed
mkdir($cacheDir, 0775);
}
# save text in cache file before returning it
TWiki::Func::saveFile($cacheFile, $text);
Foswiki::Func::saveFile($cacheFile, $text);
}

return ($text, undef);
Expand All @@ -392,12 +392,12 @@ sub handleHeadlinesTag {

&doInit();

my $href = TWiki::Func::extractNameValuePair($theArgs) ||
TWiki::Func::extractNameValuePair($theArgs, 'href');
my $refresh = TWiki::Func::extractNameValuePair($theArgs, 'refresh') || $defaultRefresh;
my $limit = TWiki::Func::extractNameValuePair($theArgs, 'limit') || $defaultLimit;
my $header = TWiki::Func::extractNameValuePair($theArgs, 'header') || $defaultHeader;
my $format = TWiki::Func::extractNameValuePair($theArgs, 'format') || $defaultFormat;
my $href = Foswiki::Func::extractNameValuePair($theArgs) ||
Foswiki::Func::extractNameValuePair($theArgs, 'href');
my $refresh = Foswiki::Func::extractNameValuePair($theArgs, 'refresh') || $defaultRefresh;
my $limit = Foswiki::Func::extractNameValuePair($theArgs, 'limit') || $defaultLimit;
my $header = Foswiki::Func::extractNameValuePair($theArgs, 'header') || $defaultHeader;
my $format = Foswiki::Func::extractNameValuePair($theArgs, 'format') || $defaultFormat;

$header =~ s/\$n([^a-zA-Z])/\n$1/gos; # expand "$n" to new line
$header =~ s/([^\n])$/$1\n/os; # append new line if needed
Expand Down Expand Up @@ -916,11 +916,11 @@ sub getUrlLWP {
eval "use LWP::UserAgent";
die $@ if $@;

my $proxyHost = TWiki::Func::getPreferencesValue('PROXYHOST') || '';
my $proxyPort = TWiki::Func::getPreferencesValue('PROXYPORT') || '';
$proxyHost ||= $TWiki::cfg{PROXY}{HOST};
$proxyPort ||= $TWiki::cfg{PROXY}{PORT};
my $proxySkip = $TWiki::cfg{PROXY}{SkipProxyForDomains} || '';
my $proxyHost = Foswiki::Func::getPreferencesValue('PROXYHOST') || '';
my $proxyPort = Foswiki::Func::getPreferencesValue('PROXYPORT') || '';
$proxyHost ||= $Foswiki::cfg{PROXY}{HOST};
$proxyPort ||= $Foswiki::cfg{PROXY}{PORT};
my $proxySkip = $Foswiki::cfg{PROXY}{SkipProxyForDomains} || '';

$userAgent = LWP::UserAgent->new();
$userAgent->agent( $userAgentName );
Expand All @@ -937,7 +937,7 @@ sub getUrlLWP {
}

my $request = HTTP::Request->new('GET', $theUrl);
$request->referer(TWiki::Func::getViewUrl($web, $topic));
$request->referer(Foswiki::Func::getViewUrl($web, $topic));
my $response = $userAgent->request($request);
if ($response->is_error) {
return (undef, $response->status_line);
Expand Down Expand Up @@ -967,11 +967,11 @@ sub getUrl {
}
return (undef, "invalid format of the href parameter") unless $path;

# figure out how to get to TWiki::Net which is wide open in Cairo and before,
# figure out how to get to Foswiki::Net which is wide open in Cairo and before,
# but Dakar uses the session object.
my $text = $TWiki::Plugins::SESSION->{net}
? $TWiki::Plugins::SESSION->{net}->getUrl( $host, $port, $path )
: TWiki::Net::getUrl( $host, $port, $path );
my $text = $Foswiki::Plugins::SESSION->{net}
? $Foswiki::Plugins::SESSION->{net}->getUrl( $host, $port, $path )
: Foswiki::Net::getUrl( $host, $port, $path );

if ($text =~ /text\/plain\s*ERROR\: (.*)/s) {
my $msg = $1;
Expand Down
4 changes: 4 additions & 0 deletions lib/Foswiki/Plugins/HeadlinesPlugin/MANIFEST
@@ -0,0 +1,4 @@
data/System/HeadlinesPlugin.txt 0644
lib/Foswiki/Plugins/HeadlinesPlugin/Core.pm 0644
lib/Foswiki/Plugins/HeadlinesPlugin.pm 0644
pub/System/HeadlinesPlugin/style.css 0644
Expand Up @@ -8,10 +8,10 @@ BEGIN
}
}

use TWiki::Contrib::Build;
use Foswiki::Contrib::Build;

# Create the build object
$build = new TWiki::Contrib::Build( 'HeadlinesPlugin' );
$build = new Foswiki::Contrib::Build( 'HeadlinesPlugin' );

# Build the target on the command line, or the default target
$build->build($build->{target});
Expand Down
4 changes: 0 additions & 4 deletions lib/TWiki/Plugins/HeadlinesPlugin/MANIFEST

This file was deleted.

File renamed without changes.

0 comments on commit 7baf364

Please sign in to comment.