Skip to content

Commit

Permalink
Item11808: perltidy them all, so people are not accidentally impacted…
Browse files Browse the repository at this point in the history
… by the new enforced rule -- Sorry Micha, could not find a way to define specific values within the file

git-svn-id: http://svn.foswiki.org/trunk/PloticusPlugin@14686 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed May 4, 2012
1 parent f2c190e commit 030c802
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 237 deletions.
165 changes: 101 additions & 64 deletions lib/Foswiki/Plugins/PloticusPlugin.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it
# Copyright (C) 2001-2006 Peter Thoeny, peter@thoeny.org
Expand Down Expand Up @@ -40,12 +40,9 @@ $VERSION = '$Rev: 1.2$';
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = 'Dakar';



# Name of this Plugin, only used in this module
$pluginName = 'PloticusPlugin';


=pod
---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean
Expand Down Expand Up @@ -73,129 +70,168 @@ and highly dangerous!
=cut


sub initPlugin {
#Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
my( $topic, $web, $user, $installWeb ) = @_;
$debug = Foswiki::Func::getPreferencesValue( 'PLOTICUSPLUGIN_DEBUG' );

#Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
my ( $topic, $web, $user, $installWeb ) = @_;
$debug = Foswiki::Func::getPreferencesValue('PLOTICUSPLUGIN_DEBUG');
$debug = 1;
Foswiki::Func::writeDebug( "Initialising PloticusPlugin...." ) if $debug;
Foswiki::Func::writeDebug("Initialising PloticusPlugin....") if $debug;

# check for Plugins.pm versions
if( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
if ( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning(
"Version mismatch between $pluginName and Plugins.pm");
return 0;
}

# register the handlePloticusTag function to handle %PLOTICUSPLOT{...}% tag
Foswiki::Func::registerTagHandler( 'PLOTICUSPLOT', \&handlePloticusTag );

# Allow a sub to be called from the REST interface
# Allow a sub to be called from the REST interface
# using the provided alias
Foswiki::Func::registerRESTHandler('Ploticus', \&restPloticus);
Foswiki::Func::registerRESTHandler( 'Ploticus', \&restPloticus );

# Plugin correctly initialized
return 1;
}


sub handlePloticusTag {
my($session, $params, $topic, $web) = @_;
my ( $session, $params, $topic, $web ) = @_;

# $session - not used.
# $params= - _DEFAULT is the name of the plot
# $topic - name of the topic in the query
# $web - name of the web in the query
# Return: rendered text for the plugin

Foswiki::Func::writeDebug( "PloticusPlugin::handlePloticusTag for $web - $topic Name=$params->{_DEFAULT}" ) if $debug;
Foswiki::Func::writeDebug(
"PloticusPlugin::handlePloticusTag for $web - $topic Name=$params->{_DEFAULT}"
) if $debug;
my $plotName = $params->{_DEFAULT};
unless ($plotName) { return showError('Plot must have a name.'); };
unless ($plotName) { return showError('Plot must have a name.'); }

# get what action we are called with
#
my $query = Foswiki::Func::getCgiQuery();
my $action = $query->param( 'ploticusPlotAction');
my $query = Foswiki::Func::getCgiQuery();
my $action = $query->param('ploticusPlotAction');

# if no action, show the plot
#
unless ($action) { return showPlot($web, $topic, $plotName); };
unless ($action) { return showPlot( $web, $topic, $plotName ); }

# otherwise, we're trying to edit or save - so, first check permissions
#
my ($meta, $text) = Foswiki::Func::readTopic($web, $topic);
my ($url, $mess);
if (!Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(), $text, $topic, $web, $meta)) {
my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
my ( $url, $mess );
if (
!Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(),
$text, $topic, $web, $meta
)
)
{

$url = Foswiki::Func::getScriptUrl(
$web, $topic, 'oops',
template => 'oopsaccessdenied',
def => 'topic_access',
param1 => 'CHANGE',
param2 => 'access not allowed on topic'
);
def => 'topic_access',
param1 => 'CHANGE',
param2 => 'access not allowed on topic'
);
$mess = "FOSWIKI ACCESS DENIED";
} else {
my $queryTarget = $query->param( 'ploticusPlotName');
if ($action eq 'edit' and $queryTarget eq $plotName) { return editPlotSettings($web, $topic, $plotName); };
if ($action eq 'save' and $queryTarget eq $plotName) { return savePlotSettings($web, $topic, $plotName, $query->param( 'ploticusPlotSettingsText')); };
}
else {
my $queryTarget = $query->param('ploticusPlotName');
if ( $action eq 'edit' and $queryTarget eq $plotName ) {
return editPlotSettings( $web, $topic, $plotName );
}
if ( $action eq 'save' and $queryTarget eq $plotName ) {
return savePlotSettings( $web, $topic, $plotName,
$query->param('ploticusPlotSettingsText') );
}
}

unless ($query->param('erp_noredirect')) {
Foswiki::Func::redirectCgiQuery(undef, $url);
} elsif ($mess) {
print CGI::header(-status => "500 $mess");
} else {
print CGI::header(-status => 200);
unless ( $query->param('erp_noredirect') ) {
Foswiki::Func::redirectCgiQuery( undef, $url );
}
elsif ($mess) {
print CGI::header( -status => "500 $mess" );
}
else {
print CGI::header( -status => 200 );
}

return 0; # Suppress standard redirection mechanism
return 0; # Suppress standard redirection mechanism

}

sub showError{
sub showError {
my $error = shift;
Foswiki::Func::writeDebug( "PloticusPlugin showError" ) if $debug;
Foswiki::Func::writeDebug("PloticusPlugin showError") if $debug;
return "Error: $error\n";
}

sub showPlot{
my ($web, $topic, $name) = @_;
sub showPlot {
my ( $web, $topic, $name ) = @_;

# have permission to see the edit button?
#
my $displayOnly = 0;
my ($meta, $text) = Foswiki::Func::readTopic($web, $topic);
if (!Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(), $text, $topic, $web, $meta)) {
my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );
if (
!Foswiki::Func::checkAccessPermission(
'CHANGE', Foswiki::Func::getWikiName(),
$text, $topic, $web, $meta
)
)
{
$displayOnly = 1;
}

Foswiki::Func::writeDebug( "PloticusPlugin::showPlot - showPlot for $web, $topic, $name" ) if $debug;
Foswiki::Func::writeDebug(
"PloticusPlugin::showPlot - showPlot for $web, $topic, $name")
if $debug;
require Foswiki::Plugins::PloticusPlugin::Plot;
my $plot = Foswiki::Plugins::PloticusPlugin::Plot->new($web, $topic, $name);
if($displayOnly) {
my $plot =
Foswiki::Plugins::PloticusPlugin::Plot->new( $web, $topic, $name );
if ($displayOnly) {
return $plot->renderForShow();
} else {
return $plot->renderForEdit();
}
else {
return $plot->renderForEdit();
}
}

sub editPlotSettings{
my ($web, $topic, $name) = @_;
Foswiki::Func::writeDebug( "PloticusPlugin::editPlotSettings for $web, $topic, $name" ) if $debug;
sub editPlotSettings {
my ( $web, $topic, $name ) = @_;
Foswiki::Func::writeDebug(
"PloticusPlugin::editPlotSettings for $web, $topic, $name")
if $debug;
require Foswiki::Plugins::PloticusPlugin::PlotSettings;
my $settings = Foswiki::Plugins::PloticusPlugin::PlotSettings->fromFile($web, $topic, $name);
my $settings =
Foswiki::Plugins::PloticusPlugin::PlotSettings->fromFile( $web, $topic,
$name );
return $settings->render();
}

sub savePlotSettings{
my ($web, $topic, $name, $text) = @_;
Foswiki::Func::writeDebug( "PloticusPlugin::savePlotSettings $web, $topic, $name, $text" ) if $debug;
sub savePlotSettings {
my ( $web, $topic, $name, $text ) = @_;
Foswiki::Func::writeDebug(
"PloticusPlugin::savePlotSettings $web, $topic, $name, $text")
if $debug;
require Foswiki::Plugins::PloticusPlugin::PlotSettings;
Foswiki::Func::writeDebug( "PloticusPlugin::savePlotSettings ----------------------------------------------------" ) if $debug;
Foswiki::Plugins::PloticusPlugin::PlotSettings::writeFile($web, $topic, $name, $text);
Foswiki::Func::writeDebug( "PloticusPlugin::savePlotSettings OOOOO----------------------------------------------------" ) if $debug;
Foswiki::Func::redirectCgiQuery( {}, Foswiki::Func::getScriptUrl( $web, $topic, "view" ) . "\#ploticusplot$name");
Foswiki::Func::writeDebug(
"PloticusPlugin::savePlotSettings ----------------------------------------------------"
) if $debug;
Foswiki::Plugins::PloticusPlugin::PlotSettings::writeFile( $web, $topic,
$name, $text );
Foswiki::Func::writeDebug(
"PloticusPlugin::savePlotSettings OOOOO----------------------------------------------------"
) if $debug;
Foswiki::Func::redirectCgiQuery( {},
Foswiki::Func::getScriptUrl( $web, $topic, "view" )
. "\#ploticusplot$name" );
}

=pod
Expand All @@ -213,8 +249,9 @@ For more information, check Foswiki:System.CommandAndCGIScripts#rest
=cut

sub restPloticus {
#my ($session) = @_;
return "This is an example of a REST invocation\n\n";

#my ($session) = @_;
return "This is an example of a REST invocation\n\n";
}

1;
Loading

0 comments on commit 030c802

Please sign in to comment.